[Bf-blender-cvs] [cb205b76821] temp-geometry-nodes-attribute-search: UI: Add an option to search buttons to allow any string input
Hans Goudey
noreply at git.blender.org
Thu Feb 25 00:31:55 CET 2021
Commit: cb205b76821f0a4cb7cffddbec76f6db12e3fd74
Author: Hans Goudey
Date: Wed Feb 24 14:14:43 2021 -0600
Branches: temp-geometry-nodes-attribute-search
https://developer.blender.org/rBcb205b76821f0a4cb7cffddbec76f6db12e3fd74
UI: Add an option to search buttons to allow any string input
For geometry nodes we will use search buttons to display a list of
attributes available the last time the node tree was executed (D10519).
Because this list is just a hint, we need to be able to enter any string,
not just strings from the search items.
This patch adds a boolean option to string buttons to enable this.
The change is quite simple, changes to behavior are only required in
two places. The type-specific button struct changes help a lot here.
Differential Revision: https://developer.blender.org/D10527
===================================================================
M source/blender/editors/include/UI_interface.h
M source/blender/editors/interface/interface.c
M source/blender/editors/interface/interface_handlers.c
M source/blender/editors/interface/interface_intern.h
M source/blender/editors/interface/interface_region_search.c
===================================================================
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 81641239c6a..029e5998da1 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1602,6 +1602,7 @@ void UI_but_func_search_set(uiBut *but,
void UI_but_func_search_set_context_menu(uiBut *but, uiButSearchContextMenuFn context_menu_fn);
void UI_but_func_search_set_tooltip(uiBut *but, uiButSearchTooltipFn tooltip_fn);
void UI_but_func_search_set_sep_string(uiBut *but, const char *search_sep_string);
+void UI_but_func_search_set_all_strings_valid(uiBut *but, const bool value);
/* height in pixels, it's using hardcoded values still */
int UI_searchbox_size_y(void);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 6e25ec9d275..b1e524ca62e 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -6661,6 +6661,14 @@ void UI_but_func_search_set_tooltip(uiBut *but, uiButSearchTooltipFn tooltip_fn)
but_search->item_tooltip_fn = tooltip_fn;
}
+void UI_but_func_search_set_all_strings_valid(uiBut *but, const bool value)
+{
+ uiButSearch *but_search = (uiButSearch *)but;
+ BLI_assert(but->type == UI_BTYPE_SEARCH_MENU);
+
+ but_search->all_strings_valid = value;
+}
+
/* Callbacks for operator search button. */
static void operator_enum_search_update_fn(const struct bContext *C,
void *but,
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 5de330d7136..d4280548cda 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -3407,7 +3407,10 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
}
if (data->searchbox) {
- if (data->cancel == false) {
+ uiButSearch *but_search = (uiButSearch *)but;
+ BLI_assert(but->type == UI_BTYPE_SEARCH_MENU);
+
+ if (data->cancel == false && !but_search->all_strings_valid) {
if ((ui_searchbox_apply(but, data->searchbox) == false) &&
(ui_searchbox_find_index(data->searchbox, but->editstr) == -1)) {
data->cancel = true;
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 3da66d45abd..a4e542d1377 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -316,6 +316,12 @@ typedef struct uiButSearch {
struct PointerRNA rnasearchpoin;
struct PropertyRNA *rnasearchprop;
+
+ /**
+ * The search box only provides suggestions, it does not force
+ * the string to match one of the search items when applying.
+ */
+ bool all_strings_valid;
} uiButSearch;
/** Derived struct for #UI_BTYPE_DECORATOR */
diff --git a/source/blender/editors/interface/interface_region_search.c b/source/blender/editors/interface/interface_region_search.c
index 2c07f5c3c03..f40c888197f 100644
--- a/source/blender/editors/interface/interface_region_search.c
+++ b/source/blender/editors/interface/interface_region_search.c
@@ -1052,14 +1052,16 @@ void ui_but_search_refresh(uiButSearch *search_but)
ui_searchbox_update_fn(but->block->evil_C, search_but, but->drawstr, items);
- /* Only red-alert when we are sure of it, this can miss cases when >10 matches. */
- if (items->totitem == 0) {
- UI_but_flag_enable(but, UI_BUT_REDALERT);
- }
- else if (items->more == 0) {
- if (UI_search_items_find_index(items, but->drawstr) == -1) {
+ if (!search_but->all_strings_valid) {
+ /* Only red-alert when we are sure of it, this can miss cases when >10 matches. */
+ if (items->totitem == 0) {
UI_but_flag_enable(but, UI_BUT_REDALERT);
}
+ else if (items->more == 0) {
+ if (UI_search_items_find_index(items, but->drawstr) == -1) {
+ UI_but_flag_enable(but, UI_BUT_REDALERT);
+ }
+ }
}
for (x1 = 0; x1 < items->maxitem; x1++) {
More information about the Bf-blender-cvs
mailing list