Skip to content

Commit

Permalink
Tests and fixes to verify that spanned views are including spacing in…
Browse files Browse the repository at this point in the history
… measurements (#15119)

* Tests and fixes to verify that spanned views are including spacing in their measurements

* Update src/Core/src/Layouts/GridLayoutManager.cs

* Auto-format source code

* Update GridLayoutManagerTests.cs

---------

Co-authored-by: GitHub Actions Autoformatter <autoformat@example.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
  • Loading branch information
3 people committed May 19, 2023
1 parent 46e02ac commit e85d0f0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Core/src/Layouts/GridLayoutManager.cs
Expand Up @@ -966,6 +966,11 @@ void UpdateKnownMeasureWidth(Cell cell)
for (int column = cell.Column; column < cell.Column + cell.ColumnSpan; column++)
{
measureWidth += _columns[column].Size;

if (column > cell.Column)
{
measureWidth += _columnSpacing;
}
}

cell.MeasureWidth = measureWidth;
Expand All @@ -977,6 +982,11 @@ void UpdateKnownMeasureHeight(Cell cell)
for (int row = cell.Row; row < cell.Row + cell.RowSpan; row++)
{
measureHeight += _rows[row].Size;

if (row > cell.Row)
{
measureHeight += _rowSpacing;
}
}

cell.MeasureHeight = measureHeight;
Expand Down
40 changes: 40 additions & 0 deletions src/Core/tests/UnitTests/Layouts/GridLayoutManagerTests.cs
Expand Up @@ -2859,6 +2859,46 @@ public void StarColumnsHandleGreedyMeasures(string columnDefinitions)
AssertArranged(view1, new Rect(400, 0, 100, 100));
}

[Theory]
[InlineData("100", 1, 10, 100)]
[InlineData("100, 100", 2, 0, 100 + 0 + 100)]
[InlineData("100, 100", 2, 10, 100 + 10 + 100)]
[InlineData("100, 100, 50", 3, 20, 100 + 20 + 100 + 20 + 50)]
public void SpannedColumnMeasureIncludesSpacing(string columnDefinitions, int columnSpan, double spacing, double expectedWidth)
{
var grid = CreateGridLayout(columns: columnDefinitions);
grid.ColumnSpacing.Returns(spacing);

var view0 = CreateTestView(new Size(20, 20));

SubstituteChildren(grid, view0);
SetLocation(grid, view0, row: 0, col: 0, colSpan: columnSpan);

MeasureAndArrange(grid, double.PositiveInfinity, double.PositiveInfinity);

view0.Received().Measure(Arg.Is<double>(expectedWidth), Arg.Any<Double>());
}

[Theory]
[InlineData("100", 1, 10, 100)]
[InlineData("100, 100", 2, 0, 100 + 0 + 100)]
[InlineData("100, 100", 2, 10, 100 + 10 + 100)]
[InlineData("100, 100, 50", 3, 20, 100 + 20 + 100 + 20 + 50)]
public void SpannedRowMeasureIncludesSpacing(string rowDefinitions, int rowSpan, double spacing, double expectedHeight)
{
var grid = CreateGridLayout(rows: rowDefinitions);
grid.RowSpacing.Returns(spacing);

var view0 = CreateTestView(new Size(20, 20));

SubstituteChildren(grid, view0);
SetLocation(grid, view0, row: 0, col: 0, rowSpan: rowSpan);

MeasureAndArrange(grid, double.PositiveInfinity, double.PositiveInfinity);

view0.Received().Measure(Arg.Any<double>(), Arg.Is<Double>(expectedHeight));
}

[Theory, Category(GridStarSizing)]
[InlineData(0, 0)]
[InlineData(16, 0)]
Expand Down

0 comments on commit e85d0f0

Please sign in to comment.