Fix #111804: Remove padding between node sockets when hidden

Node drawing was adding some extra padding for each socket even when it
isn't visible. This patch makes the padding conditional on whether the
socket is visible and only when there is preceding items that require a
spacer.

![Screenshot_20230905_162302](/attachments/da52983a-a053-44c8-9d5c-859f89a652a1)

Pull Request: https://projects.blender.org/blender/blender/pulls/111981
This commit is contained in:
Lukas Tönne 2023-09-06 10:34:18 +02:00
parent 2b5f97b8c4
commit ba8d165d3b
1 changed files with 28 additions and 14 deletions

View File

@ -480,15 +480,19 @@ static void node_update_basis_from_declaration(
BLI_assert(is_node_panels_supported(node));
BLI_assert(node.runtime->panels.size() == node.num_panel_states);
const nodes::NodeDeclaration &decl = *node.declaration();
const bool has_buttons = node_update_basis_buttons(C, ntree, node, block, locy);
/* Checked at various places to avoid adding duplicate spacers without anything in between. */
bool need_spacer_after_item = false;
/* Space at the top. */
locy -= NODE_DYS / 2;
need_spacer_after_item = node_update_basis_buttons(C, ntree, node, block, locy);
bNodeSocket *current_input = static_cast<bNodeSocket *>(node.inputs.first);
bNodeSocket *current_output = static_cast<bNodeSocket *>(node.outputs.first);
bNodePanelState *current_panel_state = node.panel_states_array;
bke::bNodePanelRuntime *current_panel_runtime = node.runtime->panels.begin();
bool has_sockets = false;
/* The panel stack keeps track of the hierarchy of panels. When a panel declaration is found a
* new #PanelUpdate is added to the stack. Items in the declaration are added to the top panel of
@ -503,6 +507,7 @@ static void node_update_basis_from_declaration(
bke::bNodePanelRuntime *runtime;
};
bool is_first = true;
Stack<PanelUpdate> panel_updates;
for (const nodes::ItemDeclarationPtr &item_decl : decl.items) {
bool is_parent_collapsed = false;
@ -513,11 +518,6 @@ static void node_update_basis_from_declaration(
is_parent_collapsed = parent_update->is_collapsed;
}
/* Space after header and between items. */
if (!is_parent_collapsed) {
locy -= NODE_SOCKDY;
}
if (nodes::PanelDeclaration *panel_decl = dynamic_cast<nodes::PanelDeclaration *>(
item_decl.get())) {
BLI_assert(node.panel_states().contains_ptr(current_panel_state));
@ -525,6 +525,8 @@ static void node_update_basis_from_declaration(
if (!is_parent_collapsed) {
locy -= NODE_DY;
is_first = false;
need_spacer_after_item = true;
}
SET_FLAG_FROM_TEST(
@ -552,8 +554,14 @@ static void node_update_basis_from_declaration(
current_input->runtime->location = float2(locx, round(locy + NODE_DYS));
}
else {
has_sockets |= node_update_basis_socket(
C, ntree, node, *current_input, block, locx, locy);
/* Space between items. */
if (!is_first && current_input->is_visible()) {
locy -= NODE_SOCKDY;
}
if (node_update_basis_socket(C, ntree, node, *current_input, block, locx, locy)) {
is_first = false;
need_spacer_after_item = true;
}
}
current_input = current_input->next;
break;
@ -567,8 +575,14 @@ static void node_update_basis_from_declaration(
round(locy + NODE_DYS));
}
else {
has_sockets |= node_update_basis_socket(
C, ntree, node, *current_output, block, locx, locy);
/* Space between items. */
if (!is_first && current_output->is_visible()) {
locy -= NODE_SOCKDY;
}
if (node_update_basis_socket(C, ntree, node, *current_output, block, locx, locy)) {
is_first = false;
need_spacer_after_item = true;
}
}
current_output = current_output->next;
break;
@ -591,9 +605,9 @@ static void node_update_basis_from_declaration(
/* Enough items should have been added to close all panels. */
BLI_assert(panel_updates.is_empty());
/* Little bit of space in end. */
if (has_sockets || !has_buttons) {
if (need_spacer_after_item) {
locy -= NODE_DYS / 2;
need_spacer_after_item = false;
}
}