UI: Move UI_paneltype_draw into layout code

No functional changes, needed for persistent popovers.
This commit is contained in:
Campbell Barton
2018-05-25 12:19:04 +02:00
parent fbc65c6b28
commit e9908134e8
3 changed files with 37 additions and 38 deletions

View File

@@ -429,8 +429,6 @@ void UI_popup_menu_but_set(uiPopupMenu *pup, struct ARegion *butregion, uiBut *b
typedef struct uiPopover uiPopover;
void UI_popover_panel_from_type(
struct bContext *C, struct uiLayout *layout, struct PanelType *pt);
int UI_popover_panel_invoke(
struct bContext *C, int space_id, int region_id, const char *idname,
struct ReportList *reports);
@@ -949,6 +947,7 @@ const char *uiLayoutIntrospect(uiLayout *layout); // XXX - testing
struct MenuType *UI_but_menutype_get(uiBut *but);
struct PanelType *UI_but_paneltype_get(uiBut *but);
void UI_menutype_draw(struct bContext *C, struct MenuType *mt, struct uiLayout *layout);
void UI_paneltype_draw(struct bContext *C, struct PanelType *pt, struct uiLayout *layout);
/* Only for convenience. */
void uiLayoutSetContextFromBut(uiLayout *layout, uiBut *but);

View File

@@ -1851,16 +1851,7 @@ static void ui_item_menutype_func(bContext *C, uiLayout *layout, void *arg_mt)
static void ui_item_paneltype_func(bContext *C, uiLayout *layout, void *arg_pt)
{
PanelType *pt = (PanelType *)arg_pt;
if (layout->context) {
CTX_store_set(C, layout->context);
}
UI_popover_panel_from_type(C, layout, pt);
if (layout->context) {
CTX_store_set(C, NULL);
}
UI_paneltype_draw(C, pt, layout);
}
static uiBut *ui_item_menu(
@@ -3740,3 +3731,32 @@ void UI_menutype_draw(bContext *C, MenuType *mt, struct uiLayout *layout)
CTX_store_set(C, NULL);
}
}
/**
* Used for popup panels only.
*/
void UI_paneltype_draw(bContext *C, PanelType *pt, uiLayout *layout)
{
Panel *panel = MEM_callocN(sizeof(Panel), "popover panel");
panel->type = pt;
if (layout->context) {
CTX_store_set(C, layout->context);
}
if (pt->draw_header) {
panel->layout = uiLayoutRow(layout, false);
pt->draw_header(C, panel);
panel->layout = NULL;
}
panel->layout = layout;
pt->draw(C, panel);
panel->layout = NULL;
if (layout->context) {
CTX_store_set(C, NULL);
}
MEM_freeN(panel);
}

View File

@@ -257,25 +257,6 @@ uiPopupBlockHandle *ui_popover_panel_create(
* \{ */
void UI_popover_panel_from_type(bContext *C, uiLayout *layout, PanelType *pt)
{
/* TODO: move into UI_paneltype_draw */
Panel *panel = MEM_callocN(sizeof(Panel), "popover panel");
panel->type = pt;
if (pt->draw_header) {
panel->layout = uiLayoutRow(layout, false);
pt->draw_header(C, panel);
panel->layout = NULL;
}
panel->layout = layout;
pt->draw(C, panel);
panel->layout = NULL;
MEM_freeN(panel);
}
int UI_popover_panel_invoke(
bContext *C, int space_id, int region_id, const char *idname,
@@ -296,13 +277,12 @@ int UI_popover_panel_invoke(
return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
}
uiPopover *pup = UI_popover_begin(C);
layout = UI_popover_layout(pup);
UI_popover_panel_from_type(C, layout, pt);
UI_popover_end(C, pup, NULL);
{
uiPopover *pup = UI_popover_begin(C);
layout = UI_popover_layout(pup);
UI_paneltype_draw(C, pt, layout);
UI_popover_end(C, pup, NULL);
}
return OPERATOR_INTERFACE;
}