Skip to content

Commit

Permalink
Allow hiding top panel via blueprint (#6409)
Browse files Browse the repository at this point in the history
### What

- `rrb.TopPanel` is now exposed, works similarly to `rrb.TimePanel`
- `TimePanel` hidden state now fully hides the time panel

### 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/6409?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/6409?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)!

- [PR Build Summary](https://build.rerun.io/pr/6409)
- [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`.

---------

Co-authored-by: Andreas Reich <andreas@rerun.io>
  • Loading branch information
jprochazk and Wumpf authored May 27, 2024
1 parent b0b49aa commit 30ec825
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 39 deletions.
4 changes: 4 additions & 0 deletions crates/re_time_panel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ impl TimePanel {
ui: &mut egui::Ui,
state: PanelState,
) {
if state == PanelState::Hidden {
return;
}

// Naturally, many parts of the time panel need the time control.
// Copy it once, read/edit, and then write back at the end if there was a change.
let time_ctrl_before = rec_cfg.time_ctrl.read().clone();
Expand Down
19 changes: 8 additions & 11 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use re_entity_db::entity_db::EntityDb;
use re_log_types::{ApplicationId, FileSource, LogMsg, StoreKind};
use re_renderer::WgpuResourcePoolStatistics;
use re_smart_channel::{ReceiveSet, SmartChannelSource};
use re_types::blueprint::components::PanelState;
use re_ui::{toasts, UICommand, UICommandSender};
use re_viewer_context::{
command_channel,
Expand Down Expand Up @@ -884,16 +883,14 @@ impl App {

crate::ui::mobile_warning_ui(&self.re_ui, ui);

if app_blueprint.top_panel_state != PanelState::Hidden {
crate::ui::top_panel(
frame,
self,
app_blueprint,
store_context,
gpu_resource_stats,
ui,
);
}
crate::ui::top_panel(
frame,
self,
app_blueprint,
store_context,
gpu_resource_stats,
ui,
);

self.memory_panel_ui(ui, gpu_resource_stats, store_stats);

Expand Down
65 changes: 39 additions & 26 deletions crates/re_viewer/src/ui/top_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,33 @@ pub fn top_panel(

let style_like_web = app.is_screenshotting();
let top_bar_style = app.re_ui().top_bar_style(style_like_web);

egui::TopBottomPanel::top("top_bar")
.frame(app.re_ui().top_panel_frame())
.exact_height(top_bar_style.height)
.show_inside(ui, |ui| {
// React to dragging and double-clicking the top bar:
#[cfg(not(target_arch = "wasm32"))]
if !re_ui::NATIVE_WINDOW_BAR {
// Interact with background first, so that buttons in the top bar gets input priority
// (last added widget has priority for input).
let title_bar_response = ui.interact(
ui.max_rect(),
ui.id().with("background"),
egui::Sense::click(),
);
if title_bar_response.double_clicked() {
let maximized = ui.input(|i| i.viewport().maximized.unwrap_or(false));
ui.ctx()
.send_viewport_cmd(egui::ViewportCommand::Maximized(!maximized));
} else if title_bar_response.is_pointer_button_down_on() {
ui.ctx().send_viewport_cmd(egui::ViewportCommand::StartDrag);
}
let top_panel_frame = app.re_ui().top_panel_frame();

let mut content = |ui: &mut egui::Ui, show_content: bool| {
// React to dragging and double-clicking the top bar:
#[cfg(not(target_arch = "wasm32"))]
if !re_ui::NATIVE_WINDOW_BAR {
// Interact with background first, so that buttons in the top bar gets input priority
// (last added widget has priority for input).
let title_bar_response = ui.interact(
ui.max_rect(),
ui.id().with("background"),
egui::Sense::click(),
);
if title_bar_response.double_clicked() {
let maximized = ui.input(|i| i.viewport().maximized.unwrap_or(false));
ui.ctx()
.send_viewport_cmd(egui::ViewportCommand::Maximized(!maximized));
} else if title_bar_response.is_pointer_button_down_on() {
ui.ctx().send_viewport_cmd(egui::ViewportCommand::StartDrag);
}
}

egui::menu::bar(ui, |ui| {
ui.set_height(top_bar_style.height);
ui.add_space(top_bar_style.indent);
egui::menu::bar(ui, |ui| {
ui.set_height(top_bar_style.height);
ui.add_space(top_bar_style.indent);

if show_content {
top_bar_ui(
frame,
app,
Expand All @@ -56,8 +55,22 @@ pub fn top_panel(
ui,
gpu_resource_stats,
);
});
}
});
};

let panel = egui::TopBottomPanel::top("top_bar")
.frame(top_panel_frame)
.exact_height(top_bar_style.height);
let is_expanded = app_blueprint.top_panel_state.is_expanded();

// On MacOS, we show the close/minimize/maximize buttons in the top panel.
// We _always_ want to show the top panel in that case, and only hide its content.
if !re_ui::NATIVE_WINDOW_BAR {
panel.show_inside(ui, |ui| content(ui, is_expanded));
} else {
panel.show_animated_inside(ui, is_expanded, |ui| content(ui, is_expanded));
}
}

fn top_bar_ui(
Expand Down
1 change: 1 addition & 0 deletions rerun_py/rerun_sdk/rerun/blueprint/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions rerun_py/rerun_sdk/rerun/blueprint/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ def __init__(self, *, expanded: bool | None = None, state: PanelStateLike | None
state:
Whether the panel is expanded, collapsed, or hidden.
Collapsed and hidden both fully hide the top panel.
"""
super().__init__(blueprint_path="top_panel", expanded=expanded, state=state)

Expand All @@ -335,6 +337,8 @@ def __init__(self, *, expanded: bool | None = None, state: PanelStateLike | None
state:
Whether the panel is expanded, collapsed, or hidden.
Collapsed and hidden both fully hide the blueprint panel.
"""
super().__init__(blueprint_path="blueprint_panel", expanded=expanded, state=state)

Expand All @@ -353,6 +357,8 @@ def __init__(self, *, expanded: bool | None = None, state: PanelStateLike | None
state:
Whether the panel is expanded, collapsed, or hidden.
Collapsed and hidden both fully hide the selection panel.
"""
super().__init__(blueprint_path="selection_panel", expanded=expanded, state=state)

Expand All @@ -371,6 +377,9 @@ def __init__(self, *, expanded: bool | None = None, state: PanelStateLike | None
state:
Whether the panel is expanded, collapsed, or hidden.
Expanded fully shows the panel, collapsed shows a simplified panel,
hidden fully hides the panel.
"""
super().__init__(blueprint_path="time_panel", expanded=expanded, state=state)

Expand All @@ -383,7 +392,7 @@ def __init__(self, *, expanded: bool | None = None, state: PanelStateLike | None
helper classes.
"""

BlueprintPart = Union[ContainerLike, BlueprintPanel, SelectionPanel, TimePanel]
BlueprintPart = Union[ContainerLike, TopPanel, BlueprintPanel, SelectionPanel, TimePanel]
"""
The types that make up a blueprint.
"""
Expand Down Expand Up @@ -430,7 +439,9 @@ def __init__(
Defaults to `False` unless no Containers or SpaceViews are provided, in which case it defaults to `True`.
If you want to create a completely empty Blueprint, you must explicitly set this to `False`.
collapse_panels:
Whether to collapse the panels in the viewer. Defaults to `False`.
Whether to collapse panels in the viewer. Defaults to `False`.
This fully hides the blueprint/selection panels, and shows the simplified time panel.
"""
from .containers import Tabs
Expand All @@ -442,6 +453,10 @@ def __init__(
for part in parts:
if isinstance(part, (Container, SpaceView)):
contents.append(part)
elif isinstance(part, TopPanel):
if hasattr(self, "top_panel"):
raise ValueError("Only one top panel can be provided")
self.top_panel = part
elif isinstance(part, BlueprintPanel):
if hasattr(self, "blueprint_panel"):
raise ValueError("Only one blueprint panel can be provided")
Expand Down Expand Up @@ -492,6 +507,9 @@ def _log_to_stream(self, stream: RecordingStream) -> None:

stream.log("viewport", viewport_arch) # type: ignore[attr-defined]

if hasattr(self, "top_panel"):
self.top_panel._log_to_stream(stream)

if hasattr(self, "blueprint_panel"):
self.blueprint_panel._log_to_stream(stream)
elif self.collapse_panels:
Expand Down

0 comments on commit 30ec825

Please sign in to comment.