Ejemplo n.º 1
0
        // Token: 0x06005698 RID: 22168 RVA: 0x0017F0C4 File Offset: 0x0017D2C4
        internal static Size StackMeasureHelper(IStackMeasure measureElement, IStackMeasureScrollData scrollData, Size constraint)
        {
            Size size = default(Size);
            UIElementCollection internalChildren = measureElement.InternalChildren;
            Size   availableSize = constraint;
            bool   flag          = measureElement.Orientation == Orientation.Horizontal;
            int    num           = -1;
            int    i;
            double num2;

            if (flag)
            {
                availableSize.Width = double.PositiveInfinity;
                if (measureElement.IsScrolling && measureElement.CanVerticallyScroll)
                {
                    availableSize.Height = double.PositiveInfinity;
                }
                i    = (measureElement.IsScrolling ? StackPanel.CoerceOffsetToInteger(scrollData.Offset.X, internalChildren.Count) : 0);
                num2 = constraint.Width;
            }
            else
            {
                availableSize.Height = double.PositiveInfinity;
                if (measureElement.IsScrolling && measureElement.CanHorizontallyScroll)
                {
                    availableSize.Width = double.PositiveInfinity;
                }
                i    = (measureElement.IsScrolling ? StackPanel.CoerceOffsetToInteger(scrollData.Offset.Y, internalChildren.Count) : 0);
                num2 = constraint.Height;
            }
            int j     = 0;
            int count = internalChildren.Count;

            while (j < count)
            {
                UIElement uielement = internalChildren[j];
                if (uielement != null)
                {
                    uielement.Measure(availableSize);
                    Size   desiredSize = uielement.DesiredSize;
                    double num3;
                    if (flag)
                    {
                        size.Width += desiredSize.Width;
                        size.Height = Math.Max(size.Height, desiredSize.Height);
                        num3        = desiredSize.Width;
                    }
                    else
                    {
                        size.Width   = Math.Max(size.Width, desiredSize.Width);
                        size.Height += desiredSize.Height;
                        num3         = desiredSize.Height;
                    }
                    if (measureElement.IsScrolling && num == -1 && j >= i)
                    {
                        num2 -= num3;
                        if (DoubleUtil.LessThanOrClose(num2, 0.0))
                        {
                            num = j;
                        }
                    }
                }
                j++;
            }
            if (measureElement.IsScrolling)
            {
                Size   viewport = constraint;
                Size   extent   = size;
                Vector offset   = scrollData.Offset;
                if (num == -1)
                {
                    num = internalChildren.Count - 1;
                }
                while (i > 0)
                {
                    double num4 = num2;
                    if (flag)
                    {
                        num4 -= internalChildren[i - 1].DesiredSize.Width;
                    }
                    else
                    {
                        num4 -= internalChildren[i - 1].DesiredSize.Height;
                    }
                    if (DoubleUtil.LessThan(num4, 0.0))
                    {
                        break;
                    }
                    i--;
                    num2 = num4;
                }
                int count2 = internalChildren.Count;
                int num5   = num - i;
                if (num5 == 0 || DoubleUtil.GreaterThanOrClose(num2, 0.0))
                {
                    num5++;
                }
                if (flag)
                {
                    scrollData.SetPhysicalViewport(viewport.Width);
                    viewport.Width = (double)num5;
                    extent.Width   = (double)count2;
                    offset.X       = (double)i;
                    offset.Y       = Math.Max(0.0, Math.Min(offset.Y, extent.Height - viewport.Height));
                }
                else
                {
                    scrollData.SetPhysicalViewport(viewport.Height);
                    viewport.Height = (double)num5;
                    extent.Height   = (double)count2;
                    offset.Y        = (double)i;
                    offset.X        = Math.Max(0.0, Math.Min(offset.X, extent.Width - viewport.Width));
                }
                size.Width  = Math.Min(size.Width, constraint.Width);
                size.Height = Math.Min(size.Height, constraint.Height);
                StackPanel.VerifyScrollingData(measureElement, scrollData, viewport, extent, offset);
            }
            return(size);
        }