示例#1
0
文件: Stack.cs 项目: beda2280/wpf-1
        /// <summary>
        ///     Helper method which implements the stack like arrange.
        /// </summary>
        internal static Size StackArrangeHelper(IStackMeasure arrangeElement, IStackMeasureScrollData scrollData, Size arrangeSize)
        {
            UIElementCollection children = arrangeElement.InternalChildren;
            bool   fHorizontal           = (arrangeElement.Orientation == Orientation.Horizontal);
            Rect   rcChild           = new Rect(arrangeSize);
            double previousChildSize = 0.0;


            //
            // Compute scroll offset and seed it into rcChild.
            //
            if (arrangeElement.IsScrolling)
            {
                if (fHorizontal)
                {
                    rcChild.X = ComputePhysicalFromLogicalOffset(arrangeElement, scrollData.ComputedOffset.X, true);
                    rcChild.Y = -1.0 * scrollData.ComputedOffset.Y;
                }
                else
                {
                    rcChild.X = -1.0 * scrollData.ComputedOffset.X;
                    rcChild.Y = ComputePhysicalFromLogicalOffset(arrangeElement, scrollData.ComputedOffset.Y, false);
                }
            }

            //
            // Arrange and Position Children.
            //
            for (int i = 0, count = children.Count; i < count; ++i)
            {
                UIElement child = (UIElement)children[i];

                if (child == null)
                {
                    continue;
                }

                if (fHorizontal)
                {
                    rcChild.X        += previousChildSize;
                    previousChildSize = child.DesiredSize.Width;
                    rcChild.Width     = previousChildSize;
                    rcChild.Height    = Math.Max(arrangeSize.Height, child.DesiredSize.Height);
                }
                else
                {
                    rcChild.Y        += previousChildSize;
                    previousChildSize = child.DesiredSize.Height;
                    rcChild.Height    = previousChildSize;
                    rcChild.Width     = Math.Max(arrangeSize.Width, child.DesiredSize.Width);
                }

                child.Arrange(rcChild);
            }
            return(arrangeSize);
        }
示例#2
0
        // Token: 0x0600569A RID: 22170 RVA: 0x0017F4C0 File Offset: 0x0017D6C0
        internal static Size StackArrangeHelper(IStackMeasure arrangeElement, IStackMeasureScrollData scrollData, Size arrangeSize)
        {
            UIElementCollection internalChildren = arrangeElement.InternalChildren;
            bool   flag      = arrangeElement.Orientation == Orientation.Horizontal;
            Rect   finalRect = new Rect(arrangeSize);
            double num       = 0.0;

            if (arrangeElement.IsScrolling)
            {
                if (flag)
                {
                    finalRect.X = StackPanel.ComputePhysicalFromLogicalOffset(arrangeElement, scrollData.ComputedOffset.X, true);
                    finalRect.Y = -1.0 * scrollData.ComputedOffset.Y;
                }
                else
                {
                    finalRect.X = -1.0 * scrollData.ComputedOffset.X;
                    finalRect.Y = StackPanel.ComputePhysicalFromLogicalOffset(arrangeElement, scrollData.ComputedOffset.Y, false);
                }
            }
            int i     = 0;
            int count = internalChildren.Count;

            while (i < count)
            {
                UIElement uielement = internalChildren[i];
                if (uielement != null)
                {
                    if (flag)
                    {
                        finalRect.X     += num;
                        num              = uielement.DesiredSize.Width;
                        finalRect.Width  = num;
                        finalRect.Height = Math.Max(arrangeSize.Height, uielement.DesiredSize.Height);
                    }
                    else
                    {
                        finalRect.Y     += num;
                        num              = uielement.DesiredSize.Height;
                        finalRect.Height = num;
                        finalRect.Width  = Math.Max(arrangeSize.Width, uielement.DesiredSize.Width);
                    }
                    uielement.Arrange(finalRect);
                }
                i++;
            }
            return(arrangeSize);
        }
