コード例 #1
0
        public override Size ArrangeChildren(Rect bounds)
        {
            var structure = _gridStructure ?? new GridStructure(Grid, bounds.Width, bounds.Height);

            var reverseColumns = Grid.ColumnDefinitions.Count > 1 && !Grid.ShouldArrangeLeftToRight();

            foreach (var view in Grid)
            {
                if (view.Visibility == Visibility.Collapsed)
                {
                    continue;
                }

                var cell = structure.GetCellBoundsFor(view, bounds.Left, bounds.Top);

                if (reverseColumns)
                {
                    var adjustedXPosition = bounds.Right - cell.Left - cell.Width;
                    cell.Left = adjustedXPosition;
                }

                view.Arrange(cell);
            }

            var actual = new Size(structure.MeasuredGridWidth(), structure.MeasuredGridHeight());

            return(actual.AdjustForFill(bounds, Grid));
        }
コード例 #2
0
        static Size InsetScrollView(double widthConstraint, double heightConstraint, Func <double, double, Size> internalMeasure, IScrollView scrollView)
        {
            var padding          = scrollView.Padding;
            var presentedContent = scrollView.PresentedContent;

            if (presentedContent == null)
            {
                return(new Size(padding.HorizontalThickness, padding.VerticalThickness));
            }

            // Exclude the padding while measuring the internal content ...
            var measurementWidth  = widthConstraint - padding.HorizontalThickness;
            var measurementHeight = heightConstraint - padding.VerticalThickness;

            var result = internalMeasure.Invoke(measurementWidth, measurementHeight);

            // ... and add the padding back in to the final result
            var fullSize = new Size(result.Width + padding.HorizontalThickness, result.Height + padding.VerticalThickness);

            if (double.IsInfinity(widthConstraint))
            {
                widthConstraint = result.Width;
            }

            if (double.IsInfinity(heightConstraint))
            {
                heightConstraint = result.Height;
            }

            // If the presented content has LayoutAlignment Fill, we'll need to adjust the measurement to account for that
            return(fullSize.AdjustForFill(new Rect(0, 0, widthConstraint, heightConstraint), presentedContent));
        }
コード例 #3
0
        public override Size ArrangeChildren(Rectangle bounds)
        {
            var padding = Stack.Padding;

            double stackHeight = padding.Top + bounds.Y;
            double left        = padding.Left + bounds.X;
            double width       = bounds.Width - padding.HorizontalThickness;

            for (int n = 0; n < Stack.Count; n++)
            {
                var child = Stack[n];

                if (child.Visibility == Visibility.Collapsed)
                {
                    continue;
                }

                var destination = new Rectangle(left, stackHeight, width, child.DesiredSize.Height);
                child.Arrange(destination);
                stackHeight += destination.Height + Stack.Spacing;
            }

            var actual = new Size(width, stackHeight);

            return(actual.AdjustForFill(bounds, Stack));
        }
コード例 #4
0
        public override Size ArrangeChildren(Rect bounds)
        {
            var    padding = Stack.Padding;
            double top     = padding.Top + bounds.Top;

            var    height = bounds.Height - padding.VerticalThickness;
            double stackWidth;

            bool leftToRight = Stack.ShouldArrangeLeftToRight();

            // Figure out where we're starting from (the left edge of the padded area, or the right edge)
            double xPosition = leftToRight ? padding.Left + bounds.Left : bounds.Right - padding.Right;

            // If we're arranging from the right, spacing will be added to the left
            double spacingDelta = leftToRight ? Stack.Spacing : -Stack.Spacing;

            for (int n = 0; n < Stack.Count; n++)
            {
                var child = Stack[n];

                if (child.Visibility == Visibility.Collapsed)
                {
                    continue;
                }

                xPosition += leftToRight
                                        ? ArrangeChildFromLeftEdge(child, height, top, xPosition)
                                        : ArrangeChildFromRightEdge(child, height, top, xPosition);

                if (n < Stack.Count - 1)
                {
                    // If we have more than one child and we're not on the last one, add spacing
                    xPosition += spacingDelta;
                }
            }

            // If we started from the left, the total width is the current x position;
            // If we started from the right, it's the difference between the right edge and the current x position
            stackWidth = leftToRight ? xPosition : bounds.Right - xPosition;

            var actual = new Size(stackWidth, height);

            return(actual.AdjustForFill(bounds, Stack));
        }
コード例 #5
0
        public override Size ArrangeChildren(Rectangle bounds)
        {
            var structure = _gridStructure ?? new GridStructure(Grid, bounds.Width, bounds.Height);

            foreach (var view in Grid)
            {
                if (view.Visibility == Visibility.Collapsed)
                {
                    continue;
                }

                var cell = structure.GetCellBoundsFor(view, bounds.Left, bounds.Top);

                view.Arrange(cell);
            }

            var actual = new Size(structure.MeasuredGridWidth(), structure.MeasuredGridHeight());

            return(actual.AdjustForFill(bounds, Grid));
        }
コード例 #6
0
        public override Size ArrangeChildren(Rectangle bounds)
        {
            var    padding = Stack.Padding;
            double top     = padding.Top + bounds.Top;
            double left    = padding.Left + bounds.Left;
            var    height  = bounds.Height - padding.VerticalThickness;
            double stackWidth;

            if (Stack.FlowDirection == FlowDirection.LeftToRight)
            {
                stackWidth = ArrangeLeftToRight(height, left, top, Stack.Spacing, Stack);
            }
            else
            {
                // We _could_ simply reverse the list of child views when arranging from right to left,
                // but this way we avoid extra list and enumerator allocations
                stackWidth = ArrangeRightToLeft(height, left, top, Stack.Spacing, Stack);
            }

            var actual = new Size(height, stackWidth);

            return(actual.AdjustForFill(bounds, Stack));
        }