UI: Increase width of asset shelf popup and clamp by window size

Increasing the width of the popup makes it show more assets on the
screen and reduces the need to scroll in bigger asset libraries. Plus,
in a follow-up commit the size of previews will be increased so that
there's more space to display the full name. Makes sense to increase the
popup size together with that, so a similar amount of assets can remain
visible still.

Increasing the size means it's more likely to overflow the window, so
this also makes sure the popup is clamped nicely by the window size.
This commit is contained in:
Julian Eisel
2024-10-03 19:42:49 +02:00
parent f308e42d56
commit 3355ca3813

View File

@@ -180,18 +180,29 @@ static AssetShelfType *lookup_type_from_idname_in_context(const bContext *C)
}
constexpr int LEFT_COL_WIDTH_UNITS = 10;
constexpr int RIGHT_COL_WIDTH_UNITS = 30;
constexpr int LAYOUT_WIDTH_UNITS = LEFT_COL_WIDTH_UNITS + RIGHT_COL_WIDTH_UNITS;
constexpr int RIGHT_COL_WIDTH_UNITS_DEFAULT = 50;
/**
* Ensure the popover width fits into the window: Clamp width by the window width, minus some
* padding.
*/
static int layout_width_units_clamped(const wmWindow *win)
{
const int max_units_x = (win->sizex / UI_UNIT_X) - 2;
return std::min(LEFT_COL_WIDTH_UNITS + RIGHT_COL_WIDTH_UNITS_DEFAULT, max_units_x);
}
static void popover_panel_draw(const bContext *C, Panel *panel)
{
const wmWindow *win = CTX_wm_window(C);
const int layout_width_units = layout_width_units_clamped(win);
AssetShelfType *shelf_type = lookup_type_from_idname_in_context(C);
BLI_assert_msg(shelf_type != nullptr, "couldn't find asset shelf type from context");
const ARegion *region = CTX_wm_region_popup(C) ? CTX_wm_region_popup(C) : CTX_wm_region(C);
uiLayout *layout = panel->layout;
uiLayoutSetUnitsX(layout, LAYOUT_WIDTH_UNITS);
uiLayoutSetUnitsX(layout, layout_width_units);
AssetShelf *shelf = get_shelf_for_popup(*C, *shelf_type);
if (!shelf) {
@@ -224,7 +235,8 @@ static void popover_panel_draw(const bContext *C, Panel *panel)
ICON_VIEWZOOM);
uiLayout *asset_view_col = uiLayoutColumn(right_col, false);
uiLayoutSetUnitsX(asset_view_col, RIGHT_COL_WIDTH_UNITS);
BLI_assert((layout_width_units - LEFT_COL_WIDTH_UNITS) > 0);
uiLayoutSetUnitsX(asset_view_col, layout_width_units - LEFT_COL_WIDTH_UNITS);
uiLayoutSetFixedSize(asset_view_col, true);
build_asset_view(*asset_view_col, shelf->settings.asset_library_reference, *shelf, *C, *region);