Browse Source

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.
pull/22/head
reuk 3 years ago
parent
commit
7eb99ed8ec
No known key found for this signature in database GPG Key ID: 9ADCD339CFC98A11
1 changed files with 13 additions and 2 deletions
  1. +13
    -2
      modules/juce_gui_basics/layout/juce_Grid.cpp

+ 13
- 2
modules/juce_gui_basics/layout/juce_Grid.cpp 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)


Loading…
Cancel
Save