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

Add a hook for views to add additional UI in the tab title bar #7438

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions crates/viewer/re_viewer_context/src/space_view/space_view_class.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use nohash_hasher::IntSet;

use re_entity_db::EntityDb;
use re_log_types::EntityPath;
use re_types::{ComponentName, SpaceViewClassIdentifier};
Expand Down Expand Up @@ -180,6 +181,20 @@ pub trait SpaceViewClass: Send + Sync {
Ok(())
}

/// 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(
&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.
Expand Down
29 changes: 25 additions & 4 deletions crates/viewer/re_viewport/src/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,8 @@ impl<'a, 'b> egui_tiles::Behavior<SpaceViewId> 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();
Expand Down Expand Up @@ -699,9 +700,29 @@ impl<'a, 'b> egui_tiles::Behavior<SpaceViewId> 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 view title bar 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);
});
Expand Down
Loading