From 8a78c14d0362a3cacee8552cb890a79b826a2571 Mon Sep 17 00:00:00 2001 From: Leon Schittek Date: Tue, 14 Oct 2025 18:05:11 +0200 Subject: [PATCH] Nodes: Remove resize widgets from collapsed nodes Collapsed nodes had a specific widget to change their width. Now that collapsed nodes are square rather than pill-shaped, the edges can be used to resize them, just like in the uncollapsed state. Therefore the scape widget can be removed. Pull Request: https://projects.blender.org/blender/blender/pulls/147576 --- source/blender/editors/space_node/drawnode.cc | 24 ++++++------ .../blender/editors/space_node/node_draw.cc | 37 +------------------ .../blender/editors/space_node/node_edit.cc | 14 ++++++- 3 files changed, 27 insertions(+), 48 deletions(-) diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc index cb47926b172..88fc081ffac 100644 --- a/source/blender/editors/space_node/drawnode.cc +++ b/source/blender/editors/space_node/drawnode.cc @@ -201,7 +201,9 @@ NodeResizeDirection node_get_resize_direction(const SpaceNode &snode, const int x, const int y) { - const float size = NODE_RESIZE_MARGIN * math::max(snode.runtime->aspect, 1.0f); + const bool node_is_collapsed = node->flag & NODE_COLLAPSED; + const float size = NODE_RESIZE_MARGIN * math::max(snode.runtime->aspect, 1.0f) * + (node_is_collapsed ? 3.0f : 1.0f); if (node->is_frame()) { NodeFrame *data = (NodeFrame *)node->storage; @@ -231,17 +233,6 @@ NodeResizeDirection node_get_resize_direction(const SpaceNode &snode, return dir; } - if (node->flag & NODE_COLLAPSED) { - /* right part of node */ - rctf bounds = node->runtime->draw_bounds; - bounds.xmin = node->runtime->draw_bounds.xmax - 1.0f * U.widget_unit; - if (BLI_rctf_isect_pt(&bounds, x, y)) { - return NODE_RESIZE_RIGHT; - } - - return NODE_RESIZE_NONE; - } - const rctf &bounds = node->runtime->draw_bounds; NodeResizeDirection dir = NODE_RESIZE_NONE; @@ -250,6 +241,15 @@ NodeResizeDirection node_get_resize_direction(const SpaceNode &snode, } if (x >= bounds.xmin && x < bounds.xmin + size && y >= bounds.ymin && y < bounds.ymax) { dir |= NODE_RESIZE_LEFT; + + if (node_is_collapsed) { + /* Prevent conflict with the collapse/expand icon. */ + if ((abs(y - BLI_rctf_cent_y(&bounds)) < 0.4f * U.widget_unit) && + (x > (bounds.xmin + 0.4f * U.widget_unit))) + { + dir = NODE_RESIZE_NONE; + } + } } return dir; } diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 15ba46c83e5..0dcdfdb749b 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -3427,14 +3427,14 @@ static void node_draw_collapsed(const bContext &C, /* Collapse/expand icon. */ { - const int but_size = U.widget_unit * 1.0f; + const int but_size = 0.8f * U.widget_unit; UI_block_emboss_set(&block, ui::EmbossType::None); uiBut *but = uiDefIconBut(&block, ButType::ButToggle, 0, ICON_RIGHTARROW, - rct.xmin + (NODE_MARGIN_X / 3), + rct.xmin + (NODE_MARGIN_X / 3) + 0.1f * U.widget_unit, centy - but_size / 2, but_size, but_size, @@ -3502,39 +3502,6 @@ static void node_draw_collapsed(const bContext &C, UI_but_flag_enable(but, UI_BUT_INACTIVE); } - /* Scale widget thing. */ - uint pos = GPU_vertformat_attr_add( - immVertexFormat(), "pos", blender::gpu::VertAttrType::SFLOAT_32_32); - GPU_blend(GPU_BLEND_ALPHA); - immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); - - immUniformThemeColorShadeAlpha(TH_TEXT, -40, -180); - float dx = 0.5f * U.widget_unit; - const float dx2 = 0.15f * U.widget_unit * snode.runtime->aspect; - const float dy = 0.2f * U.widget_unit; - - immBegin(GPU_PRIM_LINES, 4); - immVertex2f(pos, rct.xmax - dx, centy - dy); - immVertex2f(pos, rct.xmax - dx, centy + dy); - - immVertex2f(pos, rct.xmax - dx - dx2, centy - dy); - immVertex2f(pos, rct.xmax - dx - dx2, centy + dy); - immEnd(); - - immUniformThemeColorShadeAlpha(TH_TEXT, 0, -180); - dx -= snode.runtime->aspect; - - immBegin(GPU_PRIM_LINES, 4); - immVertex2f(pos, rct.xmax - dx, centy - dy); - immVertex2f(pos, rct.xmax - dx, centy + dy); - - immVertex2f(pos, rct.xmax - dx - dx2, centy - dy); - immVertex2f(pos, rct.xmax - dx - dx2, centy + dy); - immEnd(); - - immUnbindProgram(); - GPU_blend(GPU_BLEND_NONE); - node_draw_sockets(C, block, snode, ntree, node); UI_block_end_ex(&C, diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc index 7918f821c9c..bf41dd25b79 100644 --- a/source/blender/editors/space_node/node_edit.cc +++ b/source/blender/editors/space_node/node_edit.cc @@ -1286,6 +1286,15 @@ bNodeSocket *node_find_indicated_socket(SpaceNode &snode, } } if (distance < max_distance) { + if (node_collapsed) { + if ((cursor.x - location.x > NODE_SOCKSIZE) || + ((location.x < cursor.x) && (cursor.x - location.x <= padded_socket_size) && + (abs(location.y - cursor.y) > NODE_SOCKSIZE))) + { + /* Needed to be able to resize collapsed nodes. */ + continue; + } + } update_best_socket(sock, distance); } } @@ -1299,7 +1308,10 @@ bNodeSocket *node_find_indicated_socket(SpaceNode &snode, const float distance = math::distance(location, cursor); if (distance < max_distance) { if (node_collapsed) { - if (location.x - cursor.x > padded_socket_size) { + if ((location.x - cursor.x > NODE_SOCKSIZE) || + ((location.x > cursor.x) && (location.x - cursor.x <= padded_socket_size) && + (abs(location.y - cursor.y) > NODE_SOCKSIZE))) + { /* Needed to be able to resize collapsed nodes. */ continue; }