示例#1
0
            double[] CalcDefaultSizes(SizeConstraint width, SizeConstraint height, bool allowShrink)
            {
                double requiredSize = 0, totminsize = 0;
                double availableSize = width.AvailableSize;
                double spacing       = this.owner.Spacing;

                var widthConstraint  = SizeConstraint.Unconstrained;
                var heightConstraint = height;

                //  var sizes = new Dictionary<BoxPlacement, double>();

                var mw = new double[this.owner.Placements.Count];
                var ww = new double[this.owner.Placements.Count];
                var hh = 0.0;

                int nexpands = 0;

                // Get the natural size of each child
                for (int nit = 0; nit < this.owner.Placements.Count; nit++)
                {
                    var b = this.owner.Placements[nit].Child;
                    var s = (Size)b.GetBackend().GetPreferredSize(widthConstraint, heightConstraint);
                    mw[nit]       = MinWidth(b, s);
                    ww[nit]       = s.Width;
                    hh            = Math.Max(s.Height, hh);
                    requiredSize += ww[nit];
                    totminsize   += mw[nit];

                    if (b.ExpandHorizontal)
                    {
                        nexpands++;
                    }
                }
                double remaining = availableSize - totminsize - (spacing * (double)(this.owner.Placements.Count - 1));

                if (remaining > 0)
                {
                    var remaining2 = availableSize - requiredSize - (spacing * (double)(this.owner.Placements.Count - 1));
                    if (remaining2 > 0)
                    {
                        var expandRemaining = new SizeSplitter(remaining2 - (requiredSize - totminsize), nexpands);
                        for (int nit = 0; nit < this.owner.Placements.Count; nit++)
                        {
                            var b = this.owner.Placements[nit].Child;
                            ww[nit] = mw[nit];
                            if (b.ExpandHorizontal)
                            {
                                ww[nit] += expandRemaining.NextSizePart();
                                //todo getprefsize
                            }
                        }
                    }
                    else if (remaining2 < 0)
                    {
                        var dd = remaining - (requiredSize - totminsize);
                        var expandRemaining = new SizeSplitter((requiredSize - totminsize), this.owner.Placements.Count);
                        for (int nit = 0; nit < this.owner.Placements.Count; nit++)
                        {
                            var b = this.owner.Placements[nit].Child;
                            ww[nit] = mw[nit] + dd * (ww[nit] - mw[nit]) / (requiredSize - totminsize);
                            if (b.ExpandHorizontal)
                            {
                                ww[nit] += expandRemaining.NextSizePart();
                            }
                            //if (ExpandsForOrientation(bp.Child))
                            //    nextsize[bp] = minsize[bp]+expandRemaining.NextSizePart();
                        }
                    }
                }
                else //if (/*allowShrink &&*/ remaining < 0)
                {
                    for (int nit = 0; nit < this.owner.Placements.Count; nit++)
                    {
                        ww[nit] = mw[nit];
                    }
                }
                return(ww.ToArray());
            }
