diff options
author | Hans Goudey <h.goudey@me.com> | 2020-09-02 22:13:26 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-09-02 22:13:26 +0300 |
commit | ba4a2a4c8b827201b18e97d9dd025ef93a4db754 (patch) | |
tree | a71d6b72aaf0616ebda671bf4b011880b49bb280 /source/blender/makesrna/intern/rna_ui.c | |
parent | ff7d74235023d0c927c0ad3f4d72d1c5dd41b240 (diff) |
UI: Use instanced panel custom data instead of list index
For modifier shortcuts we added a "custom_data" field to panels.
This commit uses the same system for accessing the list data that
corresponds to each panel. This way the context is only used once
and the modifier for each panel can be accessed more easily later.
This ends up being mostly a cleanup commit with a few small changes
in interface_panel.c. The large changes in the UI functions are due
to the fact that the panel custom data is now passed around as a
single pointer instead of being created again for every panel.
The list_index variable in Panel.runtime is removed as it's now
unnecessary.
Differential Revision: https://developer.blender.org/D8559
Diffstat (limited to 'source/blender/makesrna/intern/rna_ui.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_ui.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index 5228f00d0de..8ce6ab957b8 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -405,6 +405,21 @@ static StructRNA *rna_Panel_refine(PointerRNA *ptr) return (menu->type && menu->type->rna_ext.srna) ? menu->type->rna_ext.srna : &RNA_Panel; } +static StructRNA *rna_Panel_custom_data_typef(PointerRNA *ptr) +{ + Panel *panel = (Panel *)ptr->data; + + return UI_panel_custom_data_get(panel)->type; +} + +static PointerRNA rna_Panel_custom_data_get(PointerRNA *ptr) +{ + Panel *panel = (Panel *)ptr->data; + + /* Because the panel custom data is general we can't refine the pointer type here. */ + return *UI_panel_custom_data_get(panel); +} + /* UIList */ static unsigned int rna_UIList_filter_const_FILTER_ITEM_get(PointerRNA *UNUSED(ptr)) { @@ -1347,9 +1362,12 @@ static void rna_def_panel(BlenderRNA *brna) RNA_def_property_string_sdna(prop, NULL, "drawname"); RNA_def_property_ui_text(prop, "Text", "XXX todo"); - prop = RNA_def_int( - srna, "list_panel_index", 0, 0, INT_MAX, "Instanced Panel Data Index", "", 0, INT_MAX); - RNA_def_property_int_sdna(prop, NULL, "runtime.list_index"); + prop = RNA_def_property(srna, "custom_data", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "Constraint"); + RNA_def_property_pointer_sdna(prop, NULL, "runtime.custom_data_ptr"); + RNA_def_property_pointer_funcs( + prop, "rna_Panel_custom_data_get", NULL, "rna_Panel_custom_data_typef", NULL); + RNA_def_property_ui_text(prop, "Custom Data", "Panel Data"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* registration */ |