示例#3
0
        // Token: 0x0600569E RID: 22174 RVA: 0x0017F690 File Offset: 0x0017D890
        private static void VerifyScrollingData(IStackMeasure measureElement, IStackMeasureScrollData scrollData, Size viewport, Size extent, Vector offset)
        {
            bool flag = true;

            flag &= DoubleUtil.AreClose(viewport, scrollData.Viewport);
            flag &= DoubleUtil.AreClose(extent, scrollData.Extent);
            flag &= DoubleUtil.AreClose(offset, scrollData.ComputedOffset);
            scrollData.Offset = offset;
            if (!flag)
            {
                scrollData.Viewport       = viewport;
                scrollData.Extent         = extent;
                scrollData.ComputedOffset = offset;
                measureElement.OnScrollChange();
            }
        }
示例#4
0
文件: Stack.cs 项目: beda2280/wpf-1
        /// <summary>
        ///     Helper method which implements the stack like measure.
        /// </summary>
        internal static Size StackMeasureHelper(IStackMeasure measureElement, IStackMeasureScrollData scrollData, Size constraint)
        {
            Size stackDesiredSize        = new Size();
            UIElementCollection children = measureElement.InternalChildren;
            Size layoutSlotSize          = constraint;
            bool fHorizontal             = (measureElement.Orientation == Orientation.Horizontal);
            int  firstViewport;         // First child index in the viewport.
            int  lastViewport = -1;     // Last child index in the viewport.  -1 indicates we have not yet iterated through the last child.

            double logicalVisibleSpace, childLogicalSize;


            //
            // Initialize child sizing and iterator data
            // Allow children as much size as they want along the stack.
            //
            if (fHorizontal)
            {
                layoutSlotSize.Width = Double.PositiveInfinity;
                if (measureElement.IsScrolling && measureElement.CanVerticallyScroll)
                {
                    layoutSlotSize.Height = Double.PositiveInfinity;
                }
                firstViewport       = (measureElement.IsScrolling) ? CoerceOffsetToInteger(scrollData.Offset.X, children.Count) : 0;
                logicalVisibleSpace = constraint.Width;
            }
            else
            {
                layoutSlotSize.Height = Double.PositiveInfinity;
                if (measureElement.IsScrolling && measureElement.CanHorizontallyScroll)
                {
                    layoutSlotSize.Width = Double.PositiveInfinity;
                }
                firstViewport       = (measureElement.IsScrolling) ? CoerceOffsetToInteger(scrollData.Offset.Y, children.Count) : 0;
                logicalVisibleSpace = constraint.Height;
            }

            //
            //  Iterate through children.
            //  While we still supported virtualization, this was hidden in a child iterator (see source history).
            //
            for (int i = 0, count = children.Count; i < count; ++i)
            {
                // Get next child.
                UIElement child = children[i];

                if (child == null)
                {
                    continue;
                }

                // Measure the child.
                child.Measure(layoutSlotSize);
                Size childDesiredSize = child.DesiredSize;

                // Accumulate child size.
                if (fHorizontal)
                {
                    stackDesiredSize.Width += childDesiredSize.Width;
                    stackDesiredSize.Height = Math.Max(stackDesiredSize.Height, childDesiredSize.Height);
                    childLogicalSize        = childDesiredSize.Width;
                }
                else
                {
                    stackDesiredSize.Width   = Math.Max(stackDesiredSize.Width, childDesiredSize.Width);
                    stackDesiredSize.Height += childDesiredSize.Height;
                    childLogicalSize         = childDesiredSize.Height;
                }

                // Adjust remaining viewport space if we are scrolling and within the viewport region.
                // While scrolling (not virtualizing), we always measure children before and after the viewport.
                if (measureElement.IsScrolling && lastViewport == -1 && i >= firstViewport)
                {
                    logicalVisibleSpace -= childLogicalSize;
                    if (DoubleUtil.LessThanOrClose(logicalVisibleSpace, 0.0))
                    {
                        lastViewport = i;
                    }
                }
            }

            //
            // Compute Scrolling stuff.
            //
            if (measureElement.IsScrolling)
            {
                // Compute viewport and extent.
                Size   viewport = constraint;
                Size   extent   = stackDesiredSize;
                Vector offset   = scrollData.Offset;

                // If we have not yet set the last child in the viewport, set it to the last child.
                if (lastViewport == -1)
                {
                    lastViewport = children.Count - 1;
                }

                // If we or children have resized, it's possible that we can now display more content.
                // This is true if we started at a nonzero offeset and still have space remaining.
                // In this case, we loop back through previous children until we run out of space.
                while (firstViewport > 0)
                {
                    double projectedLogicalVisibleSpace = logicalVisibleSpace;
                    if (fHorizontal)
                    {
                        projectedLogicalVisibleSpace -= children[firstViewport - 1].DesiredSize.Width;
                    }
                    else
                    {
                        projectedLogicalVisibleSpace -= children[firstViewport - 1].DesiredSize.Height;
                    }

                    // If we have run out of room, break.
                    if (DoubleUtil.LessThan(projectedLogicalVisibleSpace, 0.0))
                    {
                        break;
                    }

                    // Adjust viewport
                    firstViewport--;
                    logicalVisibleSpace = projectedLogicalVisibleSpace;
                }

                int logicalExtent   = children.Count;
                int logicalViewport = lastViewport - firstViewport;

                // We are conservative when estimating a viewport, not including the last element in case it is only partially visible.
                // We want to count it if it is fully visible (>= 0 space remaining) or the only element in the viewport.
                if (logicalViewport == 0 || DoubleUtil.GreaterThanOrClose(logicalVisibleSpace, 0.0))
                {
                    logicalViewport++;
                }

                if (fHorizontal)
                {
                    scrollData.SetPhysicalViewport(viewport.Width);
                    viewport.Width = logicalViewport;
                    extent.Width   = logicalExtent;
                    offset.X       = firstViewport;
                    offset.Y       = Math.Max(0, Math.Min(offset.Y, extent.Height - viewport.Height));
                }
                else
                {
                    scrollData.SetPhysicalViewport(viewport.Height);
                    viewport.Height = logicalViewport;
                    extent.Height   = logicalExtent;
                    offset.Y        = firstViewport;
                    offset.X        = Math.Max(0, Math.Min(offset.X, extent.Width - viewport.Width));
                }

                // Since we can offset and clip our content, we never need to be larger than the parent suggestion.
                // If we returned the full size of the content, we would always be so big we didn't need to scroll.  :)
                stackDesiredSize.Width  = Math.Min(stackDesiredSize.Width, constraint.Width);
                stackDesiredSize.Height = Math.Min(stackDesiredSize.Height, constraint.Height);

                // Verify Scroll Info, invalidate ScrollOwner if necessary.
                VerifyScrollingData(measureElement, scrollData, viewport, extent, offset);
            }

            return(stackDesiredSize);
        }
