Esempio n. 1
0
        private Size Measure(Size constraint, ILayout layout)
        {
            Layout.CheckBreakOnMeasure(this);

            double vMax = 0;

            var uTotalSpacing = Math.Max(0, Spacing * (InternalChildren.Count - 1));
            var uAvailable    = Math.Max(0, layout.GetU(constraint) - uTotalSpacing);
            var vAvailable    = layout.GetV(constraint);
            var availableSize = layout.ToSize(uAvailable, vAvailable);

            double sumWeight = 0;
            double uSum      = 0;

            foreach (UIElement child in InternalChildren)
            {
                var growth = GetGrowth(child);
                sumWeight += Math.Abs(growth);
                if (growth <= 0)
                {
                    child.Measure(availableSize);
                    var desiredSize = child.DesiredSize;
                    vMax  = Math.Max(vMax, layout.GetV(desiredSize));
                    uSum += layout.GetU(desiredSize);
                }
            }

            var uRemaining = Math.Max(0, uAvailable - uSum);

            foreach (UIElement child in InternalChildren)
            {
                var growth = GetGrowth(child);
                if (growth > 0)
                {
                    var uSize = Math.Abs(growth) * uRemaining / sumWeight;
                    child.Measure(layout.ToSize(uSize, vAvailable));
                    var desiredSize = child.DesiredSize;
                    vMax  = Math.Max(vMax, layout.GetV(desiredSize));
                    uSum += double.IsInfinity(uSize) ? layout.GetU(desiredSize) : uSize;
                }
            }

            return(layout.ToSize(uSum + uTotalSpacing, vMax));
        }
Esempio n. 2
0
        private Size Arrange(Size arrangeBounds, ILayout layout)
        {
            Layout.CheckBreakOnArrange(this);

            double uSpacing = 0;
            double spacing  = Spacing;

            double uDesired        = 0;
            double totalFlexWeight = 0;

            foreach (UIElement child in InternalChildren)
            {
                var growth = GetGrowth(child);
                uDesired        += (growth <= 0 ? layout.GetU(child.DesiredSize) : 0) + uSpacing;
                totalFlexWeight += Math.Abs(growth);
                uSpacing         = spacing;
            }

            var uRemaining = Math.Max(0, layout.GetU(arrangeBounds) - uDesired);

            double cursor = 0;

            uSpacing = 0;

            foreach (UIElement child in InternalChildren)
            {
                cursor += uSpacing;
                var growth  = GetGrowth(child);
                var stretch = totalFlexWeight <= 0 ? 0 : uRemaining *Math.Abs(growth) / totalFlexWeight;

                var    uBase = growth <= 0 ? layout.GetU(child.DesiredSize) : 0;
                double uSize = Math.Max(0, uBase + stretch);
                child.Arrange(layout.ToRect(cursor, 0, uSize, layout.GetV(arrangeBounds)));
                cursor  += uSize;
                uSpacing = spacing;
            }

            return(arrangeBounds);
            //return new Size(cursor, arrangeBounds.Height);
        }