From 300d82a5bab15f2fad5d338fc69e49952ef7e26b Mon Sep 17 00:00:00 2001 From: Antoine Beyeler <49431240+abey79@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:20:55 +0100 Subject: [PATCH] Automatically expand and scroll the streams tree when focusing on an item (#5494) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What - Follow up to #5482 - Fixes #5232 This PR adds support for expanding and scrolling to the focus item in the Streams view. It also adds expanding/scrolling the Blueprint tree when focusing on a component. - Blocked on https://github.com/emilk/egui/pull/4174 TODO: - [x] update egui commit once ☝🏻 is merged https://github.com/rerun-io/rerun/assets/49431240/55c2959f-bb9b-4f67-b20b-06ba82175d71 ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using newly built examples: [app.rerun.io](https://app.rerun.io/pr/5494/index.html) * Using examples from latest `main` build: [app.rerun.io](https://app.rerun.io/pr/5494/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [app.rerun.io](https://app.rerun.io/pr/5494/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! - [PR Build Summary](https://build.rerun.io/pr/5494) - [Docs preview](https://rerun.io/preview/e879778c92dd2e50eb05bc6fdefee9ac79b93872/docs) - [Examples preview](https://rerun.io/preview/e879778c92dd2e50eb05bc6fdefee9ac79b93872/examples) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) --- crates/re_time_panel/src/lib.rs | 21 ++++++++++++++++++ .../re_viewport/src/viewport_blueprint_ui.rs | 22 +++++++++++++++---- tests/python/release_checklist/check_focus.py | 6 +++-- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/crates/re_time_panel/src/lib.rs b/crates/re_time_panel/src/lib.rs index 9521a2f911a0..64a4ffd9d262 100644 --- a/crates/re_time_panel/src/lib.rs +++ b/crates/re_time_panel/src/lib.rs @@ -584,6 +584,18 @@ impl TimePanel { clip_rect.max.x = tree_max_y; ui.set_clip_rect(clip_rect); + // expand if children is focused + let focused_entity_path = ctx + .focused_item + .as_ref() + .and_then(|item| item.entity_path()); + + if focused_entity_path.is_some_and(|entity_path| entity_path.is_descendant_of(&tree.path)) { + CollapseScope::StreamsTree + .entity(tree.path.clone()) + .set_open(ui.ctx(), true); + } + let re_ui::list_item::ShowCollapsingResponse { item_response: response, body_response, @@ -625,6 +637,15 @@ impl TimePanel { ); }); + if Some(&tree.path) == focused_entity_path { + // Scroll only if the entity isn't already visible. This is important because that's what + // happens when double-clicking an entity _in the blueprint tree_. In such case, it would be + // annoying to induce a scroll motion. + if !ui.clip_rect().contains_rect(response.rect) { + response.scroll_to_me(Some(egui::Align::Center)); + } + } + context_menu_ui_for_item( ctx, viewport_blueprint, diff --git a/crates/re_viewport/src/viewport_blueprint_ui.rs b/crates/re_viewport/src/viewport_blueprint_ui.rs index 588fefd8c047..382e62c8880e 100644 --- a/crates/re_viewport/src/viewport_blueprint_ui.rs +++ b/crates/re_viewport/src/viewport_blueprint_ui.rs @@ -64,7 +64,10 @@ impl Viewport<'_, '_> { .auto_shrink([true, false]) .show(ui, |ui| { ctx.re_ui.panel_content(ui, |_, ui| { - self.state.blueprint_tree_scroll_to_item = self.handle_focused_item(ctx, ui); + self.state.blueprint_tree_scroll_to_item = ctx + .focused_item + .as_ref() + .and_then(|item| self.handle_focused_item(ctx, ui, item)); self.root_container_tree_ui(ctx, ui); @@ -86,8 +89,12 @@ impl Viewport<'_, '_> { } /// Expend all required items and compute which item we should scroll to. - fn handle_focused_item(&self, ctx: &ViewerContext<'_>, ui: &egui::Ui) -> Option { - let focused_item = ctx.focused_item.as_ref()?; + fn handle_focused_item( + &self, + ctx: &ViewerContext<'_>, + ui: &egui::Ui, + focused_item: &Item, + ) -> Option { match focused_item { Item::Container(container_id) => { self.expand_all_contents_until(ui.ctx(), &Contents::Container(*container_id)); @@ -129,8 +136,15 @@ impl Viewport<'_, '_> { res } + Item::ComponentPath(component_path) => self.handle_focused_item( + ctx, + ui, + &Item::InstancePath(InstancePath::entity_splat( + component_path.entity_path.clone(), + )), + ), - Item::StoreId(_) | Item::ComponentPath(_) => None, + Item::StoreId(_) => None, } } diff --git a/tests/python/release_checklist/check_focus.py b/tests/python/release_checklist/check_focus.py index f2d1bf5a34cd..2f4a711e957e 100644 --- a/tests/python/release_checklist/check_focus.py +++ b/tests/python/release_checklist/check_focus.py @@ -19,8 +19,10 @@ ## Checks -- Collapse all in the blueprint tree. -- Double-click on the box in the first space view, check corresponding space view expands. +- Collapse all in the blueprint tree and the streams view +- Double-click on the box in the first space view + - check corresponding space view expands and scrolls + - check the streams view expands and scrolls - Collapse all in the blueprint tree. - Double-click on the leaf "boxes3d" entity in the streams view, check both space views expand. """