Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically expand and scroll the streams tree when focusing on an item #5494

Merged
merged 9 commits into from
Mar 18, 2024
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
Loading