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/windowmanager/intern/wm_uilist_type.c | |
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/windowmanager/intern/wm_uilist_type.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_uilist_type.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/source/blender/windowmanager/intern/wm_uilist_type.c b/source/blender/windowmanager/intern/wm_uilist_type.c index 45c14c0bbe9..434131903fc 100644 --- a/source/blender/windowmanager/intern/wm_uilist_type.c +++ b/source/blender/windowmanager/intern/wm_uilist_type.c @@ -28,7 +28,10 @@ #include "MEM_guardedalloc.h" +#include "UI_interface.h" + #include "BLI_ghash.h" +#include "BLI_string.h" #include "BLI_utildefines.h" #include "BKE_screen.h" @@ -88,3 +91,21 @@ void WM_uilisttype_free(void) BLI_ghash_free(uilisttypes_hash, NULL, MEM_freeN); uilisttypes_hash = NULL; } + +/** + * The "full" list-ID is an internal name used for storing and identifying a list. It is built like + * this: + * "{uiListType.idname}_{list_id}", wherby "list_id" is an optional parameter passed to + * `UILayout.template_list()`. If it is not set, the full list-ID is just "{uiListType.idname}_". + * + * Note that whenever the Python API refers to the list-ID, it's the short, "non-full" one it + * passed to `UILayout.template_list()`. C code can query that through + * #WM_uilisttype_list_id_get(). + */ +void WM_uilisttype_to_full_list_id(const uiListType *ult, + const char *list_id, + char r_full_list_id[UI_MAX_NAME_STR]) +{ + /* We tag the list id with the list type... */ + BLI_snprintf(r_full_list_id, UI_MAX_NAME_STR, "%s_%s", ult->idname, list_id ? list_id : ""); +} |