UI: Respect fixed layout width in grid view layout calculations

Fixed layout widths would previously be ignored, resulting in incorrectly sized
grid view items. This is especially relevant for displaying grid views in
popups, where these fixed width are commonly used.

Necessary for the brush assets project which adds a popup version of the asset
shelf, see #116337.
This commit is contained in:
Julian Eisel
2024-05-08 13:32:44 +02:00
parent 25c134fd08
commit d3b2906348

View File

@@ -356,7 +356,13 @@ void GridViewLayoutBuilder::build_from_view(const AbstractGridView &grid_view,
uiLayout &layout = *uiLayoutColumn(parent_layout, true);
const GridViewStyle &style = grid_view.get_style();
const int cols_per_row = std::max(uiLayoutGetWidth(&layout) / style.tile_width, 1);
/* We might not actually know the width available for the grid view. Let's just assume that
* either there is a fixed width defined via #uiLayoutSetUnitsX() or that the layout is close to
* the root level and inherits its width. Might need a more reliable method. */
const int guessed_layout_width = (uiLayoutGetUnitsX(parent_layout) > 0) ?
uiLayoutGetUnitsX(parent_layout) * UI_UNIT_X :
uiLayoutGetWidth(parent_layout);
const int cols_per_row = std::max(guessed_layout_width / style.tile_width, 1);
BuildOnlyVisibleButtonsHelper build_visible_helper(v2d, grid_view, cols_per_row);