From cea0716eb6452b7897b42383fa36b85f25eb3e3c Mon Sep 17 00:00:00 2001 From: ardocrat Date: Thu, 27 Apr 2023 22:02:10 +0300 Subject: [PATCH] gui: optimize title panel --- src/gui/screens/accounts.rs | 26 +++++++++++++------------- src/gui/views/title_panel.rs | 12 ++++++------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/gui/screens/accounts.rs b/src/gui/screens/accounts.rs index e3c33cc..6782e38 100644 --- a/src/gui/screens/accounts.rs +++ b/src/gui/screens/accounts.rs @@ -13,6 +13,7 @@ // limitations under the License. use std::ops::{Deref, DerefMut}; +use egui::Widget; use crate::gui::platform::PlatformCallbacks; use crate::gui::screens::{Navigator, Screen, ScreenId}; use crate::gui::{SYM_ACCOUNTS, SYM_ARROW_BACK, SYM_NETWORK, SYM_SETTINGS}; @@ -44,22 +45,21 @@ impl Screen for Accounts { cb: &dyn PlatformCallbacks) { let Self { title } = self; - TitlePanel::default() + let mut panel: TitlePanel = TitlePanel::default() .title(title.to_owned()) - .left_action(if !dual_panel_mode(frame) { - Some(PanelAction { - icon: SYM_NETWORK.into(), - on_click: Box::new(on_left_click), - }) - } else { - None - }) - .right_action(Some(PanelAction { + .right_action(PanelAction { icon: SYM_SETTINGS.into(), on_click: Box::new(on_right_click), - })) - .with_navigator(nav) - .ui(ui); + }) + .with_navigator(nav); + if !dual_panel_mode(frame) { + panel = panel.left_action(PanelAction { + icon: SYM_NETWORK.into(), + on_click: Box::new(on_left_click), + }); + } + panel.ui(ui); + ui.label(format!("{}Here we go 10000 ツ", SYM_ARROW_BACK)); if ui.button("TEST").clicked() { nav.to(ScreenId::Account) diff --git a/src/gui/views/title_panel.rs b/src/gui/views/title_panel.rs index 656f053..3ef6d9a 100644 --- a/src/gui/views/title_panel.rs +++ b/src/gui/views/title_panel.rs @@ -45,13 +45,13 @@ impl<'screen> TitlePanel<'screen> { self } - pub fn left_action(mut self, action: Option) -> Self { - self.actions.left = action; + pub fn left_action(mut self, action: PanelAction) -> Self { + self.actions.left = Some(action); self } - pub fn right_action(mut self, action: Option) -> Self { - self.actions.right = action; + pub fn right_action(mut self, action: PanelAction) -> Self { + self.actions.right = Some(action); self } @@ -61,8 +61,8 @@ impl<'screen> TitlePanel<'screen> { } } -impl TitlePanel<'_> { - pub(crate) fn ui(&mut self, ui: &mut egui::Ui) { +impl View for TitlePanel<'_> { + fn ui(&mut self, ui: &mut egui::Ui) { // Disable stroke around panel ui.style_mut().visuals.widgets.noninteractive.bg_stroke = Stroke::NONE;