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

Refactor rerun menu slightly #8177

Merged
merged 3 commits into from
Nov 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
143 changes: 74 additions & 69 deletions crates/viewer/re_viewer/src/ui/rerun_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const SPACING: f32 = 12.0;
impl App {
pub fn rerun_menu_button_ui(
&mut self,
frame: &eframe::Frame,
render_state: Option<&egui_wgpu::RenderState>,
_store_context: Option<&StoreContext<'_>>,
ui: &mut egui::Ui,
) {
Expand All @@ -25,93 +25,101 @@ impl App {
.max_height(desired_icon_height);

ui.menu_image_button(image, |ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend); // no wrapping: make as wide as needed

ui.menu_button("About", |ui| self.about_rerun_ui(frame, ui));
self.rerun_menu_ui(ui, render_state, _store_context);
});
}

ui.add_space(SPACING);
fn rerun_menu_ui(
&mut self,
ui: &mut egui::Ui,
render_state: Option<&egui_wgpu::RenderState>,
_store_context: Option<&StoreContext<'_>>,
) {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);
// no wrapping: make as wide as needed

UICommand::ToggleCommandPalette.menu_button_ui(ui, &self.command_sender);
ui.menu_button("About", |ui| self.about_rerun_ui(ui, render_state));

ui.add_space(SPACING);
ui.add_space(SPACING);

UICommand::Open.menu_button_ui(ui, &self.command_sender);
UICommand::Import.menu_button_ui(ui, &self.command_sender);
UICommand::ToggleCommandPalette.menu_button_ui(ui, &self.command_sender);

self.save_buttons_ui(ui, _store_context);
ui.add_space(SPACING);

UICommand::SaveBlueprint.menu_button_ui(ui, &self.command_sender);
UICommand::Open.menu_button_ui(ui, &self.command_sender);
UICommand::Import.menu_button_ui(ui, &self.command_sender);

UICommand::CloseCurrentRecording.menu_button_ui(ui, &self.command_sender);
self.save_buttons_ui(ui, _store_context);

ui.add_space(SPACING);
UICommand::SaveBlueprint.menu_button_ui(ui, &self.command_sender);

#[cfg(not(target_arch = "wasm32"))]
{
// On the web the browser controls the zoom
let zoom_factor = ui.ctx().zoom_factor();
ui.weak(format!("Current zoom: {:.0}%", zoom_factor * 100.0))
.on_hover_text(
"The UI zoom level on top of the operating system's default value",
);
UICommand::ZoomIn.menu_button_ui(ui, &self.command_sender);
UICommand::ZoomOut.menu_button_ui(ui, &self.command_sender);
ui.add_enabled_ui(zoom_factor != 1.0, |ui| {
UICommand::ZoomReset.menu_button_ui(ui, &self.command_sender)
});
UICommand::CloseCurrentRecording.menu_button_ui(ui, &self.command_sender);

UICommand::ToggleFullscreen.menu_button_ui(ui, &self.command_sender);
ui.add_space(SPACING);

ui.add_space(SPACING);
}
#[cfg(not(target_arch = "wasm32"))]
{
// On the web the browser controls the zoom
let zoom_factor = ui.ctx().zoom_factor();
ui.weak(format!("Current zoom: {:.0}%", zoom_factor * 100.0))
.on_hover_text("The UI zoom level on top of the operating system's default value");
UICommand::ZoomIn.menu_button_ui(ui, &self.command_sender);
UICommand::ZoomOut.menu_button_ui(ui, &self.command_sender);
ui.add_enabled_ui(zoom_factor != 1.0, |ui| {
UICommand::ZoomReset.menu_button_ui(ui, &self.command_sender)
});

{
UICommand::ResetViewer.menu_button_ui(ui, &self.command_sender);
UICommand::ToggleFullscreen.menu_button_ui(ui, &self.command_sender);

#[cfg(not(target_arch = "wasm32"))]
UICommand::OpenProfiler.menu_button_ui(ui, &self.command_sender);
ui.add_space(SPACING);
}

UICommand::ToggleMemoryPanel.menu_button_ui(ui, &self.command_sender);
UICommand::ToggleChunkStoreBrowser.menu_button_ui(ui, &self.command_sender);
{
UICommand::ResetViewer.menu_button_ui(ui, &self.command_sender);

#[cfg(debug_assertions)]
UICommand::ToggleEguiDebugPanel.menu_button_ui(ui, &self.command_sender);
}
#[cfg(not(target_arch = "wasm32"))]
UICommand::OpenProfiler.menu_button_ui(ui, &self.command_sender);

ui.add_space(SPACING);
UICommand::ToggleMemoryPanel.menu_button_ui(ui, &self.command_sender);
UICommand::ToggleChunkStoreBrowser.menu_button_ui(ui, &self.command_sender);

UICommand::Settings.menu_button_ui(ui, &self.command_sender);
#[cfg(debug_assertions)]
UICommand::ToggleEguiDebugPanel.menu_button_ui(ui, &self.command_sender);
}

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

