diff options
author | Hans Goudey <h.goudey@me.com> | 2021-08-27 16:27:24 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-08-27 16:27:24 +0300 |
commit | 8b9a3b94fc148d197b137aa892855c60db2783e6 (patch) | |
tree | 0afd1a3538e76a029c0d6365f5bc06d681da92d9 /source/blender/makesdna/DNA_ID.h | |
parent | 3f5e0f7d91e0e13870d98fe721a871e6be210489 (diff) |
Refactor IDProperty UI data storage
The storage of IDProperty UI data (min, max, default value, etc) is
quite complicated. For every property, retrieving a single one of these
values involves three string lookups. First for the "_RNA_UI" group
property, then another for a group with the property's name, then for
the data value name. Not only is this inefficient, it's hard to reason
about, unintuitive, and not at all self-explanatory.
This commit replaces that system with a UI data struct directly in the
IDProperty. If it's not used, the only cost is of a NULL pointer. Beyond
storing the description, name, and RNA subtype, derived structs are used
to store type specific UI data like min and max.
Note that this means that addons using (abusing) the `_RNA_UI` custom
property will have to be changed. A few places in the addons repository
will be changed after this commit with D9919.
**Before**
Before, first the _RNA_UI subgroup is retrieved the _RNA_UI group,
then the subgroup for the original property, then specific UI data
is accessed like any other IDProperty.
```
prop = rna_idprop_ui_prop_get(idproperties_owner, "prop_name", create=True)
prop["min"] = 1.0
```
**After**
After, the `id_properties_ui` function for RNA structs returns a python
object specifically for managing an IDProperty's UI data.
```
ui_data = idproperties_owner.id_properties_ui("prop_name")
ui_data.update(min=1.0)
```
In addition to `update`, there are now other functions:
- `as_dict`: Returns a dictionary of the property's UI data.
- `clear`: Removes the property's UI data.
- `update_from`: Copy UI data between properties,
even if they have different owners.
Differential Revision: https://developer.blender.org/D9697
Diffstat (limited to 'source/blender/makesdna/DNA_ID.h')
-rw-r--r-- | source/blender/makesdna/DNA_ID.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h index 10a5a0f1c47..5b7c99f2545 100644 --- a/source/blender/makesdna/DNA_ID.h +++ b/source/blender/makesdna/DNA_ID.h @@ -59,6 +59,58 @@ typedef struct DrawDataList { struct DrawData *first, *last; } DrawDataList; +typedef struct IDPropertyUIData { + /** Tooltip / property description pointer. Owned by the IDProperty. */ + char *description; + /** RNA subtype, used for every type except string properties (PropertySubType). */ + int rna_subtype; + + char _pad[4]; +} IDPropertyUIData; + +/* IDP_UI_DATA_TYPE_INT */ +typedef struct IDPropertyUIDataInt { + IDPropertyUIData base; + int *default_array; /* Only for array properties. */ + int default_array_len; + char _pad[4]; + + int min; + int max; + int soft_min; + int soft_max; + int step; + int default_value; +} IDPropertyUIDataInt; + +/* IDP_UI_DATA_TYPE_FLOAT */ +typedef struct IDPropertyUIDataFloat { + IDPropertyUIData base; + double *default_array; /* Only for array properties. */ + int default_array_len; + char _pad[4]; + + float step; + int precision; + + double min; + double max; + double soft_min; + double soft_max; + double default_value; +} IDPropertyUIDataFloat; + +/* IDP_UI_DATA_TYPE_STRING */ +typedef struct IDPropertyUIDataString { + IDPropertyUIData base; + char *default_value; +} IDPropertyUIDataString; + +/* IDP_UI_DATA_TYPE_ID */ +typedef struct IDPropertyUIDataID { + IDPropertyUIData base; +} IDPropertyUIDataID; + typedef struct IDPropertyData { void *pointer; ListBase group; @@ -87,6 +139,8 @@ typedef struct IDProperty { /* totallen is total length of allocated array/string, including a buffer. * Note that the buffering is mild; the code comes from python's list implementation. */ int totallen; + + IDPropertyUIData *ui_data; } IDProperty; #define MAX_IDPROP_NAME 64 |