Skip to content

Commit

Permalink
Let the Grid skip * measurements during the first pass if they'll be …
Browse files Browse the repository at this point in the history
…overwritten later (#13523)

Co-authored-by: E.Z. Hart <hartez@gmail.com>
  • Loading branch information
github-actions[bot] and hartez authored Feb 24, 2023
1 parent 708a393 commit d177231
Showing 1 changed file with 54 additions and 44 deletions.
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

0 comments on commit d177231

Please sign in to comment.