UI: Region polling support #105088
|
@ -155,6 +155,16 @@ typedef struct wmRegionMessageSubscribeParams {
|
|||
struct ARegion *region;
|
||||
} wmRegionMessageSubscribeParams;
|
||||
|
||||
typedef struct RegionPollParams {
|
||||
/** Context in case non-WM context is needed. Any screen/area/region context should be obtained
|
||||
* using the members below instead (avoids many context queries on redraws). */
|
||||
const struct bContext *context;
|
||||
|
||||
const struct bScreen *screen;
|
||||
const struct ScrArea *area;
|
||||
const struct ARegion *region;
|
||||
} RegionPollParams;
|
||||
|
||||
JulianEisel marked this conversation as resolved
Outdated
Hans Goudey
commented
Outdated
Review
```
/**
* Optional callback to decide whether the region should be treated as existing given the
* current context. When returning false, the region will be kept in storage, but is not
* available to the user in any way. Callbacks can assume that context has the owning area and
* space-data set.
*/
|
||||
typedef struct ARegionType {
|
||||
struct ARegionType *next, *prev;
|
||||
|
||||
|
@ -170,7 +180,7 @@ typedef struct ARegionType {
|
|||
* available to the user in any way. Callbacks can assume that context has the owning area and
|
||||
* space-data set.
|
||||
*/
|
||||
bool (*poll)(const struct bContext *C);
|
||||
bool (*poll)(const RegionPollParams *params);
|
||||
/* draw entirely, view changes should be handled here */
|
||||
void (*draw)(const struct bContext *C, struct ARegion *region);
|
||||
/**
|
||||
|
|
|
@ -713,14 +713,23 @@ void ED_screens_init(Main *bmain, wmWindowManager *wm)
|
|||
}
|
||||
}
|
||||
|
||||
static bool region_poll(const bContext *C, 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. */
|
||||
return true;
|
||||
}
|
||||
|
||||
return region->type->poll(C);
|
||||
RegionPollParams params = {0};
|
||||
params.context = C;
|
||||
params.screen = screen;
|
||||
params.area = area;
|
||||
params.region = region;
|
||||
|
||||
return region->type->poll(¶ms);
|
||||
}
|
||||
|
||||
static void screen_regions_poll(bContext *C, const wmWindow *win, bScreen *screen)
|
||||
|
@ -738,7 +747,7 @@ static void screen_regions_poll(bContext *C, const wmWindow *win, bScreen *scree
|
|||
region->flag &= ~RGN_FLAG_POLL_FAILED;
|
||||
|
||||
CTX_wm_region_set(C, region);
|
||||
if (region_poll(C, region) == false) {
|
||||
if (region_poll(C, screen, area, region) == false) {
|
||||
region->flag |= RGN_FLAG_POLL_FAILED;
|
||||
}
|
||||
|
||||
|
|
|
@ -633,9 +633,9 @@ static void movieclip_main_area_set_view2d(const bContext *C, ARegion *region)
|
|||
region->v2d.cur.ymax /= h;
|
||||
}
|
||||
|
||||
static bool clip_main_region_poll(const bContext *C)
|
||||
static bool clip_main_region_poll(const RegionPollParams *params)
|
||||
{
|
||||
const SpaceClip *sclip = CTX_wm_space_clip(C);
|
||||
const SpaceClip *sclip = static_cast<SpaceClip *>(params->area->spacedata.first);
|
||||
return ELEM(sclip->view, SC_VIEW_CLIP);
|
||||
}
|
||||
|
||||
|
@ -794,9 +794,9 @@ static void clip_main_region_listener(const wmRegionListenerParams *params)
|
|||
|
||||
/****************** preview region ******************/
|
||||
|
||||
static bool clip_preview_region_poll(const bContext *C)
|
||||
static bool clip_preview_region_poll(const RegionPollParams *params)
|
||||
{
|
||||
const SpaceClip *sclip = CTX_wm_space_clip(C);
|
||||
const SpaceClip *sclip = static_cast<SpaceClip *>(params->area->spacedata.first);
|
||||
return ELEM(sclip->view, SC_VIEW_GRAPH, SC_VIEW_DOPESHEET);
|
||||
}
|
||||
|
||||
|
@ -925,9 +925,9 @@ static void clip_preview_region_listener(const wmRegionListenerParams * /*params
|
|||
|
||||
/****************** channels region ******************/
|
||||
|
||||
static bool clip_channels_region_poll(const bContext *C)
|
||||
static bool clip_channels_region_poll(const RegionPollParams *params)
|
||||
{
|
||||
const SpaceClip *sclip = CTX_wm_space_clip(C);
|
||||
const SpaceClip *sclip = static_cast<SpaceClip *>(params->area->spacedata.first);
|
||||
return ELEM(sclip->view, SC_VIEW_DOPESHEET);
|
||||
}
|
||||
|
||||
|
@ -1005,9 +1005,9 @@ static void clip_header_region_listener(const wmRegionListenerParams *params)
|
|||
|
||||
/****************** tools region ******************/
|
||||
|
||||
static bool clip_tools_region_poll(const bContext *C)
|
||||
static bool clip_tools_region_poll(const RegionPollParams *params)
|
||||
{
|
||||
const SpaceClip *sclip = CTX_wm_space_clip(C);
|
||||
const SpaceClip *sclip = static_cast<SpaceClip *>(params->area->spacedata.first);
|
||||
return ELEM(sclip->view, SC_VIEW_CLIP);
|
||||
}
|
||||
|
||||
|
@ -1061,9 +1061,9 @@ static void clip_props_region_listener(const wmRegionListenerParams *params)
|
|||
|
||||
/****************** properties region ******************/
|
||||
|
||||
static bool clip_properties_region_poll(const bContext *C)
|
||||
static bool clip_properties_region_poll(const RegionPollParams *params)
|
||||
{
|
||||
const SpaceClip *sclip = CTX_wm_space_clip(C);
|
||||
const SpaceClip *sclip = static_cast<SpaceClip *>(params->area->spacedata.first);
|
||||
return ELEM(sclip->view, SC_VIEW_CLIP);
|
||||
}
|
||||
|
||||
|
|
|
@ -629,22 +629,22 @@ static void file_keymap(struct wmKeyConfig *keyconf)
|
|||
WM_keymap_ensure(keyconf, "File Browser Buttons", SPACE_FILE, 0);
|
||||
}
|
||||
|
||||
static bool file_ui_region_poll(const bContext *C)
|
||||
static bool file_ui_region_poll(const RegionPollParams *params)
|
||||
{
|
||||
const SpaceFile *sfile = CTX_wm_space_file(C);
|
||||
const SpaceFile *sfile = (SpaceFile *)params->area->spacedata.first;
|
||||
/* Always visible except when browsing assets. */
|
||||
return sfile->browse_mode != FILE_BROWSE_MODE_ASSETS;
|
||||
}
|
||||
|
||||
static bool file_tool_props_region_poll(const bContext *C)
|
||||
static bool file_tool_props_region_poll(const RegionPollParams *params)
|
||||
{
|
||||
const SpaceFile *sfile = CTX_wm_space_file(C);
|
||||
const SpaceFile *sfile = (SpaceFile *)params->area->spacedata.first;
|
||||
return (sfile->browse_mode == FILE_BROWSE_MODE_ASSETS) || (sfile->op != NULL);
|
||||
}
|
||||
|
||||
static bool file_execution_region_poll(const bContext *C)
|
||||
static bool file_execution_region_poll(const RegionPollParams *params)
|
||||
{
|
||||
const SpaceFile *sfile = CTX_wm_space_file(C);
|
||||
const SpaceFile *sfile = (SpaceFile *)params->area->spacedata.first;
|
||||
return sfile->op != NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -440,9 +440,9 @@ static void sequencer_gizmos(void)
|
|||
|
||||
/* *********************** sequencer (main) region ************************ */
|
||||
|
||||
static bool sequencer_main_region_poll(const bContext *C)
|
||||
static bool sequencer_main_region_poll(const RegionPollParams *params)
|
||||
{
|
||||
const SpaceSeq *sseq = CTX_wm_space_seq(C);
|
||||
const SpaceSeq *sseq = (SpaceSeq *)params->area->spacedata.first;
|
||||
return ELEM(sseq->view, SEQ_VIEW_SEQUENCE, SEQ_VIEW_SEQUENCE_PREVIEW);
|
||||
}
|
||||
|
||||
|
@ -700,9 +700,9 @@ static void sequencer_tools_region_draw(const bContext *C, ARegion *region)
|
|||
}
|
||||
/* *********************** preview region ************************ */
|
||||
|
||||
static bool sequencer_preview_region_poll(const bContext *C)
|
||||
static bool sequencer_preview_region_poll(const RegionPollParams *params)
|
||||
{
|
||||
const SpaceSeq *sseq = CTX_wm_space_seq(C);
|
||||
const SpaceSeq *sseq = (SpaceSeq *)params->area->spacedata.first;
|
||||
return ELEM(sseq->view, SEQ_VIEW_PREVIEW, SEQ_VIEW_SEQUENCE_PREVIEW);
|
||||
}
|
||||
|
||||
|
@ -928,9 +928,9 @@ static void sequencer_id_remap(ScrArea *UNUSED(area),
|
|||
|
||||
/* ************************************* */
|
||||
|
||||
static bool sequencer_channel_region_poll(const bContext *C)
|
||||
static bool sequencer_channel_region_poll(const RegionPollParams *params)
|
||||
{
|
||||
const SpaceSeq *sseq = CTX_wm_space_seq(C);
|
||||
const SpaceSeq *sseq = (SpaceSeq *)params->area->spacedata.first;
|
||||
return ELEM(sseq->view, SEQ_VIEW_SEQUENCE);
|
||||
}
|
||||
|
||||
|
|
|
@ -156,10 +156,9 @@ static void userpref_navigation_region_draw(const bContext *C, ARegion *region)
|
|||
ED_region_panels(C, region);
|
||||
}
|
||||
|
||||
static bool userpref_execute_region_poll(const bContext *C)
|
||||
static bool userpref_execute_region_poll(const RegionPollParams *params)
|
||||
{
|
||||
const ScrArea *area = CTX_wm_area(C);
|
||||
const ARegion *region_header = BKE_area_find_region_type(area, RGN_TYPE_HEADER);
|
||||
const ARegion *region_header = BKE_area_find_region_type(params->area, RGN_TYPE_HEADER);
|
||||
return !region_header->visible;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue