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

Replace the "Options" submenu with a settings screen #8001

Merged
merged 4 commits into from
Nov 6, 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ enum MapProvider: ubyte (

/// Mapbox Streets is a minimalistic map designed by Mapbox.
///
/// **Note**: Requires a Mapbox API key in the `RERUN_MAPBOX_ACCESS_TOKEN` environment variable.
/// **Note**: Requires a Mapbox access token in the settings or using the `RERUN_MAPBOX_ACCESS_TOKEN` environment variable.
MapboxStreets,

/// Mapbox Dark is a dark-themed map designed by Mapbox.
///
/// **Note**: Requires a Mapbox API key in the `RERUN_MAPBOX_ACCESS_TOKEN` environment variable.
/// **Note**: Requires a Mapbox access token in the settings or using the `RERUN_MAPBOX_ACCESS_TOKEN` environment variable.
MapboxDark,

/// Mapbox Satellite is a satellite map designed by Mapbox.
///
/// **Note**: Requires a Mapbox API key in the `RERUN_MAPBOX_ACCESS_TOKEN` environment variable.
/// **Note**: Requires a Mapbox access token in the settings or using the `RERUN_MAPBOX_ACCESS_TOKEN` environment variable.
MapboxSatellite,
}
12 changes: 6 additions & 6 deletions crates/store/re_types/src/blueprint/components/map_provider.rs

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

