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:
2019-03-25 20:31:06 +11:00
parent d8d06120e4
commit a3e9b61a2f
5 changed files with 91 additions and 2 deletions

View File

@@ -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;