コード例 #1
0
ファイル: Stack.cs プロジェクト: nlh774/DotNetReferenceSource
        /// <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;
        }
コード例 #2
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);
        }
コード例 #3
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);
        }