From 649a01d6f43d4871ba4750685334524a50d234be Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 19 Nov 2024 14:45:59 +0100 Subject: [PATCH] Break out a long function --- crates/viewer/re_viewer/src/ui/rerun_menu.rs | 130 ++++++++++--------- 1 file changed, 69 insertions(+), 61 deletions(-) diff --git a/crates/viewer/re_viewer/src/ui/rerun_menu.rs b/crates/viewer/re_viewer/src/ui/rerun_menu.rs index ea84b0b20412..a53da627b3a3 100644 --- a/crates/viewer/re_viewer/src/ui/rerun_menu.rs +++ b/crates/viewer/re_viewer/src/ui/rerun_menu.rs @@ -25,90 +25,98 @@ 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(ui, render_state)); + 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, frame); - 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, ui: &mut egui::Ui, render_state: Option<&egui_wgpu::RenderState>) {