[Bf-blender-cvs] [1d3b92bdeab] master: UI: Improve node group input / output list interface

Hans Goudey noreply at git.blender.org
Sun Jan 10 20:24:43 CET 2021


Commit: 1d3b92bdeabc4a556372603c548155fad1e87be0
Author: Hans Goudey
Date:   Sun Jan 10 13:24:37 2021 -0600
Branches: master
https://developer.blender.org/rB1d3b92bdeabc4a556372603c548155fad1e87be0

UI: Improve node group input / output list interface

This commit replaces the two-column list for editing node group inputs
and outputs with a cleaner solution with two panels. The new layout
has several benefits:
 - It uses the vertical space in the node editor sidebar better.
 - It should be more familiar because of similarity with other UI lists.
 - It should look better with consistent alignment and icons.

Note that displaying the "Name" property outside of the list itself is
a bit inconsistent and could possibly be removed in the future.

Differential Revision: https://developer.blender.org/D9683

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

M	source/blender/editors/space_node/drawnode.c
M	source/blender/editors/space_node/node_buttons.c
M	source/blender/editors/space_node/node_edit.c
M	source/blender/makesrna/intern/rna_nodetree.c

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

diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 1333c9ed215..4b5ba2af050 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3665,37 +3665,35 @@ static void std_node_socket_interface_draw(bContext *UNUSED(C), uiLayout *layout
 {
   bNodeSocket *sock = ptr->data;
   int type = sock->typeinfo->type;
-  /*int subtype = sock->typeinfo->subtype;*/
+
+  uiLayout *col = uiLayoutColumn(layout, false);
 
   switch (type) {
     case SOCK_FLOAT: {
-      uiLayout *row;
-      uiItemR(layout, ptr, "default_value", DEFAULT_FLAGS, NULL, 0);
-      row = uiLayoutRow(layout, true);
-      uiItemR(row, ptr, "min_value", DEFAULT_FLAGS, IFACE_("Min"), 0);
-      uiItemR(row, ptr, "max_value", DEFAULT_FLAGS, IFACE_("Max"), 0);
+      uiItemR(col, ptr, "default_value", DEFAULT_FLAGS, IFACE_("Default"), ICON_NONE);
+      uiLayout *sub = uiLayoutColumn(col, true);
+      uiItemR(sub, ptr, "min_value", DEFAULT_FLAGS, IFACE_("Min"), ICON_NONE);
+      uiItemR(sub, ptr, "max_value", DEFAULT_FLAGS, IFACE_("Max"), ICON_NONE);
       break;
     }
     case SOCK_INT: {
-      uiLayout *row;
-      uiItemR(layout, ptr, "default_value", DEFAULT_FLAGS, NULL, 0);
-      row = uiLayoutRow(layout, true);
-      uiItemR(row, ptr, "min_value", DEFAULT_FLAGS, IFACE_("Min"), 0);
-      uiItemR(row, ptr, "max_value", DEFAULT_FLAGS, IFACE_("Max"), 0);
+      uiItemR(col, ptr, "default_value", DEFAULT_FLAGS, IFACE_("Default"), ICON_NONE);
+      uiLayout *sub = uiLayoutColumn(col, true);
+      uiItemR(sub, ptr, "min_value", DEFAULT_FLAGS, IFACE_("Min"), ICON_NONE);
+      uiItemR(sub, ptr, "max_value", DEFAULT_FLAGS, IFACE_("Max"), ICON_NONE);
       break;
     }
     case SOCK_VECTOR: {
-      uiLayout *row;
-      uiItemR(layout, ptr, "default_value", UI_ITEM_R_EXPAND, NULL, DEFAULT_FLAGS);
-      row = uiLayoutRow(layout, true);
-      uiItemR(row, ptr, "min_value", DEFAULT_FLAGS, IFACE_("Min"), 0);
-      uiItemR(row, ptr, "max_value", DEFAULT_FLAGS, IFACE_("Max"), 0);
+      uiItemR(col, ptr, "default_value", UI_ITEM_R_EXPAND, IFACE_("Default"), ICON_NONE);
+      uiLayout *sub = uiLayoutColumn(col, true);
+      uiItemR(sub, ptr, "min_value", DEFAULT_FLAGS, IFACE_("Min"), ICON_NONE);
+      uiItemR(sub, ptr, "max_value", DEFAULT_FLAGS, IFACE_("Max"), ICON_NONE);
       break;
     }
     case SOCK_BOOLEAN:
     case SOCK_RGBA:
     case SOCK_STRING: {
-      uiItemR(layout, ptr, "default_value", DEFAULT_FLAGS, NULL, 0);
+      uiItemR(col, ptr, "default_value", DEFAULT_FLAGS, IFACE_("Default"), 0);
       break;
     }
   }
diff --git a/source/blender/editors/space_node/node_buttons.c b/source/blender/editors/space_node/node_buttons.c
index 0aba45ceafc..c9a0c827a09 100644
--- a/source/blender/editors/space_node/node_buttons.c
+++ b/source/blender/editors/space_node/node_buttons.c
@@ -93,59 +93,35 @@ static bool node_tree_interface_poll(const bContext *C, PanelType *UNUSED(pt))
           (snode->edittree->inputs.first || snode->edittree->outputs.first));
 }
 
