Skip to content
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
2 changes: 2 additions & 0 deletions src/Core/src/Layouts/GridLayoutManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ void SecondMeasurePass()
{
height += _rows[n].Size;
}
height += _rowSpacing * (cell.RowSpan > 0 ? cell.RowSpan - 1 : 0);
}

if (double.IsInfinity(cell.MeasureWidth))
Expand All @@ -465,6 +466,7 @@ void SecondMeasurePass()
{
width += _columns[n].Size;
}
width += _columnSpacing * (cell.ColumnSpan > 0 ? cell.ColumnSpan - 1 : 0);
}

if (width == 0 || height == 0)
Expand Down
47 changes: 45 additions & 2 deletions src/Core/tests/UnitTests/Layouts/GridLayoutManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
Expand Down Expand Up @@ -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<double>(width => width == 200), Arg.Any<double>());
}

[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<double>(), Arg.Is<double>(height => height == 200));
}
}
}
Loading