Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-03-25 12:31:06 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-03-25 12:34:47 +0300
commita3e9b61a2f9264213e29fc203408d624e5660b7c (patch)
treed0bbd28da4342fcf16f82c49ea0fbb9f2d5910eb /source/blender/editors/interface
parentd8d06120e4b5888c7a9a30a85565cef6f9d8a759 (diff)
RNA: add UILayout.prop_with_menu function
Matches prop_with_popover, supporting menu types, useful if we want to control behavior of enum switching.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface.c28
-rw-r--r--source/blender/editors/interface/interface_intern.h2
-rw-r--r--source/blender/editors/interface/interface_layout.c26
3 files changed, 54 insertions, 2 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 13796fb84a5..361f2048d58 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -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;
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 62a828660dd..794c6c2568a 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -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 */
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 7e475a3829b..1bb32cdeeee 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.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;