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

New auto-layout of space views #2558

Merged
merged 15 commits into from
Jun 29, 2023
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ debug = true
# As a last resport, patch with a commit to our own repository.
# ALWAYS document what PR the commit hash is part of, or when it was merged into the upstream trunk.

egui_tiles = { git = "https://github.com/rerun-io/egui_tiles.git", rev = "f958d8af7ed27d925bc2ff7862fb1c1c45961b9e" }
egui_tiles = { git = "https://github.com/rerun-io/egui_tiles.git", rev = "3fff2b01310aa3569e29d2dd3ee97b2e62c45870" } # 2023-06-29: drag-and-drop fixes
4 changes: 4 additions & 0 deletions crates/re_space_view_bar_chart/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ impl SpaceViewClass for BarChartSpaceView {
None
}

fn layout_priority(&self) -> re_viewer_context::SpaceViewClassLayoutPriority {
re_viewer_context::SpaceViewClassLayoutPriority::Low
}

fn selection_ui(
&self,
_ctx: &mut ViewerContext<'_>,
Expand Down
4 changes: 4 additions & 0 deletions crates/re_space_view_spatial/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ impl SpaceViewClass for SpatialSpaceView {
}
}

fn layout_priority(&self) -> re_viewer_context::SpaceViewClassLayoutPriority {
re_viewer_context::SpaceViewClassLayoutPriority::High
}

