Skip to content
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