From ed4b2ac499d7c83870dc0deff59a3aa539f16c39 Mon Sep 17 00:00:00 2001 From: Felix Kaaman Date: Mon, 6 Jun 2022 10:44:40 +0200 Subject: [PATCH 1/4] Prevent global panning and opening a new finder from a finder --- egui_node_graph/src/editor_ui.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/egui_node_graph/src/editor_ui.rs b/egui_node_graph/src/editor_ui.rs index ab37351..14fa2bc 100644 --- a/egui_node_graph/src/editor_ui.rs +++ b/egui_node_graph/src/editor_ui.rs @@ -71,6 +71,7 @@ where let cursor_pos = ui.ctx().input().pointer.hover_pos().unwrap_or(Pos2::ZERO); let mut cursor_in_editor = editor_rect.contains(cursor_pos); + let mut cursor_in_finder = false; // Gets filled with the port locations as nodes are drawn let mut port_locations = PortLocations::new(); @@ -109,7 +110,7 @@ where delayed_responses.extend(responses); } - let r = ui.allocate_rect(ui.min_rect(), Sense::click()); + let r = ui.allocate_rect(ui.min_rect(), Sense::click().union(Sense::drag())); if r.clicked() { click_on_background = true; } @@ -142,6 +143,7 @@ where // if the cursor is in the finder, then we can consider that also in the editor. if !cursor_in_editor && finder_rect.contains(cursor_pos) { cursor_in_editor = true; + cursor_in_finder = true; } }); } @@ -246,15 +248,18 @@ where self.connection_in_progress = None; } - if mouse.button_down(PointerButton::Secondary) && cursor_in_editor { + if mouse.button_released(PointerButton::Secondary) && cursor_in_editor && !cursor_in_finder + { self.node_finder = Some(NodeFinder::new_at(cursor_pos)); } if ui.ctx().input().key_pressed(Key::Escape) { self.node_finder = None; } - if ui.ctx().input().pointer.middle_down() { - self.pan_zoom.pan += ui.ctx().input().pointer.delta(); + if r.dragged() { + if ui.ctx().input().pointer.middle_down() { + self.pan_zoom.pan += ui.ctx().input().pointer.delta(); + } } // Deselect and deactivate finder if the editor backround is clicked, From 1ced8c560929f98e37254a65f30b22f739acc677 Mon Sep 17 00:00:00 2001 From: Felix Kaaman Date: Mon, 6 Jun 2022 10:45:33 +0200 Subject: [PATCH 2/4] Always put finder on top --- egui_node_graph/src/editor_ui.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egui_node_graph/src/editor_ui.rs b/egui_node_graph/src/editor_ui.rs index 14fa2bc..564aa5b 100644 --- a/egui_node_graph/src/editor_ui.rs +++ b/egui_node_graph/src/editor_ui.rs @@ -118,7 +118,7 @@ where /* Draw the node finder, if open */ let mut should_close_node_finder = false; if let Some(ref mut node_finder) = self.node_finder { - let mut node_finder_area = Area::new("node_finder"); + let mut node_finder_area = Area::new("node_finder").order(Order::Foreground); if let Some(pos) = node_finder.position { node_finder_area = node_finder_area.current_pos(pos); } From b91610c7ee46c01fbf0a2b13c0d0b7fc3f99cd00 Mon Sep 17 00:00:00 2001 From: Setzer22 Date: Tue, 21 Jun 2022 11:07:18 +0200 Subject: [PATCH 3/4] Change button_released for secondary_down The code in the original PR was correct, but button_released is not available on egui 0.18 from crates.io, this commit moves back to the old behavior of using secondary_down instead. --- egui_node_graph/src/editor_ui.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/egui_node_graph/src/editor_ui.rs b/egui_node_graph/src/editor_ui.rs index 564aa5b..358d0f1 100644 --- a/egui_node_graph/src/editor_ui.rs +++ b/egui_node_graph/src/editor_ui.rs @@ -248,18 +248,15 @@ where self.connection_in_progress = None; } - if mouse.button_released(PointerButton::Secondary) && cursor_in_editor && !cursor_in_finder - { + if mouse.secondary_down() && cursor_in_editor && !cursor_in_finder { self.node_finder = Some(NodeFinder::new_at(cursor_pos)); } if ui.ctx().input().key_pressed(Key::Escape) { self.node_finder = None; } - if r.dragged() { - if ui.ctx().input().pointer.middle_down() { - self.pan_zoom.pan += ui.ctx().input().pointer.delta(); - } + if r.dragged() && ui.ctx().input().pointer.middle_down() { + self.pan_zoom.pan += ui.ctx().input().pointer.delta(); } // Deselect and deactivate finder if the editor backround is clicked, From 615fc5f6ce88a516e1510fcea38e58f89fe62e62 Mon Sep 17 00:00:00 2001 From: Setzer22 Date: Tue, 21 Jun 2022 11:09:03 +0200 Subject: [PATCH 4/4] Whitespace fmt --- egui_node_graph/src/traits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egui_node_graph/src/traits.rs b/egui_node_graph/src/traits.rs index 2f5c6d6..1c80490 100644 --- a/egui_node_graph/src/traits.rs +++ b/egui_node_graph/src/traits.rs @@ -21,7 +21,7 @@ pub trait DataTypeTrait: PartialEq + Eq { /// The name of this datatype. Return type is specified as Cow because /// some implementations will need to allocate a new string to provide an - /// answer while others won't. + /// answer while others won't. /// /// ## Example (borrowed value) /// Use this when you can get the name of the datatype from its fields or as