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/interface.c
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/interface.c')
-rw-r--r--source/blender/editors/interface/interface.c28
1 files changed, 27 insertions, 1 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;