gui: pass navigator to title panel at separate method

This commit is contained in:
ardocrat 2023-04-27 21:49:37 +03:00
parent 3cb7918db2
commit f7c911fd9b
2 changed files with 16 additions and 9 deletions

View file

@ -58,7 +58,8 @@ impl Screen for Accounts {
icon: SYM_SETTINGS.into(), icon: SYM_SETTINGS.into(),
on_click: Box::new(on_right_click), 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)); ui.label(format!("{}Here we go 10000 ツ", SYM_ARROW_BACK));
if ui.button("TEST").clicked() { if ui.button("TEST").clicked() {
nav.to(ScreenId::Account) nav.to(ScreenId::Account)

View file

@ -33,12 +33,13 @@ pub struct PanelActions {
} }
#[derive(Default)] #[derive(Default)]
pub struct TitlePanel { pub struct TitlePanel<'screen> {
title: Option<String>, title: Option<String>,
actions: PanelActions actions: PanelActions,
navigator: Option<&'screen mut Navigator>
} }
impl TitlePanel { impl<'screen> TitlePanel<'screen> {
pub fn title(mut self, title: String) -> Self { pub fn title(mut self, title: String) -> Self {
self.title = Some(title); self.title = Some(title);
self self
@ -53,17 +54,22 @@ impl TitlePanel {
self.actions.right = action; self.actions.right = action;
self self
} }
pub fn with_navigator(mut self, nav: &'screen mut Navigator) -> Self {
self.navigator = Some(nav);
self
}
} }
impl TitlePanel { impl TitlePanel<'_> {
pub(crate) fn ui(&mut self, ui: &mut egui::Ui, nav: &mut Option<&mut Navigator>) { pub(crate) fn ui(&mut self, ui: &mut egui::Ui) {
// Disable stroke around panel // Disable stroke around panel
ui.style_mut().visuals.widgets.noninteractive.bg_stroke = Stroke::NONE; ui.style_mut().visuals.widgets.noninteractive.bg_stroke = Stroke::NONE;
// Disable stroke around buttons on hover // Disable stroke around buttons on hover
ui.style_mut().visuals.widgets.active.bg_stroke = Stroke::NONE; 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") egui::TopBottomPanel::top("title_panel")
.resizable(false) .resizable(false)
@ -96,7 +102,7 @@ impl TitlePanel {
.ui(ui) .ui(ui)
.interact(Sense::click_and_drag()); .interact(Sense::click_and_drag());
if b.drag_released() || b.clicked() { if b.drag_released() || b.clicked() {
(action.on_click)(nav); (action.on_click)(navigator);
}; };
}); });
} }
@ -125,7 +131,7 @@ impl TitlePanel {
).fill(Color32::TRANSPARENT) ).fill(Color32::TRANSPARENT)
.ui(ui).interact(Sense::click_and_drag()); .ui(ui).interact(Sense::click_and_drag());
if b.drag_released() || b.clicked() { if b.drag_released() || b.clicked() {
(action.on_click)(nav); (action.on_click)(navigator);
}; };
}); });
} }