mirror of
https://github.com/jwinterm/grim.git
synced 2026-10-23 00:08:33 +02:00
gui: refactor navigator, add back button handling on android
This commit is contained in:
@@ -63,7 +63,6 @@ impl Network {
|
||||
pub fn ui(&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
frame: &mut eframe::Frame,
|
||||
nav: &mut Navigator,
|
||||
_: &dyn PlatformCallbacks) {
|
||||
|
||||
egui::TopBottomPanel::top("network_title")
|
||||
@@ -76,7 +75,7 @@ impl Network {
|
||||
..Default::default()
|
||||
})
|
||||
.show_inside(ui, |ui| {
|
||||
self.draw_title(ui, frame, nav);
|
||||
self.draw_title(ui, frame);
|
||||
});
|
||||
|
||||
egui::TopBottomPanel::bottom("network_tabs")
|
||||
@@ -145,10 +144,7 @@ impl Network {
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_title(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, nav: &mut Navigator) {
|
||||
// Disable stroke around title buttons on hover
|
||||
ui.style_mut().visuals.widgets.active.bg_stroke = Stroke::NONE;
|
||||
|
||||
fn draw_title(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
StripBuilder::new(ui)
|
||||
.size(Size::exact(52.0))
|
||||
.vertical(|mut strip| {
|
||||
@@ -172,7 +168,7 @@ impl Network {
|
||||
if !is_dual_panel_mode(frame) {
|
||||
ui.centered_and_justified(|ui| {
|
||||
View::title_button(ui, CARDHOLDER, || {
|
||||
nav.toggle_left_panel();
|
||||
Navigator::toggle_side_panel();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -163,7 +163,6 @@ impl NetworkTab for NetworkNode {
|
||||
[false, false, true, false]);
|
||||
});
|
||||
columns[1].vertical_centered(|ui| {
|
||||
let ts = stats.chain_stats.latest_timestamp;
|
||||
View::rounded_box(ui,
|
||||
stats.peer_count.to_string(),
|
||||
t!("peers"),
|
||||
|
||||
@@ -23,7 +23,13 @@ use crate::gui::views::View;
|
||||
|
||||
pub struct TitlePanelAction {
|
||||
pub(crate) icon: Box<str>,
|
||||
pub(crate) on_click: Box<dyn Fn(&mut Navigator)>,
|
||||
pub(crate) on_click: Box<dyn Fn()>,
|
||||
}
|
||||
|
||||
impl TitlePanelAction {
|
||||
pub fn new(icon: Box<str>, on_click: fn()) -> Option<Self> {
|
||||
Option::from(Self { icon, on_click: Box::new(on_click) })
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -32,41 +38,31 @@ pub struct TitlePanelActions {
|
||||
right: Option<TitlePanelAction>
|
||||
}
|
||||
|
||||
pub struct TitlePanel<'nav> {
|
||||
title: Option<String>,
|
||||
pub struct TitlePanel {
|
||||
title: String,
|
||||
actions: TitlePanelActions,
|
||||
nav: &'nav mut Navigator
|
||||
}
|
||||
|
||||
impl<'nav> TitlePanel<'nav> {
|
||||
pub fn new(nav: &'nav mut Navigator) -> TitlePanel<'nav> {
|
||||
impl TitlePanel {
|
||||
pub fn new(title: String) -> Self {
|
||||
Self {
|
||||
title: None,
|
||||
actions: Default::default(),
|
||||
nav,
|
||||
title,
|
||||
actions: TitlePanelActions::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn title(mut self, title: String) -> Self {
|
||||
self.title = Some(title);
|
||||
pub fn left_action(mut self, action: Option<TitlePanelAction>) -> Self {
|
||||
self.actions.left = action;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn left_action(mut self, action: TitlePanelAction) -> Self {
|
||||
self.actions.left = Some(action);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn right_action(mut self, action: TitlePanelAction) -> Self {
|
||||
self.actions.right = Some(action);
|
||||
pub fn right_action(mut self, action: Option<TitlePanelAction>) -> Self {
|
||||
self.actions.right = action;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui) {
|
||||
// Disable stroke around panel buttons on hover
|
||||
ui.style_mut().visuals.widgets.active.bg_stroke = Stroke::NONE;
|
||||
|
||||
let Self { actions, title, nav } = self;
|
||||
let Self { actions, title } = self;
|
||||
|
||||
egui::TopBottomPanel::top("title_panel")
|
||||
.resizable(false)
|
||||
@@ -88,19 +84,19 @@ impl<'nav> TitlePanel<'nav> {
|
||||
.size(Size::exact(52.0))
|
||||
.horizontal(|mut strip| {
|
||||
strip.cell(|ui| {
|
||||
show_action(ui, actions.left.as_ref(), nav);
|
||||
show_action(ui, actions.left.as_ref());
|
||||
});
|
||||
strip.strip(|builder| {
|
||||
builder
|
||||
.size(Size::remainder())
|
||||
.vertical(|mut strip| {
|
||||
strip.cell(|ui| {
|
||||
show_title(&*title, ui);
|
||||
show_title(title, ui);
|
||||
});
|
||||
});
|
||||
});
|
||||
strip.cell(|ui| {
|
||||
show_action(ui, actions.right.as_ref(), nav);
|
||||
show_action(ui, actions.right.as_ref());
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -109,35 +105,32 @@ impl<'nav> TitlePanel<'nav> {
|
||||
}
|
||||
}
|
||||
|
||||
fn show_action(ui: &mut egui::Ui, action: Option<&TitlePanelAction>, navigator: &mut Navigator) {
|
||||
fn show_action(ui: &mut egui::Ui, action: Option<&TitlePanelAction>) {
|
||||
if action.is_some() {
|
||||
let action = action.unwrap();
|
||||
ui.centered_and_justified(|ui| {
|
||||
View::title_button(ui, &action.icon, || {
|
||||
(action.on_click)(navigator);
|
||||
(action.on_click)();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn show_title(title: &Option<String>, ui: &mut egui::Ui) {
|
||||
if title.is_some() {
|
||||
ui.centered_and_justified(|ui| {
|
||||
let title_text = title.as_ref().unwrap().to_uppercase();
|
||||
let mut job = LayoutJob::single_section(title_text, TextFormat {
|
||||
font_id: FontId::proportional(20.0),
|
||||
color: COLOR_DARK,
|
||||
.. Default::default()
|
||||
});
|
||||
job.wrap = TextWrapping {
|
||||
max_rows: 1,
|
||||
break_anywhere: false,
|
||||
overflow_character: Option::from('﹍'),
|
||||
..Default::default()
|
||||
};
|
||||
ui.label(job);
|
||||
|
||||
fn show_title(title: &String, ui: &mut egui::Ui) {
|
||||
ui.centered_and_justified(|ui| {
|
||||
let mut job = LayoutJob::single_section(title.to_uppercase(), TextFormat {
|
||||
font_id: FontId::proportional(20.0),
|
||||
color: COLOR_DARK,
|
||||
.. Default::default()
|
||||
});
|
||||
}
|
||||
job.wrap = TextWrapping {
|
||||
max_rows: 1,
|
||||
break_anywhere: false,
|
||||
overflow_character: Option::from('﹍'),
|
||||
..Default::default()
|
||||
};
|
||||
ui.label(job);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+13
-13
@@ -24,15 +24,20 @@ impl View {
|
||||
pub const DEFAULT_STROKE: Stroke = Stroke { width: 1.0, color: Color32::from_gray(190) };
|
||||
|
||||
pub fn title_button(ui: &mut egui::Ui, icon: &str, action: impl FnOnce()) {
|
||||
let b = egui::widgets::Button::new(
|
||||
RichText::new(icon.to_string()).size(24.0).color(COLOR_DARK)
|
||||
).fill(Color32::TRANSPARENT)
|
||||
.ui(ui).interact(Sense::click_and_drag());
|
||||
ui.scope(|ui| {
|
||||
// Disable stroke around title buttons on hover
|
||||
ui.style_mut().visuals.widgets.active.bg_stroke = Stroke::NONE;
|
||||
|
||||
// Click optimization for touch screens
|
||||
if b.drag_released() || b.clicked() {
|
||||
(action)();
|
||||
};
|
||||
let b = egui::widgets::Button::new(
|
||||
RichText::new(icon.to_string()).size(24.0).color(COLOR_DARK)
|
||||
).fill(Color32::TRANSPARENT)
|
||||
.ui(ui).interact(Sense::click_and_drag());
|
||||
|
||||
// Click optimization for touch screens
|
||||
if b.drag_released() || b.clicked() {
|
||||
(action)();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
pub fn tab_button(ui: &mut egui::Ui, icon: &str, active: bool, mut action: impl FnMut()) {
|
||||
@@ -53,11 +58,6 @@ impl View {
|
||||
.fill(color)
|
||||
.ui(ui).interact(Sense::click_and_drag());
|
||||
|
||||
|
||||
let vel_y = ui.ctx().input().pointer.delta().y;
|
||||
let vel_x = ui.ctx().input().pointer.delta().x;
|
||||
println!("12345, vel {}, {}", vel_y, vel_x);
|
||||
|
||||
// Click optimization for touch screens
|
||||
if b.drag_released() || b.clicked() {
|
||||
(action)();
|
||||
|
||||
Reference in New Issue
Block a user