diff --git a/src/gui/screens/accounts.rs b/src/gui/screens/accounts.rs index 1935b87..1e7a46e 100644 --- a/src/gui/screens/accounts.rs +++ b/src/gui/screens/accounts.rs @@ -18,7 +18,7 @@ use crate::gui::icons::{ARROW_CIRCLE_LEFT, GLOBE, PLUS}; use crate::gui::{Colors, Navigator}; use crate::gui::platform::PlatformCallbacks; use crate::gui::screens::{Screen, ScreenId}; -use crate::gui::views::{TitlePanel, TitlePanelAction, View}; +use crate::gui::views::{TitlePanel, TitleAction, View}; #[derive(Default)] pub struct Accounts; @@ -29,16 +29,15 @@ impl Screen for Accounts { } fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) { - TitlePanel::new(t!("screen_accounts.title")) - .ui(if !View::is_dual_panel_mode(frame) { - TitlePanelAction::new(GLOBE, || { - Navigator::toggle_side_panel(); - }) - } else { - None - }, TitlePanelAction::new(PLUS, || { - //TODO: add account - }), ui); + TitlePanel::ui(t!("screen_accounts.title"), if !View::is_dual_panel_mode(frame) { + TitleAction::new(GLOBE, || { + Navigator::toggle_side_panel(); + }) + } else { + None + }, TitleAction::new(PLUS, || { + //TODO: add account + }), ui); egui::CentralPanel::default() .frame(Frame { diff --git a/src/gui/views/network/container.rs b/src/gui/views/network/container.rs index 9696b62..1ad9844 100644 --- a/src/gui/views/network/container.rs +++ b/src/gui/views/network/container.rs @@ -23,7 +23,7 @@ use crate::AppConfig; use crate::gui::{Colors, Navigator}; use crate::gui::icons::{CARDHOLDER, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE}; use crate::gui::platform::PlatformCallbacks; -use crate::gui::views::{Modal, ModalContainer, View}; +use crate::gui::views::{Modal, ModalContainer, TitlePanel, View}; use crate::gui::views::network::configs::server::ServerSetup; use crate::gui::views::network::configs::stratum::StratumServerSetup; use crate::gui::views::network::metrics::NetworkMetrics; @@ -171,7 +171,7 @@ impl NetworkContainer { /// Draw title content. fn title_ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) { StripBuilder::new(ui) - .size(Size::exact(52.0)) + .size(Size::exact(TitlePanel::DEFAULT_HEIGHT)) .vertical(|mut strip| { strip.strip(|builder| { builder diff --git a/src/gui/views/title_panel.rs b/src/gui/views/title_panel.rs index 11bc7c6..7af5844 100644 --- a/src/gui/views/title_panel.rs +++ b/src/gui/views/title_panel.rs @@ -18,29 +18,23 @@ use egui_extras::{Size, StripBuilder}; use crate::gui::Colors; use crate::gui::views::View; -pub struct TitlePanelAction { +pub struct TitleAction { pub(crate) icon: Box<&'static str>, pub(crate) on_click: Box, } -impl TitlePanelAction { +impl TitleAction { pub fn new(icon: &'static str, on_click: fn()) -> Option { Option::from(Self { icon: Box::new(icon), on_click: Box::new(on_click) }) } } -pub struct TitlePanel { - title: String, -} +pub struct TitlePanel; impl TitlePanel { - const PANEL_HEIGHT: f32 = 52.0; + pub const DEFAULT_HEIGHT: f32 = 52.0; - pub fn new(title: String) -> Self { - Self { title: title.to_uppercase() } - } - - pub fn ui(&self, l: Option, r: Option, ui: &mut egui::Ui) { + pub fn ui(title: String, l: Option, r: Option, ui: &mut egui::Ui) { egui::TopBottomPanel::top("title_panel") .resizable(false) .frame(egui::Frame { @@ -52,22 +46,22 @@ impl TitlePanel { }) .show_inside(ui, |ui| { StripBuilder::new(ui) - .size(Size::exact(Self::PANEL_HEIGHT)) + .size(Size::exact(Self::DEFAULT_HEIGHT)) .vertical(|mut strip| { strip.strip(|builder| { builder - .size(Size::exact(Self::PANEL_HEIGHT)) + .size(Size::exact(Self::DEFAULT_HEIGHT)) .size(Size::remainder()) - .size(Size::exact(Self::PANEL_HEIGHT)) + .size(Size::exact(Self::DEFAULT_HEIGHT)) .horizontal(|mut strip| { strip.cell(|ui| { - self.draw_action(ui, l); + Self::draw_action(ui, l); }); strip.cell(|ui| { - self.draw_title(ui); + Self::draw_title(ui, title); }); strip.cell(|ui| { - self.draw_action(ui, r); + Self::draw_action(ui, r); }); }); }); @@ -75,7 +69,7 @@ impl TitlePanel { }); } - fn draw_action(&self, ui: &mut egui::Ui, action: Option) { + fn draw_action(ui: &mut egui::Ui, action: Option) { if action.is_some() { let action = action.unwrap(); ui.centered_and_justified(|ui| { @@ -86,10 +80,9 @@ impl TitlePanel { } } - fn draw_title(&self, ui: &mut egui::Ui) { - let Self { title } = self; + fn draw_title(ui: &mut egui::Ui, title: String) { ui.centered_and_justified(|ui| { - View::ellipsize_text(ui, title.into(), 20.0, Colors::TITLE); + View::ellipsize_text(ui, title.to_uppercase(), 20.0, Colors::TITLE); }); } }