From 8576e358116a9af09e9120b901425e703a04ad0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20G=C3=B6rtler?= Date: Tue, 17 Dec 2024 18:03:09 +0100 Subject: [PATCH] Fix node selection in graph view --- crates/viewer/re_view_graph/src/ui/draw.rs | 17 +++++++---------- crates/viewer/re_view_graph/src/view.rs | 18 +++++++++++++----- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/crates/viewer/re_view_graph/src/ui/draw.rs b/crates/viewer/re_view_graph/src/ui/draw.rs index 5ab8ac73fde9..ad58886a3761 100644 --- a/crates/viewer/re_view_graph/src/ui/draw.rs +++ b/crates/viewer/re_view_graph/src/ui/draw.rs @@ -330,7 +330,7 @@ pub fn draw_graph( layout: &Layout, query: &ViewQuery<'_>, lod: LevelOfDetail, - hovered: &mut Option, + hover_click_item: &mut Option<(Item, Response)>, ) -> Rect { let entity_path = graph.entity(); let entity_highlights = query.highlights.entity_highlight(entity_path.hash()); @@ -364,21 +364,18 @@ pub fn draw_graph( }); }); - if response.hovered() { - *hovered = Some(Item::DataResult(query.view_id, instance_path.clone())); - } - - if response.clicked() { - ctx.selection_state() - .set_selection(Item::DataResult(query.view_id, instance_path.clone())); - } - + // Warning! The order is very important here. if response.double_clicked() { // Select the entire entity ctx.selection_state().set_selection(Item::DataResult( query.view_id, instance_path.entity_path.clone().into(), )); + } else if response.hovered() || response.clicked() { + *hover_click_item = Some(( + Item::DataResult(query.view_id, instance_path.clone()), + response.clone(), + )); } response diff --git a/crates/viewer/re_view_graph/src/view.rs b/crates/viewer/re_view_graph/src/view.rs index 78dd94a9957f..b7ecf8b0d91e 100644 --- a/crates/viewer/re_view_graph/src/view.rs +++ b/crates/viewer/re_view_graph/src/view.rs @@ -1,3 +1,4 @@ +use egui::Response; use re_log_types::EntityPath; use re_types::{ blueprint::{ @@ -191,20 +192,27 @@ Display a graph of nodes and edges. let level_of_detail = LevelOfDetail::from_scaling(ui_from_world.scaling); - let mut hovered: Option = None; + let mut hover_click_item: Option<(Item, Response)> = None; let resp = zoom_pan_area(ui, &mut ui_from_world, |ui| { let mut world_bounding_rect = egui::Rect::NOTHING; for graph in &graphs { - let graph_rect = - draw_graph(ui, ctx, graph, layout, query, level_of_detail, &mut hovered); + let graph_rect = draw_graph( + ui, + ctx, + graph, + layout, + query, + level_of_detail, + &mut hover_click_item, + ); world_bounding_rect = world_bounding_rect.union(graph_rect); } }); - if let Some(hovered_item) = hovered { - ctx.selection_state().set_hovered(hovered_item); + if let Some((item, response)) = hover_click_item { + ctx.handle_select_hover_drag_interactions(&response, item, false); } else if resp.hovered() { ctx.selection_state().set_hovered(Item::View(query.view_id)); }