The Change
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.
| Before | After |
Note that this means that addons using (abusing) the _RNA_UI custom
property will have to be changed. I made the few changes required to the
addon directory in D9919 (which I will update again if this patch is reviewed).
The New API
Before
# Find the special "UI data" IDProperty group and create a new subgroup for a property. prop = rna_idprop_ui_prop_get(idproperties_owner, "prop_name", create=True) # Use more IDProperties to set some UI data values. prop["min"] = 1.0
After
# Retrieve the UI data manager for the property.
ui_data = idproperties_owner.id_properties_ui("prop_name")
# Update some UI data values.
ui_data.update(min=1.0)In addition to update, there are now other helper function for accessing the UI data:
- as_dict: Returns a dictionary of a property's UI data.
- clear: Removes a property's UI data.
- update_from: Copy UI data between properties, even if they have different owners
Motivations
I made a post about this on devtalk. The original impetus for these changes came
from implementing the IDProperty creation for the nodes modifier. Doing that I got
frustrated enough that I was motivated to make a system that made more sense in my free time.
This should also make it easier to add new IDProperty types in the future, since their UI
data is clearly separated (boolean properties for example).

