Skip to content

Commit

Permalink
Use SpaceViewClassLayoutPriority in auto-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jun 29, 2023
1 parent 6430e40 commit e2ed87c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
32 changes: 13 additions & 19 deletions crates/re_viewport/src/auto_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ use itertools::Itertools as _;

use re_viewer_context::SpaceViewId;

use super::{space_view::SpaceViewBlueprint, view_category::ViewCategory};
use super::space_view::SpaceViewBlueprint;

#[derive(Clone, Debug)]
struct SpaceMakeInfo {
id: SpaceViewId,
category: ViewCategory,
layout_priority: re_viewer_context::SpaceViewClassLayoutPriority,
}

pub(crate) fn tree_from_space_views(
space_view_class_registry: &re_viewer_context::SpaceViewClassRegistry,
space_views: &BTreeMap<SpaceViewId, SpaceViewBlueprint>,
) -> egui_tiles::Tree<SpaceViewId> {
if space_views.is_empty() {
Expand All @@ -33,9 +34,14 @@ pub(crate) fn tree_from_space_views(
*space_view_id,
)
})
.map(|(space_view_id, space_view)| SpaceMakeInfo {
id: *space_view_id,
category: space_view.category,
.map(|(space_view_id, space_view)| {
let layout_priority = space_view
.class(space_view_class_registry)
.layout_priority();
SpaceMakeInfo {
id: *space_view_id,
layout_priority,
}
})
.collect_vec();

Expand Down Expand Up @@ -92,21 +98,9 @@ fn arrange_three(
// +----------+------------+
//
// But which space gets a full side, and which doesn't?
// Answer: we prioritize them by category:
// Answer: we prioritize them based on a class-specific layout priority:

/// lower is better
fn category_priority(category: ViewCategory) -> usize {
match category {
ViewCategory::Spatial => 0,
ViewCategory::Tensor => 1,
ViewCategory::TimeSeries => 2,
ViewCategory::BarChart => 3,
ViewCategory::TextBox => 4,
ViewCategory::Text => 5,
}
}

spaces.sort_by_key(|smi| category_priority(smi.category));
spaces.sort_by_key(|smi| -(smi.layout_priority as isize));

let pane_ids = spaces
.into_iter()
Expand Down
5 changes: 4 additions & 1 deletion crates/re_viewport/src/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,10 @@ impl Viewport {
&mut maximized_tree
} else {
if self.tree.is_empty() {
self.tree = super::auto_layout::tree_from_space_views(&self.space_views);
self.tree = super::auto_layout::tree_from_space_views(
ctx.space_view_class_registry,
&self.space_views,
);
}
&mut self.tree
};
Expand Down

0 comments on commit e2ed87c

Please sign in to comment.