Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(autolayout): collapsed children don't count in the measure (backport #663) #674

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ protected override Size ArrangeOverride(Size finalSize)
var child = children[i];
var calculatedChild = _calculatedChildren[i];

if (child is FrameworkElement { Visibility: Visibility.Collapsed })
{
continue;
}

if (!ReferenceEquals(child, calculatedChild.Element))
{
// Invalid calculated child, invalidate measure and wait for next pass to fix this.
Expand Down Expand Up @@ -152,6 +157,11 @@ protected override Size ArrangeOverride(Size finalSize)
continue; // next child, current offset remains unchanged
}

if (children[i] is FrameworkElement { Visibility: Visibility.Collapsed })
{
continue;
}

// Calculate the length of the child (size in the panel orientation)

// Length depends on the role of the child
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ protected override Size MeasureOverride(Size availableSize)
// 8b. Calculate the desired size of the panel, when there's at least one filled child
var stackedChildrenDesiredSize =
_calculatedChildren!
.Where(child => child.IsVisible)
.Select(c => c.MeasuredLength)
.Sum()
+ totalSpacingSize;
Expand Down Expand Up @@ -212,7 +213,7 @@ private void ApplyMinMaxValues(ref Size desiredSize)
{
var calculatedChild = _calculatedChildren[i];

if (calculatedChild.Role != AutoLayoutRole.Fixed)
if (calculatedChild.Role != AutoLayoutRole.Fixed || !calculatedChild.IsVisible)
{
continue;
}
Expand Down Expand Up @@ -243,7 +244,7 @@ private void ApplyMinMaxValues(ref Size desiredSize)
{
var calculatedChild = _calculatedChildren![i];

if (calculatedChild.Role != AutoLayoutRole.Hug)
if (calculatedChild.Role != AutoLayoutRole.Hug || !calculatedChild.IsVisible)
{
continue;
}
Expand Down Expand Up @@ -282,7 +283,7 @@ private void ApplyMinMaxValues(ref Size desiredSize)
{
var child = _calculatedChildren![i];

if (child.Role == AutoLayoutRole.Filled)
if (child.Role == AutoLayoutRole.Filled || child.IsVisible)
{
filledChildrenCount++;
}
Expand All @@ -299,7 +300,7 @@ private void ApplyMinMaxValues(ref Size desiredSize)
for (var i = 0; i < _calculatedChildren!.Length; i++)
{
var child = _calculatedChildren![i];
if (child.Role != AutoLayoutRole.Filled)
if (child.Role != AutoLayoutRole.Filled || !child.IsVisible)
{
continue;
}
Expand Down Expand Up @@ -446,8 +447,11 @@ public CalculatedChildren(UIElement element, AutoLayoutRole role, double measure
Element = element;
Role = role;
MeasuredLength = measuredLength;
IsVisible = element.Visibility == Visibility.Visible;
}

internal bool IsVisible { get; }

internal UIElement Element { get; }

/// <summary>
Expand Down