Skip to content

Commit

Permalink
Clean up and expand tests a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
hartez committed Oct 9, 2023
1 parent 983a723 commit 42788ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
12 changes: 10 additions & 2 deletions src/Core/src/Layouts/GridLayoutManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -813,12 +813,20 @@ public void PrepareForArrange(Size targetSize)

if (expandStarRows)
{
ExpandStarDefinitions(_rows, targetSize.Height - _padding.VerticalThickness, GridMinimumHeight() - _padding.VerticalThickness, _rowSpacing, _rowStarCount, !double.IsInfinity(_gridHeightConstraint));
// If the grid is constrained vertically, we will need to limit the upper size of * rows;
// if not, they can be whatever size makes sense for the content
var limitStarRowHeights = !double.IsInfinity(_gridHeightConstraint);
ExpandStarDefinitions(_rows, targetSize.Height - _padding.VerticalThickness, GridMinimumHeight() - _padding.VerticalThickness,
_rowSpacing, _rowStarCount, limitStarRowHeights);
}

if (expandStarColumns)
{
ExpandStarDefinitions(_columns, targetSize.Width - _padding.HorizontalThickness, GridMinimumWidth() - _padding.HorizontalThickness, _columnSpacing, _columnStarCount, !double.IsInfinity(_gridWidthConstraint));
// If the grid is constrained horizontally, we will need to limit the upper size of * columns;
// if not, they can be whatever size makes sense for the content
var limitStarRowWidths = !double.IsInfinity(_gridWidthConstraint);
ExpandStarDefinitions(_columns, targetSize.Width - _padding.HorizontalThickness, GridMinimumWidth() - _padding.HorizontalThickness,
_columnSpacing, _columnStarCount, limitStarRowWidths);
}
}

Expand Down
24 changes: 9 additions & 15 deletions src/Core/tests/UnitTests/Layouts/GridLayoutManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3171,14 +3171,10 @@ public void AutoRowIntersectionWithUnconstrainedMeasure()
AssertArranged(view0, new Rect(0, 0, 40, 20));
}


// TODO cut down test below, then dupe it for width
// Might be able to make this work single column with the oversized item in col 0

[Theory, Category(GridStarSizing)]
[InlineData(926, 845)]
//[InlineData(926, 926)]
//[InlineData(926, 1026)]
[InlineData(926, 845)]
[InlineData(926, 926)]
[InlineData(926, 1026)]
public void StarsAdjustWhenArrangeAndMeasureHeightDiffer(double heightConstraint, double arrangedHeight)
{
var grid = CreateGridLayout(rows: "*, *", columns: "*");
Expand All @@ -3194,17 +3190,16 @@ public void StarsAdjustWhenArrangeAndMeasureHeightDiffer(double heightConstraint
var gridLayoutManager = new GridLayoutManager(grid);

double widthConstraint = 400;
double yOffset = 40;

_ = gridLayoutManager.Measure(widthConstraint, heightConstraint);

// Arranging at a different size than the measurement constraints
gridLayoutManager.ArrangeChildren(new Rect(0, yOffset, widthConstraint, arrangedHeight));
gridLayoutManager.ArrangeChildren(new Rect(0, 0, widthConstraint, arrangedHeight));

double expectedHeight = arrangedHeight / 2;

AssertArranged(smallerView, new Rect(0, yOffset, widthConstraint, expectedHeight));
AssertArranged(largerView, new Rect(0, expectedHeight + yOffset, widthConstraint, expectedHeight));
AssertArranged(smallerView, new Rect(0, 0, widthConstraint, expectedHeight));
AssertArranged(largerView, new Rect(0, expectedHeight, widthConstraint, expectedHeight));
}

[Theory, Category(GridStarSizing)]
Expand All @@ -3226,17 +3221,16 @@ public void StarsAdjustWhenArrangeAndMeasureWidthDiffer(double widthConstraint,
var gridLayoutManager = new GridLayoutManager(grid);

double heightConstraint = 400;
double xOffset = 40;

_ = gridLayoutManager.Measure(widthConstraint, heightConstraint);

// Arranging at a different size than the measurement constraints
gridLayoutManager.ArrangeChildren(new Rect(xOffset, 0, arrangedWidth, heightConstraint));
gridLayoutManager.ArrangeChildren(new Rect(0, 0, arrangedWidth, heightConstraint));

double expectedWidth = arrangedWidth / 2;

AssertArranged(smallerView, new Rect(xOffset, 0, expectedWidth, heightConstraint));
AssertArranged(largerView, new Rect(expectedWidth + xOffset, 0, expectedWidth, heightConstraint));
AssertArranged(smallerView, new Rect(0, 0, expectedWidth, heightConstraint));
AssertArranged(largerView, new Rect(expectedWidth, 0, expectedWidth, heightConstraint));
}
}
}

0 comments on commit 42788ad

Please sign in to comment.