From e2ed87c0b256ef57bf48ffeddebaf7786c380cb8 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 29 Jun 2023 11:27:43 +0200 Subject: [PATCH] Use SpaceViewClassLayoutPriority in auto-layout --- crates/re_viewport/src/auto_layout.rs | 32 +++++++++++---------------- crates/re_viewport/src/viewport.rs | 5 ++++- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/crates/re_viewport/src/auto_layout.rs b/crates/re_viewport/src/auto_layout.rs index 3e84e807f497..8c37e7fc5d21 100644 --- a/crates/re_viewport/src/auto_layout.rs +++ b/crates/re_viewport/src/auto_layout.rs @@ -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, ) -> egui_tiles::Tree { if space_views.is_empty() { @@ -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(); @@ -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() diff --git a/crates/re_viewport/src/viewport.rs b/crates/re_viewport/src/viewport.rs index b9b31b686001..d6ac0c9d5fed 100644 --- a/crates/re_viewport/src/viewport.rs +++ b/crates/re_viewport/src/viewport.rs @@ -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 };