UI: Asset Shelf (Experimental Feature) #104831
|
@ -219,35 +219,56 @@ AssetShelfSettings *settings_from_context(const bContext *C)
|
|||
/** \name Catalog toggle buttons
|
||||
* \{ */
|
||||
|
||||
static uiBut *add_tab_button(uiBlock &block, StringRefNull name)
|
||||
{
|
||||
const uiStyle *style = UI_style_get_dpi();
|
||||
const int string_width = UI_fontstyle_string_width(&style->widget, name.c_str());
|
||||
const int pad_x = UI_UNIT_X * 0.3f;
|
||||
const int but_width = std::min(string_width + 2 * pad_x, UI_UNIT_X * 8);
|
||||
|
||||
uiBut *but = uiDefBut(&block,
|
||||
UI_BTYPE_TAB,
|
||||
0,
|
||||
name.c_str(),
|
||||
0,
|
||||
0,
|
||||
but_width,
|
||||
UI_UNIT_Y,
|
||||
nullptr,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"Enable catalog, making contained assets visible in the asset shelf");
|
||||
|
||||
UI_but_drawflag_enable(but, UI_BUT_ALIGN_TOP);
|
||||
|
||||
return but;
|
||||
}
|
||||
|
||||
static void add_catalog_toggle_buttons(AssetShelfSettings &shelf_settings, uiLayout &layout)
|
||||
{
|
||||
uiBlock *block = uiLayoutGetBlock(&layout);
|
||||
const uiStyle *style = UI_style_get_dpi();
|
||||
|
||||
/* "All" tab. */
|
||||
{
|
||||
uiBut *but = add_tab_button(*block, IFACE_("All"));
|
||||
UI_but_func_set(but, [&shelf_settings](bContext &C) {
|
||||
shelf::settings_set_all_catalog_active(shelf_settings);
|
||||
shelf::send_redraw_notifier(C);
|
||||
});
|
||||
UI_but_func_pushed_state_set(but, [&shelf_settings](const uiBut &) -> bool {
|
||||
return shelf::settings_is_all_catalog_active(shelf_settings);
|
||||
});
|
||||
}
|
||||
|
||||
uiItemS(&layout);
|
||||
|
||||
/* Regular catalog tabs. */
|
||||
shelf::settings_foreach_enabled_catalog_path(
|
||||
shelf_settings, [&shelf_settings, block, style](const asset_system::AssetCatalogPath &path) {
|
||||
const char *name = path.name().c_str();
|
||||
const int string_width = UI_fontstyle_string_width(&style->widget, name);
|
||||
const int pad_x = UI_UNIT_X * 0.3f;
|
||||
const int but_width = std::min(string_width + 2 * pad_x, UI_UNIT_X * 8);
|
||||
shelf_settings, [&shelf_settings, block](const asset_system::AssetCatalogPath &path) {
|
||||
uiBut *but = add_tab_button(*block, path.name());
|
||||
|
||||
uiBut *but = uiDefBut(
|
||||
block,
|
||||
UI_BTYPE_TAB,
|
||||
0,
|
||||
name,
|
||||
0,
|
||||
0,
|
||||
but_width,
|
||||
UI_UNIT_Y,
|
||||
nullptr,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"Enable catalog, making contained assets visible in the asset shelf");
|
||||
|
||||
UI_but_drawflag_enable(but, UI_BUT_ALIGN_TOP);
|
||||
UI_but_func_set(but, [&shelf_settings, path](bContext &C) {
|
||||
shelf::settings_set_active_catalog(shelf_settings, path);
|
||||
shelf::send_redraw_notifier(C);
|
||||
|
|
|
@ -28,8 +28,10 @@ void send_redraw_notifier(const bContext &C);
|
|||
void settings_clear_enabled_catalogs(AssetShelfSettings &shelf_settings);
|
||||
void settings_set_active_catalog(AssetShelfSettings &shelf_settings,
|
||||
const asset_system::AssetCatalogPath &path);
|
||||
void settings_set_all_catalog_active(AssetShelfSettings &shelf_settings);
|
||||
bool settings_is_active_catalog(const AssetShelfSettings &shelf_settings,
|
||||
const asset_system::AssetCatalogPath &path);
|
||||
bool settings_is_all_catalog_active(const AssetShelfSettings &shelf_settings);
|
||||
bool settings_is_catalog_path_enabled(const AssetShelfSettings &shelf_settings,
|
||||
const asset_system::AssetCatalogPath &path);
|
||||
void settings_set_catalog_path_enabled(AssetShelfSettings &shelf_settings,
|
||||
|
|
|
@ -98,12 +98,23 @@ void settings_set_active_catalog(AssetShelfSettings &shelf_settings,
|
|||
shelf_settings.active_catalog_path = BLI_strdupn(path.c_str(), path.length());
|
||||
}
|
||||
|
||||
void settings_set_all_catalog_active(AssetShelfSettings &shelf_settings)
|
||||
{
|
||||
MEM_delete(shelf_settings.active_catalog_path);
|
||||
shelf_settings.active_catalog_path = nullptr;
|
||||
}
|
||||
|
||||
bool settings_is_active_catalog(const AssetShelfSettings &shelf_settings,
|
||||
const asset_system::AssetCatalogPath &path)
|
||||
{
|
||||
return shelf_settings.active_catalog_path && shelf_settings.active_catalog_path == path.str();
|
||||
}
|
||||
|
||||
bool settings_is_all_catalog_active(const AssetShelfSettings &shelf_settings)
|
||||
{
|
||||
return !shelf_settings.active_catalog_path || !shelf_settings.active_catalog_path[0];
|
||||
}
|
||||
|
||||
bool settings_is_catalog_path_enabled(const AssetShelfSettings &shelf_settings,
|
||||
const asset_system::AssetCatalogPath &path)
|
||||
{
|
||||
|
|
|
@ -763,6 +763,7 @@ enum {
|
|||
typedef struct AssetShelfSettings {
|
||||
/* TODO make this per mode? (or use a custom identifier?) */
|
||||
ListBase enabled_catalog_paths; /* #LinkData */
|
||||
/** If not set (null or empty string), all assets will be displayed ("All" catalog behavior). */
|
||||
const char *active_catalog_path;
|
||||
} AssetShelfSettings;
|
||||
|
||||
|
|
Loading…
Reference in New Issue