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

Allow overriding app blueprint from web #6419

Merged
merged 19 commits into from
May 27, 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 Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5109,7 +5109,11 @@ dependencies = [
"rfd",
"ron",
"serde",
"serde-wasm-bindgen",
"serde_json",
"static_assertions",
"strum",
"strum_macros",
"thiserror",
"time",
"wasm-bindgen",
Expand Down Expand Up @@ -5866,6 +5870,17 @@ dependencies = [
"serde_derive",
]

[[package]]
name = "serde-wasm-bindgen"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8302e169f0eddcc139c70f139d19d6467353af16f9fce27e8c30158036a1e16b"
dependencies = [
"js-sys",
"serde",
"wasm-bindgen",
]

[[package]]
name = "serde_bytes"
version = "0.11.9"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ serde = { version = "1", features = ["derive"] }
serde_bytes = "0.11"
serde_json = { version = "1", default-features = false, features = ["std"] }
serde_test = "1"
serde-wasm-bindgen = "0.6.5"
serde_yaml = { version = "0.9.21", default-features = false }
sha2 = "0.10"
similar-asserts = "1.4.2"
Expand Down
2 changes: 1 addition & 1 deletion crates/re_time_panel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl TimePanel {
ui: &mut egui::Ui,
state: PanelState,
) {
if state == PanelState::Hidden {
if state.is_hidden() {
return;
}

Expand Down
6 changes: 6 additions & 0 deletions crates/re_types/src/blueprint/components/panel_state_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ impl PanelState {
self == &Self::Expanded
}

/// Returns `true` if self is [`PanelState::Expanded`]
#[inline]
pub fn is_hidden(&self) -> bool {
self == &Self::Hidden
}

/// Sets the panel to [`Self::Hidden`] if it is collapsed or expanded, and [`Self::Expanded`] if it is hidden.
#[inline]
pub fn toggle(self) -> Self {
Expand Down
11 changes: 10 additions & 1 deletion crates/re_ui/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ pub enum UICommand {
#[cfg(not(target_arch = "wasm32"))]
OpenProfiler,

TogglePanelStateOverrides,
ToggleMemoryPanel,
ToggleTopPanel,
ToggleBlueprintPanel,
ToggleSelectionPanel,
ToggleTimePanel,
Expand Down Expand Up @@ -143,6 +145,9 @@ impl UICommand {
"Toggle memory panel",
"View and track current RAM usage inside Rerun Viewer",
),

Self::TogglePanelStateOverrides => ("Toggle panel state overrides", "Toggle panel state between app blueprint and overrides"),
Self::ToggleTopPanel => ("Toggle top panel", "Toggle the top panel"),
Self::ToggleBlueprintPanel => ("Toggle blueprint panel", "Toggle the left panel"),
Self::ToggleSelectionPanel => ("Toggle selection panel", "Toggle the right panel"),
Self::ToggleTimePanel => ("Toggle time panel", "Toggle the bottom panel"),
Expand All @@ -165,6 +170,7 @@ impl UICommand {
"Toggle fullscreen",
"Toggle between windowed and fullscreen viewer",
),

#[cfg(not(target_arch = "wasm32"))]
Self::ZoomIn => ("Zoom in", "Increases the UI zoom level"),
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -235,7 +241,7 @@ impl UICommand {
Self::RestartWithWebGpu => (
"Restart with WebGPU",
"Reloads the webpage and force WebGPU for rendering. All data will be lost."
),
)
}
}

Expand Down Expand Up @@ -280,6 +286,8 @@ impl UICommand {
#[cfg(not(target_arch = "wasm32"))]
Self::OpenProfiler => Some(ctrl_shift(Key::P)),
Self::ToggleMemoryPanel => Some(ctrl_shift(Key::M)),
Self::TogglePanelStateOverrides => None,
Self::ToggleTopPanel => None,
Self::ToggleBlueprintPanel => Some(ctrl_shift(Key::B)),
Self::ToggleSelectionPanel => Some(ctrl_shift(Key::S)),
Self::ToggleTimePanel => Some(ctrl_shift(Key::T)),
Expand All @@ -292,6 +300,7 @@ impl UICommand {

#[cfg(not(target_arch = "wasm32"))]
Self::ToggleFullscreen => Some(key(Key::F11)),

#[cfg(not(target_arch = "wasm32"))]
Self::ZoomIn => Some(egui::gui_zoom::kb_shortcuts::ZOOM_IN),
#[cfg(not(target_arch = "wasm32"))]
Expand Down
4 changes: 4 additions & 0 deletions crates/re_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ rfd.workspace = true
ron.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
serde-wasm-bindgen.workspace = true
static_assertions.workspace = true
strum.workspace = true
strum_macros.workspace = true
thiserror.workspace = true
time = { workspace = true, features = ["formatting"] }
web-time.workspace = true
Expand Down
22 changes: 22 additions & 0 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use re_viewer_context::{
SystemCommandSender,
};

use crate::app_blueprint::PanelStateOverrides;
use crate::{
app_blueprint::AppBlueprint, app_state::WelcomeScreenState, background_tasks::BackgroundTasks,
AppState,
Expand Down Expand Up @@ -69,6 +70,8 @@ pub struct StartupOptions {

/// Forces wgpu backend to use the specified graphics API.
pub force_wgpu_backend: Option<String>,

pub panel_state_overrides: PanelStateOverrides,
}

impl Default for StartupOptions {
Expand All @@ -91,6 +94,8 @@ impl Default for StartupOptions {

expect_data_soon: None,
force_wgpu_backend: None,

panel_state_overrides: Default::default(),
}
}
}
Expand Down Expand Up @@ -155,6 +160,9 @@ pub struct App {

/// All known space view types.
space_view_class_registry: SpaceViewClassRegistry,

pub(crate) panel_state_overrides_active: bool,
pub(crate) panel_state_overrides: PanelStateOverrides,
}

impl App {
Expand Down Expand Up @@ -230,6 +238,8 @@ impl App {

analytics.on_viewer_started(build_info);

let panel_state_overrides = startup_options.panel_state_overrides;

Self {
build_info,
startup_options,
Expand Down Expand Up @@ -269,6 +279,9 @@ impl App {
space_view_class_registry,

analytics,

panel_state_overrides_active: true,
panel_state_overrides,
}
}

Expand Down Expand Up @@ -582,6 +595,12 @@ impl App {
UICommand::ToggleMemoryPanel => {
self.memory_panel_open ^= true;
}
UICommand::TogglePanelStateOverrides => {
self.panel_state_overrides_active ^= true;
}
UICommand::ToggleTopPanel => {
app_blueprint.toggle_top_panel(&self.command_sender);
}
UICommand::ToggleBlueprintPanel => {
app_blueprint.toggle_blueprint_panel(&self.command_sender);
}
Expand All @@ -605,6 +624,7 @@ impl App {
let fullscreen = egui_ctx.input(|i| i.viewport().fullscreen.unwrap_or(false));
egui_ctx.send_viewport_cmd(egui::ViewportCommand::Fullscreen(!fullscreen));
}

#[cfg(not(target_arch = "wasm32"))]
UICommand::ZoomIn => {
let mut zoom_factor = egui_ctx.zoom_factor();
Expand Down Expand Up @@ -1507,6 +1527,8 @@ impl eframe::App for App {
store_context.as_ref(),
&self.state.blueprint_query_for_viewer(),
egui_ctx,
self.panel_state_overrides_active
.then_some(self.panel_state_overrides),
);

self.ui(
Expand Down
Loading
Loading