示例#5
0
        private static void VerifyScrollingData(IStackMeasure measureElement, IStackMeasureScrollData scrollData, Size viewport, Size extent, Vector offset)
        {
            bool fValid = true;

            Debug.Assert(measureElement.IsScrolling);

            fValid &= DoubleUtil.AreClose(viewport, scrollData.Viewport);
            fValid &= DoubleUtil.AreClose(extent, scrollData.Extent);
            fValid &= DoubleUtil.AreClose(offset, scrollData.ComputedOffset);
            scrollData.Offset = offset;

            if (!fValid)
            {
                scrollData.Viewport = viewport;
                scrollData.Extent = extent;
                scrollData.ComputedOffset = offset;
                measureElement.OnScrollChange();
            }
        }
示例#6
0
        /// <summary>
        ///     Helper method which implements the stack like arrange.
        /// </summary>
        internal static Size StackArrangeHelper(IStackMeasure arrangeElement, IStackMeasureScrollData scrollData, Size arrangeSize)
        {
            UIElementCollection children = arrangeElement.InternalChildren;
            bool fHorizontal = (arrangeElement.Orientation == Orientation.Horizontal);
            Rect rcChild = new Rect(arrangeSize);
            double previousChildSize = 0.0;


            //
            // Compute scroll offset and seed it into rcChild.
            //
            if (arrangeElement.IsScrolling)
            {
                if (fHorizontal)
                {
                    rcChild.X = ComputePhysicalFromLogicalOffset(arrangeElement, scrollData.ComputedOffset.X, true);
                    rcChild.Y = -1.0 * scrollData.ComputedOffset.Y;
                }
                else
                {
                    rcChild.X = -1.0 * scrollData.ComputedOffset.X;
                    rcChild.Y = ComputePhysicalFromLogicalOffset(arrangeElement, scrollData.ComputedOffset.Y, false);
                }
            }

            //
            // Arrange and Position Children.
            //
            for (int i = 0, count = children.Count; i < count; ++i)
            {
                UIElement child = (UIElement)children[i];

                if (child == null) { continue; }

                if (fHorizontal)
                {
                    rcChild.X += previousChildSize;
                    previousChildSize = child.DesiredSize.Width;
                    rcChild.Width = previousChildSize;
                    rcChild.Height = Math.Max(arrangeSize.Height, child.DesiredSize.Height);
                }
                else
                {
                    rcChild.Y += previousChildSize;
                    previousChildSize = child.DesiredSize.Height;
                    rcChild.Height = previousChildSize;
                    rcChild.Width = Math.Max(arrangeSize.Width, child.DesiredSize.Width);
                }

                child.Arrange(rcChild);
            }
            return arrangeSize;
        }
