git.lucas.co / cce-graph
node-based graph editor
git clone https://git.lucas.co/cce-graph.git

commitb7372c3925c2059a35ec8e0cbdcddc9770a267c0
parent8ca364b2ea
authorLucas Galante <[email protected]>
date2026-06-03 10:35
feat: Implement trackpad panning on Graph widget via handle_mouse_wheel

 src/main.rs | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/main.rs b/src/main.rs
index fa883df..3535ac2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -26,6 +26,8 @@ struct GraphApp {
     show_grid: bool,
     uniform_background: bool,
     network_opacity: f32,
+    pan_x: f32,
+    pan_y: f32,
 }
 
 impl GraphApp {
@@ -122,10 +124,13 @@ impl Application for GraphApp {
             show_grid: true,
             uniform_background: false,
             network_opacity: 0.95,
+            pan_x: 60.0,
+            pan_y: 60.0,
         };
         
         app.menu_bar.set_rect(0.0, 0.0, 1024.0, 26.0);
         app.graph.set_rect(0.0, 26.0, 1024.0, 768.0 - 26.0);
+        app.graph.set_grid_origin(60.0, 60.0);
         app.rebuild_text_items();
         app
     }
@@ -217,6 +222,7 @@ impl Application for GraphApp {
             
             // Layout Graph below MenuBar
             self.graph.set_rect(0.0, 26.0, size.width, size.height - 26.0);
+            self.graph.set_grid_origin(self.pan_x, self.pan_y);
             
             self.rebuild_text_items();
             self.needs_rebuild = false;
@@ -351,7 +357,25 @@ impl Application for GraphApp {
         msg_out
     }
 
-    fn handle_mouse_wheel(&mut self, _delta: &MouseScrollDelta, _pos: LogicalPosition, _needs_rebuild: &mut bool) {}
+    fn handle_mouse_wheel(&mut self, delta: &MouseScrollDelta, _pos: LogicalPosition, needs_rebuild: &mut bool) {
+        let changed = match delta {
+            MouseScrollDelta::LineDelta(x, y) => {
+                self.pan_x += *x * 15.0;
+                self.pan_y += *y * 15.0;
+                true
+            }
+            MouseScrollDelta::PixelDelta(pos) => {
+                self.pan_x += pos.x as f32;
+                self.pan_y += pos.y as f32;
+                true
+            }
+        };
+        if changed {
+            self.graph.set_grid_origin(self.pan_x, self.pan_y);
+            *needs_rebuild = true;
+            self.needs_rebuild = true;
+        }
+    }
 
     fn handle_key_input(&mut self, _event: &KeyEvent, _needs_rebuild: &mut bool) -> Option<Self::Message> {
         None