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/makesrna/intern/rna_ui_api.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/makesrna/intern/rna_ui_api.c')
-rw-r--r--source/blender/makesrna/intern/rna_ui_api.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c
index 02c32c5d3b8..e6c1038c48d 100644
--- a/source/blender/makesrna/intern/rna_ui_api.c
+++ b/source/blender/makesrna/intern/rna_ui_api.c
@@ -142,6 +142,32 @@ static void rna_uiItemR_with_popover(
uiItemFullR_with_popover(layout, ptr, prop, -1, 0, flag, name, icon, panel_type);
}
+static void rna_uiItemR_with_menu(
+ uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *name,
+ const char *text_ctxt, bool translate, int icon,
+ bool icon_only,
+ const char *menu_type)
+{
+ PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
+
+ if (!prop) {
+ RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
+ return;
+ }
+ if (RNA_property_type(prop) != PROP_ENUM) {
+ RNA_warning("property is not an enum: %s.%s", RNA_struct_identifier(ptr->type), propname);
+ return;
+ }
+ int flag = 0;
+
+ flag |= (icon_only) ? UI_ITEM_R_ICON_ONLY : 0;
+
+ /* Get translated name (label). */
+ name = rna_translate_ui_text(name, text_ctxt, NULL, prop, translate);
+ uiItemFullR_with_menu(layout, ptr, prop, -1, 0, flag, name, icon, menu_type);
+}
+
+
static void rna_uiItemMenuEnumR(
uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *name,
const char *text_ctxt, bool translate, int icon)
@@ -671,6 +697,13 @@ void RNA_api_ui_layout(StructRNA *srna)
parm = RNA_def_string(func, "panel", NULL, 0, "", "Identifier of the panel");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ func = RNA_def_function(srna, "prop_with_menu", "rna_uiItemR_with_menu");
+ api_ui_item_rna_common(func);
+ api_ui_item_common(func);
+ RNA_def_boolean(func, "icon_only", false, "", "Draw only icons in tabs, no text");
+ parm = RNA_def_string(func, "menu", NULL, 0, "", "Identifier of the menu");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
func = RNA_def_function(srna, "prop_tabs_enum", "rna_uiItemTabsEnumR");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
api_ui_item_rna_common(func);