Skip to content

Commit

Permalink
Automatically expand and scroll the streams tree when focusing on an …
Browse files Browse the repository at this point in the history
…item (#5494)

### 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 emilk/egui#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)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/e879778c92dd2e50eb05bc6fdefee9ac79b93872/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
  • Loading branch information
abey79 committed Mar 18, 2024
1 parent 253b720 commit 300d82a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
21 changes: 21 additions & 0 deletions crates/re_time_panel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 18 additions & 4 deletions crates/re_viewport/src/viewport_blueprint_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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<Item> {
let focused_item = ctx.focused_item.as_ref()?;
fn handle_focused_item(
&self,
ctx: &ViewerContext<'_>,
ui: &egui::Ui,
focused_item: &Item,
) -> Option<Item> {
match focused_item {
Item::Container(container_id) => {
self.expand_all_contents_until(ui.ctx(), &Contents::Container(*container_id));
Expand Down Expand Up @@ -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,
}
}

Expand Down
6 changes: 4 additions & 2 deletions tests/python/release_checklist/check_focus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down

0 comments on commit 300d82a

Please sign in to comment.