diff --git a/src/Core/src/Layouts/GridLayoutManager.cs b/src/Core/src/Layouts/GridLayoutManager.cs index 22d9428f6f90..42076d6829ce 100644 --- a/src/Core/src/Layouts/GridLayoutManager.cs +++ b/src/Core/src/Layouts/GridLayoutManager.cs @@ -453,6 +453,7 @@ void SecondMeasurePass() { height += _rows[n].Size; } + height += _rowSpacing * (cell.RowSpan > 0 ? cell.RowSpan - 1 : 0); } if (double.IsInfinity(cell.MeasureWidth)) @@ -465,6 +466,7 @@ void SecondMeasurePass() { width += _columns[n].Size; } + width += _columnSpacing * (cell.ColumnSpan > 0 ? cell.ColumnSpan - 1 : 0); } if (width == 0 || height == 0) diff --git a/src/Core/tests/UnitTests/Layouts/GridLayoutManagerTests.cs b/src/Core/tests/UnitTests/Layouts/GridLayoutManagerTests.cs index 9bc738a3f43d..d034c06798ca 100644 --- a/src/Core/tests/UnitTests/Layouts/GridLayoutManagerTests.cs +++ b/src/Core/tests/UnitTests/Layouts/GridLayoutManagerTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; @@ -3235,5 +3235,48 @@ public void StarsAdjustWhenArrangeAndMeasureWidthDiffer(double widthConstraint, AssertArranged(smallerView, new Rect(0, 0, expectedWidth, heightConstraint)); AssertArranged(largerView, new Rect(expectedWidth, 0, expectedWidth, heightConstraint)); } - } +[Fact] +public void SpannedCellMeasurementIncludesColumnSpacingIssue26633() +{ +// Issue: https://github.com/dotnet/maui/issues/26633 +// Grid cells spanning multiple columns with ColumnSpacing > 0 have incorrect measurement + +var grid = CreateGridLayout(columns: "auto, *, auto", colSpacing: 6); +var view = CreateTestView(new Size(50, 50)); + +SubstituteExtensions.ReturnsForAnyArgs(view.DesiredSize, new Size(50, 50)); + +SubstituteChildren(grid, view); +SetLocation(grid, view, row: 0, col: 0, colSpan: 3); + +var manager = new GridLayoutManager(grid); +var measure = manager.Measure(200, double.PositiveInfinity); + +// Cell spans all 3 columns: should get full grid width of 200px +// Without fix: gets 188px (missing spacing in calculation) +view.Received().Measure(Arg.Is(width => width == 200), Arg.Any()); +} + +[Fact] +public void SpannedCellMeasurementIncludesRowSpacingIssue26633() +{ +// Issue: https://github.com/dotnet/maui/issues/26633 +// Grid cells spanning multiple rows with RowSpacing > 0 have incorrect measurement + +var grid = CreateGridLayout(rows: "auto, *, auto", rowSpacing: 6); +var view = CreateTestView(new Size(50, 50)); + +SubstituteExtensions.ReturnsForAnyArgs(view.DesiredSize, new Size(50, 50)); + +SubstituteChildren(grid, view); +SetLocation(grid, view, row: 0, col: 0, rowSpan: 3); + +var manager = new GridLayoutManager(grid); +var measure = manager.Measure(double.PositiveInfinity, 200); + +// Cell spans all 3 rows: should get full grid width of 200px +// Without fix: gets 188px (missing spacing in calculation) +view.Received().Measure(Arg.Any(), Arg.Is(height => height == 200)); +} } +} \ No newline at end of file