[Bf-blender-cvs] [45f6c9bd053] temp-geometry-nodes-attribute-search: Attribute Search: Always add current value to the search list

Hans Goudey noreply at git.blender.org
Mon Feb 22 22:51:13 CET 2021


Commit: 45f6c9bd05334818a61e103a92cf3c74208e9f42
Author: Hans Goudey
Date:   Mon Feb 22 15:51:06 2021 -0600
Branches: temp-geometry-nodes-attribute-search
https://developer.blender.org/rB45f6c9bd05334818a61e103a92cf3c74208e9f42

Attribute Search: Always add current value to the search list

This way the button isn't red if the socket value is any of
"HELLO!", "DOES", "THIS", "WORK???".

And the answer is no, it doesn't work, because all buttons are still
not interactive. I haven't been able to figure out why, but the UI code
doesn't see them as active (i.e. they are deactivated before they can
open the menu).

===================================================================

M	source/blender/editors/space_node/drawnode.c
M	source/blender/editors/space_node/node_geometry_attribute_search.cc

===================================================================

diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index e57e860f472..34fbe65f115 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3402,7 +3402,7 @@ static void std_node_socket_draw(
                                      UI_BTYPE_SEARCH_MENU,
                                      0,
                                      ICON_NONE,
-                                     NULL,
+                                     "",
                                      0,
                                      0,
                                      200,
diff --git a/source/blender/editors/space_node/node_geometry_attribute_search.cc b/source/blender/editors/space_node/node_geometry_attribute_search.cc
index 234eacd502d..b8054e4bedc 100644
--- a/source/blender/editors/space_node/node_geometry_attribute_search.cc
+++ b/source/blender/editors/space_node/node_geometry_attribute_search.cc
@@ -68,6 +68,7 @@ struct AttributeSearchData {
   const bNodeTree &node_tree;
   const bNode &node;
   bNodeSocket &socket;
+  std::string current_value;
 };
 
 static void attribute_search_update_fn(const bContext *C,
@@ -100,6 +101,9 @@ static void attribute_search_update_fn(const bContext *C,
     }
   }
 
+  /* Always add the current value. */
+  UI_search_item_add(items, data->current_value.c_str(), &data->current_value, ICON_NONE, 0, 0);
+
   MEM_freeN(filtered_items);
   BLI_string_search_free(search);
 }
@@ -123,6 +127,14 @@ static void attribute_search_free_fn(void *arg)
 
 void button_add_attribute_search(const bContext *C, bNode *node, bNodeSocket *socket, uiBut *but)
 {
+  BLI_assert(socket->type == SOCK_STRING);
+
+  /* Always adding the button default value is valid because this search menu
+   * shouldn't display when the socket is connected with an input link anyway. */
+  const bNodeSocketValueString *socket_value = static_cast<bNodeSocketValueString *>(
+      socket->default_value);
+  const char *current_value = socket_value->value;
+
   /* TODO: This could just get a node tree argument. */
   SpaceNode *space_node = CTX_wm_space_node(C);
   if (space_node == nullptr) {
@@ -132,7 +144,9 @@ void button_add_attribute_search(const bContext *C, bNode *node, bNodeSocket *so
     return;
   }
 
-  AttributeSearchData *data = new AttributeSearchData{*space_node->edittree, *node, *socket};
+  AttributeSearchData *data = new AttributeSearchData{
+      *space_node->edittree, *node, *socket, current_value};
+
   UI_but_func_search_set(but,
                          nullptr,
                          attribute_search_update_fn,



More information about the Bf-blender-cvs mailing list