Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[net7.0] Let the Grid skip * measurements during the first pass if they'll be overwritten later #13523

Merged
merged 1 commit into from
Feb 24, 2023
Merged
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
98 changes: 54 additions & 44 deletions src/Core/src/Layouts/GridLayoutManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ static double SumDefinitions(Definition[] definitions, double spacing)

void MeasureCells()
{
AutoMeasurePass();
KnownMeasurePass();

if (!_isStarWidthPrecomputable)
{
Expand Down Expand Up @@ -367,49 +367,59 @@ Size MeasureCell(Cell cell, double width, double height)
return result;
}

void AutoMeasurePass()
{
for (int n = 0; n < _cells.Length; n++)
{
var cell = _cells[n];

if (double.IsNaN(cell.MeasureHeight) || double.IsNaN(cell.MeasureWidth))
{
cell.NeedsSecondPass = true;
}

var measureWidth = double.IsNaN(cell.MeasureWidth) ? double.PositiveInfinity : cell.MeasureWidth;
var measureHeight = double.IsNaN(cell.MeasureHeight) ? double.PositiveInfinity : cell.MeasureHeight;

var measure = MeasureCell(cell, measureWidth, measureHeight);

if (cell.IsColumnSpanAuto)
{
if (cell.ColumnSpan == 1)
{
_columns[cell.Column].Update(measure.Width);
}
else
{
TrackSpan(new Span(cell.Column, cell.ColumnSpan, true, measure.Width));
}
}

if (cell.IsRowSpanAuto)
{
if (cell.RowSpan == 1)
{
_rows[cell.Row].Update(measure.Height);
}
else
{
TrackSpan(new Span(cell.Row, cell.RowSpan, false, measure.Height));
}
}
}
}

void SecondMeasurePass()
void KnownMeasurePass()
{
for (int n = 0; n < _cells.Length; n++)
{
var cell = _cells[n];

if (double.IsNaN(cell.MeasureHeight) || double.IsNaN(cell.MeasureWidth))
{
// We still have some unknown measure constraints (* rows/columns that need to have
// the Auto measurements settled before we can measure them). So mark this cell for the
// second pass, once we know the constraints.
cell.NeedsSecondPass = true;

if (!cell.IsColumnSpanAuto && !cell.IsRowSpanAuto)
{
// If neither span of this cell includes _any_ Auto values, then there's no reason
// to measure it at all during this pass; we can skip it for now
continue;
}
}

var measureWidth = double.IsNaN(cell.MeasureWidth) ? double.PositiveInfinity : cell.MeasureWidth;
var measureHeight = double.IsNaN(cell.MeasureHeight) ? double.PositiveInfinity : cell.MeasureHeight;

var measure = MeasureCell(cell, measureWidth, measureHeight);

if (cell.IsColumnSpanAuto)
{
if (cell.ColumnSpan == 1)
{
_columns[cell.Column].Update(measure.Width);
}
else
{
TrackSpan(new Span(cell.Column, cell.ColumnSpan, true, measure.Width));
}
}

if (cell.IsRowSpanAuto)
{
if (cell.RowSpan == 1)
{
_rows[cell.Row].Update(measure.Height);
}
else
{
TrackSpan(new Span(cell.Row, cell.RowSpan, false, measure.Height));
}
}
}
}

void SecondMeasurePass()
{
foreach (var cell in _cells)
{
Expand Down