示例#2
0
        Dictionary <BoxPlacement, double> CalcDefaultSizes(SizeConstraint width, SizeConstraint height, bool allowShrink)
        {
            var nextsize = new Dictionary <BoxPlacement, double>();
            var minsize  = new Dictionary <BoxPlacement, double>();

            bool   vertical = direction == Orientation.Vertical;
            int    nexpands = 0;
            double requiredSize = 0, totminsize = 0;
            double availableSize = vertical ? height.AvailableSize : width.AvailableSize;

            var widthConstraint  = vertical ? width : SizeConstraint.Unconstrained;
            var heightConstraint = vertical ? SizeConstraint.Unconstrained : height;

            var    children = (ChildrenCollection <BoxPlacement>)GetFieldValuePrivate(typeof(Box), owner, "children");
            double spacing  = owner.Spacing;

            var visibleChildren = children.Where(b => b.Child.Visible).ToArray();
            //  var sizes = new Dictionary<BoxPlacement, double>();
            Size s3;

            // Get the natural size of each child
            foreach (var bp in visibleChildren)
            {
                var s1 = bp.Child.Surface.GetPreferredSize();
                //   var s2 = bp.Child.GetBackend().GetPreferredSize(widthConstraint, heightConstraint);
                s3 = (Size)bp.Child.GetType().InvokePrivate(bp.Child, "OnGetPreferredSize", new object[] { widthConstraint, heightConstraint });
                var s4 = bp.Child.Size;
                var s  = (Size)bp.Child.GetType().InvokePrivate(bp.Child, "OnGetPreferredSize", new object[] { widthConstraint, heightConstraint });
                minsize[bp]  = vertical ? MinHeight(bp.Child, s) : MinWidth(bp.Child, s);
                nextsize[bp] = Math.Max(minsize[bp], vertical ? s.Height : s.Width);
                if (minsize[bp] < 0)
                {
                    minsize[bp] = nextsize[bp];
                }
                requiredSize += nextsize[bp];
                totminsize   += minsize[bp];
                //      sizes[bp] = nextsize[bp];
                if (ExpandsForOrientation(bp.Child))
                {
                    nexpands++;
                }
            }

            double remaining = availableSize - totminsize - (spacing * (double)(visibleChildren.Length - 1));

            if (remaining > 0) // more space as minimum
            {
                var remaining2 = availableSize - requiredSize - (spacing * (double)(visibleChildren.Length - 1));
                if (remaining2 > 0) // more space as getpreffered
                {
                    var expandRemaining = new SizeSplitter(remaining2, nexpands);
                    foreach (var bp in visibleChildren)
                    {
                        //  nextsize[bp] = minsize[bp];
                        if (ExpandsForOrientation(bp.Child))
                        {
                            nextsize[bp] += expandRemaining.NextSizePart();
                            // todo getprefsize

                            /*   switch (AlligmMent(bp.Child))
                             * {
                             *     case WidgetPlacement.Fill: break;
                             *     default:*/
                            {
                                //      s3 = (Size)bp.Child.GetType().InvokePrivate(bp.Child, "OnGetPreferredSize", new object[] { vertical ? widthConstraint : SizeConstraint.WithSize(nextsize[bp]), vertical ? SizeConstraint.WithSize(nextsize[bp]) : heightConstraint });
                                //      nextsize[bp] = vertical ? s3.Height : s3.Width;
                            }

                            /*      break;
                             * }*/
                            //  Debug.Assert(nextsize[bp] > 0);
                        }
                    }
                }
                else if (remaining2 < 0) // between minimum ans getpreffered
                {
                    var dd = remaining - (requiredSize - totminsize);
                    var expandRemaining = new SizeSplitter((requiredSize - totminsize), nexpands);
                    foreach (var bp in visibleChildren)
                    {
                        nextsize[bp] += remaining2 * (nextsize[bp] - minsize[bp]) / (requiredSize - totminsize);
                        if (ExpandsForOrientation(bp.Child))
                        {
                            //      nextsize[bp] += expandRemaining.NextSizePart();

                            /*    switch (AlligmMent(bp.Child))
                             *  {
                             *      case WidgetPlacement.Fill: break;
                             *      default:
                             *          {*/

//                                        s3 = (Size)bp.Child.GetType().InvokePrivate(bp.Child, "OnGetPreferredSize", new object[] { vertical ? widthConstraint : SizeConstraint.WithSize(nextsize[bp]), vertical ? SizeConstraint.WithSize(nextsize[bp]) : heightConstraint });
//                                      nextsize[bp] = vertical ? s3.Height : s3.Width;

                            /*    break;
                             * }
                             * }*/
                            //     Debug.Assert(nextsize[bp] > 0);
                        }
                        //if (ExpandsForOrientation(bp.Child))
                        //    nextsize[bp] = minsize[bp]+expandRemaining.NextSizePart();
                    }
                }
            }
            else //if (/*allowShrink &&*/ remaining < 0)
            {
                foreach (var bp in visibleChildren)
                {
                    nextsize[bp] = minsize[bp];
                }
            }
            return(nextsize);
        }