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

Collapse space-view by default if there is only one child #1762

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions crates/re_viewer/src/ui/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ use crate::{
};

use super::{
data_blueprint::DataBlueprintGroupHandle, space_view_entity_picker::SpaceViewEntityPicker,
space_view_heuristics::all_possible_space_views, view_category::ViewCategory, SpaceView,
SpaceViewId,
data_blueprint::{DataBlueprintGroup, DataBlueprintGroupHandle},
space_view_entity_picker::SpaceViewEntityPicker,
space_view_heuristics::all_possible_space_views,
view_category::ViewCategory,
SpaceView, SpaceViewId,
};

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -120,8 +122,11 @@ impl Viewport {
});
}

// If a group or spaceview has a total of this number of elements or less, show its subtree by default.
const MAX_ELEM_FOR_DEFAULT_OPEN: usize = 3;
/// If a group or spaceview has a total of this number of elements, show its subtree by default?
fn default_open_for_group(group: &DataBlueprintGroup) -> bool {
let num_children = group.children.len() + group.entities.len();
2 <= num_children && num_children <= 3
}

fn space_view_entry_ui(
&mut self,
Expand All @@ -140,8 +145,7 @@ impl Viewport {
let mut is_space_view_visible = self.visible.contains(space_view_id);

let root_group = space_view.data_blueprint.root_group();
let default_open = root_group.children.len() + root_group.entities.len()
<= Self::MAX_ELEM_FOR_DEFAULT_OPEN;
let default_open = Self::default_open_for_group(root_group);
let collapsing_header_id = ui.id().with(space_view.id);
egui::collapsing_header::CollapsingState::load_with_default_open(
ui.ctx(),
Expand Down Expand Up @@ -265,8 +269,7 @@ impl Viewport {
};

let mut remove_group = false;
let default_open = child_group.children.len() + child_group.entities.len()
<= Self::MAX_ELEM_FOR_DEFAULT_OPEN;
let default_open = Self::default_open_for_group(child_group);
egui::collapsing_header::CollapsingState::load_with_default_open(
ui.ctx(),
ui.id().with(child_group_handle),
Expand Down