diff --git a/src/gui/screens/accounts.rs b/src/gui/screens/accounts.rs index a24cf12..e3c33cc 100644 --- a/src/gui/screens/accounts.rs +++ b/src/gui/screens/accounts.rs @@ -58,7 +58,8 @@ impl Screen for Accounts { icon: SYM_SETTINGS.into(), on_click: Box::new(on_right_click), })) - .ui(ui, &mut Some(nav)); + .with_navigator(nav) + .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 5901954..656f053 100644 --- a/src/gui/views/title_panel.rs +++ b/src/gui/views/title_panel.rs @@ -33,12 +33,13 @@ pub struct PanelActions { } #[derive(Default)] -pub struct TitlePanel { +pub struct TitlePanel<'screen> { title: Option, - actions: PanelActions + actions: PanelActions, + navigator: Option<&'screen mut Navigator> } -impl TitlePanel { +impl<'screen> TitlePanel<'screen> { pub fn title(mut self, title: String) -> Self { self.title = Some(title); self @@ -53,17 +54,22 @@ impl TitlePanel { self.actions.right = action; self } + + pub fn with_navigator(mut self, nav: &'screen mut Navigator) -> Self { + self.navigator = Some(nav); + self + } } -impl TitlePanel { - pub(crate) fn ui(&mut self, ui: &mut egui::Ui, nav: &mut Option<&mut Navigator>) { +impl TitlePanel<'_> { + pub(crate) fn ui(&mut self, ui: &mut egui::Ui) { // Disable stroke around panel ui.style_mut().visuals.widgets.noninteractive.bg_stroke = Stroke::NONE; // Disable stroke around buttons on hover ui.style_mut().visuals.widgets.active.bg_stroke = Stroke::NONE; - let Self { actions, title } = self; + let Self { actions, title, navigator } = self; egui::TopBottomPanel::top("title_panel") .resizable(false) @@ -96,7 +102,7 @@ impl TitlePanel { .ui(ui) .interact(Sense::click_and_drag()); if b.drag_released() || b.clicked() { - (action.on_click)(nav); + (action.on_click)(navigator); }; }); } @@ -125,7 +131,7 @@ impl TitlePanel { ).fill(Color32::TRANSPARENT) .ui(ui).interact(Sense::click_and_drag()); if b.drag_released() || b.clicked() { - (action.on_click)(nav); + (action.on_click)(navigator); }; }); }