Status Submenu: add submenu UI to [Status] tab

This commit is contained in:
hinto-janaiyo 2022-12-27 16:29:12 -05:00
parent 51816323cd
commit a66e52bee5
No known key found for this signature in database
GPG key ID: B1C5A64B80691E45
5 changed files with 86 additions and 10 deletions

View file

@ -482,7 +482,7 @@ You need [`cargo`](https://www.rust-lang.org/learn/get-started), Rust's build to
The `--release` profile in Gupax is set to prefer code performance & small binary sizes over compilation speed (see [`Cargo.toml`](https://github.com/hinto-janaiyo/gupax/blob/main/Cargo.toml)). Gupax itself (with all dependencies already built) takes around 1m30s to build (vs 10s on a normal `--release`) with a Ryzen 5950x.
There are `25` unit tests throughout the codebase files, you should probably run:
There are `26` unit tests throughout the codebase files, you should probably run:
```
cargo test
```

View file

@ -63,8 +63,10 @@ r#"*---------------------------------------*
| Escape | Quit screen |
| Up | Start/Restart |
| Down | Stop |
| Z | Switch to Left Tab |
| X | Switch to Right Tab |
| Z | Left Tab |
| X | Right Tab |
| C | Left Submenu |
| V | Right Submenu |
| S | Save |
| R | Reset |
*---------------------------------------*"#;
@ -173,6 +175,10 @@ pub const STATUS_XMRIG_DIFFICULTY: &str = "The current difficulty of the job XMR
pub const STATUS_XMRIG_SHARES: &str = "The amount of accepted and rejected shares";
pub const STATUS_XMRIG_POOL: &str = "The pool XMRig is currently mining to";
pub const STATUS_XMRIG_THREADS: &str = "The amount of threads XMRig is currently using";
// Status Submenus
pub const STATUS_SUBMENU_PROCESSES: &str = "View the status of process related data for [Gupax|P2Pool|XMRig]";
pub const STATUS_SUBMENU_P2POOL: &str = "View P2Pool specific data";
pub const STATUS_SUBMENU_MONERO: &str = "View general Monero blockchain data";
// Gupax
pub const GUPAX_UPDATE: &str = "Check for updates on Gupax, P2Pool, and XMRig via GitHub's API and upgrade automatically";

View file

@ -209,6 +209,14 @@ impl HumanNumber {
let hash = format!("{:.3} GH/s", hash);
Self(hash)
}
pub fn from_f64_13_floating_point(f: f64) -> Self {
let f = format!("{:.13}", f);
Self(f)
}
pub fn from_f64_no_fmt(f: f64) -> Self {
let f = format!("{}", f);
Self(f)
}
}
//---------------------------------------------------------------------------------------------------- TESTS

View file

@ -649,6 +649,8 @@ enum KeyPressed {
Esc,
Z,
X,
C,
V,
S,
R,
D,
@ -683,6 +685,12 @@ impl KeyPressed {
fn is_d(&self) -> bool {
*self == Self::D
}
fn is_c(&self) -> bool {
*self == Self::C
}
fn is_v(&self) -> bool {
*self == Self::V
}
fn is_none(&self) -> bool {
*self == Self::None
}
@ -1006,6 +1014,10 @@ impl eframe::App for App {
KeyPressed::Z
} else if input.consume_key(Modifiers::NONE, Key::X) {
KeyPressed::X
} else if input.consume_key(Modifiers::NONE, Key::C) {
KeyPressed::C
} else if input.consume_key(Modifiers::NONE, Key::V) {
KeyPressed::V
} else if input.consume_key(Modifiers::NONE, Key::ArrowUp) {
KeyPressed::Up
} else if input.consume_key(Modifiers::NONE, Key::ArrowDown) {
@ -1049,6 +1061,36 @@ impl eframe::App for App {
Tab::P2pool => self.tab = Tab::Xmrig,
Tab::Xmrig => self.tab = Tab::About,
};
// Change Submenu LEFT
} else if key.is_c() && !wants_input {
match self.tab {
Tab::Status => {
match self.state.status.submenu {
Submenu::Processes => self.state.status.submenu = Submenu::Monero,
Submenu::P2pool => self.state.status.submenu = Submenu::Processes,
Submenu::Monero => self.state.status.submenu = Submenu::P2pool,
}
},
Tab::Gupax => self.state.gupax.simple = !self.state.gupax.simple,
Tab::P2pool => self.state.p2pool.simple = !self.state.p2pool.simple,
Tab::Xmrig => self.state.xmrig.simple = !self.state.xmrig.simple,
_ => (),
};
// Change Submenu RIGHT
} else if key.is_v() && !wants_input {
match self.tab {
Tab::Status => {
match self.state.status.submenu {
Submenu::Processes => self.state.status.submenu = Submenu::P2pool,
Submenu::P2pool => self.state.status.submenu = Submenu::Monero,
Submenu::Monero => self.state.status.submenu = Submenu::Processes,
}
},
Tab::Gupax => self.state.gupax.simple = !self.state.gupax.simple,
Tab::P2pool => self.state.p2pool.simple = !self.state.p2pool.simple,
Tab::Xmrig => self.state.xmrig.simple = !self.state.xmrig.simple,
_ => (),
};
}
// Refresh AT LEAST once a second
@ -1398,10 +1440,7 @@ impl eframe::App for App {
// [Save/Reset]
ui.with_layout(Layout::right_to_left(Align::RIGHT), |ui| {
let width = match self.tab {
Tab::Gupax => (ui.available_width()/2.0)-(SPACE*3.0),
_ => (ui.available_width()/3.0)-(SPACE*3.0),
};
let width = (ui.available_width()/3.0)-(SPACE*3.0);
ui.group(|ui| {
ui.set_enabled(self.diff);
let width = width / 2.0;
@ -1440,9 +1479,25 @@ impl eframe::App for App {
// [Simple/Advanced] + [Start/Stop/Restart]
match self.tab {
Tab::Status => {
ui.group(|ui| {
let width = (ui.available_width() / 3.0)-14.25;
if ui.add_sized([width, height], SelectableLabel::new(self.state.status.submenu == Submenu::Monero, "Monero")).on_hover_text(STATUS_SUBMENU_MONERO).clicked() {
self.state.status.submenu = Submenu::Monero;
}
ui.separator();
if ui.add_sized([width, height], SelectableLabel::new(self.state.status.submenu == Submenu::P2pool, "P2Pool")).on_hover_text(STATUS_SUBMENU_P2POOL).clicked() {
self.state.status.submenu = Submenu::P2pool;
}
ui.separator();
if ui.add_sized([width, height], SelectableLabel::new(self.state.status.submenu == Submenu::Processes, "Processes")).on_hover_text(STATUS_SUBMENU_PROCESSES).clicked() {
self.state.status.submenu = Submenu::Processes;
}
});
},
Tab::Gupax => {
ui.group(|ui| {
let width = width / 2.0;
let width = (ui.available_width() / 2.0)-10.5;
if ui.add_sized([width, height], SelectableLabel::new(!self.state.gupax.simple, "Advanced")).on_hover_text(GUPAX_ADVANCED).clicked() {
self.state.gupax.simple = false;
}
@ -1698,7 +1753,7 @@ XMRig console byte length: {}\n
}
Tab::Status => {
debug!("App | Entering [Status] Tab");
crate::disk::Status::show(&self.pub_sys, &self.p2pool_api, &self.xmrig_api, &self.p2pool_img, &self.xmrig_img, p2pool_is_alive, xmrig_is_alive, self.max_threads, self.width, self.height, ctx, ui);
crate::disk::Status::show(&mut self.state.status, &self.pub_sys, &self.p2pool_api, &self.xmrig_api, &self.p2pool_img, &self.xmrig_img, p2pool_is_alive, xmrig_is_alive, self.max_threads, self.width, self.height, ctx, ui);
}
Tab::Gupax => {
debug!("App | Entering [Gupax] Tab");

View file

@ -22,6 +22,8 @@ use crate::{
ImgXmrig,
constants::*,
Sys,
Hash,
Submenu,
};
use std::sync::{Arc,Mutex};
use log::*;
@ -32,7 +34,9 @@ use egui::{
};
impl crate::disk::Status {
pub fn show(sys: &Arc<Mutex<Sys>>, p2pool_api: &Arc<Mutex<PubP2poolApi>>, xmrig_api: &Arc<Mutex<PubXmrigApi>>, p2pool_img: &Arc<Mutex<ImgP2pool>>, xmrig_img: &Arc<Mutex<ImgXmrig>>, p2pool_alive: bool, xmrig_alive: bool, max_threads: usize, width: f32, height: f32, _ctx: &egui::Context, ui: &mut egui::Ui) {
pub fn show(&mut self, sys: &Arc<Mutex<Sys>>, p2pool_api: &Arc<Mutex<PubP2poolApi>>, xmrig_api: &Arc<Mutex<PubXmrigApi>>, p2pool_img: &Arc<Mutex<ImgP2pool>>, xmrig_img: &Arc<Mutex<ImgXmrig>>, p2pool_alive: bool, xmrig_alive: bool, max_threads: usize, width: f32, height: f32, _ctx: &egui::Context, ui: &mut egui::Ui) {
//---------------------------------------------------------------------------------------------------- [Processes]
if self.submenu == Submenu::Processes {
let width = (width/3.0)-(SPACE*1.666);
let min_height = height/1.1;
let height = height/25.0;
@ -118,5 +122,8 @@ pub fn show(sys: &Arc<Mutex<Sys>>, p2pool_api: &Arc<Mutex<PubP2poolApi>>, xmrig_
drop(api);
})});
});
} else if self.submenu == Submenu::P2pool {
} else if self.submenu == Submenu::Monero {
}
}
}