gui: optimize title panel

This commit is contained in:
ardocrat 2023-04-27 22:02:10 +03:00
parent f7c911fd9b
commit cea0716eb6
2 changed files with 19 additions and 19 deletions

View file

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use egui::Widget;
use crate::gui::platform::PlatformCallbacks; use crate::gui::platform::PlatformCallbacks;
use crate::gui::screens::{Navigator, Screen, ScreenId}; use crate::gui::screens::{Navigator, Screen, ScreenId};
use crate::gui::{SYM_ACCOUNTS, SYM_ARROW_BACK, SYM_NETWORK, SYM_SETTINGS}; use crate::gui::{SYM_ACCOUNTS, SYM_ARROW_BACK, SYM_NETWORK, SYM_SETTINGS};
@ -44,22 +45,21 @@ impl Screen for Accounts {
cb: &dyn PlatformCallbacks) { cb: &dyn PlatformCallbacks) {
let Self { title } = self; let Self { title } = self;
TitlePanel::default() let mut panel: TitlePanel = TitlePanel::default()
.title(title.to_owned()) .title(title.to_owned())
.left_action(if !dual_panel_mode(frame) { .right_action(PanelAction {
Some(PanelAction {
icon: SYM_NETWORK.into(),
on_click: Box::new(on_left_click),
})
} else {
None
})
.right_action(Some(PanelAction {
icon: SYM_SETTINGS.into(), icon: SYM_SETTINGS.into(),
on_click: Box::new(on_right_click), on_click: Box::new(on_right_click),
})) })
.with_navigator(nav) .with_navigator(nav);
.ui(ui); 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)); 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

@ -45,13 +45,13 @@ impl<'screen> TitlePanel<'screen> {
self self
} }
pub fn left_action(mut self, action: Option<PanelAction>) -> Self { pub fn left_action(mut self, action: PanelAction) -> Self {
self.actions.left = action; self.actions.left = Some(action);
self self
} }
pub fn right_action(mut self, action: Option<PanelAction>) -> Self { pub fn right_action(mut self, action: PanelAction) -> Self {
self.actions.right = action; self.actions.right = Some(action);
self self
} }
@ -61,8 +61,8 @@ impl<'screen> TitlePanel<'screen> {
} }
} }
impl TitlePanel<'_> { impl View for TitlePanel<'_> {
pub(crate) fn ui(&mut self, ui: &mut egui::Ui) { 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;