Skip to content

Commit

Permalink
Fix GraphEdit connections not updating when a child of GraphNode goes…
Browse files Browse the repository at this point in the history
… invisible or changes size
  • Loading branch information
Geometror committed Dec 23, 2024
1 parent 216b330 commit f2dcf3b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions doc/classes/GraphNode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@
</member>
</members>
<signals>
<signal name="slot_sizes_changed">
<description>
Emitted when any slot's size might have changed.
</description>
</signal>
<signal name="slot_updated">
<param index="0" name="slot_index" type="int" />
<description>
Expand Down
2 changes: 2 additions & 0 deletions scene/gui/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ void GraphEdit::add_child_notify(Node *p_child) {
GraphNode *graph_node = Object::cast_to<GraphNode>(graph_element);
if (graph_node) {
graph_node->connect("slot_updated", callable_mp(this, &GraphEdit::_graph_node_slot_updated).bind(graph_element));
graph_node->connect(SNAME("slot_sizes_changed"), callable_mp(this, &GraphEdit::_graph_node_rect_changed).bind(graph_node));
graph_node->connect(SceneStringName(item_rect_changed), callable_mp(this, &GraphEdit::_graph_node_rect_changed).bind(graph_node));
_ensure_node_order_from(graph_node);
}
Expand Down Expand Up @@ -688,6 +689,7 @@ void GraphEdit::remove_child_notify(Node *p_child) {
GraphNode *graph_node = Object::cast_to<GraphNode>(graph_element);
if (graph_node) {
graph_node->disconnect("slot_updated", callable_mp(this, &GraphEdit::_graph_node_slot_updated));
graph_node->disconnect(SNAME("slot_sizes_changed"), callable_mp(this, &GraphEdit::_graph_node_rect_changed));
graph_node->disconnect(SceneStringName(item_rect_changed), callable_mp(this, &GraphEdit::_graph_node_rect_changed));

// Invalidate all adjacent connections, so that they are removed before the next redraw.
Expand Down
4 changes: 3 additions & 1 deletion scene/gui/graph_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ void GraphNode::_resort() {

queue_redraw();
port_pos_dirty = true;
emit_signal(SNAME("slot_sizes_changed"));
}

void GraphNode::draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color) {
Expand Down Expand Up @@ -658,7 +659,7 @@ void GraphNode::_port_pos_update() {
int slot_index = 0;

for (int i = 0; i < get_child_count(false); i++) {
Control *child = as_sortable_control(get_child(i, false), SortableVisbilityMode::IGNORE);
Control *child = as_sortable_control(get_child(i, false), SortableVisbilityMode::VISIBLE_IN_TREE);
if (!child) {
continue;
}
Expand Down Expand Up @@ -888,6 +889,7 @@ void GraphNode::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ignore_invalid_connection_type"), "set_ignore_invalid_connection_type", "is_ignoring_valid_connection_type");

ADD_SIGNAL(MethodInfo("slot_updated", PropertyInfo(Variant::INT, "slot_index")));
ADD_SIGNAL(MethodInfo("slot_sizes_changed"));

BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, panel);
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, panel_selected);
Expand Down

0 comments on commit f2dcf3b

Please sign in to comment.