diff options
author | Julian Eisel <julian@blender.org> | 2021-07-14 17:01:53 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-07-15 17:12:36 +0300 |
commit | 788d38046032736531cb77507e397cbea7993549 (patch) | |
tree | f13c551bb2f95a0b3b7481d4b8dc211b20e106cf /source/blender/makesrna/intern | |
parent | 6e01b52100f3f9674c49127cbcc445e7e5c987d2 (diff) |
UI: UI list refactor & preparations for asset view template
This is more of a first-pass refactor for the UI list template. More
improvements could be done, but that's better done separately. Main
purpose of this is to make the UI list code more manageable and ready
for the asset view template.
No functional changes for users.
* Split the huge template function into more manageable functions, with
clear names and a few structs with high coherency.
* Move runtime data management to the template code, with a free
callback called from BKE. This is UI data and should be managed at
that level.
* Replace boolean arguments with bit-flags (easily extendable and more
readable from the caller).
* Allow passing custom-data to the UI list for callbacks to access.
* Make list grip button for resizing optional.
* Put logic for generating the internal UI list identifier (stored in
.blends) into function. This is a quite important bit and a later
commit adds a related function. Good to have a clear API for this.
* Improve naming, comments, etc.
As part of further cleanups I'd like to move this to an own file.
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/rna_ui_api.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c index aa235b599b7..4b8938053ba 100644 --- a/source/blender/makesrna/intern/rna_ui_api.c +++ b/source/blender/makesrna/intern/rna_ui_api.c @@ -525,6 +525,46 @@ static void rna_uiTemplateAnyID(uiLayout *layout, uiTemplateAnyID(layout, ptr, propname, proptypename, name); } +void rna_uiTemplateList(uiLayout *layout, + struct bContext *C, + const char *listtype_name, + const char *list_id, + struct PointerRNA *dataptr, + const char *propname, + struct PointerRNA *active_dataptr, + const char *active_propname, + const char *item_dyntip_propname, + const int rows, + const int maxrows, + const int layout_type, + const int columns, + const bool sort_reverse, + const bool sort_lock) +{ + int flags = UI_TEMPLATE_LIST_FLAG_NONE; + if (sort_reverse) { + flags |= UI_TEMPLATE_LIST_SORT_REVERSE; + } + if (sort_lock) { + flags |= UI_TEMPLATE_LIST_SORT_LOCK; + } + + uiTemplateList(layout, + C, + listtype_name, + list_id, + dataptr, + propname, + active_dataptr, + active_propname, + item_dyntip_propname, + rows, + maxrows, + layout_type, + columns, + flags); +} + static void rna_uiTemplateCacheFile(uiLayout *layout, bContext *C, PointerRNA *ptr, @@ -1508,7 +1548,7 @@ void RNA_api_ui_layout(StructRNA *srna) parm = RNA_def_pointer(func, "clip_user", "MovieClipUser", "", ""); RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR); - func = RNA_def_function(srna, "template_list", "uiTemplateList"); + func = RNA_def_function(srna, "template_list", "rna_uiTemplateList"); RNA_def_function_ui_description(func, "Item. A list widget to display data, e.g. vertexgroups."); RNA_def_function_flag(func, FUNC_USE_CONTEXT); parm = RNA_def_string(func, "listtype_name", NULL, 0, "", "Identifier of the list type to use"); |