Skip to content

Commit f35f86b

Browse files
author
alexej
committed
extracted connection drag state logic
1 parent 8166d41 commit f35f86b

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

connection_drag_state.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class ConnectionDragState:
2+
def __init__(self):
3+
self.active = False
4+
self.start_node = None # Typically a Node or node id
5+
self.end_pos = None # (x, y) tuple
6+
7+
def start(self, start_node, end_pos=None):
8+
self.active = True
9+
self.start_node = start_node
10+
self.end_pos = end_pos
11+
12+
def update_end(self, end_pos):
13+
self.end_pos = end_pos
14+
15+
def stop(self):
16+
self.active = False
17+
self.start_node = None
18+
self.end_pos = None
19+
20+
def is_active(self):
21+
return self.active

editor.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from fps_counter import FPSCounter
1818
from renderer import NodeEditorRenderer # <-- new import
1919
from canvas_panning import CanvasPanning
20+
from connection_drag_state import ConnectionDragState
2021

2122
class NodeEditor:
2223
def __init__(self, toolbar=None, undo_depth=10):
@@ -29,9 +30,7 @@ def __init__(self, toolbar=None, undo_depth=10):
2930
self.connections = ConnectionList()
3031
self.undo_stack = UndoStack(max_depth=undo_depth)
3132
self.selection = NodeSelection() # multiple selection of nodes
32-
self.dragging_connection: bool = False
33-
self.connection_start_node: tuple[int, int] | None = None
34-
self.connection_end_pos: tuple[int,int] | None = None
33+
self.connection_drag = ConnectionDragState()
3534
self.next_node_id = 1
3635
self.zoom: float = 1.0 # 1.0 = 100%, min 0.1 (1:10), max e.g. 2.0
3736
self.toolbar = toolbar if toolbar else Toolbar()
@@ -182,6 +181,9 @@ def handle_mouse_motion(self, event):
182181
self.panning_state.update_panning(
183182
(x, y), self.zoom, PANNING_FOLLOWS_MOUSE
184183
)
184+
# Handle connection dragging
185+
if self.connection_drag.is_active():
186+
self.connection_drag.update_end((x, y))
185187

186188
def handle_mouse_wheel(self, event):
187189
# Get mouse position

0 commit comments

Comments
 (0)