示例#7
0
        /// <summary>
        ///     Helper method which implements the stack like measure.
        /// </summary>
        internal static Size StackMeasureHelper(IStackMeasure measureElement, IStackMeasureScrollData scrollData, Size constraint)
        {
            Size stackDesiredSize = new Size();
            UIElementCollection children = measureElement.InternalChildren;
            Size layoutSlotSize = constraint;
            bool fHorizontal = (measureElement.Orientation == Orientation.Horizontal);
            int firstViewport;          // First child index in the viewport.
            int lastViewport = -1;      // Last child index in the viewport.  -1 indicates we have not yet iterated through the last child.

            double logicalVisibleSpace, childLogicalSize;


            //
            // Initialize child sizing and iterator data
            // Allow children as much size as they want along the stack.
            //
            if (fHorizontal)
            {
                layoutSlotSize.Width = Double.PositiveInfinity;
                if (measureElement.IsScrolling && measureElement.CanVerticallyScroll) { layoutSlotSize.Height = Double.PositiveInfinity; }
                firstViewport = (measureElement.IsScrolling) ? CoerceOffsetToInteger(scrollData.Offset.X, children.Count) : 0;
                logicalVisibleSpace = constraint.Width;
            }
            else
            {
                layoutSlotSize.Height = Double.PositiveInfinity;
                if (measureElement.IsScrolling && measureElement.CanHorizontallyScroll) { layoutSlotSize.Width = Double.PositiveInfinity; }
                firstViewport = (measureElement.IsScrolling) ? CoerceOffsetToInteger(scrollData.Offset.Y, children.Count) : 0;
                logicalVisibleSpace = constraint.Height;
            }

            //
            //  Iterate through children.
            //  While we still supported virtualization, this was hidden in a child iterator (see source history).
            //
            for (int i = 0, count = children.Count; i < count; ++i)
            {
                // Get next child.
                UIElement child = children[i];

                if (child == null) { continue; }

                // Measure the child.
                child.Measure(layoutSlotSize);
                Size childDesiredSize = child.DesiredSize;

                // Accumulate child size.
                if (fHorizontal)
                {
                    stackDesiredSize.Width += childDesiredSize.Width;
                    stackDesiredSize.Height = Math.Max(stackDesiredSize.Height, childDesiredSize.Height);
                    childLogicalSize = childDesiredSize.Width;
                }
                else
                {
                    stackDesiredSize.Width = Math.Max(stackDesiredSize.Width, childDesiredSize.Width);
                    stackDesiredSize.Height += childDesiredSize.Height;
                    childLogicalSize = childDesiredSize.Height;
                }

                // Adjust remaining viewport space if we are scrolling and within the viewport region.
                // While scrolling (not virtualizing), we always measure children before and after the viewport.
                if (measureElement.IsScrolling && lastViewport == -1 && i >= firstViewport)
                {
                    logicalVisibleSpace -= childLogicalSize;
                    if (DoubleUtil.LessThanOrClose(logicalVisibleSpace, 0.0))
                    {
                        lastViewport = i;
                    }
                }
            }

            //
            // Compute Scrolling stuff.
            //
            if (measureElement.IsScrolling)
            {
                // Compute viewport and extent.
                Size viewport = constraint;
                Size extent = stackDesiredSize;
                Vector offset = scrollData.Offset;

                // If we have not yet set the last child in the viewport, set it to the last child.
                if (lastViewport == -1) { lastViewport = children.Count - 1; }

                // If we or children have resized, it's possible that we can now display more content.
                // This is true if we started at a nonzero offeset and still have space remaining.
                // In this case, we loop back through previous children until we run out of space.
                while (firstViewport > 0)
                {
                    double projectedLogicalVisibleSpace = logicalVisibleSpace;
                    if (fHorizontal) { projectedLogicalVisibleSpace -= children[firstViewport - 1].DesiredSize.Width; }
                    else { projectedLogicalVisibleSpace -= children[firstViewport - 1].DesiredSize.Height; }

                    // If we have run out of room, break.
                    if (DoubleUtil.LessThan(projectedLogicalVisibleSpace, 0.0)) { break; }

                    // Adjust viewport
                    firstViewport--;
                    logicalVisibleSpace = projectedLogicalVisibleSpace;
                }

                int logicalExtent = children.Count;
                int logicalViewport = lastViewport - firstViewport;

                // We are conservative when estimating a viewport, not including the last element in case it is only partially visible.
                // We want to count it if it is fully visible (>= 0 space remaining) or the only element in the viewport.
                if (logicalViewport == 0 || DoubleUtil.GreaterThanOrClose(logicalVisibleSpace, 0.0)) { logicalViewport++; }

                if (fHorizontal)
                {
                    scrollData.SetPhysicalViewport(viewport.Width);
                    viewport.Width = logicalViewport;
                    extent.Width = logicalExtent;
                    offset.X = firstViewport;
                    offset.Y = Math.Max(0, Math.Min(offset.Y, extent.Height - viewport.Height));
                }
                else
                {
                    scrollData.SetPhysicalViewport(viewport.Height);
                    viewport.Height = logicalViewport;
                    extent.Height = logicalExtent;
                    offset.Y = firstViewport;
                    offset.X = Math.Max(0, Math.Min(offset.X, extent.Width - viewport.Width));
                }

                // Since we can offset and clip our content, we never need to be larger than the parent suggestion.
                // If we returned the full size of the content, we would always be so big we didn't need to scroll.  :)
                stackDesiredSize.Width = Math.Min(stackDesiredSize.Width, constraint.Width);
                stackDesiredSize.Height = Math.Min(stackDesiredSize.Height, constraint.Height);

                // Verify Scroll Info, invalidate ScrollOwner if necessary.
                VerifyScrollingData(measureElement, scrollData, viewport, extent, offset);
            }

            return stackDesiredSize;
        }
示例#8
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);
        }