fn prepare_populate(
&self,
ctx: &mut re_viewer_context::ViewerContext<'_>,
Expand Down
4 changes: 4 additions & 0 deletions crates/re_space_view_tensor/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ impl SpaceViewClass for TensorSpaceView {
None
}

fn layout_priority(&self) -> re_viewer_context::SpaceViewClassLayoutPriority {
re_viewer_context::SpaceViewClassLayoutPriority::Medium
}

fn selection_ui(
&self,
ctx: &mut ViewerContext<'_>,
Expand Down
4 changes: 4 additions & 0 deletions crates/re_space_view_text/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ impl SpaceViewClass for TextSpaceView {
Some(2.0) // Make text logs wide
}

fn layout_priority(&self) -> re_viewer_context::SpaceViewClassLayoutPriority {
re_viewer_context::SpaceViewClassLayoutPriority::Low
}

fn selection_ui(
&self,
ctx: &mut ViewerContext<'_>,
Expand Down
4 changes: 4 additions & 0 deletions crates/re_space_view_text_box/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ impl SpaceViewClass for TextBoxSpaceView {
"Displays text from a text entry components.".into()
}

fn layout_priority(&self) -> re_viewer_context::SpaceViewClassLayoutPriority {
re_viewer_context::SpaceViewClassLayoutPriority::Low
}

fn selection_ui(
&self,
ctx: &mut ViewerContext<'_>,
Expand Down
4 changes: 4 additions & 0 deletions crates/re_space_view_time_series/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ impl SpaceViewClass for TimeSeriesSpaceView {
None
}

fn layout_priority(&self) -> re_viewer_context::SpaceViewClassLayoutPriority {
re_viewer_context::SpaceViewClassLayoutPriority::Low
}

fn selection_ui(
&self,
_ctx: &mut ViewerContext<'_>,
Expand Down
16 changes: 9 additions & 7 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,15 @@ fn blueprint_ui(
space_view.class_name(),
);

space_view.class(ctx).selection_ui(
ctx,
ui,
space_view_state,
&space_view.space_origin,
space_view.id,
);
space_view
.class(ctx.space_view_class_registry)
.selection_ui(
ctx,
ui,
space_view_state,
&space_view.space_origin,
space_view.id,
);
}
}

Expand Down
7 changes: 4 additions & 3 deletions crates/re_viewer_context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ pub use selection_state::{
};
pub use space_view::{
ArchetypeDefinition, DynSpaceViewClass, Scene, SceneContext, SceneContextPart, ScenePart,
ScenePartCollection, SceneQuery, SpaceViewClass, SpaceViewClassName, SpaceViewClassRegistry,
SpaceViewClassRegistryError, SpaceViewEntityHighlight, SpaceViewHighlights,
SpaceViewOutlineMasks, SpaceViewState, TypedScene,
ScenePartCollection, SceneQuery, SpaceViewClass, SpaceViewClassLayoutPriority,
SpaceViewClassName, SpaceViewClassRegistry, SpaceViewClassRegistryError,
SpaceViewEntityHighlight, SpaceViewHighlights, SpaceViewOutlineMasks, SpaceViewState,
TypedScene,
};
pub use store_context::StoreContext;
pub use tensor::{TensorDecodeCache, TensorStats, TensorStatsCache};
Expand Down
18 changes: 18 additions & 0 deletions crates/re_viewer_context/src/space_view/dyn_space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ re_string_interner::declare_new_type!(
pub struct SpaceViewClassName;
);

#[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd, Ord, Eq)]
pub enum SpaceViewClassLayoutPriority {
/// This space view can share space with others
///
/// Used for boring things like text and plots.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think of our plots as boring :P

Low,

#[default]
Medium,

/// Give this space view lots of space.
/// Used for spatial views (2D/3D).
High,
}

/// Defines a class of space view without any concrete types making it suitable for storage and interfacing.
///
/// Implemented by [`crate::SpaceViewClass`].
Expand Down Expand Up @@ -56,6 +71,9 @@ pub trait DynSpaceViewClass {
/// Preferred aspect ratio for the ui tiles of this space view.
fn preferred_tile_aspect_ratio(&self, state: &dyn SpaceViewState) -> Option<f32>;

/// Controls how likely this space view will get a large tile in the ui.
fn layout_priority(&self) -> SpaceViewClassLayoutPriority;

/// Executed before the scene is populated, can be use for heuristic & state updates before populating the scene.
///
/// Is only allowed to access archetypes defined by [`Self::blueprint_archetype`]
Expand Down
3 changes: 2 additions & 1 deletion crates/re_viewer_context/src/space_view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ mod space_view_class_placeholder;
mod space_view_class_registry;

pub use dyn_space_view_class::{
ArchetypeDefinition, DynSpaceViewClass, SpaceViewClassName, SpaceViewState,
ArchetypeDefinition, DynSpaceViewClass, SpaceViewClassLayoutPriority, SpaceViewClassName,
SpaceViewState,
};
pub use highlights::{SpaceViewEntityHighlight, SpaceViewHighlights, SpaceViewOutlineMasks};
pub use scene::{Scene, TypedScene};
Expand Down
8 changes: 8 additions & 0 deletions crates/re_viewer_context/src/space_view/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ pub trait SpaceViewClass: std::marker::Sized {
None
}

/// Controls how likely this space view will get a large tile in the ui.
fn layout_priority(&self) -> crate::SpaceViewClassLayoutPriority;

/// Optional archetype of the Space View's blueprint properties.
///
/// Blueprint components that only apply to the space view itself, not to the entities it displays.
Expand Down Expand Up @@ -125,6 +128,11 @@ impl<T: SpaceViewClass + 'static> DynSpaceViewClass for T {
typed_state_wrapper(state, |state| self.preferred_tile_aspect_ratio(state))
}

#[inline]
fn layout_priority(&self) -> crate::SpaceViewClassLayoutPriority {
self.layout_priority()
}

fn blueprint_archetype(&self) -> Option<ArchetypeDefinition> {
self.blueprint_archetype()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ impl SpaceViewClass for SpaceViewClassPlaceholder {
"The Space View Class was not recognized.\nThis happens if either the Blueprint specifies an invalid Space View Class or this version of the Viewer does not know about this type.".into()
}

fn layout_priority(&self) -> crate::SpaceViewClassLayoutPriority {
crate::SpaceViewClassLayoutPriority::Low
}

fn selection_ui(
&self,
_ctx: &mut crate::ViewerContext<'_>,
Expand Down
Loading