Skip to content

Commit

Permalink
respect node dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
blitzarx1 committed Nov 17, 2024
1 parent 89c1cad commit f733450
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/graph_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ where
}
}

// handle mouse drag
if resp.dragged()
&& self.g.dragged_node().is_some()
&& (resp.drag_delta().x.abs() > 0. || resp.drag_delta().y.abs() > 0.)
Expand All @@ -396,6 +397,18 @@ where
self.move_node(n_idx_dragged, delta_in_graph_coords);
}

// compensate movement of the node which is not caused by dragging
if let Some(n_idx_dragged) = self.g.dragged_node() {
if let Some(mouse_pos) = resp.hover_pos() {
if let Some(node) = self.g.node(n_idx_dragged) {
let node_pos = node.location() * meta.zoom + meta.pan;
let delta = mouse_pos - node_pos;

self.move_node(n_idx_dragged, delta / meta.zoom);
}
}
}

if resp.drag_stopped() && self.g.dragged_node().is_some() {
let n_idx = self.g.dragged_node().unwrap();
self.set_drag_end(n_idx);
Expand Down

0 comments on commit f733450

Please sign in to comment.