diff --git a/icons/valve_control/dark/wiggle.svg b/icons/valve_control/dark/wiggle.svg new file mode 100644 index 0000000000000000000000000000000000000000..f033a58e4a904951697bb1e001a560cc6c40e3d7 --- /dev/null +++ b/icons/valve_control/dark/wiggle.svg @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --> + +<svg + width="800px" + height="800px" + viewBox="0 0 24 24" + fill="none" + version="1.1" + id="svg1" + sodipodi:docname="rotate-svgrepo-com.svg" + inkscape:version="1.4 (e7c3feb1, 2024-10-09)" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg"> + <defs + id="defs1" /> + <sodipodi:namedview + id="namedview1" + pagecolor="#505050" + bordercolor="#eeeeee" + borderopacity="1" + inkscape:showpageshadow="0" + inkscape:pageopacity="0" + inkscape:pagecheckerboard="0" + inkscape:deskcolor="#505050" + inkscape:zoom="0.26520082" + inkscape:cx="350.67764" + inkscape:cy="444.94583" + inkscape:window-width="1104" + inkscape:window-height="847" + inkscape:window-x="0" + inkscape:window-y="25" + inkscape:window-maximized="0" + inkscape:current-layer="svg1" /> + <path + d="M4.06189 13C4.02104 12.6724 4 12.3387 4 12C4 7.58172 7.58172 4 12 4C14.5006 4 16.7332 5.14727 18.2002 6.94416M19.9381 11C19.979 11.3276 20 11.6613 20 12C20 16.4183 16.4183 20 12 20C9.61061 20 7.46589 18.9525 6 17.2916M9 17H6V17.2916M18.2002 4V6.94416M18.2002 6.94416V6.99993L15.2002 7M6 20V17.2916" + stroke="#000000" + stroke-width="2" + stroke-linecap="round" + stroke-linejoin="round" + id="path1" + style="fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#8c8c8c;stroke-opacity:1" /> +</svg> diff --git a/icons/valve_control/light/wiggle.svg b/icons/valve_control/light/wiggle.svg new file mode 100644 index 0000000000000000000000000000000000000000..864577ec13906b906d6217c335ca58e493b88a66 --- /dev/null +++ b/icons/valve_control/light/wiggle.svg @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --> + +<svg + width="800px" + height="800px" + viewBox="0 0 24 24" + fill="none" + version="1.1" + id="svg1" + sodipodi:docname="wiggle.svg" + inkscape:version="1.4 (e7c3feb1, 2024-10-09)" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg"> + <defs + id="defs1" /> + <sodipodi:namedview + id="namedview1" + pagecolor="#505050" + bordercolor="#eeeeee" + borderopacity="1" + inkscape:showpageshadow="0" + inkscape:pageopacity="0" + inkscape:pagecheckerboard="0" + inkscape:deskcolor="#505050" + inkscape:zoom="0.26520082" + inkscape:cx="350.67765" + inkscape:cy="444.94583" + inkscape:window-width="1104" + inkscape:window-height="847" + inkscape:window-x="0" + inkscape:window-y="25" + inkscape:window-maximized="0" + inkscape:current-layer="svg1" /> + <path + d="M4.06189 13C4.02104 12.6724 4 12.3387 4 12C4 7.58172 7.58172 4 12 4C14.5006 4 16.7332 5.14727 18.2002 6.94416M19.9381 11C19.979 11.3276 20 11.6613 20 12C20 16.4183 16.4183 20 12 20C9.61061 20 7.46589 18.9525 6 17.2916M9 17H6V17.2916M18.2002 4V6.94416M18.2002 6.94416V6.99993L15.2002 7M6 20V17.2916" + stroke="#000000" + stroke-width="2" + stroke-linecap="round" + stroke-linejoin="round" + id="path1" + style="fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#505050;stroke-opacity:1" /> +</svg> diff --git a/src/ui/panes/valve_control.rs b/src/ui/panes/valve_control.rs index 6564ae30f46ad6b08b88c2bd327cd94e68e005e3..d1971b68d77ef8ae0a1cea8dab7e8db4d36b18ec 100644 --- a/src/ui/panes/valve_control.rs +++ b/src/ui/panes/valve_control.rs @@ -22,6 +22,7 @@ use strum::IntoEnumIterator; use tracing::{error, info, warn}; use crate::{ + error::ErrInstrument, mavlink::{MavMessage, TimedMessage}, ui::{ app::PaneResponse, @@ -87,6 +88,7 @@ impl Default for ValveControlPane { } impl PaneBehavior for ValveControlPane { + #[profiling::function] fn ui(&mut self, ui: &mut Ui, shortcut_handler: &mut ShortcutHandler) -> PaneResponse { let mut pane_response = PaneResponse::default(); @@ -152,6 +154,7 @@ impl PaneBehavior for ValveControlPane { pane_response } + #[profiling::function] fn get_message_subscriptions(&self) -> Box<dyn Iterator<Item = u32>> { let mut subscriptions = vec![]; if self.needs_refresh() { @@ -169,6 +172,7 @@ impl PaneBehavior for ValveControlPane { Box::new(subscriptions.into_iter()) } + #[profiling::function] fn update(&mut self, messages: &[&TimedMessage]) { if self.needs_refresh() { // TODO @@ -192,6 +196,7 @@ impl PaneBehavior for ValveControlPane { self.reset_last_refresh(); } + #[profiling::function] fn drain_outgoing_messages(&mut self) -> Vec<MavMessage> { let mut outgoing = vec![]; @@ -213,6 +218,7 @@ const BTN_MAX_WIDTH: f32 = 125.; impl ValveControlPane { fn pane_ui(&mut self) -> impl FnOnce(&mut Ui) { |ui| { + profiling::function_scope!("pane_ui"); ui.set_min_width(BTN_MAX_WIDTH); let n = (ui.max_rect().width() / BTN_MAX_WIDTH) as usize; let valve_chunks = SYMBOL_LIST.chars().zip(Valve::iter()).chunks(n.max(1)); @@ -232,6 +238,7 @@ impl ValveControlPane { fn menu_ui(&mut self) -> impl FnOnce(&mut Ui) { |ui| { + profiling::function_scope!("menu_ui"); if ui.button("Refresh now").clicked() { self.manual_refresh = true; ui.close_menu(); @@ -245,6 +252,7 @@ impl ValveControlPane { fn settings_window_ui(auto_refresh_setting: &mut Option<Duration>) -> impl FnOnce(&mut Ui) { |ui| { + profiling::function_scope!("settings_window_ui"); // Display auto refresh setting let mut auto_refresh = auto_refresh_setting.is_some(); ui.horizontal(|ui| { @@ -271,6 +279,7 @@ impl ValveControlPane { fn valve_frame_ui(&self, valve: Valve, symbol: char) -> impl FnOnce(&mut Ui) { move |ui| { + profiling::function_scope!("valve_frame_ui"); let valve_str = valve.to_string(); let timing = self.valves_state.get_timing_for(valve); let aperture = self.valves_state.get_aperture_for(valve); @@ -308,34 +317,6 @@ impl ValveControlPane { .ui(ui); }; - fn big_number_ui( - response: &Response, - symbol: char, - text_color: Color32, - ) -> impl Fn(&mut Ui) { - move |ui: &mut Ui| { - let visuals = ui.style().interact(response); - let number = RichText::new(symbol.to_string()) - .color(text_color) - .font(FontId::monospace(20.)); - - let fill_color = if response.hovered() { - visuals.bg_fill.gamma_multiply(0.8).to_opaque() - } else { - visuals.bg_fill - }; - - Frame::canvas(ui.style()) - .fill(fill_color) - .stroke(Stroke::NONE) - .inner_margin(Margin::same(5)) - .corner_radius(visuals.corner_radius) - .show(ui, |ui| { - Label::new(number).selectable(false).ui(ui); - }); - } - } - let labels_ui = |ui: &mut Ui| { let icon_size = Vec2::splat(17.); let text_format = TextFormat { @@ -377,9 +358,9 @@ impl ValveControlPane { }; fn inside_frame( - response: &Response, valve_title_ui: impl FnOnce(&mut Ui), symbol: char, + btn_fill_color: Color32, text_color: Color32, labels_ui: impl FnOnce(&mut Ui), ) -> impl FnOnce(&mut Ui) { @@ -387,7 +368,7 @@ impl ValveControlPane { ui.vertical(|ui| { valve_title_ui(ui); ui.horizontal(|ui| { - big_number_ui(response, symbol, text_color)(ui); + big_symbol_ui(symbol, btn_fill_color, text_color)(ui); labels_ui(ui); }); }); @@ -408,6 +389,12 @@ impl ValveControlPane { visuals.bg_fill.gamma_multiply(0.3) }; + let btn_fill_color = if response.hovered() { + visuals.bg_fill.gamma_multiply(0.8).to_opaque() + } else { + visuals.bg_fill + }; + Frame::canvas(ui.style()) .fill(fill_color) .stroke(Stroke::NONE) @@ -416,9 +403,9 @@ impl ValveControlPane { .show( ui, inside_frame( - &response, &valve_title_ui, symbol, + btn_fill_color, text_color, &labels_ui, ), @@ -442,11 +429,13 @@ impl ValveControlPane { action: Option<PaneAction>, ) -> impl FnOnce(&mut Ui) { move |ui| { + profiling::function_scope!("valve_control_window_ui"); let icon_size = Vec2::splat(25.); let text_size = 16.; fn btn_ui<R>( valve: Valve, + key: Key, add_contents: impl FnOnce(&mut Ui) -> R, ) -> impl FnOnce(&mut Ui) -> Response { move |ui| { @@ -455,7 +444,7 @@ impl ValveControlPane { .corner_radius(ui.visuals().noninteractive().corner_radius); wiggle_btn = ui.ctx().input(|input| { - if input.key_down(ValveControlPane::WIGGLE_KEY) { + if input.key_down(key) { wiggle_btn .fill(ui.visuals().widgets.active.bg_fill) .stroke(ui.visuals().widgets.active.fg_stroke) @@ -471,16 +460,28 @@ impl ValveControlPane { .id_salt(format!("valve_control_window_{}_wiggle", valve)) .sense(Sense::click()), |ui| { - wiggle_btn.show(ui, |ui| ui.horizontal(|ui| add_contents(ui))); + wiggle_btn.show(ui, |ui| { + ui.set_width(200.); + ui.horizontal(|ui| add_contents(ui)) + }); }, ) .response } } - let wiggle_btn_response = btn_ui(valve, |ui| { + let wiggle_btn_response = btn_ui(valve, Self::WIGGLE_KEY, |ui| { + big_symbol_ui( + Self::WIGGLE_KEY + .symbol_or_name() + .chars() + .next() + .log_unwrap(), + ui.visuals().widgets.inactive.bg_fill, + ui.visuals().text_color(), + )(ui); ui.add( - Icon::Aperture + Icon::Wiggle .as_image(ui.ctx().theme()) .fit_to_exact_size(icon_size), ); @@ -488,7 +489,16 @@ impl ValveControlPane { })(ui); let mut aperture = 0_u32; - let aperture_btn_response = btn_ui(valve, |ui| { + let aperture_btn_response = btn_ui(valve, Self::APERTURE_KEY, |ui| { + big_symbol_ui( + Self::APERTURE_KEY + .symbol_or_name() + .chars() + .next() + .log_unwrap(), + ui.visuals().widgets.inactive.bg_fill, + ui.visuals().text_color(), + )(ui); ui.add( Icon::Aperture .as_image(ui.ctx().theme()) @@ -506,7 +516,16 @@ impl ValveControlPane { })(ui); let mut timing_ms = 0_u32; - let timing_btn_response = btn_ui(valve, |ui| { + let timing_btn_response = btn_ui(valve, Self::TIMING_KEY, |ui| { + big_symbol_ui( + Self::TIMING_KEY + .symbol_or_name() + .chars() + .next() + .log_unwrap(), + ui.visuals().widgets.inactive.bg_fill, + ui.visuals().text_color(), + )(ui); ui.add( Icon::Timing .as_image(ui.ctx().theme()) @@ -532,6 +551,7 @@ impl ValveControlPane { } } + #[profiling::function] fn keyboard_actions(&self, shortcut_handler: &mut ShortcutHandler) -> Option<PaneAction> { let mut key_action_pairs = Vec::new(); match self @@ -627,6 +647,23 @@ impl ValveControlPane { } } +fn big_symbol_ui(symbol: char, fill_color: Color32, text_color: Color32) -> impl Fn(&mut Ui) { + move |ui: &mut Ui| { + let number = RichText::new(symbol.to_string()) + .color(text_color) + .font(FontId::monospace(20.)); + + Frame::canvas(ui.style()) + .fill(fill_color) + .stroke(Stroke::NONE) + .inner_margin(Margin::same(5)) + .corner_radius(ui.visuals().widgets.noninteractive.corner_radius) + .show(ui, |ui| { + Label::new(number).selectable(false).ui(ui); + }); + } +} + // ┌───────────────────────────┐ // │ UTILS METHODS │ // └───────────────────────────┘ diff --git a/src/ui/panes/valve_control/icons.rs b/src/ui/panes/valve_control/icons.rs index f8d70a96c88d77ec728d7b4bcf3648cef2b179b4..b8b14e419b3a6f870b2312af4ea8cf0373c46937 100644 --- a/src/ui/panes/valve_control/icons.rs +++ b/src/ui/panes/valve_control/icons.rs @@ -7,6 +7,7 @@ use crate::error::ErrInstrument; #[derive(Debug, Clone, Copy, EnumIter)] pub enum Icon { + Wiggle, Aperture, Timing, } @@ -14,6 +15,18 @@ pub enum Icon { impl Icon { fn as_image_source(&self, theme: Theme) -> ImageSource { match (&self, theme) { + (Icon::Wiggle, Theme::Light) => { + egui::include_image!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/icons/valve_control/light/wiggle.svg" + )) + } + (Icon::Wiggle, Theme::Dark) => { + egui::include_image!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/icons/valve_control/dark/wiggle.svg" + )) + } (Icon::Aperture, Theme::Light) => { egui::include_image!(concat!( env!("CARGO_MANIFEST_DIR"), @@ -56,9 +69,4 @@ impl Icon { pub fn as_image(&self, theme: Theme) -> Image { Image::new(self.as_image_source(theme)) } - - pub fn reset_cache(&self, ui: &mut Ui) { - let img: Image = self.as_image(ui.ctx().theme()); - ui.ctx().forget_image(img.uri().log_unwrap()); - } }