Skip to content

Commit 191f5fd

Browse files
authored
Add a hook for views to add additional UI in the tab title bar (#7438)
### What Add a hook so views can have additional buttons in the title bar. Unblocks #4466. Background: will be used for column show/hide UI of the dataframe UI. We had ample discussion on doing so, how different it is from other views, and on how we accept that (and eventually embrace that in other views). See eg this comment: #7067 (comment) <img width="770" alt="image" src="https://github.com/user-attachments/assets/05a533ae-62cb-40ba-bfad-f5fb4fc94188"> ### 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 examples from latest `main` build: [rerun.io/viewer](https://rerun.io/viewer/pr/7438?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [rerun.io/viewer](https://rerun.io/viewer/pr/7438?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 * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! * [x] If have noted any breaking changes to the log API in `CHANGELOG.md` and the migration guide - [PR Build Summary](https://build.rerun.io/pr/7438) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) To run all checks from `main`, comment on the PR with `@rerun-bot full-check`.
1 parent 38a442e commit 191f5fd

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

crates/viewer/re_viewer_context/src/space_view/space_view_class.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use nohash_hasher::IntSet;
2+
23
use re_entity_db::EntityDb;
34
use re_log_types::EntityPath;
45
use re_types::{ComponentName, SpaceViewClassIdentifier};
@@ -180,6 +181,20 @@ pub trait SpaceViewClass: Send + Sync {
180181
Ok(())
181182
}
182183

184+
/// Additional UI displayed in the tab title bar, between the "maximize" and "help" buttons.
185+
///
186+
/// Note: this is a right-to-left layout.
187+
fn extra_title_bar_ui(
188+
&self,
189+
_ctx: &ViewerContext<'_>,
190+
_ui: &mut egui::Ui,
191+
_state: &mut dyn SpaceViewState,
192+
_space_origin: &EntityPath,
193+
_space_view_id: SpaceViewId,
194+
) -> Result<(), SpaceViewSystemExecutionError> {
195+
Ok(())
196+
}
197+
183198
/// Draws the ui for this space view class and handles ui events.
184199
///
185200
/// The passed state is kept frame-to-frame.

crates/viewer/re_viewport/src/viewport.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,8 @@ impl<'a, 'b> egui_tiles::Behavior<SpaceViewId> for TabViewer<'a, 'b> {
671671
};
672672
let space_view_id = *space_view_id;
673673

674-
let Some(space_view) = self.viewport_blueprint.space_views.get(&space_view_id) else {
674+
let Some(space_view_blueprint) = self.viewport_blueprint.space_views.get(&space_view_id)
675+
else {
675676
return;
676677
};
677678
let num_space_views = tiles.tiles().filter(|tile| tile.is_pane()).count();
@@ -699,9 +700,29 @@ impl<'a, 'b> egui_tiles::Behavior<SpaceViewId> for TabViewer<'a, 'b> {
699700
}
700701
}
701702

702-
let help_markdown = space_view
703-
.class(self.ctx.space_view_class_registry)
704-
.help_markdown(self.ctx.egui_ctx);
703+
let space_view_class = space_view_blueprint.class(self.ctx.space_view_class_registry);
704+
705+
// give the view a chance to display some extra UI in the top bar.
706+
let view_state = self
707+
.view_states
708+
.get_mut_or_create(space_view_id, space_view_class);
709+
space_view_class
710+
.extra_title_bar_ui(
711+
self.ctx,
712+
ui,
713+
view_state,
714+
&space_view_blueprint.space_origin,
715+
space_view_id,
716+
)
717+
.unwrap_or_else(|err| {
718+
re_log::error!(
719+
"Error in view title bar UI (class: {}, display name: {}): {err}",
720+
space_view_blueprint.class_identifier(),
721+
space_view_class.display_name(),
722+
);
723+
});
724+
725+
let help_markdown = space_view_class.help_markdown(self.ctx.egui_ctx);
705726
ui.help_hover_button().on_hover_ui(|ui| {
706727
ui.markdown_ui(&help_markdown);
707728
});

0 commit comments

Comments
 (0)