Skip to content

Commit 984d159

Browse files
authored
Add DataUi implementations for Blueprint Components (#4547)
### What Now that we have archetypified blueprints, make the UI a bit nicer with some DataUi implementations. ![image](https://github.com/rerun-io/rerun/assets/3312232/5ca3d2d4-634a-4a7f-957d-0d2f879d8f55) ### 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 the web demo (if applicable): * Using newly built examples: [app.rerun.io](https://app.rerun.io/pr/4547/index.html) * Using examples from latest `main` build: [app.rerun.io](https://app.rerun.io/pr/4547/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [app.rerun.io](https://app.rerun.io/pr/4547/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/4547) - [Docs preview](https://rerun.io/preview/c3a2d19e766d5cd280e374fef05b8840943470ae/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/c3a2d19e766d5cd280e374fef05b8840943470ae/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
1 parent 2f90674 commit 984d159

File tree

8 files changed

+187
-47
lines changed

8 files changed

+187
-47
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use re_types::blueprint::components::IncludedQueries;
2+
use re_viewer_context::{
3+
BlueprintId, BlueprintIdRegistry, DataQueryId, UiVerbosity, ViewerContext,
4+
};
5+
6+
use crate::{item_ui::entity_path_button_to, DataUi};
7+
8+
impl DataUi for IncludedQueries {
9+
#[allow(clippy::only_used_in_recursion)]
10+
fn data_ui(
11+
&self,
12+
_ctx: &ViewerContext<'_>,
13+
ui: &mut egui::Ui,
14+
verbosity: UiVerbosity,
15+
_query: &re_arrow_store::LatestAtQuery,
16+
) {
17+
match verbosity {
18+
UiVerbosity::Small => {
19+
ui.label(format!("{} Queries", self.0.len()));
20+
}
21+
UiVerbosity::Full | UiVerbosity::LimitHeight | UiVerbosity::Reduced => {
22+
for query in &self.0 {
23+
let query: DataQueryId = (*query).into();
24+
query.data_ui(_ctx, ui, verbosity, _query);
25+
ui.end_row();
26+
}
27+
}
28+
}
29+
}
30+
}
31+
32+
impl<T: BlueprintIdRegistry> DataUi for BlueprintId<T> {
33+
#[allow(clippy::only_used_in_recursion)]
34+
fn data_ui(
35+
&self,
36+
ctx: &ViewerContext<'_>,
37+
ui: &mut egui::Ui,
38+
_verbosity: UiVerbosity,
39+
_query: &re_arrow_store::LatestAtQuery,
40+
) {
41+
entity_path_button_to(ctx, ui, None, &self.as_entity_path(), self.to_string());
42+
}
43+
}

crates/re_data_ui/src/component_ui_registry.rs

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,51 @@ use super::EntityDataUi;
99
pub fn create_component_ui_registry() -> ComponentUiRegistry {
1010
re_tracing::profile_function!();
1111

12-
/// Registers how to show a given component in the ui.
13-
pub fn add<C: EntityDataUi + re_types::Component>(registry: &mut ComponentUiRegistry) {
14-
registry.add(
15-
C::name(),
16-
Box::new(
17-
|ctx, ui, verbosity, query, entity_path, component, instance| match component
18-
.lookup::<C>(instance)
19-
{
20-
Ok(component) => {
21-
component.entity_data_ui(ctx, ui, verbosity, entity_path, query);
22-
}
23-
Err(re_query::QueryError::ComponentNotFound) => {
24-
ui.weak("(not found)");
25-
}
26-
Err(err) => {
27-
re_log::warn_once!("Expected component {}, {}", C::name(), err);
28-
}
29-
},
30-
),
31-
);
32-
}
33-
3412
let mut registry = ComponentUiRegistry::new(Box::new(&fallback_component_ui));
3513

36-
add::<re_types::components::AnnotationContext>(&mut registry);
37-
add::<re_types::components::ClassId>(&mut registry);
38-
add::<re_types::components::Color>(&mut registry);
39-
add::<re_types::components::PinholeProjection>(&mut registry);
40-
add::<re_types::components::KeypointId>(&mut registry);
41-
add::<re_types::components::LineStrip2D>(&mut registry);
42-
add::<re_types::components::LineStrip3D>(&mut registry);
43-
add::<re_types::components::Resolution>(&mut registry);
44-
add::<re_types::components::Rotation3D>(&mut registry);
45-
add::<re_types::components::Material>(&mut registry);
46-
add::<re_types::components::MeshProperties>(&mut registry);
47-
add::<re_types::components::TensorData>(&mut registry);
48-
add::<re_types::components::Transform3D>(&mut registry);
49-
add::<re_types::components::OutOfTreeTransform3D>(&mut registry);
50-
add::<re_types::components::ViewCoordinates>(&mut registry);
14+
add_to_registry::<re_types::components::AnnotationContext>(&mut registry);
15+
add_to_registry::<re_types::components::ClassId>(&mut registry);
16+
add_to_registry::<re_types::components::Color>(&mut registry);
17+
add_to_registry::<re_types::components::PinholeProjection>(&mut registry);
18+
add_to_registry::<re_types::components::KeypointId>(&mut registry);
19+
add_to_registry::<re_types::components::LineStrip2D>(&mut registry);
20+
add_to_registry::<re_types::components::LineStrip3D>(&mut registry);
21+
add_to_registry::<re_types::components::Resolution>(&mut registry);
22+
add_to_registry::<re_types::components::Rotation3D>(&mut registry);
23+
add_to_registry::<re_types::components::Material>(&mut registry);
24+
add_to_registry::<re_types::components::MeshProperties>(&mut registry);
25+
add_to_registry::<re_types::components::TensorData>(&mut registry);
26+
add_to_registry::<re_types::components::Transform3D>(&mut registry);
27+
add_to_registry::<re_types::components::OutOfTreeTransform3D>(&mut registry);
28+
add_to_registry::<re_types::components::ViewCoordinates>(&mut registry);
29+
30+
add_to_registry::<re_types::blueprint::components::IncludedQueries>(&mut registry);
5131

5232
registry
5333
}
5434

35+
/// Registers how to show a given component in the ui.
36+
pub fn add_to_registry<C: EntityDataUi + re_types::Component>(registry: &mut ComponentUiRegistry) {
37+
registry.add(
38+
C::name(),
39+
Box::new(
40+
|ctx, ui, verbosity, query, entity_path, component, instance| match component
41+
.lookup::<C>(instance)
42+
{
43+
Ok(component) => {
44+
component.entity_data_ui(ctx, ui, verbosity, entity_path, query);
45+
}
46+
Err(re_query::QueryError::ComponentNotFound) => {
47+
ui.weak("(not found)");
48+
}
49+
Err(err) => {
50+
re_log::warn_once!("Expected component {}, {}", C::name(), err);
51+
}
52+
},
53+
),
54+
);
55+
}
56+
5557
fn fallback_component_ui(
5658
_ctx: &ViewerContext<'_>,
5759
ui: &mut egui::Ui,

crates/re_data_ui/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use re_types::ComponentName;
99
use re_viewer_context::{UiVerbosity, ViewerContext};
1010

1111
mod annotation_context;
12+
mod blueprint_data;
1213
mod component;
1314
mod component_path;
1415
mod component_ui_registry;
@@ -28,7 +29,7 @@ pub use crate::image::{
2829
show_zoomed_image_region, show_zoomed_image_region_area_outline,
2930
tensor_summary_ui_grid_contents,
3031
};
31-
pub use component_ui_registry::create_component_ui_registry;
32+
pub use component_ui_registry::{add_to_registry, create_component_ui_registry};
3233
pub use image_meaning::image_meaning_for_entity;
3334

3435
/// Filter out components that should not be shown in the UI,

crates/re_viewer/src/app.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ impl App {
205205

206206
let (command_sender, command_receiver) = command_channel();
207207

208-
let component_ui_registry = re_data_ui::create_component_ui_registry();
208+
let mut component_ui_registry = re_data_ui::create_component_ui_registry();
209+
re_viewport::blueprint::register_ui_components(&mut component_ui_registry);
209210

210211
// TODO(emilk): `Instant::MIN` when we have our own `Instant` that supports it.;
211212
let long_time_ago = web_time::Instant::now()

crates/re_viewer_context/src/blueprint_id.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ use once_cell::sync::Lazy;
55
use re_log_types::{EntityPath, EntityPathPart};
66

77
pub trait BlueprintIdRegistry {
8-
fn registry() -> &'static EntityPath;
8+
fn registry_name() -> &'static str;
9+
fn registry_path() -> &'static EntityPath;
910
}
1011

1112
/// A unique id for a type of Blueprint contents.
1213
#[derive(
13-
Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Deserialize, serde::Serialize,
14+
Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Deserialize, serde::Serialize,
1415
)]
1516
pub struct BlueprintId<T: BlueprintIdRegistry> {
1617
id: uuid::Uuid,
@@ -34,7 +35,7 @@ impl<T: BlueprintIdRegistry> BlueprintId<T> {
3435
}
3536

3637
pub fn from_entity_path(path: &EntityPath) -> Self {
37-
if !path.is_child_of(T::registry()) {
38+
if !path.is_child_of(T::registry_path()) {
3839
return Self::invalid();
3940
}
4041

@@ -77,7 +78,7 @@ impl<T: BlueprintIdRegistry> BlueprintId<T> {
7778

7879
#[inline]
7980
pub fn as_entity_path(&self) -> EntityPath {
80-
T::registry()
81+
T::registry_path()
8182
.iter()
8283
.cloned()
8384
.chain(std::iter::once(EntityPathPart::new(self.id.to_string())))
@@ -86,7 +87,7 @@ impl<T: BlueprintIdRegistry> BlueprintId<T> {
8687

8788
#[inline]
8889
pub fn registry() -> &'static EntityPath {
89-
T::registry()
90+
T::registry_path()
9091
}
9192

9293
#[inline]
@@ -125,7 +126,14 @@ impl<T: BlueprintIdRegistry> From<BlueprintId<T>> for re_types::datatypes::Uuid
125126
impl<T: BlueprintIdRegistry> std::fmt::Display for BlueprintId<T> {
126127
#[inline]
127128
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
128-
write!(f, "{}({:#})", T::registry(), self.id)
129+
write!(f, "{}({})", T::registry_name(), self.id)
130+
}
131+
}
132+
133+
impl<T: BlueprintIdRegistry> std::fmt::Debug for BlueprintId<T> {
134+
#[inline]
135+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
136+
write!(f, "{}({})", T::registry_name(), self.id)
129137
}
130138
}
131139

@@ -141,7 +149,11 @@ macro_rules! define_blueprint_id_type {
141149
}
142150

143151
impl BlueprintIdRegistry for $registry {
144-
fn registry() -> &'static EntityPath {
152+
fn registry_name() -> &'static str {
153+
stringify!($type)
154+
}
155+
156+
fn registry_path() -> &'static EntityPath {
145157
static REGISTRY_PATH: Lazy<EntityPath> = Lazy::new(|| $registry::REGISTRY.into());
146158
&REGISTRY_PATH
147159
}

crates/re_viewer_context/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub use annotations::{
2727
AnnotationMap, Annotations, ResolvedAnnotationInfo, ResolvedAnnotationInfos,
2828
};
2929
pub use app_options::AppOptions;
30-
pub use blueprint_id::{DataQueryId, SpaceViewId};
30+
pub use blueprint_id::{BlueprintId, BlueprintIdRegistry, DataQueryId, SpaceViewId};
3131
pub use caches::{Cache, Caches};
3232
pub use command_sender::{
3333
command_channel, CommandReceiver, CommandSender, SystemCommand, SystemCommandSender,
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
use re_data_ui::{add_to_registry, DataUi};
2+
use re_viewer_context::{ComponentUiRegistry, SpaceViewId, UiVerbosity, ViewerContext};
3+
4+
use super::components::{IncludedSpaceViews, SpaceViewMaximized, ViewportLayout};
5+
6+
impl DataUi for IncludedSpaceViews {
7+
#[allow(clippy::only_used_in_recursion)]
8+
fn data_ui(
9+
&self,
10+
_ctx: &ViewerContext<'_>,
11+
ui: &mut egui::Ui,
12+
verbosity: UiVerbosity,
13+
_query: &re_arrow_store::LatestAtQuery,
14+
) {
15+
match verbosity {
16+
UiVerbosity::Small => {
17+
ui.label(format!("{} Space Views", self.0.len()));
18+
}
19+
UiVerbosity::Full | UiVerbosity::LimitHeight | UiVerbosity::Reduced => {
20+
for space_view in &self.0 {
21+
let space_view: SpaceViewId = (*space_view).into();
22+
space_view.data_ui(_ctx, ui, verbosity, _query);
23+
ui.end_row();
24+
}
25+
}
26+
}
27+
}
28+
}
29+
30+
impl DataUi for SpaceViewMaximized {
31+
#[allow(clippy::only_used_in_recursion)]
32+
fn data_ui(
33+
&self,
34+
ctx: &ViewerContext<'_>,
35+
ui: &mut egui::Ui,
36+
verbosity: UiVerbosity,
37+
query: &re_arrow_store::LatestAtQuery,
38+
) {
39+
match self.0 {
40+
Some(space_view) => {
41+
let space_view: SpaceViewId = space_view.into();
42+
space_view.data_ui(ctx, ui, verbosity, query);
43+
}
44+
None => {
45+
ui.label("None");
46+
}
47+
}
48+
}
49+
}
50+
51+
impl DataUi for ViewportLayout {
52+
#[allow(clippy::only_used_in_recursion)]
53+
fn data_ui(
54+
&self,
55+
_ctx: &ViewerContext<'_>,
56+
ui: &mut egui::Ui,
57+
verbosity: UiVerbosity,
58+
_query: &re_arrow_store::LatestAtQuery,
59+
) {
60+
match verbosity {
61+
UiVerbosity::Small => {
62+
ui.label(format!("ViewportLayout with {} tiles", self.0.tiles.len()));
63+
}
64+
UiVerbosity::Full | UiVerbosity::LimitHeight | UiVerbosity::Reduced => {
65+
ui.label(format!("{:?}", self.0));
66+
}
67+
}
68+
}
69+
}
70+
71+
pub fn register_ui_components(registry: &mut ComponentUiRegistry) {
72+
re_tracing::profile_function!();
73+
74+
add_to_registry::<IncludedSpaceViews>(registry);
75+
add_to_registry::<SpaceViewMaximized>(registry);
76+
add_to_registry::<ViewportLayout>(registry);
77+
}

crates/re_viewport/src/blueprint/mod.rs

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)