RNA: add UILayout.prop_with_menu function
Matches prop_with_popover, supporting menu types, useful if we want to control behavior of enum switching.
This commit is contained in:
@@ -86,6 +86,7 @@
|
||||
static void ui_but_to_pixelrect(struct rcti *rect, const struct ARegion *ar, struct uiBlock *block, struct uiBut *but);
|
||||
static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *but_p);
|
||||
static void ui_def_but_rna__panel_type(bContext *UNUSED(C), uiLayout *layout, void *but_p);
|
||||
static void ui_def_but_rna__menu_type(bContext *UNUSED(C), uiLayout *layout, void *but_p);
|
||||
|
||||
/* avoid unneeded calls to ui_but_value_get */
|
||||
#define UI_BUT_VALUE_UNSET DBL_MAX
|
||||
@@ -1152,7 +1153,8 @@ static bool ui_but_event_property_operator_string(
|
||||
(RNA_property_type(but_parent->rnaprop) == PROP_ENUM) &&
|
||||
ELEM(but_parent->menu_create_func,
|
||||
ui_def_but_rna__menu,
|
||||
ui_def_but_rna__panel_type))
|
||||
ui_def_but_rna__panel_type,
|
||||
ui_def_but_rna__menu_type))
|
||||
{
|
||||
prop_enum_value = (int)but->hardmin;
|
||||
ptr = &but_parent->rnapoin;
|
||||
@@ -3863,6 +3865,30 @@ bool ui_but_menu_draw_as_popover(const uiBut *but)
|
||||
return (but->menu_create_func == ui_def_but_rna__panel_type);
|
||||
}
|
||||
|
||||
static void ui_def_but_rna__menu_type(bContext *C, uiLayout *layout, void *but_p)
|
||||
{
|
||||
uiBut *but = but_p;
|
||||
const char *menu_type = but->func_argN;
|
||||
MenuType *mt = WM_menutype_find(menu_type, true);
|
||||
if (mt) {
|
||||
ui_item_menutype_func(C, layout, mt);
|
||||
}
|
||||
else {
|
||||
char msg[256];
|
||||
SNPRINTF(msg, "Missing Menu: %s", menu_type);
|
||||
uiItemL(layout, msg, ICON_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
void ui_but_rna_menu_convert_to_menu_type(uiBut *but, const char *menu_type)
|
||||
{
|
||||
BLI_assert(but->type == UI_BTYPE_MENU);
|
||||
BLI_assert(but->menu_create_func == ui_def_but_rna__menu);
|
||||
BLI_assert((void *)but->poin == but);
|
||||
but->menu_create_func = ui_def_but_rna__menu_type;
|
||||
but->func_argN = BLI_strdup(menu_type);
|
||||
}
|
||||
|
||||
static void ui_but_submenu_enable(uiBlock *block, uiBut *but)
|
||||
{
|
||||
but->flag |= UI_BUT_ICON_SUBMENU;
|
||||
|
Reference in New Issue
Block a user