UI: use draw_header function for popover buttons
Add 'is_popover' for panel draw functions to check if they're in a popup. This puts dyntopo toggle next to the popover.
This commit is contained in:
parent
ec8a20fec0
commit
7fdde7fd86
|
@ -883,12 +883,13 @@ class VIEW3D_PT_sculpt_dyntopo(Panel, View3DPaintPanel):
|
|||
return (context.sculpt_object and context.tool_settings.sculpt)
|
||||
|
||||
def draw_header(self, context):
|
||||
is_popover = self.is_popover
|
||||
layout = self.layout
|
||||
layout.operator(
|
||||
"sculpt.dynamic_topology_toggle",
|
||||
icon='CHECKBOX_HLT' if context.sculpt_object.use_dynamic_topology_sculpting else 'CHECKBOX_DEHLT',
|
||||
text="",
|
||||
emboss=False,
|
||||
emboss=is_popover,
|
||||
)
|
||||
|
||||
def draw(self, context):
|
||||
|
|
|
@ -2044,12 +2044,23 @@ void uiItemPopoverPanel_ptr(uiLayout *layout, bContext *C, PanelType *pt, const
|
|||
name = CTX_IFACE_(pt->translation_context, pt->label);
|
||||
}
|
||||
|
||||
if (layout->root->type == UI_LAYOUT_MENU && !icon)
|
||||
if (layout->root->type == UI_LAYOUT_MENU && !icon) {
|
||||
icon = ICON_BLANK1;
|
||||
}
|
||||
|
||||
const bool ok = (pt->poll == NULL) || pt->poll(C, pt);
|
||||
if (ok && (pt->draw_header != NULL)) {
|
||||
layout = uiLayoutRow(layout, true);
|
||||
Panel panel = {
|
||||
.type = pt,
|
||||
.layout = layout,
|
||||
.flag = PNL_POPOVER,
|
||||
};
|
||||
pt->draw_header(C, &panel);
|
||||
}
|
||||
uiBut *but = ui_item_menu(layout, name, icon, ui_item_paneltype_func, pt, NULL, NULL, true);
|
||||
but->type = UI_BTYPE_POPOVER;
|
||||
if (pt->poll && (pt->poll(C, pt) == false)) {
|
||||
if (!ok) {
|
||||
but->flag |= UI_BUT_DISABLED;
|
||||
}
|
||||
}
|
||||
|
@ -4236,14 +4247,19 @@ void UI_menutype_draw(bContext *C, MenuType *mt, struct uiLayout *layout)
|
|||
}
|
||||
|
||||
|
||||
static void ui_paneltype_draw_impl(bContext *C, PanelType *pt, uiLayout *layout)
|
||||
static void ui_paneltype_draw_impl(
|
||||
bContext *C, PanelType *pt, uiLayout *layout, bool show_header)
|
||||
{
|
||||
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->flag = PNL_POPOVER;
|
||||
|
||||
if (show_header) {
|
||||
if (pt->draw_header) {
|
||||
panel->layout = uiLayoutRow(layout, false);
|
||||
pt->draw_header(C, panel);
|
||||
panel->layout = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
panel->layout = layout;
|
||||
|
@ -4261,7 +4277,7 @@ static void ui_paneltype_draw_impl(bContext *C, PanelType *pt, uiLayout *layout)
|
|||
if (pt_iter->poll == NULL || pt_iter->poll(C, pt_iter)) {
|
||||
uiItemS(layout);
|
||||
uiItemL(layout, pt_iter->label, ICON_NONE);
|
||||
ui_paneltype_draw_impl(C, pt_iter, layout);
|
||||
ui_paneltype_draw_impl(C, pt_iter, layout, true);
|
||||
}
|
||||
}
|
||||
} while ((pt_iter = pt_iter->next));
|
||||
|
@ -4276,7 +4292,7 @@ void UI_paneltype_draw(bContext *C, PanelType *pt, uiLayout *layout)
|
|||
CTX_store_set(C, layout->context);
|
||||
}
|
||||
|
||||
ui_paneltype_draw_impl(C, pt, layout);
|
||||
ui_paneltype_draw_impl(C, pt, layout, false);
|
||||
|
||||
if (layout->context) {
|
||||
CTX_store_set(C, NULL);
|
||||
|
|
|
@ -390,6 +390,7 @@ enum {
|
|||
/*PNL_TABBED = (1 << 3), */ /*UNUSED*/
|
||||
PNL_OVERLAP = (1 << 4),
|
||||
PNL_PIN = (1 << 5),
|
||||
PNL_POPOVER = (1 << 6),
|
||||
};
|
||||
|
||||
/* Panel->snap - for snapping to screen edges */
|
||||
|
|
|
@ -1132,6 +1132,11 @@ static void rna_def_panel(BlenderRNA *brna)
|
|||
RNA_def_property_ui_text(prop, "Pin", "");
|
||||
/* XXX, should only tag region for redraw */
|
||||
RNA_def_property_update(prop, NC_WINDOW, NULL);
|
||||
|
||||
prop = RNA_def_property(srna, "is_popover", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", PNL_POPOVER);
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_ui_text(prop, "Popover", "");
|
||||
}
|
||||
|
||||
static void rna_def_uilist(BlenderRNA *brna)
|
||||
|
|
Loading…
Reference in New Issue