Skip to content

Commit

Permalink
Add missing click and hover interactions for views (#8495)
Browse files Browse the repository at this point in the history
### 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.
-->
  • Loading branch information
grtlr authored Dec 17, 2024
1 parent 019bbac commit a7acf15
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
4 changes: 4 additions & 0 deletions crates/viewer/re_view_graph/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ Display a graph of nodes and edges.
}
});

if resp.hovered() {
ctx.selection_state().set_hovered(Item::View(query.view_id));
}

if resp.clicked() {
// clicked elsewhere, select the view
ctx.selection_state()
Expand Down
2 changes: 2 additions & 0 deletions crates/viewer/re_view_map/src/map_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ fn handle_ui_interactions(
// clicked elsewhere, select the view
ctx.selection_state()
.set_selection(Item::View(query.view_id));
} else if map_response.hovered() {
ctx.selection_state().set_hovered(Item::View(query.view_id));
}
}

Expand Down
22 changes: 17 additions & 5 deletions crates/viewer/re_view_text_document/src/view_class.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use egui::Label;

use egui::Sense;
use re_types::View;
use re_types::ViewClassIdentifier;
use re_ui::UiExt as _;
use re_view::suggest_view_for_each_entity;

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

fn ui(
&self,
_ctx: &ViewerContext<'_>,
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
state: &mut dyn ViewState,

_query: &ViewQuery<'_>,
query: &ViewQuery<'_>,
system_output: re_viewer_context::SystemExecutionOutput,
) -> Result<(), ViewSystemExecutionError> {
let state = state.downcast_mut::<TextDocumentViewState>()?;
let text_document = system_output.view_systems.get::<TextDocumentSystem>()?;

egui::Frame {
let response = egui::Frame {
inner_margin: re_ui::DesignTokens::view_padding().into(),
..egui::Frame::default()
}
Expand Down Expand Up @@ -176,7 +177,18 @@ Displays text from a text component, as raw text or markdown."
})
})
.response
});
})
.response
.interact(Sense::click());

if response.hovered() {
ctx.selection_state().set_hovered(Item::View(query.view_id));
}

if response.clicked() {
ctx.selection_state()
.set_selection(Item::View(query.view_id));
}

Ok(())
}
Expand Down
17 changes: 17 additions & 0 deletions tests/python/release_checklist/check_hover_select_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
* If you think this is unexpected, create an issue.
* Double-click the entity and verify that it becomes selected and highlighted in the blueprint tree.
### Graph Select
Should work just as 2D/3D views.
### Text view
Clicking on a text view (what you're reading right now) should select the view.
Hovering the view should work as well.
### Reset
For each of the views:
* Zoom and/or pan the view
Expand Down Expand Up @@ -83,13 +90,23 @@ def log_points_2d() -> None:
rr.log("2D/points", rr.Points2D(positions, colors=colors, radii=radii))


def log_graph() -> None:
rr.log("graph", rr.GraphNodes(["a", "b"], labels=["A", "B"]))


def log_map() -> None:
rr.log("points", rr.GeoPoints(lat_lon=[[47.6344, 19.1397], [47.6334, 19.1399]], radii=rr.Radius.ui_points(20.0)))


def run(args: Namespace) -> None:
rr.script_setup(args, f"{os.path.basename(__file__)}", recording_id=uuid4())

log_readme()
log_plots()
log_points_3d()
log_points_2d()
log_graph()
log_map()


if __name__ == "__main__":
Expand Down

0 comments on commit a7acf15

Please sign in to comment.