1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Grid: Avoid hangs when positioning auto-placement items that are too large for the explicit grid

Previously, positioning such an item would hang while trying to find an
appropriate position for the item, because no position in the grid was
suitable, and implicit cells in the layout direction would be added
until a viable position was found.

We now ensure that there are enough cells in the cross direction to hold
each of the auto-placement items before trying to position those items.
This commit is contained in:
reuk 2022-06-24 13:22:38 +01:00
parent 9c0786e4fe
commit 7eb99ed8ec
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -597,6 +597,11 @@ struct Grid::AutoPlacement
return referenceCell;
}
void updateMaxCrossDimensionFromAutoPlacementItem (int columnSpan, int rowSpan)
{
highestCrossDimension = jmax (highestCrossDimension, 1 + getCrossDimension ({ columnSpan, rowSpan }));
}
private:
struct SortableCell
{
@ -642,9 +647,10 @@ struct Grid::AutoPlacement
bool isOutOfBounds (Cell cell, int columnSpan, int rowSpan) const
{
const auto crossSpan = columnFirst ? rowSpan : columnSpan;
const auto highestIndexOfCell = getCrossDimension (cell) + getCrossDimension ({ columnSpan, rowSpan });
const auto highestIndexOfGrid = getHighestCrossDimension();
return (getCrossDimension (cell) + crossSpan) > getHighestCrossDimension();
return highestIndexOfGrid < highestIndexOfCell;
}
int getHighestCrossDimension() const
@ -807,6 +813,11 @@ struct Grid::AutoPlacement
}
}
// https://www.w3.org/TR/css-grid-1/#auto-placement-algo step 3.3
for (auto* item : sortedItems)
if (hasAutoPlacement (*item))
plane.updateMaxCrossDimensionFromAutoPlacementItem (getSpanFromAuto (item->column), getSpanFromAuto (item->row));
lastInsertionCell = { 1, 1 };
for (auto* item : sortedItems)