1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-15 13:51:40 +00:00

Merge pull request #105370 from yuantianle/fix-graphnodes-connected-to-headers-rather-than-ports

Fix GraphNode frag/vert port positions misaligned
This commit is contained in:
Thaddeus Crews
2025-04-16 10:45:16 -05:00

View File

@@ -976,10 +976,15 @@ Size2 GraphNode::get_minimum_size() const {
void GraphNode::_port_pos_update() { void GraphNode::_port_pos_update() {
int edgeofs = theme_cache.port_h_offset; int edgeofs = theme_cache.port_h_offset;
int separation = theme_cache.separation;
// 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.
int vertical_ofs = titlebar_hbox->get_size().height + theme_cache.titlebar->get_minimum_size().height + theme_cache.panel->get_margin(SIDE_TOP);
left_port_cache.clear(); left_port_cache.clear();
right_port_cache.clear(); right_port_cache.clear();
int slot_index = 0;
slot_count = 0; // Reset the slot count, which is the index of the current slot.
for (int i = 0; i < get_child_count(false); i++) { for (int i = 0; i < get_child_count(false); i++) {
Control *child = as_sortable_control(get_child(i, false), SortableVisibilityMode::IGNORE); Control *child = as_sortable_control(get_child(i, false), SortableVisibilityMode::IGNORE);
@@ -987,31 +992,33 @@ void GraphNode::_port_pos_update() {
continue; continue;
} }
Size2i size = child->get_rect().size; Size2 size = child->get_size();
Point2 pos = child->get_position();
if (slot_table.has(slot_index)) { if (slot_table.has(slot_count)) {
if (slot_table[slot_index].enable_left) { const Slot &slot = slot_table[slot_count];
PortCache port_cache;
port_cache.pos = Point2i(edgeofs, pos.y + size.height / 2); int port_y;
port_cache.type = slot_table[slot_index].type_left;
port_cache.color = slot_table[slot_index].color_left; // Check if it is using resort layout (e.g. Shader Graph nodes slots).
port_cache.slot_index = slot_index; if (slot_y_cache.is_empty()) {
left_port_cache.push_back(port_cache); port_y = vertical_ofs + size.height * 0.5; // The y centor is calculated from the widget position.
} else {
port_y = child->get_position().y + size.height * 0.5; // The y centor is calculated from the class object position.
} }
if (slot_table[slot_index].enable_right) {
PortCache port_cache; if (slot.enable_left) {
port_cache.pos = Point2i(get_size().width - edgeofs, pos.y + size.height / 2); PortCache port_cache_left{ Point2i(edgeofs, port_y), slot_count, slot.type_left, slot.color_left };
port_cache.type = slot_table[slot_index].type_right; left_port_cache.push_back(port_cache_left);
port_cache.color = slot_table[slot_index].color_right; }
port_cache.slot_index = slot_index; if (slot.enable_right) {
right_port_cache.push_back(port_cache); PortCache port_cache_right{ Point2i(get_size().width - edgeofs, port_y), slot_count, slot.type_right, slot.color_right };
right_port_cache.push_back(port_cache_right);
} }
} }
vertical_ofs += size.height + separation; // Add the height of the child and the separation to the vertical offset.
slot_index++; slot_count++; // Go to the next slot
} }
slot_count = slot_index;
if (selected_slot >= slot_count) { if (selected_slot >= slot_count) {
selected_slot = -1; selected_slot = -1;
} }