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;
|
||||
|
@@ -486,6 +486,7 @@ extern uiButExtraIconType ui_but_icon_extra_get(uiBut *but);
|
||||
extern void ui_but_default_set(struct bContext *C, const bool all, const bool use_afterfunc);
|
||||
|
||||
extern void ui_but_rna_menu_convert_to_panel_type(struct uiBut *but, const char *panel_type);
|
||||
extern void ui_but_rna_menu_convert_to_menu_type(struct uiBut *but, const char *menu_type);
|
||||
extern bool ui_but_menu_draw_as_popover(const uiBut *but);
|
||||
|
||||
extern void ui_but_update(uiBut *but);
|
||||
@@ -787,6 +788,7 @@ void ui_layout_add_but(uiLayout *layout, uiBut *but);
|
||||
void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRNA *searchptr, PropertyRNA *searchprop);
|
||||
void ui_layout_list_set_labels_active(uiLayout *layout);
|
||||
/* menu callback */
|
||||
void ui_item_menutype_func(struct bContext *C, struct uiLayout *layout, void *arg_mt);
|
||||
void ui_item_paneltype_func(struct bContext *C, struct uiLayout *layout, void *arg_pt);
|
||||
|
||||
/* interface_align.c */
|
||||
|
@@ -2017,6 +2017,30 @@ void uiItemFullR_with_popover(
|
||||
}
|
||||
}
|
||||
|
||||
void uiItemFullR_with_menu(
|
||||
uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index, int value, int flag, const char *name, int icon,
|
||||
const char *menu_type)
|
||||
{
|
||||
uiBlock *block = layout->root->block;
|
||||
uiBut *but = block->buttons.last;
|
||||
uiItemFullR(layout, ptr, prop, index, value, flag, name, icon);
|
||||
but = but->next;
|
||||
while (but) {
|
||||
if (but->rnaprop == prop && but->type == UI_BTYPE_MENU) {
|
||||
ui_but_rna_menu_convert_to_menu_type(but, menu_type);
|
||||
break;
|
||||
}
|
||||
but = but->next;
|
||||
}
|
||||
if (but == NULL) {
|
||||
const char *propname = RNA_property_identifier(prop);
|
||||
ui_item_disabled(layout, menu_type);
|
||||
RNA_warning(
|
||||
"property could not use a menu: %s.%s (%s)",
|
||||
RNA_struct_identifier(ptr->type), propname, menu_type);
|
||||
}
|
||||
}
|
||||
|
||||
void uiItemEnumR_prop(uiLayout *layout, const char *name, int icon, struct PointerRNA *ptr, PropertyRNA *prop, int value)
|
||||
{
|
||||
if (RNA_property_type(prop) != PROP_ENUM) {
|
||||
@@ -2318,7 +2342,7 @@ void uiItemPointerR(
|
||||
}
|
||||
|
||||
/* menu item */
|
||||
static void ui_item_menutype_func(bContext *C, uiLayout *layout, void *arg_mt)
|
||||
void ui_item_menutype_func(bContext *C, uiLayout *layout, void *arg_mt)
|
||||
{
|
||||
MenuType *mt = (MenuType *)arg_mt;
|
||||
|
||||
|
Reference in New Issue
Block a user