Skip to content

Commit

Permalink
New auto-layout of space views (#2558)
Browse files Browse the repository at this point in the history
Closes #2139

### What
This simplifies the auto-layout of space views.

We make heavy use of `egui_tiles::Grid`, which is responsive to the
current viewport size. This means that space views may move around as
you resize window in an effort to keep each one square-ish. In the
future we can make `egui_tiles` smarter here and inform it of the
desired aspect ratio of each space view.

We make an exception for the (common) case of exactly three space views,
which doesn't fit nicely in a grid anyways.



### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested https://demo.rerun.io/pr/2558 

<!-- This line will get updated when the PR build summary job finishes.
-->
PR Build Summary: https://build.rerun.io/pr/2558

<!-- pr-link-docs:start -->
Docs preview: https://rerun.io/preview/e2ed87c/docs
Examples preview: https://rerun.io/preview/e2ed87c/examples
<!-- pr-link-docs:end -->


### Testing
In order to test this I used the `run_all.py` script and found a bunch
of issues with is, so I fixed them.


![image](https://github.com/rerun-io/rerun/assets/1148717/af84bbde-7828-45f5-ab31-df20b3f099df)


![image](https://github.com/rerun-io/rerun/assets/1148717/d845a3b6-3c4d-4a2c-8317-90d35a1a423d)


![image](https://github.com/rerun-io/rerun/assets/1148717/c4005fd2-00c4-44bb-a120-f114f4e2bff8)


![image](https://github.com/rerun-io/rerun/assets/1148717/9844c977-d7a1-49a1-8255-e659288991ee)


![image](https://github.com/rerun-io/rerun/assets/1148717/6546b29f-2107-4713-bfe2-be1efd2cae1e)


![image](https://github.com/rerun-io/rerun/assets/1148717/05353922-02fb-4293-89c7-6b8372240e2b)
  • Loading branch information
emilk committed Jun 29, 2023
1 parent 59907c8 commit 2d0f59d
Show file tree
Hide file tree
Showing 20 changed files with 263 additions and 368 deletions.
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.
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

0 comments on commit 2d0f59d

Please sign in to comment.