From bf6f69399ffd88cd2a0485cf6b8a4eb63912cf4f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 14 Apr 2023 20:11:57 +1000 Subject: [PATCH] RNA: add EnumProperty.enum_items_static_ui to access separators & titles Expose the full enum including separators and section titles, useful for the tool system so it's possible to read separators from brush enums (not part of this commit). --- source/blender/makesrna/intern/rna_rna.c | 42 +++++++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index 4f9cecc307e..ac264687cb4 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -1013,21 +1013,33 @@ static int rna_enum_check_separator(CollectionPropertyIterator *UNUSED(iter), vo return (item->identifier[0] == 0); } -static void rna_EnumProperty_items_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +static void rna_EnumProperty_items_begin_impl(CollectionPropertyIterator *iter, + PointerRNA *ptr, + IteratorSkipFunc skip_fn) { PropertyRNA *prop = (PropertyRNA *)ptr->data; - /* EnumPropertyRNA *eprop; */ /* UNUSED */ + // EnumPropertyRNA *eprop; /* UNUSED */ const EnumPropertyItem *item = NULL; int totitem; bool free; prop = rna_ensure_property(prop); - /* eprop = (EnumPropertyRNA *)prop; */ + // eprop = (EnumPropertyRNA *)prop; RNA_property_enum_items_ex( NULL, ptr, prop, STREQ(iter->prop->identifier, "enum_items_static"), &item, &totitem, &free); - rna_iterator_array_begin( - iter, (void *)item, sizeof(EnumPropertyItem), totitem, free, rna_enum_check_separator); + rna_iterator_array_begin(iter, (void *)item, sizeof(EnumPropertyItem), totitem, free, skip_fn); +} + +static void rna_EnumProperty_items_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + rna_EnumProperty_items_begin_impl(iter, ptr, rna_enum_check_separator); +} + +static void rna_EnumProperty_items_ui_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + /* No skip-funciton, include all "UI" items. */ + rna_EnumProperty_items_begin_impl(iter, ptr, NULL); } static void rna_EnumPropertyItem_identifier_get(PointerRNA *ptr, char *value) @@ -3360,6 +3372,26 @@ static void rna_def_enum_property(BlenderRNA *brna, StructRNA *srna) "Static Items", "Possible values for the property (never calls optional dynamic generation of those)"); + /* Expose a UI version of `enum_items_static` to allow separator & title access, + * needed for the tool-system to access separators from brush enums. */ + prop = RNA_def_property(srna, "enum_items_static_ui", PROP_COLLECTION, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_struct_type(prop, "EnumPropertyItem"); + RNA_def_property_collection_funcs(prop, + "rna_EnumProperty_items_ui_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + NULL, + NULL, + NULL, + NULL); + RNA_def_property_ui_text( + prop, + "Static Items with UI Elements", + "Possible values for the property (never calls optional dynamic generation of those). " + "Includes UI elements (separators and section headings)"); + srna = RNA_def_struct(brna, "EnumPropertyItem", NULL); RNA_def_struct_ui_text( srna, "Enum Item Definition", "Definition of a choice in an RNA enum property");