Skip to content

Commit

Permalink
feat(autolayout): colapsed children don't count in the measure (#663)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4784666)
  • Loading branch information
Robert-Louis authored and mergify[bot] committed Jul 21, 2023
1 parent fc3ece3 commit 14dcfec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
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 MeasureFixedChildren(
{
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 MeasureHugChildren(
{
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 bool MeasureFilledChildren(
{
var child = _calculatedChildren![i];

if (child.Role == AutoLayoutRole.Filled)
if (child.Role == AutoLayoutRole.Filled || child.IsVisible)
{
filledChildrenCount++;
}
Expand All @@ -299,7 +300,7 @@ private bool MeasureFilledChildren(
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

0 comments on commit 14dcfec

Please sign in to comment.