Пример #1
0
        Rectangle ArrangeLeft(Rectangle layoutSize)
        {
            if (layoutSize.Width >= FirstPaneMinSize + SecondPaneMinSize)
            {
                SplitterOffset = MathHelper.Clamp(SplitterOffset, FirstPaneMinSize, layoutSize.Width - SecondPaneMinSize);
            }

            var splitterBarWidth = splitterBar.DesiredSize.WidthInt;

            if (Collapsed && collapseAnim.IsOver)
            {
                displayFirstPane  = false;
                displaySecondPane = true;

                layoutSize.Width = Math.Max(layoutSize.Width, splitterBarWidth + SecondPaneMinSize);
                var arr = new ArrangerHorizontal(layoutSize);
                arr.Arrange(splitterBar, splitterBarWidth).Advance(splitterBarWidth);
                arr.Arrange(SecondPane, arr.AvailableWidth).Advance(arr.AvailableWidth);
                return(layoutSize);
            }

            displayFirstPane  = true;
            displaySecondPane = true;

            var layoutWidth2        = Math.Max(layoutSize.Width, FirstPaneMinSize + splitterBarWidth + SecondPaneMinSize);
            var animatedSplitterPos = (int)MathHelper.Clamp((1f - collapseAnim.CurrentValue) * SplitterOffset, 0, SplitterOffset);

            // FirstPane might be shrinking to zero while playing the collapse-animation.
            // We therefore arrange it with its non-collapsed sizing. The remaining parts (splitter-bar, right component)
            // will be positioned and expanded according to the current status of the animation.
            // retain the original size to avoid display artefacts while the left pane is visually shrinking.
            // if the animation is over, we either have a fully collapsed pane (see above) or a fully expanded pane.
            var arr2 = new ArrangerHorizontal(layoutSize);

            arr2.Arrange(FirstPane, SplitterOffset).Advance(animatedSplitterPos);
            arr2.Arrange(splitterBar, splitterBarWidth).Advance(splitterBarWidth);
            arr2.Arrange(SecondPane, arr2.AvailableWidth).Advance(arr2.AvailableWidth);
            layoutSize.Width = layoutWidth2;
            return(layoutSize);
        }
Пример #2
0
        Rectangle ArrangeRight(Rectangle layoutSize)
        {
            if (layoutSize.Width >= FirstPaneMinSize + SecondPaneMinSize)
            {
                SplitterOffset = MathHelper.Clamp(SplitterOffset, SecondPaneMinSize, layoutSize.Width - FirstPaneMinSize);
            }

            var splitterBarWidth = splitterBar.DesiredSize.WidthInt;

            if (Collapsed && collapseAnim.IsOver)
            {
                displayFirstPane  = true;
                displaySecondPane = false;

                layoutSize.Width = Math.Max(layoutSize.Width, splitterBarWidth + FirstPaneMinSize);

                var arr = new ArrangerHorizontal(layoutSize);
                arr.Reserve(splitterBarWidth).Arrange(FirstPane, arr.AvailableWidth).Advance(arr.AvailableWidth);
                arr.Arrange(splitterBar, splitterBarWidth).AdvanceReserved(splitterBarWidth);
                return(layoutSize);
            }

            displayFirstPane  = true;
            displaySecondPane = true;

            layoutSize.Width = Math.Max(layoutSize.Width, FirstPaneMinSize + splitterBarWidth + SecondPaneMinSize);
            var animatedSplitterPos = (int)MathHelper.Clamp((1f - collapseAnim.CurrentValue) * SplitterOffset, 0, SplitterOffset);

            var arr2 = new ArrangerHorizontal(layoutSize);

            arr2.Reserve(animatedSplitterPos);
            arr2.Reserve(splitterBarWidth);
            arr2.Arrange(FirstPane, arr2.AvailableWidth).Advance(arr2.AvailableWidth);
            arr2.Arrange(splitterBar, splitterBarWidth).AdvanceReserved(splitterBarWidth);
            arr2.Arrange(SecondPane, SplitterOffset).AdvanceReserved(animatedSplitterPos);
            return(layoutSize);
        }
Пример #3
0
        protected override Rectangle ArrangeOverride(Rectangle layoutSize)
        {
            if (string.IsNullOrEmpty(Label.Text))
            {
                Image.Arrange(layoutSize);
                return(Image.LayoutRect);
            }

            if (!Image.HasTexture)
            {
                Label.Arrange(layoutSize);
                return(Label.LayoutRect);
            }

            var actualWidth = DesiredSize.WidthInt;

            var center = layoutSize.Center;
            int left;
            int spaceToRight;

            switch (Label.Alignment)
            {
            case Alignment.Start:
            case Alignment.Fill:
            {
                left         = layoutSize.X;
                spaceToRight = Math.Max(0, layoutSize.Width - actualWidth);
                break;
            }

            case Alignment.Center:
            {
                left         = center.X - actualWidth / 2;
                spaceToRight = Math.Max(0, layoutSize.Width - (center.X + actualWidth / 2));
            }
            break;

            case Alignment.End:
            {
                left         = layoutSize.Right - actualWidth;
                spaceToRight = 0;
                break;
            }

            default:
            {
                throw new NotSupportedException();
            }
            }

            var arr = new ArrangerHorizontal(layoutSize);

            arr.Advance(left - layoutSize.X);
            arr.Reserve(spaceToRight);
            arr.Arrange(Image, Image.DesiredSize.WidthInt).Advance(Image.DesiredSize.WidthInt);
            arr.Advance(IconTextGap);
            arr.Arrange(Label, arr.AvailableWidth);

            var x      = Image.LayoutRect.X;
            var y      = Math.Min(Image.LayoutRect.Y, Label.LayoutRect.Y);
            var width  = Math.Max(0, Label.LayoutRect.Right - Image.LayoutRect.X);
            var height = Math.Max(0, Math.Max(Image.LayoutRect.Bottom, Label.LayoutRect.Bottom) - y);

            return(new Rectangle(x, y, width, height));
        }