Skip to content

Commit

Permalink
messure collaped children without spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
Poker-sang committed Feb 2, 2025
1 parent 51e0eaa commit 25359a5
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/Avalonia.Controls/DockPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,23 @@ protected override Size MeasureOverride(Size availableSize)
{
case Dock.Left:
case Dock.Right:
horizontalSpacing = true;
parentHeight = Math.Max(parentHeight, accumulatedHeight + childDesiredSize.Height);
accumulatedWidth += HorizontalSpacing;
if (child.IsVisible)
{
accumulatedWidth += HorizontalSpacing;
horizontalSpacing = true;
}
accumulatedWidth += childDesiredSize.Width;
break;

case Dock.Top:
case Dock.Bottom:
verticalSpacing = true;
parentWidth = Math.Max(parentWidth, accumulatedWidth + childDesiredSize.Width);
accumulatedHeight += VerticalSpacing;
if (child.IsVisible)
{
accumulatedHeight += VerticalSpacing;
verticalSpacing = true;
}
accumulatedHeight += childDesiredSize.Height;
break;
}
Expand Down Expand Up @@ -225,31 +231,43 @@ protected override Size ArrangeOverride(Size finalSize)

width = Math.Min(child.DesiredSize.Width, currentBounds.Width);
child.Arrange(currentBounds.WithWidth(width));
width += HorizontalSpacing;
if (child.IsVisible)
{
width += HorizontalSpacing;
}
currentBounds = new Rect(currentBounds.X + width, currentBounds.Y, Math.Max(0, currentBounds.Width - width), currentBounds.Height);

break;
case Dock.Top:

height = Math.Min(child.DesiredSize.Height, currentBounds.Height);
child.Arrange(currentBounds.WithHeight(height));
height += VerticalSpacing;
if (child.IsVisible)
{
height += VerticalSpacing;
}
currentBounds = new Rect(currentBounds.X, currentBounds.Y + height, currentBounds.Width, Math.Max(0, currentBounds.Height - height));

break;
case Dock.Right:

width = Math.Min(child.DesiredSize.Width, currentBounds.Width);
child.Arrange(new Rect(currentBounds.X + currentBounds.Width - width, currentBounds.Y, width, currentBounds.Height));
width += HorizontalSpacing;
if (child.IsVisible)
{
width += HorizontalSpacing;
}
currentBounds = currentBounds.WithWidth(Math.Max(0, currentBounds.Width - width));

break;
case Dock.Bottom:

height = Math.Min(child.DesiredSize.Height, currentBounds.Height);
child.Arrange(new Rect(currentBounds.X, currentBounds.Y + currentBounds.Height - height, currentBounds.Width, height));
height += VerticalSpacing;
if (child.IsVisible)
{
height += VerticalSpacing;
}
currentBounds = currentBounds.WithHeight(Math.Max(0, currentBounds.Height - height));

break;
Expand Down

0 comments on commit 25359a5

Please sign in to comment.