Skip to content

Commit a7acf15

Browse files
authored
Add missing click and hover interactions for views (#8495)
### Related <!-- Include links to any related issues/PRs in a bulleted list, for example: * Closes #1234 * Part of #1337 --> * Closes #8479 * Closes #5138 ### What This adds missing view interactions the following views: * Map view * Graph view * TextDocument view @Wumpf @abey79 I feel like the pattern repeats itself and it's easy to miss when writing new views. So I wonder if this could be unified. I see several options for this: * repurpose `handle_select_hover_drag_interactions` which only seems to be used for `DataResult` right now * Making each view return a `Result<(Response, ViewSystemExecutionError>` (instead of `()`) and handling it outside of the view. * Creating a function analogous to `handle_select_hover_drag_interactions`. <!-- Make sure the PR title and labels are set to maximize their usefulness for the CHANGELOG, and our `git log`. If you have noticed any breaking changes, include them in the migration guide. We track various metrics at <https://build.rerun.io>. For maintainers: * To run all checks from `main`, comment on the PR with `@rerun-bot full-check`. * To deploy documentation changes immediately after merging this PR, add the `deploy docs` label. -->
1 parent 019bbac commit a7acf15

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

crates/viewer/re_view_graph/src/view.rs

+4
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ Display a graph of nodes and edges.
206206
}
207207
});
208208

209+
if resp.hovered() {
210+
ctx.selection_state().set_hovered(Item::View(query.view_id));
211+
}
212+
209213
if resp.clicked() {
210214
// clicked elsewhere, select the view
211215
ctx.selection_state()

crates/viewer/re_view_map/src/map_view.rs

+2
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,8 @@ fn handle_ui_interactions(
499499
// clicked elsewhere, select the view
500500
ctx.selection_state()
501501
.set_selection(Item::View(query.view_id));
502+
} else if map_response.hovered() {
503+
ctx.selection_state().set_hovered(Item::View(query.view_id));
502504
}
503505
}
504506

crates/viewer/re_view_text_document/src/view_class.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use egui::Label;
22

3+
use egui::Sense;
34
use re_types::View;
45
use re_types::ViewClassIdentifier;
56
use re_ui::UiExt as _;
67
use re_view::suggest_view_for_each_entity;
78

9+
use re_viewer_context::Item;
810
use re_viewer_context::{
911
external::re_log_types::EntityPath, ViewClass, ViewClassRegistryError, ViewId, ViewQuery,
1012
ViewState, ViewStateExt as _, ViewSystemExecutionError, ViewerContext,
@@ -111,17 +113,16 @@ Displays text from a text component, as raw text or markdown."
111113

112114
fn ui(
113115
&self,
114-
_ctx: &ViewerContext<'_>,
116+
ctx: &ViewerContext<'_>,
115117
ui: &mut egui::Ui,
116118
state: &mut dyn ViewState,
117-
118-
_query: &ViewQuery<'_>,
119+
query: &ViewQuery<'_>,
119120
system_output: re_viewer_context::SystemExecutionOutput,
120121
) -> Result<(), ViewSystemExecutionError> {
121122
let state = state.downcast_mut::<TextDocumentViewState>()?;
122123
let text_document = system_output.view_systems.get::<TextDocumentSystem>()?;
123124

124-
egui::Frame {
125+
let response = egui::Frame {
125126
inner_margin: re_ui::DesignTokens::view_padding().into(),
126127
..egui::Frame::default()
127128
}
@@ -176,7 +177,18 @@ Displays text from a text component, as raw text or markdown."
176177
})
177178
})
178179
.response
179-
});
180+
})
181+
.response
182+
.interact(Sense::click());
183+
184+
if response.hovered() {
185+
ctx.selection_state().set_hovered(Item::View(query.view_id));
186+
}
187+
188+
if response.clicked() {
189+
ctx.selection_state()
190+
.set_selection(Item::View(query.view_id));
191+
}
180192

181193
Ok(())
182194
}

tests/python/release_checklist/check_hover_select_reset.py

+17
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
* If you think this is unexpected, create an issue.
3030
* Double-click the entity and verify that it becomes selected and highlighted in the blueprint tree.
3131
32+
### Graph Select
33+
Should work just as 2D/3D views.
34+
35+
### Text view
36+
Clicking on a text view (what you're reading right now) should select the view.
37+
Hovering the view should work as well.
38+
3239
### Reset
3340
For each of the views:
3441
* Zoom and/or pan the view
@@ -83,13 +90,23 @@ def log_points_2d() -> None:
8390
rr.log("2D/points", rr.Points2D(positions, colors=colors, radii=radii))
8491

8592

93+
def log_graph() -> None:
94+
rr.log("graph", rr.GraphNodes(["a", "b"], labels=["A", "B"]))
95+
96+
97+
def log_map() -> None:
98+
rr.log("points", rr.GeoPoints(lat_lon=[[47.6344, 19.1397], [47.6334, 19.1399]], radii=rr.Radius.ui_points(20.0)))
99+
100+
86101
def run(args: Namespace) -> None:
87102
rr.script_setup(args, f"{os.path.basename(__file__)}", recording_id=uuid4())
88103

89104
log_readme()
90105
log_plots()
91106
log_points_3d()
92107
log_points_2d()
108+
log_graph()
109+
log_map()
93110

94111

95112
if __name__ == "__main__":

0 commit comments

Comments
 (0)