egui_graphs icon indicating copy to clipboard operation
egui_graphs copied to clipboard

Panning jitter problem when dragging nodes

Open crane-may opened this issue 1 year ago • 2 comments

I really like this library. I am making a node editor with this library. I've noticed a small problem when node dragging, the whole canvas pans a small distance. Like this:

https://github.com/user-attachments/assets/a399b172-174a-41d3-8d72-92d13e1ba397

I've made a simple change to a line of code myself that avoids this problem, but I realize this may not be the best way to do it. I hope this helps anyone who needs it!


// src/graph_view.rs  line 467:

    fn handle_pan(&self, resp: &Response, meta: &mut Metadata) {
        if !self.settings_navigation.zoom_and_pan_enabled {
            return;
        }

        if (resp.dragged_by(PointerButton::Middle) || resp.dragged_by(PointerButton::Primary))
            && self.g.dragged_node().is_none()
            && (resp.drag_delta().x.abs() > 0. || resp.drag_delta().y.abs() > 0.)
            && !(self.settings_interaction.dragging_enabled                                       // ADD
                && resp.drag_started()                                                            // ADD
                && self.g.node_by_screen_pos(meta, resp.hover_pos().unwrap()).is_some())          // ADD
        {
            let new_pan = meta.pan + resp.drag_delta();
            self.set_pan(new_pan, meta);
        }
    }

crane-may avatar Nov 11 '24 03:11 crane-may

Hi, sorry for the long response.

Thanks for the interest and work that you've done. I will consider it in the upcoming stabilization PR's. I will leave this issue open and close, when this is done.

Feel free to open PR, I will check it later.

blitzarx1 avatar Nov 15 '24 12:11 blitzarx1

Added new feat to respect node dragging. Maybe it helps with this issue. #223

blitzarx1 avatar Nov 17 '24 12:11 blitzarx1

fixed in #264

blitzarx1 avatar Aug 15 '25 16:08 blitzarx1