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.
5 changed files with 42 additions and 14 deletions
Showing only changes of commit 2e288dad63 - Show all commits

View File

@ -163,7 +163,8 @@ typedef struct RegionPollParams {
const struct ScrArea *area;
const struct ARegion *region;
/* For now only WM context members here, could add the scene or even #bContext if needed. */
/* Full context, if WM context above is not enough. */
const struct bContext *context;
} RegionPollParams;
typedef struct ARegionType {

View File

@ -17,10 +17,13 @@ struct bContextDataResult;
struct BlendDataReader;
struct BlendWriter;
struct wmWindowManager;
struct RegionPollParams;
/* -------------------------------------------------------------------- */
/* Asset Shelf Regions */
bool ED_asset_shelf_poll(const struct RegionPollParams *params);
/** Only needed for #RGN_TYPE_ASSET_SHELF (not #RGN_TYPE_ASSET_SHELF_FOOTER). */
void ED_asset_shelf_region_listen(const struct wmRegionListenerParams *params);
void ED_asset_shelf_region_draw(const bContext *C, struct ARegion *region);

View File

@ -46,6 +46,26 @@ void send_redraw_notifier(const bContext &C)
/** \name Asset Shelf Regions
* \{ */
static bool asset_shelf_poll(const bContext *C, const SpaceLink *space_link)
{
const SpaceType *space_type = BKE_spacetype_from_id(space_link->spacetype);
/* Is there any asset shelf type registered that returns true for it's poll? */
LISTBASE_FOREACH (AssetShelfType *, shelf_type, &space_type->asset_shelf_types) {
if (shelf_type->poll && shelf_type->poll(C, shelf_type)) {
return true;
}
}
return false;
}
bool ED_asset_shelf_poll(const RegionPollParams *params)
{
return asset_shelf_poll(params->context,
static_cast<SpaceLink *>(params->area->spacedata.first));
}
static void asset_shelf_region_listen(const wmRegionListenerParams *params)
{
ARegion *region = params->region;
@ -83,17 +103,7 @@ void ED_asset_shelf_region_listen(const wmRegionListenerParams *params)
*/
static bool asset_shelf_region_header_type_poll(const bContext *C, HeaderType * /*header_type*/)
{
const SpaceLink *space_link = CTX_wm_space_data(C);
const SpaceType *space_type = BKE_spacetype_from_id(space_link->spacetype);
/* Is there any asset shelf type registered that returns true for it's poll? */
LISTBASE_FOREACH (AssetShelfType *, shelf_type, &space_type->asset_shelf_types) {
if (shelf_type->poll && shelf_type->poll(C, shelf_type)) {
return true;
}
}
return false;
return asset_shelf_poll(C, CTX_wm_space_data(C));
}
void ED_asset_shelf_region_draw(const bContext *C, ARegion *region)

View File

@ -713,7 +713,10 @@ void ED_screens_init(Main *bmain, wmWindowManager *wm)
}
}
static bool region_poll(const bScreen *screen, const ScrArea *area, const ARegion *region)
static bool region_poll(const bContext *C,
const bScreen *screen,
const ScrArea *area,
const ARegion *region)
{
if (!region->type || !region->type->poll) {
/* Show region by default. */
@ -724,20 +727,27 @@ static bool region_poll(const bScreen *screen, const ScrArea *area, const ARegio
params.screen = screen;
params.area = area;
params.region = region;
params.context = C;
return region->type->poll(&params);
}
static void screen_regions_poll(bContext *C, const wmWindow *win, bScreen *screen)
{
ScrArea *prev_area = CTX_wm_area(C);
ARegion *prev_region = CTX_wm_region(C);
bool any_changed = false;
ED_screen_areas_iter (win, screen, area) {
CTX_wm_area_set(C, area);
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
const int old_region_flag = region->flag;
region->flag &= ~RGN_FLAG_POLL_FAILED;
if (region_poll(screen, area, region) == false) {
CTX_wm_region_set(C, region);
if (region_poll(C, screen, area, region) == false) {
region->flag |= RGN_FLAG_POLL_FAILED;
}
@ -754,6 +764,8 @@ static void screen_regions_poll(bContext *C, const wmWindow *win, bScreen *scree
if (any_changed) {
screen->do_refresh = true;
}
CTX_wm_area_set(C, prev_area);
CTX_wm_region_set(C, prev_region);
}
void ED_screen_ensure_updated(bContext *C, wmWindowManager *wm, wmWindow *win, bScreen *screen)

View File

@ -2244,6 +2244,7 @@ void ED_spacetype_view3d()
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_ASSET_SHELF | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES |
ED_KEYMAP_HEADER;
art->listener = ED_asset_shelf_region_listen;
art->poll = ED_asset_shelf_poll;
art->context = view3d_asset_shelf_context;
art->init = view3d_header_region_init;
art->draw = ED_asset_shelf_region_draw;
@ -2256,6 +2257,7 @@ void ED_spacetype_view3d()
art->prefsizey = HEADERY;
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_ASSET_SHELF | ED_KEYMAP_VIEW2D | ED_KEYMAP_FOOTER;
art->init = ED_asset_shelf_footer_region_init;
art->poll = ED_asset_shelf_poll;
art->draw = ED_asset_shelf_footer_region;
art->listener = ED_asset_shelf_footer_region_listen;
art->context = view3d_asset_shelf_context;