mirror of
https://github.com/jwinterm/grim.git
synced 2026-12-05 20:24:01 +01:00
gui: node info content, new icons, remove default fonts, optimize imports, add translations
This commit is contained in:
+1
-2
@@ -13,8 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
// build and versioning information
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use eframe::{AppCreator, NativeOptions, Renderer, Theme};
|
||||
use log::LevelFilter::{Debug, Info, Trace, Warn};
|
||||
use log::LevelFilter::Info;
|
||||
#[cfg(target_os = "android")]
|
||||
use winit::platform::android::activity::AndroidApp;
|
||||
|
||||
|
||||
+8
-10
@@ -12,15 +12,13 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::cmp::min;
|
||||
|
||||
use eframe::Frame;
|
||||
use egui::{Color32, Context, Stroke};
|
||||
use eframe::epaint::Stroke;
|
||||
use egui::{Context, Frame};
|
||||
use egui::style::Margin;
|
||||
|
||||
use crate::gui::{COLOR_LIGHT, COLOR_YELLOW};
|
||||
use crate::gui::colors::COLOR_LIGHT;
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::screens::{Root, Screen};
|
||||
use crate::gui::screens::Root;
|
||||
|
||||
pub struct PlatformApp<Platform> {
|
||||
pub(crate) app: App,
|
||||
@@ -40,10 +38,10 @@ impl Default for App {
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn ui(&mut self, ctx: &Context, frame: &mut Frame, cb: &dyn PlatformCallbacks) {
|
||||
pub fn ui(&mut self, ctx: &Context, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
||||
let Self { root } = self;
|
||||
egui::CentralPanel::default()
|
||||
.frame(egui::Frame {
|
||||
.frame(Frame {
|
||||
inner_margin: Margin::same(0.0),
|
||||
outer_margin: Margin::same(0.0),
|
||||
stroke: Stroke::NONE,
|
||||
@@ -56,11 +54,11 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_dual_panel_mode(frame: &mut Frame) -> bool {
|
||||
pub fn is_dual_panel_mode(frame: &mut eframe::Frame) -> bool {
|
||||
is_landscape(frame) && frame.info().window_info.size.x > 400.0
|
||||
}
|
||||
|
||||
pub fn is_landscape(frame: &mut Frame) -> bool {
|
||||
pub fn is_landscape(frame: &mut eframe::Frame) -> bool {
|
||||
return frame.info().window_info.size.x > frame.info().window_info.size.y
|
||||
}
|
||||
|
||||
|
||||
@@ -12,3 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub const COLOR_YELLOW: egui::Color32 = egui::Color32::from_rgb(254, 241, 2);
|
||||
pub const COLOR_LIGHT: egui::Color32 = egui::Color32::from_gray(240);
|
||||
pub const COLOR_DARK: egui::Color32 = egui::Color32::from_gray(60);
|
||||
pub const COLOR_GRAY: egui::Color32 = egui::Color32::from_gray(120);
|
||||
+1273
File diff suppressed because it is too large
Load Diff
+2
-12
@@ -19,18 +19,8 @@ pub use app::PlatformApp;
|
||||
pub mod platform;
|
||||
pub mod screens;
|
||||
pub mod views;
|
||||
pub mod icons;
|
||||
pub mod colors;
|
||||
|
||||
mod app;
|
||||
|
||||
pub const COLOR_YELLOW: egui::Color32 = egui::Color32::from_rgb(254, 241, 2);
|
||||
pub const COLOR_LIGHT: egui::Color32 = egui::Color32::from_gray(240);
|
||||
pub const COLOR_DARK: egui::Color32 = egui::Color32::from_gray(60);
|
||||
|
||||
// Material icons chars
|
||||
pub const SYM_ARROW_BACK: &str = "";
|
||||
pub const SYM_ACCOUNTS: &str = "";
|
||||
pub const SYM_NETWORK: &str = "";
|
||||
pub const SYM_SETTINGS: &str = "";
|
||||
pub const SYM_TUNING: &str = "";
|
||||
pub const SYM_METRICS: &str = "";
|
||||
|
||||
|
||||
@@ -96,26 +96,13 @@ impl PlatformApp<Android> {
|
||||
|
||||
let mut fonts = egui::FontDefinitions::default();
|
||||
|
||||
// Tweak emoji icons to look nice against main font y-offset
|
||||
// fonts.font_data.insert(
|
||||
// "emoji-icon-font".to_owned(),
|
||||
// egui::FontData {
|
||||
// font: fonts.font_data.get("emoji-icon-font").unwrap().clone().font,
|
||||
// index: 0,
|
||||
// tweak: egui::FontTweak {
|
||||
// scale: 0.88,
|
||||
// y_offset_factor: 0.26,
|
||||
// y_offset: 0.0,
|
||||
// },
|
||||
// });
|
||||
|
||||
fonts.font_data.insert(
|
||||
"material".to_owned(),
|
||||
"phosphor".to_owned(),
|
||||
egui::FontData::from_static(include_bytes!(
|
||||
"../../../../fonts/material.otf"
|
||||
"../../../../fonts/phosphor.ttf"
|
||||
)).tweak(egui::FontTweak {
|
||||
scale: 1.0,
|
||||
y_offset_factor: 0.16,
|
||||
y_offset_factor: 0.14,
|
||||
y_offset: 0.0
|
||||
}),
|
||||
);
|
||||
@@ -123,7 +110,7 @@ impl PlatformApp<Android> {
|
||||
.families
|
||||
.entry(Proportional)
|
||||
.or_default()
|
||||
.insert(0, "material".to_owned());
|
||||
.insert(0, "phosphor".to_owned());
|
||||
|
||||
fonts.font_data.insert(
|
||||
"noto".to_owned(),
|
||||
@@ -141,8 +128,6 @@ impl PlatformApp<Android> {
|
||||
.or_default()
|
||||
.insert(0, "noto".to_owned());
|
||||
|
||||
|
||||
|
||||
ctx.set_fonts(fonts);
|
||||
|
||||
use egui::FontId;
|
||||
@@ -151,7 +136,6 @@ impl PlatformApp<Android> {
|
||||
let mut style = (*ctx.style()).clone();
|
||||
style.text_styles = [
|
||||
(Heading, FontId::new(20.0, Proportional)),
|
||||
(Name("icon".into()), FontId::new(24.0, Proportional)),
|
||||
(Body, FontId::new(16.0, Proportional)),
|
||||
(Button, FontId::new(18.0, Proportional)),
|
||||
(Small, FontId::new(12.0, Proportional)),
|
||||
|
||||
+14
-29
@@ -12,28 +12,16 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use eframe::epaint::{Color32, Stroke};
|
||||
use egui::Frame;
|
||||
|
||||
use egui::{Frame, Widget};
|
||||
|
||||
use crate::gui::{SYM_ARROW_BACK, SYM_NETWORK, SYM_SETTINGS};
|
||||
use crate::gui::app::is_dual_panel_mode;
|
||||
use crate::gui::icons::{ARROW_CIRCLE_LEFT, GEAR_SIX, GLOBE};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::screens::{Navigator, Screen, ScreenId};
|
||||
use crate::gui::views::{TitlePanel, TitlePanelAction};
|
||||
use crate::gui::views::{DEFAULT_STROKE, TitlePanel, TitlePanelAction};
|
||||
|
||||
pub struct Accounts {
|
||||
title: String,
|
||||
}
|
||||
|
||||
impl Default for Accounts {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
title: t!("accounts"),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Default)]
|
||||
pub struct Accounts {}
|
||||
|
||||
impl Screen for Accounts {
|
||||
fn id(&self) -> ScreenId {
|
||||
@@ -45,36 +33,33 @@ impl Screen for Accounts {
|
||||
frame: &mut eframe::Frame,
|
||||
nav: &mut Navigator,
|
||||
cb: &dyn PlatformCallbacks) {
|
||||
let Self { title } = self;
|
||||
|
||||
let mut panel: TitlePanel = TitlePanel::default()
|
||||
.title(title)
|
||||
let mut panel: TitlePanel = TitlePanel::new(nav)
|
||||
.title(t!("accounts"))
|
||||
.right_action(TitlePanelAction {
|
||||
icon: SYM_SETTINGS.into(),
|
||||
icon: GEAR_SIX.into(),
|
||||
on_click: Box::new(|nav| {
|
||||
//TODO: open settings
|
||||
}),
|
||||
})
|
||||
.with_navigator(nav);
|
||||
});
|
||||
if !is_dual_panel_mode(frame) {
|
||||
panel = panel.left_action(TitlePanelAction {
|
||||
icon: SYM_NETWORK.into(),
|
||||
icon: GLOBE.into(),
|
||||
on_click: Box::new(|nav|{
|
||||
nav.as_mut().unwrap().toggle_left_panel();
|
||||
nav.toggle_left_panel();
|
||||
}),
|
||||
});
|
||||
}
|
||||
panel.ui(ui);
|
||||
|
||||
egui::CentralPanel::default().frame(Frame {
|
||||
stroke: Stroke::new(1.0, Color32::from_gray(190)),
|
||||
stroke: DEFAULT_STROKE,
|
||||
.. Default::default()
|
||||
}).show_inside(ui, |ui| {
|
||||
ui.label(format!("{}Here we go 10000 ツ", SYM_ARROW_BACK));
|
||||
ui.label(format!("{}Here we go 10000 ツ", ARROW_CIRCLE_LEFT));
|
||||
if ui.button("TEST").clicked() {
|
||||
nav.to(ScreenId::Account)
|
||||
};
|
||||
if ui.button(format!("{}BACK ", SYM_ARROW_BACK)).clicked() {
|
||||
if ui.button(format!("{}BACK ", ARROW_CIRCLE_LEFT)).clicked() {
|
||||
nav.to(ScreenId::Account)
|
||||
};
|
||||
});
|
||||
|
||||
@@ -17,9 +17,7 @@ pub use accounts::Accounts;
|
||||
pub use navigator::Navigator;
|
||||
pub use root::Root;
|
||||
|
||||
use crate::gui::App;
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::TitlePanelAction;
|
||||
|
||||
mod navigator;
|
||||
mod root;
|
||||
@@ -28,7 +26,6 @@ mod account;
|
||||
|
||||
#[derive(Ord, Eq, PartialOrd, PartialEq)]
|
||||
pub enum ScreenId {
|
||||
Root,
|
||||
Accounts,
|
||||
Account,
|
||||
}
|
||||
|
||||
@@ -14,10 +14,6 @@
|
||||
|
||||
use std::cmp::min;
|
||||
|
||||
use eframe::epaint::{Color32, Shadow, Stroke};
|
||||
use egui::style::Margin;
|
||||
|
||||
use crate::gui::{App, COLOR_YELLOW};
|
||||
use crate::gui::app::is_dual_panel_mode;
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::screens::{Account, Accounts, Navigator, Screen, ScreenId};
|
||||
@@ -43,10 +39,6 @@ impl Default for Root {
|
||||
}
|
||||
|
||||
impl Root {
|
||||
fn id(&self) -> ScreenId {
|
||||
ScreenId::Root
|
||||
}
|
||||
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame, cb: &dyn PlatformCallbacks) {
|
||||
let is_network_panel_open = self.navigator.left_panel_open || is_dual_panel_mode(frame);
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// Copyright 2023 The Grim Developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use eframe::epaint::{Color32, Stroke};
|
||||
use egui::{RichText, Sense, Widget};
|
||||
|
||||
use crate::gui::colors::{COLOR_DARK, COLOR_LIGHT};
|
||||
use crate::gui::views::DEFAULT_STROKE;
|
||||
|
||||
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());
|
||||
|
||||
// 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()) {
|
||||
let stroke = match active {
|
||||
true => { Stroke::NONE }
|
||||
false => { DEFAULT_STROKE }
|
||||
};
|
||||
|
||||
let color = match active {
|
||||
true => { COLOR_LIGHT }
|
||||
false => { Color32::WHITE }
|
||||
};
|
||||
|
||||
let b = egui::widgets::Button::new(
|
||||
RichText::new(icon.to_string()).size(24.0).color(COLOR_DARK)
|
||||
).min_size(ui.available_size_before_wrap())
|
||||
.stroke(stroke)
|
||||
.fill(color)
|
||||
.ui(ui).interact(Sense::click_and_drag());
|
||||
|
||||
// Click optimization for touch screens
|
||||
if b.drag_released() || b.clicked() {
|
||||
(action)();
|
||||
};
|
||||
}
|
||||
|
||||
pub fn sub_title(ui: &mut egui::Ui, text: String, color: Color32) {
|
||||
ui.label(RichText::new(text).size(17.0).color(color));
|
||||
}
|
||||
@@ -12,14 +12,16 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub mod buttons;
|
||||
use eframe::epaint::{Color32, Stroke};
|
||||
|
||||
mod title_panel;
|
||||
pub use crate::gui::views::network::Network;
|
||||
pub use crate::gui::views::title_panel::{TitlePanel, TitlePanelAction, TitlePanelActions};
|
||||
|
||||
mod network;
|
||||
pub use crate::gui::views::network::Network;
|
||||
pub mod common;
|
||||
|
||||
mod title_panel;
|
||||
|
||||
mod network;
|
||||
mod network_node;
|
||||
mod network_tuning;
|
||||
mod network_metrics;
|
||||
@@ -28,3 +30,6 @@ pub trait NetworkTab {
|
||||
fn ui(&mut self, ui: &mut egui::Ui, node: &mut crate::node::Node);
|
||||
fn name(&self) -> &String;
|
||||
}
|
||||
|
||||
pub const DEFAULT_STROKE: Stroke = Stroke { width: 1.0, color: Color32::from_gray(190) };
|
||||
|
||||
|
||||
+123
-87
@@ -12,40 +12,39 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Duration;
|
||||
use chrono::Utc;
|
||||
use eframe::epaint::{Color32, FontId, Stroke};
|
||||
|
||||
use eframe::emath::lerp;
|
||||
use eframe::epaint::{Color32, FontId, Rgba, Stroke};
|
||||
use eframe::epaint::text::{LayoutJob, TextFormat, TextWrapping};
|
||||
use egui::{Response, RichText, Sense, Spinner, Widget};
|
||||
use egui::RichText;
|
||||
use egui::style::Margin;
|
||||
use egui_extras::{Size, StripBuilder};
|
||||
use grin_chain::SyncStatus;
|
||||
|
||||
use grin_core::global::ChainTypes;
|
||||
use grin_servers::ServerStats;
|
||||
|
||||
use crate::gui::app::is_dual_panel_mode;
|
||||
use crate::gui::colors::{COLOR_DARK, COLOR_YELLOW};
|
||||
use crate::gui::icons::{CARDHOLDER, DATABASE, DOTS_THREE_OUTLINE_VERTICAL, FACTORY, FADERS, GAUGE};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::screens::Navigator;
|
||||
use crate::gui::{COLOR_DARK, COLOR_LIGHT, COLOR_YELLOW, SYM_ACCOUNTS, SYM_METRICS, SYM_NETWORK};
|
||||
|
||||
use crate::gui::views::{NetworkTab, TitlePanel, TitlePanelAction};
|
||||
use crate::gui::views::{DEFAULT_STROKE, NetworkTab};
|
||||
use crate::gui::views::common::{tab_button, title_button};
|
||||
use crate::gui::views::network_node::NetworkNode;
|
||||
use crate::node;
|
||||
use crate::node::Node;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum Mode {
|
||||
Node,
|
||||
// Miner,
|
||||
Metrics,
|
||||
Miner,
|
||||
Tuning
|
||||
}
|
||||
|
||||
pub struct Network {
|
||||
current_mode: Mode,
|
||||
node: Node,
|
||||
|
||||
current_mode: Mode,
|
||||
node_view: NetworkNode,
|
||||
}
|
||||
|
||||
@@ -80,17 +79,9 @@ impl Network {
|
||||
self.draw_title(ui, frame, nav);
|
||||
});
|
||||
|
||||
egui::CentralPanel::default().frame(egui::Frame {
|
||||
stroke: Stroke::new(1.0, Color32::from_gray(190)),
|
||||
fill: Color32::WHITE,
|
||||
.. Default::default()
|
||||
}).show_inside(ui, |ui| {
|
||||
self.draw_tab_content(ui);
|
||||
});
|
||||
|
||||
egui::TopBottomPanel::bottom("network_tabs")
|
||||
.frame(egui::Frame {
|
||||
stroke: Stroke::new(1.0, Color32::from_gray(190)),
|
||||
outer_margin: Margin::same(6.0),
|
||||
.. Default::default()
|
||||
})
|
||||
.resizable(false)
|
||||
@@ -98,19 +89,41 @@ impl Network {
|
||||
self.draw_tabs(ui);
|
||||
});
|
||||
|
||||
ui.ctx().request_repaint_after(Duration::from_millis(1000));
|
||||
egui::CentralPanel::default().frame(egui::Frame {
|
||||
stroke: DEFAULT_STROKE,
|
||||
inner_margin: Margin::same(4.0),
|
||||
fill: Color32::WHITE,
|
||||
.. Default::default()
|
||||
}).show_inside(ui, |ui| {
|
||||
self.draw_tab_content(ui);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
fn draw_tabs(&self, ui: &mut egui::Ui) {
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.columns(3, |columns| {
|
||||
columns[0].horizontal_wrapped(|ui| {
|
||||
});
|
||||
columns[1].vertical_centered(|ui| {
|
||||
});
|
||||
columns[2].horizontal_wrapped(|ui| {
|
||||
fn draw_tabs(&mut self, ui: &mut egui::Ui) {
|
||||
ui.columns(4, |columns| {
|
||||
columns[0].vertical_centered(|ui| {
|
||||
tab_button(ui, DATABASE, self.current_mode == Mode::Node, || {
|
||||
self.current_mode = Mode::Node;
|
||||
});
|
||||
});
|
||||
columns[1].vertical_centered(|ui| {
|
||||
tab_button(ui, GAUGE, self.current_mode == Mode::Metrics, || {
|
||||
self.current_mode = Mode::Metrics;
|
||||
});
|
||||
});
|
||||
columns[2].vertical_centered(|ui| {
|
||||
tab_button(ui, FACTORY, self.current_mode == Mode::Miner, || {
|
||||
self.current_mode = Mode::Miner;
|
||||
});
|
||||
});
|
||||
columns[3].vertical_centered(|ui| {
|
||||
tab_button(ui, FADERS, self.current_mode == Mode::Tuning, || {
|
||||
self.current_mode = Mode::Tuning;
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -121,6 +134,7 @@ impl Network {
|
||||
}
|
||||
Mode::Metrics => {}
|
||||
Mode::Tuning => {}
|
||||
Mode::Miner => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,22 +151,22 @@ impl Network {
|
||||
.size(Size::remainder())
|
||||
.size(Size::exact(52.0))
|
||||
.horizontal(|mut strip| {
|
||||
strip.empty();
|
||||
strip.cell(|ui| {
|
||||
ui.centered_and_justified(|ui| {
|
||||
title_button(ui, DOTS_THREE_OUTLINE_VERTICAL, || {
|
||||
//TODO: Actions for node
|
||||
});
|
||||
});
|
||||
});
|
||||
strip.strip(|builder| {
|
||||
self.draw_title_text(builder);
|
||||
});
|
||||
strip.cell(|ui| {
|
||||
if !is_dual_panel_mode(frame) {
|
||||
ui.centered_and_justified(|ui| {
|
||||
let b = egui::widgets::Button::new(
|
||||
RichText::new(SYM_ACCOUNTS)
|
||||
.size(24.0)
|
||||
.color(COLOR_DARK)
|
||||
).fill(Color32::TRANSPARENT)
|
||||
.ui(ui).interact(Sense::click_and_drag());
|
||||
if b.drag_released() || b.clicked() {
|
||||
title_button(ui, CARDHOLDER, || {
|
||||
nav.toggle_left_panel();
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -161,9 +175,7 @@ impl Network {
|
||||
});
|
||||
}
|
||||
|
||||
fn draw_title_text(&self, mut builder: StripBuilder) {
|
||||
let Self { node, ..} = self;
|
||||
|
||||
fn draw_title_text(&self, builder: StripBuilder) {
|
||||
let title_text = match &self.current_mode {
|
||||
Mode::Node => {
|
||||
self.node_view.name()
|
||||
@@ -171,78 +183,107 @@ impl Network {
|
||||
Mode::Metrics => {
|
||||
self.node_view.name()
|
||||
}
|
||||
Mode::Miner => {
|
||||
self.node_view.name()
|
||||
}
|
||||
Mode::Tuning => {
|
||||
self.node_view.name()
|
||||
}
|
||||
};
|
||||
|
||||
let syncing = node.state.is_syncing();
|
||||
|
||||
let mut b = builder.size(Size::remainder());
|
||||
if syncing {
|
||||
b = b.size(Size::remainder());
|
||||
}
|
||||
b.vertical(|mut strip| {
|
||||
strip.cell(|ui| {
|
||||
ui.centered_and_justified(|ui| {
|
||||
ui.heading(title_text.to_uppercase());
|
||||
});
|
||||
});
|
||||
if syncing {
|
||||
builder
|
||||
.size(Size::exact(19.0))
|
||||
.size(Size::remainder())
|
||||
.vertical(|mut strip| {
|
||||
strip.cell(|ui| {
|
||||
ui.centered_and_justified(|ui| {
|
||||
let status_text = if node.state.is_restarting() {
|
||||
"Restarting".to_string()
|
||||
ui.label(RichText::new(title_text.to_uppercase())
|
||||
.size(19.0)
|
||||
.color(COLOR_DARK));
|
||||
});
|
||||
});
|
||||
strip.cell(|ui| {
|
||||
ui.centered_and_justified(|ui| {
|
||||
// Select sync status text
|
||||
let sync_status = self.node.state.get_sync_status();
|
||||
let status_text = if self.node.state.is_restarting() {
|
||||
t!("server_restarting")
|
||||
} else {
|
||||
let sync_status = node.state.get_sync_status();
|
||||
get_sync_status_text(sync_status.unwrap()).to_string()
|
||||
match sync_status {
|
||||
None => {
|
||||
t!("server_down")
|
||||
}
|
||||
Some(ss) => {
|
||||
get_sync_status_text(ss).to_string()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Setup text color animation based on sync status
|
||||
let idle = match sync_status {
|
||||
None => { !self.node.state.is_starting() }
|
||||
Some(ss) => { ss == SyncStatus::NoSync }
|
||||
};
|
||||
let (dark, bright) = (0.3, 1.0);
|
||||
let color_factor = if !idle {
|
||||
lerp(dark..=bright, ui.input().time.cos().abs())
|
||||
} else {
|
||||
bright
|
||||
};
|
||||
|
||||
// Repaint based on sync status
|
||||
if idle {
|
||||
ui.ctx().request_repaint_after(Duration::from_millis(600));
|
||||
} else {
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
|
||||
// Draw sync text
|
||||
let mut job = LayoutJob::single_section(status_text, TextFormat {
|
||||
font_id: FontId::proportional(15.0),
|
||||
color: COLOR_DARK,
|
||||
color: Color32::from(Rgba::from(COLOR_DARK) * color_factor as f32),
|
||||
.. Default::default()
|
||||
});
|
||||
job.wrap = TextWrapping {
|
||||
max_rows: 1,
|
||||
break_anywhere: false,
|
||||
overflow_character: Option::from('…'),
|
||||
overflow_character: Option::from('﹍'),
|
||||
..Default::default()
|
||||
};
|
||||
ui.label(job);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn get_sync_status_text(sync_status: SyncStatus) -> Cow<'static, str> {
|
||||
fn get_sync_status_text(sync_status: SyncStatus) -> String {
|
||||
match sync_status {
|
||||
SyncStatus::Initial => Cow::Borrowed("Initializing"),
|
||||
SyncStatus::NoSync => Cow::Borrowed("Running"),
|
||||
SyncStatus::AwaitingPeers(_) => Cow::Borrowed("Waiting for peers"),
|
||||
SyncStatus::Initial => t!("sync_status.initial"),
|
||||
SyncStatus::NoSync => t!("sync_status.no_sync"),
|
||||
SyncStatus::AwaitingPeers(_) => t!("sync_status.awaiting_peers"),
|
||||
SyncStatus::HeaderSync {
|
||||
sync_head,
|
||||
highest_height,
|
||||
..
|
||||
} => {
|
||||
if highest_height == 0 {
|
||||
Cow::Borrowed("Downloading headers")
|
||||
t!("sync_status.header_sync")
|
||||
} else {
|
||||
let percent = sync_head.height * 100 / highest_height;
|
||||
Cow::Owned(format!("Downloading headers: {}%", percent))
|
||||
t!("sync_status.header_sync_percent", "percent" => percent)
|
||||
}
|
||||
}
|
||||
SyncStatus::TxHashsetDownload(stat) => {
|
||||
if stat.total_size > 0 {
|
||||
let percent = stat.downloaded_size * 100 / stat.total_size;
|
||||
Cow::Owned(format!("Downloading chain state: {}%", percent))
|
||||
t!("sync_status.tx_hashset_download_percent", "percent" => percent)
|
||||
} else {
|
||||
Cow::Borrowed("Downloading chain state")
|
||||
t!("sync_status.tx_hashset_download")
|
||||
}
|
||||
}
|
||||
SyncStatus::TxHashsetSetup => {
|
||||
Cow::Borrowed("Preparing state for validation")
|
||||
t!("sync_status.tx_hashset_setup")
|
||||
}
|
||||
SyncStatus::TxHashsetRangeProofsValidation {
|
||||
rproofs,
|
||||
@@ -253,7 +294,7 @@ fn get_sync_status_text(sync_status: SyncStatus) -> Cow<'static, str> {
|
||||
} else {
|
||||
0
|
||||
};
|
||||
Cow::Owned(format!("Validating state - range proofs: {}%", r_percent))
|
||||
t!("sync_status.tx_hashset_range_proofs_validation", "percent" => r_percent)
|
||||
}
|
||||
SyncStatus::TxHashsetKernelsValidation {
|
||||
kernels,
|
||||
@@ -264,28 +305,23 @@ fn get_sync_status_text(sync_status: SyncStatus) -> Cow<'static, str> {
|
||||
} else {
|
||||
0
|
||||
};
|
||||
Cow::Owned(format!("Validating state - kernels: {}%", k_percent))
|
||||
t!("sync_status.tx_hashset_kernels_validation", "percent" => k_percent)
|
||||
}
|
||||
SyncStatus::TxHashsetSave => {
|
||||
Cow::Borrowed("Finalizing chain state")
|
||||
}
|
||||
SyncStatus::TxHashsetDone => {
|
||||
Cow::Borrowed("Finalized chain state")
|
||||
SyncStatus::TxHashsetSave | SyncStatus::TxHashsetDone => {
|
||||
t!("sync_status.tx_hashset_save")
|
||||
}
|
||||
SyncStatus::BodySync {
|
||||
current_height,
|
||||
highest_height,
|
||||
} => {
|
||||
if highest_height == 0 {
|
||||
Cow::Borrowed("Downloading blocks data")
|
||||
t!("sync_status.body_sync")
|
||||
} else {
|
||||
Cow::Owned(format!(
|
||||
"Downloading blocks: {}%",
|
||||
current_height * 100 / highest_height
|
||||
))
|
||||
let percent = current_height * 100 / highest_height;
|
||||
t!("sync_status.body_sync_percent", "percent" => percent)
|
||||
}
|
||||
}
|
||||
SyncStatus::Shutdown => Cow::Borrowed("Shutting down"),
|
||||
SyncStatus::Shutdown => t!("sync_status.shutdown"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,3 +11,29 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use egui::Ui;
|
||||
use crate::gui::views::NetworkTab;
|
||||
use crate::node::Node;
|
||||
|
||||
pub struct NetworkMetrics {
|
||||
title: String
|
||||
}
|
||||
|
||||
impl Default for NetworkMetrics {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
title: t!("metrics"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkTab for NetworkMetrics {
|
||||
fn ui(&mut self, ui: &mut Ui, node: &mut Node) {
|
||||
|
||||
}
|
||||
|
||||
fn name(&self) -> &String {
|
||||
&self.title
|
||||
}
|
||||
}
|
||||
+291
-37
@@ -12,20 +12,24 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::ptr::null;
|
||||
use std::sync::mpsc;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use chrono::Utc;
|
||||
use egui::{Ui, Widget};
|
||||
use grin_chain::SyncStatus;
|
||||
use grin_core::global::ChainTypes;
|
||||
use grin_servers::ServerStats;
|
||||
use chrono::{DateTime, Local, Offset, TimeZone, Utc};
|
||||
use chrono::format::DelayedFormat;
|
||||
use eframe::emath::Vec2;
|
||||
use eframe::epaint::{FontId, Stroke};
|
||||
use eframe::epaint::text::{LayoutJob, TextFormat, TextWrapping};
|
||||
use egui::{Color32, RichText, Rounding, ScrollArea, Spinner, Widget};
|
||||
use egui_extras::{Size, StripBuilder};
|
||||
use grin_servers::common::stats::TxStats;
|
||||
use grin_servers::PeerStats;
|
||||
|
||||
use crate::gui::views::NetworkTab;
|
||||
use crate::gui::colors::{COLOR_DARK, COLOR_GRAY, COLOR_LIGHT, COLOR_YELLOW};
|
||||
use crate::gui::icons::{AT, CUBE, DEVICES, DOWNLOAD_SIMPLE, FLOW_ARROW, HANDSHAKE, PACKAGE, PLUGS_CONNECTED, SHARE_NETWORK};
|
||||
use crate::gui::views::{DEFAULT_STROKE, NetworkTab};
|
||||
use crate::gui::views::common::sub_title;
|
||||
use crate::node::Node;
|
||||
|
||||
|
||||
pub struct NetworkNode {
|
||||
title: String
|
||||
}
|
||||
@@ -33,44 +37,294 @@ pub struct NetworkNode {
|
||||
impl Default for NetworkNode {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
title: t!("node"),
|
||||
title: t!("integrated_node"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkTab for NetworkNode {
|
||||
fn ui(&mut self, ui: &mut Ui, node: &mut Node) {
|
||||
// ui.vertical_centered_justified(|ui| {
|
||||
// let node_state = node.acquire_state();
|
||||
// let stats = &node_state.stats;
|
||||
// if stats.is_some() {
|
||||
// ui.horizontal_wrapped(|ui| {
|
||||
// let sync_status = stats.as_ref().unwrap().sync_status;
|
||||
// ui.label(get_sync_progress_status(sync_status));
|
||||
// ui.spinner();
|
||||
// });
|
||||
// } else {
|
||||
// if node.stop_state.is_stopped() {
|
||||
// ui.label("Stopped");
|
||||
// } else {
|
||||
// ui.label(get_sync_progress_status(SyncStatus::Initial));
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
if ui.button("stop").clicked() {
|
||||
node.stop();
|
||||
fn ui(&mut self, ui: &mut egui::Ui, node: &mut Node) {
|
||||
let server_stats = node.state.get_stats();
|
||||
if !server_stats.is_some() {
|
||||
ui.centered_and_justified(|ui| {
|
||||
Spinner::new().size(42.0).color(COLOR_GRAY).ui(ui);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if ui.button("re-start").clicked() {
|
||||
node.restart();
|
||||
}
|
||||
let stats = server_stats.as_ref().unwrap();
|
||||
|
||||
if ui.button("start").clicked() {
|
||||
node.start(ChainTypes::Mainnet);
|
||||
}
|
||||
// Make scroll bar thinner
|
||||
ui.style_mut().spacing.scroll_bar_width = 4.0;
|
||||
|
||||
ScrollArea::vertical()
|
||||
.auto_shrink([false; 2])
|
||||
.show(ui, |ui| {
|
||||
// Disable item spacing
|
||||
ui.style_mut().spacing.item_spacing = Vec2::new(0.0, 0.0);
|
||||
|
||||
// Show header stats
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
sub_title(ui, format!("{} {}", FLOW_ARROW, t!("header")), COLOR_DARK);
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered(|ui| {
|
||||
draw_stat_box(ui,
|
||||
stats.header_stats.last_block_h.to_string(),
|
||||
t!("hash"),
|
||||
StatBoxRounding::TopLeft);
|
||||
});
|
||||
columns[1].vertical_centered(|ui| {
|
||||
draw_stat_box(ui,
|
||||
stats.header_stats.height.to_string(),
|
||||
t!("height"),
|
||||
StatBoxRounding::TopRight);
|
||||
});
|
||||
});
|
||||
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered(|ui| {
|
||||
draw_stat_box(ui,
|
||||
stats.header_stats.total_difficulty.to_string(),
|
||||
t!("difficulty"),
|
||||
StatBoxRounding::BottomLeft);
|
||||
});
|
||||
columns[1].vertical_centered(|ui| {
|
||||
let ts = stats.header_stats.latest_timestamp;
|
||||
draw_stat_box(ui,
|
||||
format!("{}", ts.format("%d/%m/%Y %H:%M")),
|
||||
t!("time_utc"),
|
||||
StatBoxRounding::BottomRight);
|
||||
});
|
||||
});
|
||||
|
||||
// Show block stats
|
||||
ui.add_space(5.0);
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
sub_title(ui, format!("{} {}", CUBE, t!("block")), COLOR_DARK);
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered(|ui| {
|
||||
draw_stat_box(ui,
|
||||
stats.chain_stats.last_block_h.to_string(),
|
||||
t!("hash"),
|
||||
StatBoxRounding::TopLeft);
|
||||
});
|
||||
columns[1].vertical_centered(|ui| {
|
||||
draw_stat_box(ui,
|
||||
stats.chain_stats.height.to_string(),
|
||||
t!("height"),
|
||||
StatBoxRounding::TopRight);
|
||||
});
|
||||
});
|
||||
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered(|ui| {
|
||||
draw_stat_box(ui,
|
||||
stats.chain_stats.total_difficulty.to_string(),
|
||||
t!("difficulty"),
|
||||
StatBoxRounding::BottomLeft);
|
||||
});
|
||||
columns[1].vertical_centered(|ui| {
|
||||
let ts = stats.chain_stats.latest_timestamp;
|
||||
draw_stat_box(ui,
|
||||
format!("{}", ts.format("%d/%m/%Y %H:%M")),
|
||||
t!("time_utc"),
|
||||
StatBoxRounding::BottomRight);
|
||||
});
|
||||
});
|
||||
|
||||
// Show data stats
|
||||
ui.add_space(5.0);
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
sub_title(ui, format!("{} {}", SHARE_NETWORK, t!("data")), COLOR_DARK);
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered(|ui| {
|
||||
let tx_stat = match &stats.tx_stats {
|
||||
None => { "0 (0)".to_string() }
|
||||
Some(tx) => {
|
||||
format!("{} ({})", tx.tx_pool_size, tx.tx_pool_kernels)
|
||||
}
|
||||
};
|
||||
draw_stat_box(ui, tx_stat, t!("main_pool"), StatBoxRounding::TopLeft);
|
||||
});
|
||||
columns[1].vertical_centered(|ui| {
|
||||
let stem_tx_stat = match &stats.tx_stats {
|
||||
None => { "0 (0)".to_string() }
|
||||
Some(stx) => {
|
||||
format!("{} ({})", stx.stem_pool_size, stx.stem_pool_kernels)
|
||||
}
|
||||
};
|
||||
draw_stat_box(ui, stem_tx_stat, t!("stem_pool"), StatBoxRounding::TopRight);
|
||||
});
|
||||
});
|
||||
|
||||
ui.columns(2, |columns| {
|
||||
columns[0].vertical_centered(|ui| {
|
||||
draw_stat_box(ui,
|
||||
stats.disk_usage_gb.to_string(),
|
||||
t!("size"),
|
||||
StatBoxRounding::BottomLeft);
|
||||
});
|
||||
columns[1].vertical_centered(|ui| {
|
||||
let ts = stats.chain_stats.latest_timestamp;
|
||||
draw_stat_box(ui,
|
||||
stats.peer_count.to_string(),
|
||||
t!("peers"),
|
||||
StatBoxRounding::BottomRight);
|
||||
});
|
||||
});
|
||||
|
||||
// Show peers stats when available
|
||||
if stats.peer_count > 0 {
|
||||
ui.add_space(5.0);
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
sub_title(ui, format!("{} {}", HANDSHAKE, t!("peers")), COLOR_DARK);
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
|
||||
for (index, ps) in stats.peer_stats.iter().enumerate() {
|
||||
let rounding = if index == 0 {
|
||||
if stats.peer_count == 1 {
|
||||
[true, true];
|
||||
}
|
||||
[true, false]
|
||||
} else if index == &stats.peer_stats.len() - 1 {
|
||||
[false, true]
|
||||
} else {
|
||||
[false, false]
|
||||
};
|
||||
ui.vertical_centered(|ui| {
|
||||
draw_peer_stats(ui, ps, rounding);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn name(&self) -> &String {
|
||||
&self.title
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_peer_stats(ui: &mut egui::Ui, peer: &PeerStats, rounding: [bool; 2]) {
|
||||
let mut rect = ui.available_rect_before_wrap();
|
||||
rect.set_height(77.0);
|
||||
|
||||
ui.painter().rect(
|
||||
rect,
|
||||
Rounding {
|
||||
nw: if rounding[0] { 8.0 } else { 0.0 },
|
||||
ne: if rounding[0] { 8.0 } else { 0.0 },
|
||||
sw: if rounding[1] { 8.0 } else { 0.0 },
|
||||
se: if rounding[1] { 8.0 } else { 0.0 },
|
||||
},
|
||||
Color32::WHITE,
|
||||
Stroke { width: 1.0, color: Color32::from_gray(230) }
|
||||
);
|
||||
|
||||
ui.add_space(2.0);
|
||||
|
||||
ui.horizontal_top(|ui| {
|
||||
ui.add_space(6.0);
|
||||
|
||||
ui.heading(RichText::new(PLUGS_CONNECTED)
|
||||
.color(Color32::BLACK)
|
||||
.size(18.0));
|
||||
|
||||
ui.add_space(6.0);
|
||||
|
||||
// Draw peer address
|
||||
ui.heading(RichText::new(&peer.addr)
|
||||
.color(Color32::BLACK)
|
||||
.size(18.0));
|
||||
});
|
||||
|
||||
ui.horizontal_top(|ui| {
|
||||
ui.add_space(6.0);
|
||||
|
||||
ui.heading(RichText::new(PACKAGE)
|
||||
.color(COLOR_DARK)
|
||||
.size(16.0));
|
||||
|
||||
ui.add_space(6.0);
|
||||
|
||||
// Draw peer difficulty and height
|
||||
ui.heading(RichText::new(peer.total_difficulty.to_string())
|
||||
.color(COLOR_DARK)
|
||||
.size(16.0));
|
||||
ui.heading(RichText::new(AT).color(COLOR_DARK).size(16.0));
|
||||
ui.heading(RichText::new(peer.height.to_string())
|
||||
.color(COLOR_DARK)
|
||||
.size(16.0));
|
||||
});
|
||||
|
||||
ui.horizontal_top(|ui| {
|
||||
ui.add_space(6.0);
|
||||
|
||||
ui.heading(RichText::new(DEVICES)
|
||||
.color(COLOR_GRAY)
|
||||
.size(16.0));
|
||||
|
||||
ui.add_space(6.0);
|
||||
|
||||
// Draw peer user-agent
|
||||
ui.heading(RichText::new(&peer.user_agent)
|
||||
.color(COLOR_GRAY)
|
||||
.size(16.0));
|
||||
});
|
||||
|
||||
ui.add_space(2.0);
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum StatBoxRounding {
|
||||
TopLeft, TopRight, BottomRight, BottomLeft
|
||||
}
|
||||
|
||||
fn draw_stat_box(ui: &mut egui::Ui, value: String, label: String, rounding: StatBoxRounding) {
|
||||
let mut rect = ui.available_rect_before_wrap();
|
||||
rect.set_height(46.0);
|
||||
|
||||
// Draw box background
|
||||
ui.painter().rect(
|
||||
rect,
|
||||
Rounding {
|
||||
nw: if rounding == StatBoxRounding::TopLeft { 8.0 } else { 0.0 },
|
||||
ne: if rounding == StatBoxRounding::TopRight { 8.0 } else { 0.0 },
|
||||
sw: if rounding == StatBoxRounding::BottomLeft { 8.0 } else { 0.0 },
|
||||
se: if rounding == StatBoxRounding::BottomRight { 8.0 } else { 0.0 },
|
||||
},
|
||||
Color32::WHITE,
|
||||
Stroke { width: 1.0, color: Color32::from_gray(230) },
|
||||
);
|
||||
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
// Correct vertical spacing between items
|
||||
ui.style_mut().spacing.item_spacing.y = -4.0;
|
||||
|
||||
// Draw box value
|
||||
let mut job = LayoutJob::single_section(value, TextFormat {
|
||||
font_id: FontId::proportional(18.0),
|
||||
color: Color32::BLACK,
|
||||
.. Default::default()
|
||||
});
|
||||
job.wrap = TextWrapping {
|
||||
max_rows: 1,
|
||||
break_anywhere: false,
|
||||
overflow_character: Option::from('﹍'),
|
||||
..Default::default()
|
||||
};
|
||||
ui.label(job);
|
||||
|
||||
// Draw box label
|
||||
ui.label(RichText::new(label).color(COLOR_GRAY).size(15.0));
|
||||
});
|
||||
}
|
||||
@@ -12,17 +12,18 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use eframe::epaint::{FontId, Stroke};
|
||||
use eframe::epaint::text::{LayoutJob, TextFormat, TextWrapping};
|
||||
use egui::{Color32, FontId, RichText, Sense, Stroke, Widget};
|
||||
use egui::style::Margin;
|
||||
use egui_extras::{Size, StripBuilder};
|
||||
use crate::gui::colors::{COLOR_DARK, COLOR_YELLOW};
|
||||
|
||||
use crate::gui::{COLOR_DARK, COLOR_YELLOW};
|
||||
use crate::gui::screens::Navigator;
|
||||
use crate::gui::views::common::title_button;
|
||||
|
||||
pub struct TitlePanelAction {
|
||||
pub(crate) icon: Box<str>,
|
||||
pub(crate) on_click: Box<dyn Fn(&mut Option<&mut Navigator>)>,
|
||||
pub(crate) on_click: Box<dyn Fn(&mut Navigator)>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -31,15 +32,22 @@ pub struct TitlePanelActions {
|
||||
right: Option<TitlePanelAction>
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct TitlePanel<'nav> {
|
||||
title: Option<&'nav str>,
|
||||
title: Option<String>,
|
||||
actions: TitlePanelActions,
|
||||
navigator: Option<&'nav mut Navigator>
|
||||
nav: &'nav mut Navigator
|
||||
}
|
||||
|
||||
impl<'nav> TitlePanel<'nav> {
|
||||
pub fn title(mut self, title: &'nav str) -> Self {
|
||||
pub fn new(nav: &'nav mut Navigator) -> TitlePanel<'nav> {
|
||||
Self {
|
||||
title: None,
|
||||
actions: Default::default(),
|
||||
nav,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn title(mut self, title: String) -> Self {
|
||||
self.title = Some(title);
|
||||
self
|
||||
}
|
||||
@@ -54,16 +62,11 @@ impl<'nav> TitlePanel<'nav> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_navigator(mut self, nav: &'nav mut Navigator) -> Self {
|
||||
self.navigator = Some(nav);
|
||||
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, navigator } = self;
|
||||
let Self { actions, title, nav } = self;
|
||||
|
||||
egui::TopBottomPanel::top("title_panel")
|
||||
.resizable(false)
|
||||
@@ -85,50 +88,19 @@ impl<'nav> TitlePanel<'nav> {
|
||||
.size(Size::exact(52.0))
|
||||
.horizontal(|mut strip| {
|
||||
strip.cell(|ui| {
|
||||
if actions.left.is_some() {
|
||||
let action = actions.left.as_ref().unwrap();
|
||||
ui.centered_and_justified(|ui| {
|
||||
let b = egui::widgets::Button::new(
|
||||
RichText::new(&action.icon.to_string())
|
||||
.size(24.0)
|
||||
.color(COLOR_DARK)
|
||||
).fill(Color32::TRANSPARENT)
|
||||
.ui(ui)
|
||||
.interact(Sense::click_and_drag());
|
||||
if b.drag_released() || b.clicked() {
|
||||
(action.on_click)(navigator);
|
||||
};
|
||||
});
|
||||
}
|
||||
Self::show_action(ui, actions.left.as_ref(), nav);
|
||||
});
|
||||
strip.strip(|builder| {
|
||||
builder
|
||||
.size(Size::remainder())
|
||||
.vertical(|mut strip| {
|
||||
strip.cell(|ui| {
|
||||
if title.is_some() {
|
||||
ui.centered_and_justified(|ui| {
|
||||
Self::show_title(title.unwrap(), ui);
|
||||
});
|
||||
}
|
||||
Self::show_title(&*title, ui);
|
||||
});
|
||||
});
|
||||
});
|
||||
strip.cell(|ui| {
|
||||
if actions.right.is_some() {
|
||||
let action = actions.right.as_ref().unwrap();
|
||||
ui.centered_and_justified(|ui| {
|
||||
let b = egui::widgets::Button::new(
|
||||
RichText::new(action.icon.to_string())
|
||||
.size(24.0)
|
||||
.color(COLOR_DARK)
|
||||
).fill(Color32::TRANSPARENT)
|
||||
.ui(ui).interact(Sense::click_and_drag());
|
||||
if b.drag_released() || b.clicked() {
|
||||
(action.on_click)(navigator);
|
||||
};
|
||||
});
|
||||
}
|
||||
Self::show_action(ui, actions.right.as_ref(), nav);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -136,19 +108,38 @@ impl<'nav> TitlePanel<'nav> {
|
||||
});
|
||||
}
|
||||
|
||||
fn show_title(title: &str, ui: &mut egui::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);
|
||||
fn show_action(ui: &mut egui::Ui,
|
||||
action: Option<&TitlePanelAction>,
|
||||
navigator: &mut Navigator) {
|
||||
if action.is_some() {
|
||||
let action = action.unwrap();
|
||||
ui.centered_and_justified(|ui| {
|
||||
title_button(ui, &action.icon, || {
|
||||
(action.on_click)(navigator);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user