From 141b4e8c4ae2f8f6aa63e32059726130ae3f290a Mon Sep 17 00:00:00 2001 From: "Andrew D. Zonenberg" Date: Mon, 4 Dec 2023 01:25:01 -0800 Subject: [PATCH] FilterGraphEditor: When physics pushes a node outside a group, expand the group to match. Fixes #643. --- src/ngscopeclient/FilterGraphEditor.cpp | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/ngscopeclient/FilterGraphEditor.cpp b/src/ngscopeclient/FilterGraphEditor.cpp index 00d9912f6..87d283feb 100644 --- a/src/ngscopeclient/FilterGraphEditor.cpp +++ b/src/ngscopeclient/FilterGraphEditor.cpp @@ -1179,6 +1179,55 @@ void FilterGraphEditor::ApplyNodeForces( else ax::NodeEditor::SetNodePosition(nodes[i], positions[i] + f); } + + //Map of node IDs being dragged + set> dragNodes; + for(size_t i=0; i(m_context)->FindNode(gid); + auto sizeGroup = gnode->m_GroupBounds.Max - gnode->m_GroupBounds.Min; + + //Still in the group? All good + if(RectContains(posGroup, sizeGroup, posNode, sizeNode)) + continue; + + //If we get here, the node got pushed out of the group. + //We need to resize the group to encompass it. + auto brNode = posNode + sizeNode; + auto brGroup = posGroup + sizeGroup; + posGroup.x = min(posGroup.x, posNode.x); + posGroup.y = min(posGroup.y, posNode.y); + brGroup.x = max(brGroup.x, brNode.x); + brGroup.y = max(brGroup.y, brNode.y); + sizeGroup = brGroup - posGroup; + + //TODO: add a bit of padding so nodes can't go all the way to the outer border of the group? + + //Apply the changes + ax::NodeEditor::SetNodePosition(gid, posGroup); + ax::NodeEditor::SetGroupSize(gid, sizeGroup); + } } /**