Browse Source
Merge pull request #2976 from AvaloniaUI/fixes/stackpanel-layout
stackpanel copes with non-visible controls when arranging.
pull/2979/head
danwalmsley
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
31 additions and
1 deletions
-
src/Avalonia.Controls/Notifications/ReversibleStackPanel.cs
-
src/Avalonia.Controls/StackPanel.cs
-
tests/Avalonia.Controls.UnitTests/StackPanelTests.cs
|
|
|
@ -39,6 +39,11 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
foreach (Control child in children) |
|
|
|
{ |
|
|
|
if (!child.IsVisible) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
double childWidth = child.DesiredSize.Width; |
|
|
|
double childHeight = child.DesiredSize.Height; |
|
|
|
|
|
|
|
|
|
|
|
@ -251,7 +251,7 @@ namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
var child = children[i]; |
|
|
|
|
|
|
|
if (child == null) |
|
|
|
if (child == null || !child.IsVisible) |
|
|
|
{ continue; } |
|
|
|
|
|
|
|
if (fHorizontal) |
|
|
|
|
|
|
|
@ -332,6 +332,31 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
Assert.Equal(sizeWithTwoChildren, sizeWithThreeChildren); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData(Orientation.Horizontal)] |
|
|
|
[InlineData(Orientation.Vertical)] |
|
|
|
public void Only_Arrange_Visible_Children(Orientation orientation) |
|
|
|
{ |
|
|
|
|
|
|
|
var hiddenPanel = new Panel { Width = 10, Height = 10, IsVisible = false }; |
|
|
|
var panel = new Panel { Width = 10, Height = 10 }; |
|
|
|
|
|
|
|
var target = new StackPanel |
|
|
|
{ |
|
|
|
Spacing = 40, |
|
|
|
Orientation = orientation, |
|
|
|
Children = |
|
|
|
{ |
|
|
|
hiddenPanel, |
|
|
|
panel |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
target.Measure(Size.Infinity); |
|
|
|
target.Arrange(new Rect(target.DesiredSize)); |
|
|
|
Assert.Equal(new Rect(0, 0, 10, 10), panel.Bounds); |
|
|
|
} |
|
|
|
|
|
|
|
private class TestControl : Control |
|
|
|
{ |
|
|
|
public Size MeasureConstraint { get; private set; } |
|
|
|
|