-static bool node_tree_find_active_socket(bNodeTree *ntree,
-                                         bNodeSocket **r_sock,
-                                         eNodeSocketInOut *r_in_out)
+static bNodeSocket *node_tree_find_active_socket(bNodeTree *ntree, const eNodeSocketInOut in_out)
 {
-  LISTBASE_FOREACH (bNodeSocket *, socket, &ntree->inputs) {
+  ListBase *sockets = (in_out == SOCK_IN) ? &ntree->inputs : &ntree->outputs;
+  LISTBASE_FOREACH (bNodeSocket *, socket, sockets) {
     if (socket->flag & SELECT) {
-      *r_sock = socket;
-      *r_in_out = SOCK_IN;
-      return true;
+      return socket;
     }
   }
-  LISTBASE_FOREACH (bNodeSocket *, socket, &ntree->outputs) {
-    if (socket->flag & SELECT) {
-      *r_sock = socket;
-      *r_in_out = SOCK_OUT;
-      return true;
-    }
-  }
-
-  *r_sock = NULL;
-  *r_in_out = 0;
-  return false;
+  return NULL;
 }
 
-static void node_tree_interface_panel(const bContext *C, Panel *panel)
+static void draw_socket_list(const bContext *C,
+                             uiLayout *layout,
+                             bNodeTree *ntree,
+                             const eNodeSocketInOut in_out)
 {
-  SpaceNode *snode = CTX_wm_space_node(C); /* NULL checked in poll function. */
-  bNodeTree *ntree = snode->edittree;      /* NULL checked in poll function. */
-  uiLayout *layout = panel->layout;
-
-  PointerRNA ptr;
-  RNA_id_pointer_create((ID *)ntree, &ptr);
-
-  bNodeSocket *socket;
-  eNodeSocketInOut in_out;
-  node_tree_find_active_socket(ntree, &socket, &in_out);
-  PointerRNA sockptr;
-  RNA_pointer_create((ID *)ntree, &RNA_NodeSocketInterface, socket, &sockptr);
-
-  uiLayout *row = uiLayoutRow(layout, false);
+  PointerRNA tree_ptr;
+  RNA_id_pointer_create((ID *)ntree, &tree_ptr);
 
-  uiLayout *split = uiLayoutRow(row, true);
-  uiLayout *col = uiLayoutColumn(split, true);
-  wmOperatorType *ot = WM_operatortype_find("NODE_OT_tree_socket_add", false);
-  uiItemL(col, IFACE_("Inputs:"), ICON_NONE);
-  uiTemplateList(col,
+  uiLayout *split = uiLayoutRow(layout, false);
+  uiLayout *list_col = uiLayoutColumn(split, true);
+  uiTemplateList(list_col,
                  (bContext *)C,
                  "NODE_UL_interface_sockets",
-                 "inputs",
-                 &ptr,
-                 "inputs",
-                 &ptr,
-                 "active_input",
+                 (in_out == SOCK_IN) ? "inputs" : "outputs",
+                 &tree_ptr,
+                 (in_out == SOCK_IN) ? "inputs" : "outputs",
+                 &tree_ptr,
+                 (in_out == SOCK_IN) ? "active_input" : "active_output",
                  NULL,
                  0,
                  0,
@@ -154,70 +130,90 @@ static void node_tree_interface_panel(const bContext *C, Panel *panel)
                  false,
                  false);
   PointerRNA opptr;
-  uiItemFullO_ptr(col, ot, "", ICON_PLUS, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
-  RNA_enum_set(&opptr, "in_out", SOCK_IN);
+  uiLayout *ops_col = uiLayoutColumn(split, false);
+  uiLayout *add_remove_col = uiLayoutColumn(ops_col, true);
+  wmOperatorType *ot = WM_operatortype_find("NODE_OT_tree_socket_add", false);
+  uiItemFullO_ptr(add_remove_col, ot, "", ICON_ADD, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
+  RNA_enum_set(&opptr, "in_out", in_out);
+  ot = WM_operatortype_find("NODE_OT_tree_socket_remove", false);
+  uiItemFullO_ptr(add_remove_col, ot, "", ICON_REMOVE, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
+  RNA_enum_set(&opptr, "in_out", in_out);
 
-  col = uiLayoutColumn(split, true);
-  uiItemL(col, IFACE_("Outputs:"), ICON_NONE);
-  uiTemplateList(col,
-                 (bContext *)C,
-                 "NODE_UL_interface_sockets",
-                 "outputs",
-                 &ptr,
-                 "outputs",
-                 &ptr,
-                 "active_output",
-                 NULL,
-                 0,
-                 0,
-                 0,
-                 0,
-                 false,
-                 false);
-  uiItemFullO_ptr(col, ot, "", ICON_PLUS, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
-  RNA_enum_set(&opptr, "in_out", SOCK_OUT);
+  uiItemS(ops_col);
 
+  uiLayout *up_down_col = uiLayoutColumn(ops_col, true);
   ot = WM_operatortype_find("NODE_OT_tree_socket_move", false);
-  col = uiLayoutColumn(row, true);
-  uiItemFullO_ptr(col, ot, "", ICON_TRIA_UP, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
+  uiItemFullO_ptr(up_down_col, ot, "", ICON_TRIA_UP, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
   RNA_enum_set(&opptr, "direction", 1);
-  uiItemFullO_ptr(col, ot, "", ICON_TRIA_DOWN, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
+  RNA_enum_set(&opptr, "in_out", in_out);
+  uiItemFullO_ptr(up_down_col, ot, "", ICON_TRIA_DOWN, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
   RNA_enum_set(&opptr, "direction", 2);
+  RNA_enum_set(&opptr, "in_out", in_out);
 
-  if (socket) {
-    row = uiLayoutRow(layout, true);
-    uiItemR(row, &sockptr, "name", 0, NULL, ICON_NONE);
-    uiItemO(row, "", ICON_X, "NODE_OT_tree_socket_remove");
+  bNodeSocket *socket = node_tree_find_active_socket(ntree, in_out);
+  if (socket != NULL) {
+    uiLayoutSetPropSep(layout, true);
+    uiLayoutSetPropDecorate(layout, false);
+    PointerRNA socket_ptr;
+    RNA_pointer_create((ID *)ntree, &RNA_NodeSocketInterface, socket, &socket_ptr);
+    uiItemR(layout, &socket_ptr, "name", 0, NULL, ICON_NONE);
 
     if (socket->typeinfo->interface_draw) {
-      uiItemS(layout);
-      socket->typeinfo->interface_draw((bContext *)C, layout, &sockptr);
+      socket->typeinfo->interface_draw((bContext *)C, layout, &socket_ptr);
     }
   }
 }
 
+static void node_tree_interface_inputs_panel(const bContext *C, Panel *panel)
+{
+  SpaceNode *snode = CTX_wm_space_node(C); /* NULL checked in poll function. */
+  bNodeTree *ntree = snode->edittree;      /* NULL checked in poll function. */
+
+  draw_socket_list(C, panel->layout, ntree, SOCK_IN);
+}
+
+static void node_tree_interface_outputs_panel(const bContext *C, Panel *panel)
+{
+  SpaceNode *snode = CTX_wm_space_node(C); /* NULL checked in poll function. */
+  bNodeTree *ntree = snode->edittree;      /* NULL checked in poll function. */
+
+  draw_socket_list(C, panel->layout, ntree, SOCK_OUT);
+}
+
 /* ******************* node buttons registration ************** */
 
 void node_buttons_register(ARegionType *art)
 {
-  PanelType *pt;
-
-  pt = MEM_callocN(sizeof(PanelType), "spacetype node panel node sockets");
-  strcpy(pt->idname, "NODE_PT_sockets");
-  strcpy(pt->category, N_("Node"));
-  strcpy(pt->label, N_("Sockets"));
-  strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
-  pt->draw = node_sockets_panel;
-  pt->poll = node_sockets_poll;
-  pt->flag |= PANEL_TYPE_DEFAULT_CLOSED;
-  BLI_addtail(&art->paneltypes, pt);
-
-  pt = MEM_callocN(sizeof(PanelType), "spacetype node panel tree interface");
-  strcpy(pt->idname, "NODE_PT_node_tree_interface");
-  strcpy(pt->category, N_("Node"));
-  strcpy(pt->label, N_("Interface"));
-  strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
-  pt->draw = node_tree_interface_panel;
-  pt->poll = node_tree_interface_poll;
-  BLI_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list