From 47b25726291f6497ce9c353af3c345568c606c70 Mon Sep 17 00:00:00 2001 From: Antoine Beyeler Date: Tue, 17 Sep 2024 18:03:32 +0200 Subject: [PATCH 1/3] Add a hook for views to add addition UI in the tab title bar --- .../src/space_view/space_view_class.rs | 15 ++++++++++ crates/viewer/re_viewport/src/viewport.rs | 29 ++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/crates/viewer/re_viewer_context/src/space_view/space_view_class.rs b/crates/viewer/re_viewer_context/src/space_view/space_view_class.rs index 71619bf40dd8..24d97706d45e 100644 --- a/crates/viewer/re_viewer_context/src/space_view/space_view_class.rs +++ b/crates/viewer/re_viewer_context/src/space_view/space_view_class.rs @@ -1,4 +1,5 @@ use nohash_hasher::IntSet; + use re_entity_db::EntityDb; use re_log_types::EntityPath; use re_types::{ComponentName, SpaceViewClassIdentifier}; @@ -180,6 +181,20 @@ pub trait SpaceViewClass: Send + Sync { Ok(()) } + /// Addition UI displayed in the tab title bar, between the "maximize" and "help" buttons. + /// + /// Note: this is a right-to-left layout. + fn extra_title_bar_ui( + &self, + _ctx: &ViewerContext<'_>, + _ui: &mut egui::Ui, + _state: &mut dyn SpaceViewState, + _space_origin: &EntityPath, + _space_view_id: SpaceViewId, + ) -> Result<(), SpaceViewSystemExecutionError> { + Ok(()) + } + /// Draws the ui for this space view class and handles ui events. /// /// The passed state is kept frame-to-frame. diff --git a/crates/viewer/re_viewport/src/viewport.rs b/crates/viewer/re_viewport/src/viewport.rs index 9df0370492af..032290a255cc 100644 --- a/crates/viewer/re_viewport/src/viewport.rs +++ b/crates/viewer/re_viewport/src/viewport.rs @@ -670,7 +670,8 @@ impl<'a, 'b> egui_tiles::Behavior for TabViewer<'a, 'b> { }; let space_view_id = *space_view_id; - let Some(space_view) = self.viewport_blueprint.space_views.get(&space_view_id) else { + let Some(space_view_blueprint) = self.viewport_blueprint.space_views.get(&space_view_id) + else { return; }; let num_space_views = tiles.tiles().filter(|tile| tile.is_pane()).count(); @@ -698,9 +699,29 @@ impl<'a, 'b> egui_tiles::Behavior for TabViewer<'a, 'b> { } } - let help_markdown = space_view - .class(self.ctx.space_view_class_registry) - .help_markdown(self.ctx.egui_ctx); + let space_view_class = space_view_blueprint.class(self.ctx.space_view_class_registry); + + // give the view a chance to display some extra UI in the top bar. + let view_state = self + .view_states + .get_mut_or_create(space_view_id, space_view_class); + space_view_class + .extra_title_bar_ui( + self.ctx, + ui, + view_state, + &space_view_blueprint.space_origin, + space_view_id, + ) + .unwrap_or_else(|err| { + re_log::error!( + "Error in space view UI (class: {}, display name: {}): {err}", + space_view_blueprint.class_identifier(), + space_view_class.display_name(), + ); + }); + + let help_markdown = space_view_class.help_markdown(self.ctx.egui_ctx); ui.help_hover_button().on_hover_ui(|ui| { ui.markdown_ui(&help_markdown); }); From 3c98b51b2cc6b929e1b11c51a5f460b62d1b4869 Mon Sep 17 00:00:00 2001 From: Antoine Beyeler Date: Wed, 18 Sep 2024 11:09:53 +0200 Subject: [PATCH 2/3] typo --- .../viewer/re_viewer_context/src/space_view/space_view_class.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/viewer/re_viewer_context/src/space_view/space_view_class.rs b/crates/viewer/re_viewer_context/src/space_view/space_view_class.rs index 24d97706d45e..b62ca735abaf 100644 --- a/crates/viewer/re_viewer_context/src/space_view/space_view_class.rs +++ b/crates/viewer/re_viewer_context/src/space_view/space_view_class.rs @@ -181,7 +181,7 @@ pub trait SpaceViewClass: Send + Sync { Ok(()) } - /// Addition UI displayed in the tab title bar, between the "maximize" and "help" buttons. + /// Additional UI displayed in the tab title bar, between the "maximize" and "help" buttons. /// /// Note: this is a right-to-left layout. fn extra_title_bar_ui( From 221220dc26c734b3fcd7df1f0a926a8f0cce5a70 Mon Sep 17 00:00:00 2001 From: Antoine Beyeler Date: Thu, 19 Sep 2024 09:07:55 +0200 Subject: [PATCH 3/3] Improved error message --- crates/viewer/re_viewport/src/viewport.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/viewer/re_viewport/src/viewport.rs b/crates/viewer/re_viewport/src/viewport.rs index 032290a255cc..3cf15b162ca8 100644 --- a/crates/viewer/re_viewport/src/viewport.rs +++ b/crates/viewer/re_viewport/src/viewport.rs @@ -715,7 +715,7 @@ impl<'a, 'b> egui_tiles::Behavior for TabViewer<'a, 'b> { ) .unwrap_or_else(|err| { re_log::error!( - "Error in space view UI (class: {}, display name: {}): {err}", + "Error in view title bar UI (class: {}, display name: {}): {err}", space_view_blueprint.class_identifier(), space_view_class.display_name(), );