diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-25 10:55:38 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-25 11:05:13 +0300 |
commit | e5836423127e4c10c2f01657ee0976d49582fd33 (patch) | |
tree | a078ccebdb444a3d00d0554535c205bdf4116ca0 /source/blender/makesrna/intern/rna_ui_api.c | |
parent | ca0cc0518f23ad0fa8c0a3c3614d6a469f4af20e (diff) |
UI: add UILayout.prop_popover_enum function
Support for RNA enum buttons that activate popovers when clicked.
This means we get useful tooltips, shortcuts and Ctrl-Wheel cycling
over enum items.
It also avoids inconvenient & slow access of enum values currently done
via RNA type lookups on the type to get the name & icon to use for a
regular popover button.
Resolves T57738
Diffstat (limited to 'source/blender/makesrna/intern/rna_ui_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_ui_api.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c index 151b0b9b5be..afcff93738a 100644 --- a/source/blender/makesrna/intern/rna_ui_api.c +++ b/source/blender/makesrna/intern/rna_ui_api.c @@ -133,6 +133,28 @@ static void rna_uiItemMenuEnumR( uiItemMenuEnumR_prop(layout, ptr, prop, name, icon); } +static void rna_uiItemPopoverPanelEnumR( + uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *name, + const char *text_ctxt, bool translate, int icon, + const char *panel_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; + + /* Get translated name (label). */ + name = rna_translate_ui_text(name, text_ctxt, NULL, prop, translate); + uiItemFullR_with_popover(layout, ptr, prop, -1, 0, flag, name, icon, panel_type); +} + static void rna_uiItemTabsEnumR( uiLayout *layout, bContext *C, struct PointerRNA *ptr, const char *propname, @@ -639,6 +661,12 @@ void RNA_api_ui_layout(StructRNA *srna) api_ui_item_rna_common(func); api_ui_item_common(func); + func = RNA_def_function(srna, "prop_popover_enum", "rna_uiItemPopoverPanelEnumR"); + api_ui_item_rna_common(func); + api_ui_item_common(func); + 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_tabs_enum", "rna_uiItemTabsEnumR"); RNA_def_function_flag(func, FUNC_USE_CONTEXT); api_ui_item_rna_common(func); |