diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2017-11-23 15:41:07 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2017-11-23 15:54:11 +0300 |
commit | 23d148ecaf923a490c3dd4a22d6dd96ea7cb9654 (patch) | |
tree | cbc096d925f772bd28b21c18766ddf795af78f46 /source/blender/makesrna/intern/rna_access.c | |
parent | 545f671b80f2ad39c8fdee07db3b03119c274187 (diff) |
RNA: Allow structs to define tags for their properties
Adds support for defining a number of tags as part of the rna-struct
definition, which its properties can set similar to property-flags.
BPY supports setting these tags when defining custom properties too.
* To define tags for a struct (which its properties can use then), define the tags in an `EnumPropertyItem` array, and assign them to the struct using `RNA_def_struct_property_tags(...)`.
* To set tags for an RNA-property in C, use the new `RNA_def_property_tags(...)`.
* To set tags for an RNA-property in Python, use the newly added tags parameter. E.g. `bpy.props.FloatProperty(name="Some Float", tags={'SOME_TAG', 'ANOTHER_TAG'})`.
Actual usage of this will be added in a follow-up commit.
Diffstat (limited to 'source/blender/makesrna/intern/rna_access.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index d088a7c23e6..4aebcbb0aaf 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -566,6 +566,11 @@ PropertyRNA *RNA_struct_name_property(const StructRNA *type) return type->nameproperty; } +const EnumPropertyItem *RNA_struct_property_tag_defines(const StructRNA *type) +{ + return type->prop_tag_defines; +} + PropertyRNA *RNA_struct_iterator_property(StructRNA *type) { return type->iteratorproperty; @@ -947,6 +952,17 @@ int RNA_property_flag(PropertyRNA *prop) return rna_ensure_property(prop)->flag; } +/** + * Get the tags set for \a prop as int bitfield. + * \note Doesn't perform any validity check on the set bits. #RNA_def_property_tags does this + * in debug builds (to avoid performance issues in non-debug builds), which should be + * the only way to set tags. Hence, at this point we assume the tag bitfield to be valid. + */ +int RNA_property_tags(PropertyRNA *prop) +{ + return rna_ensure_property(prop)->tags; +} + bool RNA_property_builtin(PropertyRNA *prop) { return (rna_ensure_property(prop)->flag_internal & PROP_INTERN_BUILTIN) != 0; @@ -1613,6 +1629,18 @@ int RNA_enum_from_value(const EnumPropertyItem *item, const int value) return -1; } +unsigned int RNA_enum_items_count(const EnumPropertyItem *item) +{ + unsigned int i = 0; + + while (item->identifier) { + item++; + i++; + } + + return i; +} + bool RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier) { |