Skip to content

Commit

Permalink
Fix graph view node highlight on hover (#8512)
Browse files Browse the repository at this point in the history
### What

This fixes a problem introduced by #8495 that was only partially fixed
by #8508, with graph view highlights flickering (ping-ponging) in the
blueprint view.
  • Loading branch information
grtlr authored Dec 17, 2024
1 parent 5a5e2b5 commit 06fed3d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
14 changes: 7 additions & 7 deletions crates/viewer/re_view_graph/src/ui/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ pub fn draw_graph(
layout: &Layout,
query: &ViewQuery<'_>,
lod: LevelOfDetail,
hover_click_item: &mut Option<(Item, Response)>,
) -> Rect {
let entity_path = graph.entity();
let entity_highlights = query.highlights.entity_highlight(entity_path.hash());
Expand Down Expand Up @@ -363,19 +364,18 @@ pub fn draw_graph(
});
});

ctx.handle_select_hover_drag_interactions(
&response,
Item::DataResult(query.view_id, instance_path.clone()),
false,
);

// double click selects the entire entity
// 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
Expand Down
19 changes: 15 additions & 4 deletions crates/viewer/re_view_graph/src/view.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use egui::Response;
use re_log_types::EntityPath;
use re_types::{
blueprint::{
Expand Down Expand Up @@ -191,18 +192,28 @@ Display a graph of nodes and edges.

let level_of_detail = LevelOfDetail::from_scaling(ui_from_world.scaling);

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);
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);
}
});

// Don't set the view to hovered if something else was already hovered.
// (this can only mean that a graph node/edge was hovered)
if resp.hovered() && ctx.selection_state().hovered_items().is_empty() {
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));
}

Expand Down

0 comments on commit 06fed3d

Please sign in to comment.