Skip to content

Commit 11cb814

Browse files
committed
Merge pull request #105370 from yuantianle/fix-graphnodes-connected-to-headers-rather-than-ports
Fix GraphNode frag/vert port positions misaligned
2 parents d07c162 + 6e1fb68 commit 11cb814

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

scene/gui/graph_node.cpp

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -976,42 +976,49 @@ Size2 GraphNode::get_minimum_size() const {
976976

977977
void GraphNode::_port_pos_update() {
978978
int edgeofs = theme_cache.port_h_offset;
979+
int separation = theme_cache.separation;
980+
981+
// This helps to immediately achieve the initial y "original point" of the slots, which the sum of the titlebar height and the top margin of the panel.
982+
int vertical_ofs = titlebar_hbox->get_size().height + theme_cache.titlebar->get_minimum_size().height + theme_cache.panel->get_margin(SIDE_TOP);
979983

980984
left_port_cache.clear();
981985
right_port_cache.clear();
982-
int slot_index = 0;
986+
987+
slot_count = 0; // Reset the slot count, which is the index of the current slot.
983988

984989
for (int i = 0; i < get_child_count(false); i++) {
985990
Control *child = as_sortable_control(get_child(i, false), SortableVisibilityMode::IGNORE);
986991
if (!child) {
987992
continue;
988993
}
989994

990-
Size2i size = child->get_rect().size;
991-
Point2 pos = child->get_position();
992-
993-
if (slot_table.has(slot_index)) {
994-
if (slot_table[slot_index].enable_left) {
995-
PortCache port_cache;
996-
port_cache.pos = Point2i(edgeofs, pos.y + size.height / 2);
997-
port_cache.type = slot_table[slot_index].type_left;
998-
port_cache.color = slot_table[slot_index].color_left;
999-
port_cache.slot_index = slot_index;
1000-
left_port_cache.push_back(port_cache);
995+
Size2 size = child->get_size();
996+
997+
if (slot_table.has(slot_count)) {
998+
const Slot &slot = slot_table[slot_count];
999+
1000+
int port_y;
1001+
1002+
// Check if it is using resort layout (e.g. Shader Graph nodes slots).
1003+
if (slot_y_cache.is_empty()) {
1004+
port_y = vertical_ofs + size.height * 0.5; // The y centor is calculated from the widget position.
1005+
} else {
1006+
port_y = child->get_position().y + size.height * 0.5; // The y centor is calculated from the class object position.
1007+
}
1008+
1009+
if (slot.enable_left) {
1010+
PortCache port_cache_left{ Point2i(edgeofs, port_y), slot_count, slot.type_left, slot.color_left };
1011+
left_port_cache.push_back(port_cache_left);
10011012
}
1002-
if (slot_table[slot_index].enable_right) {
1003-
PortCache port_cache;
1004-
port_cache.pos = Point2i(get_size().width - edgeofs, pos.y + size.height / 2);
1005-
port_cache.type = slot_table[slot_index].type_right;
1006-
port_cache.color = slot_table[slot_index].color_right;
1007-
port_cache.slot_index = slot_index;
1008-
right_port_cache.push_back(port_cache);
1013+
if (slot.enable_right) {
1014+
PortCache port_cache_right{ Point2i(get_size().width - edgeofs, port_y), slot_count, slot.type_right, slot.color_right };
1015+
right_port_cache.push_back(port_cache_right);
10091016
}
10101017
}
1011-
1012-
slot_index++;
1018+
vertical_ofs += size.height + separation; // Add the height of the child and the separation to the vertical offset.
1019+
slot_count++; // Go to the next slot
10131020
}
1014-
slot_count = slot_index;
1021+
10151022
if (selected_slot >= slot_count) {
10161023
selected_slot = -1;
10171024
}

0 commit comments

Comments
 (0)