diff options
author | Hans Goudey <h.goudey@me.com> | 2021-10-21 21:54:48 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-10-21 21:54:48 +0300 |
commit | 1d96a482675dd2ccad2af31c274f74b9f6603d6b (patch) | |
tree | beb0406f7a9f1e6b826cc590eeab69e361a83b3b /source/blender/editors/interface/interface_region_search.c | |
parent | 65490e62708c6bb0c03d9c73fd7179fdf71355a5 (diff) |
Geometry Nodes: Attribute search in the modifier
This adds attribute search to the geometry nodes modifier
for the input and output attributes. The "New" search item
is only shown for the output attributes.
Some of the attribute search code is extracted to a new file
in the interface code, to avoid some code duplication.
The UI code required two fixes so that the search would work
for dynamic length strings (IDProperties do not have a fixed size).
Since this does changes to the UI layout of the modifier, I also
addressed T91485 here.
Differential Revisiion: https://developer.blender.org/D12788
Diffstat (limited to 'source/blender/editors/interface/interface_region_search.c')
-rw-r--r-- | source/blender/editors/interface/interface_region_search.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/source/blender/editors/interface/interface_region_search.c b/source/blender/editors/interface/interface_region_search.c index 1cd3ef89ed3..5bea03dee63 100644 --- a/source/blender/editors/interface/interface_region_search.c +++ b/source/blender/editors/interface/interface_region_search.c @@ -316,7 +316,11 @@ bool ui_searchbox_apply(uiBut *but, ARegion *region) const char *name_sep = data->use_shortcut_sep ? strrchr(name, UI_SEP_CHAR) : NULL; - BLI_strncpy(but->editstr, name, name_sep ? (name_sep - name) + 1 : data->items.maxstrlen); + /* Search button with dynamic string properties may have their own method of applying + * the search results, so only copy the result if there is a proper space for it. */ + if (but->hardmax != 0) { + BLI_strncpy(but->editstr, name, name_sep ? (name_sep - name) + 1 : data->items.maxstrlen); + } search_but->item_active = data->items.pointers[data->active]; @@ -878,7 +882,8 @@ static ARegion *ui_searchbox_create_generic_ex(bContext *C, else { data->items.maxitem = SEARCH_ITEMS; } - data->items.maxstrlen = but->hardmax; + /* In case the button's string is dynamic, make sure there are buffers available. */ + data->items.maxstrlen = but->hardmax == 0 ? UI_MAX_NAME_STR : but->hardmax; data->items.totitem = 0; data->items.names = MEM_callocN(data->items.maxitem * sizeof(void *), "search names"); data->items.pointers = MEM_callocN(data->items.maxitem * sizeof(void *), "search pointers"); @@ -886,7 +891,7 @@ static ARegion *ui_searchbox_create_generic_ex(bContext *C, data->items.states = MEM_callocN(data->items.maxitem * sizeof(int), "search flags"); data->items.name_prefix_offsets = NULL; /* Lazy initialized as needed. */ for (int i = 0; i < data->items.maxitem; i++) { - data->items.names[i] = MEM_callocN(but->hardmax + 1, "search pointers"); + data->items.names[i] = MEM_callocN(data->items.maxstrlen + 1, "search pointers"); } return region; |