Skip to content

Commit

Permalink
Collapse space-view by default if there is only one child (#1762)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk authored Apr 4, 2023
1 parent 9c1babe commit 7892098
Showing 1 changed file with 12 additions and 9 deletions.
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

0 comments on commit 7892098

Please sign in to comment.