[Bf-blender-cvs] [39e3580065c] asset-browser-grid-view: Enforce a fixed column number for the grid layout
Julian Eisel
noreply at git.blender.org
Mon Feb 7 12:20:21 CET 2022
Commit: 39e3580065c3d1df148f8d9ae593a0b14321202f
Author: Julian Eisel
Date: Mon Feb 7 12:17:17 2022 +0100
Branches: asset-browser-grid-view
https://developer.blender.org/rB39e3580065c3d1df148f8d9ae593a0b14321202f
Enforce a fixed column number for the grid layout
Avoid stretching items to fit the layout, they should always have a
fixed size.
===================================================================
M source/blender/editors/interface/grid_view.cc
===================================================================
diff --git a/source/blender/editors/interface/grid_view.cc b/source/blender/editors/interface/grid_view.cc
index 72614319bf9..ae7f527f817 100644
--- a/source/blender/editors/interface/grid_view.cc
+++ b/source/blender/editors/interface/grid_view.cc
@@ -101,9 +101,25 @@ void GridViewLayoutBuilder::build_from_view(const AbstractGridView &grid_view)
const GridViewStyle &style = grid_view.get_style();
const int cols_per_row = uiLayoutGetWidth(&layout) / style.tile_width;
- uiLayout *grid_layout = uiLayoutGridFlow(&layout, true, cols_per_row, true, true, true);
-
- grid_view.foreach_item([&](AbstractGridViewItem &item) { item.build_grid_tile(*grid_layout); });
+ /* Use `-cols_per_row` because the grid layout uses a multiple of the passed absolute value for
+ * the number of columns then, rather than distributing the number of items evenly over rows and
+ * stretching the items to fit (see #uiLayoutItemGridFlow.columns_len). */
+ uiLayout *grid_layout = uiLayoutGridFlow(&layout, true, -cols_per_row, true, true, true);
+
+ int item_count = 0;
+ grid_view.foreach_item([&](AbstractGridViewItem &item) {
+ item.build_grid_tile(*grid_layout);
+ item_count++;
+ });
+
+ /* If there are not enough items to fill the layout, add padding items so the layout doesn't
+ * stretch over the entire width. */
+ if (item_count < cols_per_row) {
+ for (int padding_item_idx = 0; padding_item_idx < (cols_per_row - item_count);
+ padding_item_idx++) {
+ uiItemS(grid_layout);
+ }
+ }
}
uiLayout *GridViewLayoutBuilder::current_layout() const
More information about the Bf-blender-cvs
mailing list