#[cfg(debug_assertions)]
ui.menu_button("Debug", |ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);
debug_menu_options_ui(ui, &mut self.state.app_options, &self.command_sender);

ui.label("egui debug options:");
ui.weak(format!(
"pixels_per_point: {:?}",
ui.ctx().pixels_per_point()
));
egui_debug_options_ui(ui);
});
UICommand::Settings.menu_button_ui(ui, &self.command_sender);

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

UICommand::OpenWebHelp.menu_button_ui(ui, &self.command_sender);
UICommand::OpenRerunDiscord.menu_button_ui(ui, &self.command_sender);
#[cfg(debug_assertions)]
ui.menu_button("Debug", |ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);
debug_menu_options_ui(ui, &mut self.state.app_options, &self.command_sender);

#[cfg(not(target_arch = "wasm32"))]
{
ui.add_space(SPACING);
UICommand::Quit.menu_button_ui(ui, &self.command_sender);
}
ui.label("egui debug options:");
ui.weak(format!(
"pixels_per_point: {:?}",
ui.ctx().pixels_per_point()
));
egui_debug_options_ui(ui);
});

ui.add_space(SPACING);

UICommand::OpenWebHelp.menu_button_ui(ui, &self.command_sender);
UICommand::OpenRerunDiscord.menu_button_ui(ui, &self.command_sender);

#[cfg(not(target_arch = "wasm32"))]
{
ui.add_space(SPACING);
UICommand::Quit.menu_button_ui(ui, &self.command_sender);
}
}

fn about_rerun_ui(&self, frame: &eframe::Frame, ui: &mut egui::Ui) {
fn about_rerun_ui(&self, ui: &mut egui::Ui, render_state: Option<&egui_wgpu::RenderState>) {
let re_build_info::BuildInfo {
crate_name,
features,
Expand Down Expand Up @@ -158,7 +166,7 @@ impl App {

ui.label(label);

if let Some(render_state) = frame.wgpu_render_state() {
if let Some(render_state) = render_state {
render_state_ui(ui, render_state);
}
}
Expand Down Expand Up @@ -308,12 +316,9 @@ fn render_state_ui(ui: &mut egui::Ui, render_state: &egui_wgpu::RenderState) {
fn backend_menu_ui(
command_sender: &re_viewer_context::CommandSender,
ui: &mut egui::Ui,
frame: &eframe::Frame,
render_state: Option<&egui_wgpu::RenderState>,
) {
if let Some(backend) = frame
.wgpu_render_state()
.map(|state| state.adapter.get_info().backend)
{
if let Some(backend) = render_state.map(|state| state.adapter.get_info().backend) {
if backend == wgpu::Backend::BrowserWebGpu {
UICommand::RestartWithWebGl.menu_button_ui(ui, command_sender);
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_viewer/src/ui/top_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn top_bar_ui(
ui: &mut egui::Ui,
gpu_resource_stats: &WgpuResourcePoolStatistics,
) {
app.rerun_menu_button_ui(frame, store_context, ui);
app.rerun_menu_button_ui(frame.wgpu_render_state(), store_context, ui);

ui.add_space(12.0);
website_link_ui(ui);
Expand Down
Loading