ui: optimize title panel

This commit is contained in:
ardocrat 2023-07-04 01:28:27 +03:00
parent 91e743fab5
commit 2ac0c108e7
3 changed files with 26 additions and 34 deletions

View file

@ -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 {

View file

@ -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

View file

@ -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<dyn Fn()>,
}
impl TitlePanelAction {
impl TitleAction {
pub fn new(icon: &'static str, on_click: fn()) -> Option<Self> {
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<TitlePanelAction>, r: Option<TitlePanelAction>, ui: &mut egui::Ui) {
pub fn ui(title: String, l: Option<TitleAction>, r: Option<TitleAction>, 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<TitlePanelAction>) {
fn draw_action(ui: &mut egui::Ui, action: Option<TitleAction>) {
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);
});
}
}