private Size xLayout(IArrangedElement container, Rectangle displayRect, bool measureOnly)
        {
            int            num2;
            FlowDirection  flowDirection  = GetFlowDirection(container);
            bool           wrapContents   = GetWrapContents(container);
            ContainerProxy containerProxy = CreateContainerProxy(container, flowDirection);

            containerProxy.DisplayRect = displayRect;
            displayRect = containerProxy.DisplayRect;
            ElementProxy elementProxy = containerProxy.ElementProxy;
            Size         empty        = Size.Empty;

            if (!wrapContents)
            {
                displayRect.Width = 0x7fffffff - displayRect.X;
            }
            for (int i = 0; i < container.Children.Count; i = num2)
            {
                Size      size2            = Size.Empty;
                Rectangle displayRectangle = new Rectangle(displayRect.X, displayRect.Y, displayRect.Width, displayRect.Height - empty.Height);
                size2 = this.MeasureRow(containerProxy, elementProxy, i, displayRectangle, out num2);
                if (!measureOnly)
                {
                    Rectangle rowBounds = new Rectangle(displayRect.X, empty.Height + displayRect.Y, size2.Width, size2.Height);
                    this.LayoutRow(containerProxy, elementProxy, i, num2, rowBounds);
                }
                empty.Width   = Math.Max(empty.Width, size2.Width);
                empty.Height += size2.Height;
            }
            if (container.Children.Count != 0)
            {
            }
            return(LayoutUtils.FlipSizeIf((flowDirection == FlowDirection.TopDown) || (GetFlowDirection(container) == FlowDirection.BottomUp), empty));
        }
Esempio n. 2
0
        /// <summary>
        ///  Both LayoutCore and GetPreferredSize forward to this method.
        ///  The measureOnly flag determines which behavior we get.
        /// </summary>
        private Size TryCalculatePreferredSize(IArrangedElement container, Rectangle displayRect, bool measureOnly)
        {
            FlowDirection flowDirection = GetFlowDirection(container);
            bool          wrapContents  = GetWrapContents(container);

            ContainerProxy containerProxy = CreateContainerProxy(container, flowDirection);

            containerProxy.DisplayRect = displayRect;

            // refetch as it's now adjusted for Vertical.
            displayRect = containerProxy.DisplayRect;

            ElementProxy elementProxy = containerProxy.ElementProxy;
            Size         layoutSize   = Size.Empty;

            if (!wrapContents)
            {
                // pretend that the container is infinitely wide to prevent wrapping.
                // DisplayRectangle.Right is Width + X - subtract X to prevent overflow.
                displayRect.Width = int.MaxValue - displayRect.X;
            }

            for (int i = 0; i < container.Children.Count;)
            {
                Size rowSize = Size.Empty;

                Rectangle measureBounds = new Rectangle(displayRect.X, displayRect.Y, displayRect.Width, displayRect.Height - layoutSize.Height);
                rowSize = MeasureRow(containerProxy, elementProxy, i, measureBounds, out int breakIndex);

                // if we are not wrapping contents, then the breakIndex (as set in MeasureRow)
                // should be equal to the count of child items in the container.
                Debug.Assert(wrapContents == true || breakIndex == container.Children.Count,
                             "We should not be trying to break the row if we are not wrapping contents.");

                if (!measureOnly)
                {
                    Rectangle rowBounds = new Rectangle(displayRect.X,
                                                        layoutSize.Height + displayRect.Y,
                                                        rowSize.Width,
                                                        rowSize.Height);
                    LayoutRow(containerProxy, elementProxy, startIndex: i, endIndex: breakIndex, rowBounds: rowBounds);
                }

                layoutSize.Width   = Math.Max(layoutSize.Width, rowSize.Width);
                layoutSize.Height += rowSize.Height;
                i = breakIndex;
            }

            // Verify that our alignment is correct
            if (container.Children.Count != 0 && !measureOnly)
            {
                Debug_VerifyAlignment(container, flowDirection);
            }

            return(LayoutUtils.FlipSizeIf(flowDirection == FlowDirection.TopDown || GetFlowDirection(container) == FlowDirection.BottomUp, layoutSize));
        }