UI: Asset Shelf (Experimental Feature) #104831

Closed
Julian Eisel wants to merge 399 commits from asset-shelf into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
7 changed files with 50 additions and 44 deletions
Showing only changes of commit 157cc9b171 - Show all commits

View File

@ -258,7 +258,7 @@ typedef struct PanelType {
char idname[BKE_ST_MAXNAME]; /* unique name */
char label[BKE_ST_MAXNAME]; /* for panel header */
char *description; /* for panel tooltip */
const char *description; /* for panel tooltip */
char translation_context[BKE_ST_MAXNAME];
char context[BKE_ST_MAXNAME]; /* for buttons window */
char category[BKE_ST_MAXNAME]; /* for category tabs */

View File

@ -41,9 +41,7 @@ void ED_asset_shelf_footer_region_init(struct wmWindowManager *wm, struct ARegio
void ED_asset_shelf_footer_region(const struct bContext *C, struct ARegion *region);
void ED_asset_shelf_footer_region_listen(const struct wmRegionListenerParams *params);
int ED_asset_shelf_footer_size(void);
void ED_asset_shelf_footer_register(struct ARegionType *region_type,
const char *idname,
const int space_type);
void ED_asset_shelf_footer_register(struct ARegionType *region_type, const int space_type);
/* -------------------------------------------------------------------- */
/* Asset Shelf Settings */

View File

@ -419,16 +419,10 @@ static void asset_shelf_footer_draw(const bContext *C, Header *header)
const AssetLibraryReference *library_ref = CTX_wm_asset_library_ref(C);
ED_assetlist_storage_fetch(library_ref, C);
uiDefIconBlockBut(block,
shelf::catalog_selector_block_draw,
nullptr,
0,
ICON_RIGHTARROW,
0,
0,
UI_UNIT_X * 1.5f,
UI_UNIT_Y,
TIP_("Select catalogs to display"));
UI_block_emboss_set(block, UI_EMBOSS_NONE);
uiItemPopoverPanel(layout, C, "ASSETSHELF_PT_catalog_selector", "", ICON_COLLAPSEMENU);
UI_block_emboss_set(block, UI_EMBOSS);
uiItemS(layout);
@ -442,17 +436,17 @@ static void asset_shelf_footer_draw(const bContext *C, Header *header)
uiItemPopoverPanel(layout, C, "ASSETSHELF_PT_display", "", ICON_IMGDISPLAY);
}
void ED_asset_shelf_footer_register(ARegionType *region_type,
const char *idname,
const int space_type)
void ED_asset_shelf_footer_register(ARegionType *region_type, const int space_type)
{
HeaderType *ht = MEM_cnew<HeaderType>(__func__);
strcpy(ht->idname, idname);
STRNCPY(ht->idname, "ASSETSHELF_HT_footer");
JulianEisel marked this conversation as resolved Outdated

Don't abbreviate things in the public API like this, ref -> reference.

Don't abbreviate things in the public API like this, ref -> reference.

We already use "asset_library_ref" in a number of other places in the API. Noted in #102877 as potential 4.0 change.

We already use `"asset_library_ref"` in a number of other places in the API. Noted in #102877 as potential 4.0 change.

Ok, I would not break API compatibility over something minor like this.

Ok, I would not break API compatibility over something minor like this.
ht->space_type = space_type;
ht->region_type = RGN_TYPE_ASSET_SHELF_FOOTER;
ht->draw = asset_shelf_footer_draw;
ht->poll = asset_shelf_region_header_type_poll;
BLI_addtail(&region_type->headertypes, ht);
shelf::catalog_selector_panel_register(region_type);
}
/** \} */

View File

@ -27,7 +27,7 @@ void build_asset_view(uiLayout &layout,
const bContext &C,
ARegion &region);
uiBlock *catalog_selector_block_draw(bContext *C, ARegion *region, void * /*arg1*/);
void catalog_selector_panel_register(struct ARegionType *region_type);
AssetShelfSettings *settings_from_context(const bContext *C);

View File

@ -10,7 +10,10 @@
#include "AS_asset_catalog_tree.hh"
#include "AS_asset_library.hh"
#include "DNA_screen_types.h"
#include "BKE_context.h"
#include "BKE_screen.h"
#include "BLT_translation.h"
@ -20,6 +23,8 @@
#include "UI_interface.hh"
#include "UI_tree_view.hh"
#include "WM_api.h"
#include "asset_shelf.hh"
using namespace blender;
@ -137,30 +142,17 @@ void AssetCatalogSelectorTree::update_shelf_settings_from_enabled_catalogs()
});
}
uiBlock *catalog_selector_block_draw(bContext *C, ARegion *region, void * /*arg1*/)
static void catalog_selector_panel_draw(const bContext *C, Panel *panel)
{
const AssetLibraryReference *library_ref = CTX_wm_asset_library_ref(C);
asset_system::AssetLibrary *library = ED_assetlist_library_get_once_available(*library_ref);
AssetShelfSettings *shelf_settings = settings_from_context(C);
uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS);
UI_block_flag_enable(block,
UI_BLOCK_KEEP_OPEN | UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_POPUP_CAN_REFRESH);
uiLayout *layout = UI_block_layout(block,
UI_LAYOUT_VERTICAL,
UI_LAYOUT_PANEL,
0,
0,
UI_UNIT_X * 12,
UI_UNIT_Y,
0,
UI_style_get());
uiItemL(layout, "Enable Catalogs", ICON_NONE);
uiItemS(layout);
uiLayout *layout = panel->layout;
uiBlock *block = uiLayoutGetBlock(layout);
uiLayoutSetEmboss(layout, UI_EMBOSS_NONE);
if (library && shelf_settings) {
ui::AbstractTreeView *tree_view = UI_block_add_view(
*block,
@ -169,11 +161,24 @@ uiBlock *catalog_selector_block_draw(bContext *C, ARegion *region, void * /*arg1
ui::TreeViewBuilder::build_tree_view(*tree_view, *layout);
}
}
UI_block_bounds_set_normal(block, 0.3f * U.widget_unit);
UI_block_direction_set(block, UI_DIR_UP);
void catalog_selector_panel_register(ARegionType *region_type)
{
/* Uses global paneltype registry to allow usage as popover. So only register this once (may be
* called from multiple spaces). */
if (WM_paneltype_find("ASSETSHELF_PT_catalog_selector", true)) {
return;
}
return block;
PanelType *pt = MEM_cnew<PanelType>(__func__);
STRNCPY(pt->idname, "ASSETSHELF_PT_catalog_selector");
STRNCPY(pt->label, N_("Catalog Selector"));
STRNCPY(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
pt->description = N_("Select catalogs to display in the asset shelf");
pt->draw = catalog_selector_panel_draw;
BLI_addtail(&region_type->paneltypes, pt);
WM_paneltype_add(pt);
}
} // namespace blender::ed::asset::shelf

View File

@ -74,13 +74,23 @@ struct uiPopover {
#endif
};
static void ui_popover_create_block(bContext *C, uiPopover *pup, wmOperatorCallContext opcontext)
/**
* \param region: Optional, the region the block will be placed in. Must be set if the popover is
* supposed to support refreshing.
*/
static void ui_popover_create_block(bContext *C,
ARegion *region,
uiPopover *pup,
wmOperatorCallContext opcontext)
{
BLI_assert(pup->ui_size_x != 0);
const uiStyle *style = UI_style_get_dpi();
pup->block = UI_block_begin(C, nullptr, __func__, UI_EMBOSS);
if (region) {
UI_block_region_set(pup->block, region);
}
UI_block_flag_enable(pup->block, UI_BLOCK_KEEP_OPEN | UI_BLOCK_POPOVER);
#ifdef USE_UI_POPOVER_ONCE
if (pup->is_once) {
@ -108,7 +118,7 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v
/* Create UI block and layout now if it wasn't done between begin/end. */
if (!pup->layout) {
ui_popover_create_block(C, pup, WM_OP_INVOKE_REGION_WIN);
ui_popover_create_block(C, handle->region, pup, WM_OP_INVOKE_REGION_WIN);
if (pup->menu_func) {
pup->block->handle = handle;
@ -123,7 +133,6 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v
uiBlock *block = pup->block;
int width, height;
UI_block_region_set(block, handle->region);
UI_block_layout_resolve(block, &width, &height);
UI_block_direction_set(block, UI_DIR_DOWN | UI_DIR_CENTER_X);
@ -347,7 +356,7 @@ uiPopover *UI_popover_begin(bContext *C, int ui_menu_width, bool from_active_but
pup->butregion = butregion;
/* Operator context default same as menus, change if needed. */
ui_popover_create_block(C, pup, WM_OP_EXEC_REGION_WIN);
ui_popover_create_block(C, nullptr, pup, WM_OP_EXEC_REGION_WIN);
/* create in advance so we can let buttons point to retval already */
pup->block->handle = MEM_cnew<uiPopupBlockHandle>(__func__);

View File

@ -2277,7 +2277,7 @@ void ED_spacetype_view3d()
art->listener = ED_asset_shelf_footer_region_listen;
art->context = view3d_asset_shelf_context;
BLI_addhead(&st->regiontypes, art);
ED_asset_shelf_footer_register(art, "VIEW3D_HT_asset_shelf_footer", SPACE_VIEW3D);
ED_asset_shelf_footer_register(art, SPACE_VIEW3D);
/* regions: hud */
art = ED_area_type_hud(st->spaceid);