From 867ec9ea793dad977066c48bf5f3aefa8a9397b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20G=C3=B6rtler?= Date: Wed, 11 Dec 2024 14:11:38 +0100 Subject: [PATCH] Fix node selection not working on graph node text labels (#8394) ### What This fixes a bug where specifically, selecting nodes via text labels was not working. We encountered this bug during our work on #8390. ### How to test To test open the `+main` manifest in the web viewer (link in bot message below), select the graph lattice example and try clicking on nodes. --- crates/viewer/re_view_graph/src/ui/draw.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/crates/viewer/re_view_graph/src/ui/draw.rs b/crates/viewer/re_view_graph/src/ui/draw.rs index a9a6b68aedc4..db9566f9778d 100644 --- a/crates/viewer/re_view_graph/src/ui/draw.rs +++ b/crates/viewer/re_view_graph/src/ui/draw.rs @@ -94,7 +94,7 @@ fn draw_circle_label( let &CircleLabel { radius, color } = label; let visuals = &ui.style().visuals.clone(); - let (resp, painter) = ui.allocate_painter(Vec2::splat(radius * 2.0), Sense::click()); + let (resp, painter) = ui.allocate_painter(Vec2::splat(radius * 2.0), Sense::hover()); painter.circle( resp.rect.center(), radius, @@ -132,13 +132,9 @@ fn draw_text_label(ui: &mut Ui, label: &TextLabel, highlight: InteractionHighlig .stroke(stroke) .fill(bg) .show(ui, |ui| { - ui.add( - egui::Label::new(galley.clone()) - .selectable(false) - .sense(Sense::click()), - ) + ui.add(egui::Label::new(galley.clone()).selectable(false)) }) - .response + .inner } /// Draws a node at the given position. @@ -148,15 +144,18 @@ fn draw_node( node: &DrawableLabel, highlight: InteractionHighlight, ) -> Response { - let builder = UiBuilder::new().max_rect(Rect::from_center_size(center, node.size())); - let mut node_ui = ui.new_child(builder); + let builder = UiBuilder::new() + .max_rect(Rect::from_center_size(center, node.size())) + .sense(Sense::click()); - // TODO(grtlr): handle highlights + let mut node_ui = ui.new_child(builder); match node { DrawableLabel::Circle(label) => draw_circle_label(&mut node_ui, label, highlight), DrawableLabel::Text(label) => draw_text_label(&mut node_ui, label, highlight), - } + }; + + node_ui.response() } /// Draws a bounding box, as well as a basic coordinate system.