Fix ElasticWrapPanel not skipping hidden children when IsFillHorizontal and ItemWidth are set (#896)
* Initial plan * Fix ElasticWrapPanel to skip invisible children in MeasureOverride and ArrangeOverride Co-authored-by: rabbitism <14807942+rabbitism@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rabbitism <14807942+rabbitism@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
f1c9dc4817
commit
860b832fe0
@@ -117,6 +117,7 @@ public class ElasticWrapPanel : WrapPanel
|
|||||||
|
|
||||||
foreach (var child in children)
|
foreach (var child in children)
|
||||||
{
|
{
|
||||||
|
if (!child.IsVisible) continue;
|
||||||
UVSize sz;
|
UVSize sz;
|
||||||
if (GetIsFixToRB(child))
|
if (GetIsFixToRB(child))
|
||||||
{
|
{
|
||||||
@@ -258,6 +259,7 @@ public class ElasticWrapPanel : WrapPanel
|
|||||||
var children = Children;
|
var children = Children;
|
||||||
foreach (var child in children)
|
foreach (var child in children)
|
||||||
{
|
{
|
||||||
|
if (!child.IsVisible) continue;
|
||||||
UVSize sz;
|
UVSize sz;
|
||||||
if (GetIsFixToRB(child))
|
if (GetIsFixToRB(child))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -216,4 +216,66 @@ public class Tests
|
|||||||
window.UpdateLayout();
|
window.UpdateLayout();
|
||||||
Assert.Equal(4, panel2.LineCount); // 1 item per line, 4 items total = 4 lines
|
Assert.Equal(4, panel2.LineCount); // 1 item per line, 4 items total = 4 lines
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[AvaloniaFact]
|
||||||
|
public void HiddenItem_IsSkipped_WithItemWidth()
|
||||||
|
{
|
||||||
|
var window = new Window();
|
||||||
|
var panel = new ElasticWrapPanel
|
||||||
|
{
|
||||||
|
Width = 400,
|
||||||
|
Height = 400,
|
||||||
|
Orientation = Orientation.Horizontal,
|
||||||
|
ItemWidth = 100,
|
||||||
|
IsFillHorizontal = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add 4 items: item[1] is hidden
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
var rect = new Rectangle
|
||||||
|
{
|
||||||
|
Width = 100,
|
||||||
|
Height = 100,
|
||||||
|
IsVisible = i != 1,
|
||||||
|
};
|
||||||
|
panel.Children.Add(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.Content = panel;
|
||||||
|
window.Show();
|
||||||
|
|
||||||
|
// 3 visible items of width 100 fit on one line in a 400-wide panel
|
||||||
|
Assert.Equal(1, panel.LineCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
[AvaloniaFact]
|
||||||
|
public void HiddenItem_IsSkipped_WithoutItemWidth()
|
||||||
|
{
|
||||||
|
var window = new Window();
|
||||||
|
var panel = new ElasticWrapPanel
|
||||||
|
{
|
||||||
|
Width = 400,
|
||||||
|
Height = 400,
|
||||||
|
Orientation = Orientation.Horizontal,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add 4 items: item[1] is hidden
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
var rect = new Rectangle
|
||||||
|
{
|
||||||
|
Width = 100,
|
||||||
|
Height = 100,
|
||||||
|
IsVisible = i != 1,
|
||||||
|
};
|
||||||
|
panel.Children.Add(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.Content = panel;
|
||||||
|
window.Show();
|
||||||
|
|
||||||
|
// 3 visible items of width 100 fit on one line in a 400-wide panel
|
||||||
|
Assert.Equal(1, panel.LineCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user