15 changes: 10 additions & 5 deletions crates/viewer/re_space_view_map/src/map_space_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ impl MapSpaceViewState {
// This method ensures that tiles is initialized and returns mutable references to tiles and map_memory.
pub fn ensure_and_get_mut_refs(
&mut self,
ctx: &egui::Context,
ctx: &ViewerContext<'_>,
egui_ctx: &egui::Context,
) -> Result<(&mut HttpTiles, &mut MapMemory), SpaceViewSystemExecutionError> {
if self.tiles.is_none() {
let tiles = get_tile_manager(self.selected_provider, ctx);
let tiles = get_tile_manager(ctx, self.selected_provider, egui_ctx);
self.tiles = Some(tiles);
}

Expand Down Expand Up @@ -217,7 +218,7 @@ Displays geospatial primitives on a map.
// Map UI
//

let (tiles, map_memory) = match state.ensure_and_get_mut_refs(ui.ctx()) {
let (tiles, map_memory) = match state.ensure_and_get_mut_refs(ctx, ui.ctx()) {
Ok(refs) => refs,
Err(err) => return Err(err),
};
Expand Down Expand Up @@ -446,8 +447,12 @@ fn handle_ui_interactions(
}
}

fn get_tile_manager(provider: MapProvider, egui_ctx: &Context) -> HttpTiles {
let mapbox_access_token = std::env::var("RERUN_MAPBOX_ACCESS_TOKEN").unwrap_or_default();
fn get_tile_manager(
ctx: &ViewerContext<'_>,
provider: MapProvider,
egui_ctx: &Context,
) -> HttpTiles {
let mapbox_access_token = ctx.app_options.mapbox_access_token().unwrap_or_default();

match provider {
MapProvider::OpenStreetMap => {
Expand Down
3 changes: 3 additions & 0 deletions crates/viewer/re_ui/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub enum UICommand {
ToggleSelectionPanel,
ToggleTimePanel,
ToggleChunkStoreBrowser,
Settings,

#[cfg(debug_assertions)]
ToggleBlueprintInspectionPanel,
Expand Down Expand Up @@ -155,6 +156,7 @@ impl UICommand {
Self::ToggleSelectionPanel => ("Toggle selection panel", "Toggle the right panel"),
Self::ToggleTimePanel => ("Toggle time panel", "Toggle the bottom panel"),
Self::ToggleChunkStoreBrowser => ("Toggle chunk store browser", "Toggle the chunk store browser"),
Self::Settings => ("Settings…", "Show the settings screen"),

#[cfg(debug_assertions)]
Self::ToggleBlueprintInspectionPanel => (
Expand Down Expand Up @@ -308,6 +310,7 @@ impl UICommand {
Self::ToggleSelectionPanel => Some(ctrl_shift(Key::S)),
Self::ToggleTimePanel => Some(ctrl_shift(Key::T)),
Self::ToggleChunkStoreBrowser => Some(ctrl_shift(Key::D)),
Self::Settings => None,

#[cfg(debug_assertions)]
Self::ToggleBlueprintInspectionPanel => Some(ctrl_shift(Key::I)),
Expand Down
4 changes: 4 additions & 0 deletions crates/viewer/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,10 @@ impl App {
self.toggle_fullscreen();
}

UICommand::Settings => {
self.state.show_settings_ui = true;
}

#[cfg(not(target_arch = "wasm32"))]
UICommand::ZoomIn => {
let mut zoom_factor = egui_ctx.zoom_factor();
Expand Down
25 changes: 21 additions & 4 deletions crates/viewer/re_viewer/src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use re_viewport_blueprint::ui::add_space_view_or_container_modal_ui;
use re_viewport_blueprint::ViewportBlueprint;

use crate::app_blueprint::AppBlueprint;
use crate::ui::recordings_panel_ui;
use crate::ui::{recordings_panel_ui, settings_screen_ui};

const WATERMARK: bool = false; // Nice for recording media material

Expand All @@ -43,9 +43,17 @@ pub struct AppState {
#[serde(skip)]
datastore_ui: re_chunk_store_ui::DatastoreUi,

/// Display the datastore UI instead of the regular viewer UI.
#[serde(skip)]
pub(crate) show_datastore_ui: bool,

/// Display the settings UI.
///
/// If both `show_datastore_ui` and `show_settings_ui` are true, the settings UI takes
/// precedence.
#[serde(skip)]
pub(crate) show_settings_ui: bool,

/// Storage for the state of each `SpaceView`
///
/// This is stored here for simplicity. An exclusive reference for that is passed to the users,
Expand Down Expand Up @@ -77,6 +85,7 @@ impl Default for AppState {
welcome_screen: Default::default(),
datastore_ui: Default::default(),
show_datastore_ui: false,
show_settings_ui: false,
view_states: Default::default(),
selection_state: Default::default(),
focused_item: Default::default(),
Expand Down Expand Up @@ -152,6 +161,7 @@ impl AppState {
welcome_screen,
datastore_ui,
show_datastore_ui,
show_settings_ui,
view_states,
selection_state,
focused_item,
Expand Down Expand Up @@ -309,8 +319,13 @@ impl AppState {
}
};

// TODO(jleibs): The need to rebuild this after updating the queries is kind of annoying,
// but it's just a bunch of refs so not really that big of a deal in practice.
// must happen before we recreate the view context as we mutably borrow the app options
if *show_settings_ui {
settings_screen_ui(ui, app_options, show_settings_ui);
}

// We need to recreate the context to appease the borrow checker. It is a bit annoying, but
// it's just a bunch of refs so not really that big of a deal in practice.
let ctx = ViewerContext {
app_options,
cache: store_context.caches,
Expand All @@ -331,7 +346,9 @@ impl AppState {
focused_item,
};

if *show_datastore_ui {
if *show_settings_ui {
// nothing: this is already handled above
} else if *show_datastore_ui {
datastore_ui.ui(&ctx, ui, show_datastore_ui, app_options.time_zone);
} else {
//
Expand Down
3 changes: 2 additions & 1 deletion crates/viewer/re_viewer/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ mod top_panel;
mod welcome_screen;

pub(crate) mod memory_panel;
mod settings_screen;

pub use recordings_panel::recordings_panel_ui;
// ----

pub(crate) use {
self::mobile_warning_ui::mobile_warning_ui, self::top_panel::top_panel,
self::welcome_screen::WelcomeScreen,
self::welcome_screen::WelcomeScreen, settings_screen::settings_screen_ui,
};
111 changes: 20 additions & 91 deletions crates/viewer/re_viewer/src/ui/rerun_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use egui::NumExt as _;

use re_log_types::TimeZone;
use re_ui::{UICommand, UiExt as _};
use re_ui::UICommand;
use re_viewer_context::StoreContext;

use crate::App;
Expand Down Expand Up @@ -81,10 +80,10 @@ impl App {

ui.add_space(SPACING);

ui.menu_button("Options", |ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);
options_menu_ui(&self.command_sender, ui, frame, &mut self.state.app_options);
});
UICommand::Settings.menu_button_ui(ui, &self.command_sender);

#[cfg(target_arch = "wasm32")]
backend_menu_ui(&self.command_sender, ui, frame);

#[cfg(debug_assertions)]
ui.menu_button("Debug", |ui| {
Expand Down Expand Up @@ -302,103 +301,31 @@ fn render_state_ui(ui: &mut egui::Ui, render_state: &egui_wgpu::RenderState) {
});
}

fn options_menu_ui(
_command_sender: &re_viewer_context::CommandSender,
/// Adapter switching UI.
// Only implemented for web so far. For native it's less well defined since the application may be
// embedded in another application that reads arguments differently.
#[cfg(target_arch = "wasm32")]
fn backend_menu_ui(
command_sender: &re_viewer_context::CommandSender,
ui: &mut egui::Ui,
frame: &eframe::Frame,
app_options: &mut re_viewer_context::AppOptions,
) {
ui.re_checkbox(&mut app_options.show_metrics, "Show performance metrics")
.on_hover_text("Show metrics for milliseconds/frame and RAM usage in the top bar");

ui.horizontal(|ui| {
ui.label("Timezone:");
});
ui.horizontal(|ui| {
ui.re_radio_value(&mut app_options.time_zone, TimeZone::Utc, "UTC")
.on_hover_text("Display timestamps in UTC");
ui.re_radio_value(&mut app_options.time_zone, TimeZone::Local, "Local")
.on_hover_text("Display timestamps in the local timezone");
ui.re_radio_value(
&mut app_options.time_zone,
TimeZone::UnixEpoch,
"Unix epoch",
)
.on_hover_text("Display timestamps in seconds since unix epoch");
});

ui.re_checkbox(
&mut app_options.include_welcome_screen_button_in_recordings_panel,
"Show 'Welcome screen' button",
);

{
use re_video::decode::DecodeHardwareAcceleration;

let hardware_acceleration = &mut app_options.video_decoder_hw_acceleration;

ui.horizontal(|ui| {
ui.label("Video Decoder:");
egui::ComboBox::from_id_salt("video_decoder_hw_acceleration")
.selected_text(hardware_acceleration.to_string())
.show_ui(ui, |ui| {
ui.selectable_value(
hardware_acceleration,
DecodeHardwareAcceleration::Auto,
DecodeHardwareAcceleration::Auto.to_string(),
) | ui.selectable_value(
hardware_acceleration,
DecodeHardwareAcceleration::PreferSoftware,
DecodeHardwareAcceleration::PreferSoftware.to_string(),
) | ui.selectable_value(
hardware_acceleration,
DecodeHardwareAcceleration::PreferHardware,
DecodeHardwareAcceleration::PreferHardware.to_string(),
)
});
// Note that the setting is part of the video's cache key, so if it changes the cache entries outdate automatically.
});
}

// Currently, the wasm target does not have any experimental features. Remove this conditional
// compilation directive if/when this changes.
#[cfg(not(target_arch = "wasm32"))]
{
ui.add_space(SPACING);
ui.label("Experimental features:");
experimental_feature_ui(ui, app_options);
}

if let Some(_backend) = frame
if let Some(backend) = frame
.wgpu_render_state()
.map(|state| state.adapter.get_info().backend)
{
// Adapter switching only implemented for web so far.
// For native it's less well defined since the application may be embedded in another application that reads arguments differently.
#[cfg(target_arch = "wasm32")]
{
ui.add_space(SPACING);
if _backend == wgpu::Backend::BrowserWebGpu {
UICommand::RestartWithWebGl.menu_button_ui(ui, _command_sender);
} else {
UICommand::RestartWithWebGpu.menu_button_ui(ui, _command_sender);
}
if backend == wgpu::Backend::BrowserWebGpu {
UICommand::RestartWithWebGl.menu_button_ui(ui, command_sender);
} else {
UICommand::RestartWithWebGpu.menu_button_ui(ui, command_sender);
}
}
}

// IMPORTANT: if/when adding wasm-compatible experimental features, move this conditional
// compilation directive to `space_view_screenshot` and remove the one above the call size of this
// function!!
#[cfg(not(target_arch = "wasm32"))]
fn experimental_feature_ui(ui: &mut egui::Ui, app_options: &mut re_viewer_context::AppOptions) {
ui
.re_checkbox(&mut app_options.experimental_space_view_screenshots, "Space view screenshots")
.on_hover_text("Allow taking screenshots of 2D and 3D space views via their context menu. Does not contain labels.");
}

#[cfg(debug_assertions)]
fn egui_debug_options_ui(ui: &mut egui::Ui) {
use re_ui::UiExt as _;

let mut debug = ui.style().debug;
let mut any_clicked = false;

Expand Down Expand Up @@ -441,6 +368,8 @@ fn debug_menu_options_ui(
app_options: &mut re_viewer_context::AppOptions,
command_sender: &CommandSender,
) {
use re_ui::UiExt as _;

#[cfg(not(target_arch = "wasm32"))]
{
if ui.button("Mobile size").clicked() {
Expand Down
Loading
Loading