From 109c9a28b71f85e58ae8a0c23cf63dcfc6f1344b Mon Sep 17 00:00:00 2001 From: Cyrix126 <58007246+Cyrix126@users.noreply.github.com> Date: Wed, 1 Jan 2025 15:02:07 +0100 Subject: [PATCH] feat: resizable consoles (#65) --- src/app/panels/middle/common/console.rs | 64 +++++++++++++++---------- src/app/panels/middle/node.rs | 4 +- src/app/panels/middle/p2pool/mod.rs | 2 +- src/app/panels/middle/xmrig.rs | 4 +- src/app/panels/middle/xmrig_proxy.rs | 4 +- src/app/panels/middle/xvb.rs | 3 +- src/disk/state.rs | 10 ++++ src/disk/tests.rs | 5 ++ src/utils/constants.rs | 1 + 9 files changed, 64 insertions(+), 33 deletions(-) diff --git a/src/app/panels/middle/common/console.rs b/src/app/panels/middle/common/console.rs index 76cc964..776f957 100644 --- a/src/app/panels/middle/common/console.rs +++ b/src/app/panels/middle/common/console.rs @@ -19,33 +19,47 @@ use std::sync::{Arc, Mutex}; use egui::{Label, TextEdit, TextStyle, TextWrapMode, Ui}; -use crate::{DARK_GRAY, helper::Process, miscs::height_txt_before_button, regex::num_lines}; +use crate::{ + DARK_GRAY, + helper::{Process, ProcessName}, + miscs::height_txt_before_button, + regex::num_lines, +}; -pub fn console(ui: &mut Ui, text: &str) { +pub fn console(ui: &mut Ui, text: &str, console_height: &mut u32, process_name: ProcessName) { let nb_lines = num_lines(text); - let height = ui.available_height() / 2.8; - egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| { - ui.style_mut().wrap_mode = Some(TextWrapMode::Wrap); - ui.style_mut().override_text_style = Some(TextStyle::Small); - egui::ScrollArea::vertical() - .stick_to_bottom(true) - .max_width(ui.available_width()) - .max_height(height) - .auto_shrink([false; 2]) - // .show_viewport(ui, |ui, _| { - .show_rows( - ui, - ui.text_style_height(&TextStyle::Small), - nb_lines, - |ui, row_range| { - for i in row_range { - if let Some(line) = text.lines().nth(i) { - ui.label(line); - } - } - }, - ); - }); + *console_height = egui::Resize::default() + .id_salt(process_name.to_string()) + .default_height(*console_height as f32) + .min_width(ui.available_width()) + .max_width(ui.available_width()) + .show(ui, |ui| { + egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| { + ui.style_mut().wrap_mode = Some(TextWrapMode::Wrap); + ui.style_mut().override_text_style = Some(TextStyle::Small); + egui::ScrollArea::vertical() + .stick_to_bottom(true) + .max_width(ui.available_width()) + .max_height(ui.available_height()) + .auto_shrink([false; 2]) + // .show_viewport(ui, |ui, _| { + .show_rows( + ui, + ui.text_style_height(&TextStyle::Small), + nb_lines, + |ui, row_range| { + for i in row_range { + if let Some(line) = text.lines().nth(i) { + ui.label(line); + } + } + }, + ); + }) + }) + .response + .rect + .height() as u32; } // input args diff --git a/src/app/panels/middle/node.rs b/src/app/panels/middle/node.rs index 7fca241..18144b9 100644 --- a/src/app/panels/middle/node.rs +++ b/src/app/panels/middle/node.rs @@ -29,8 +29,8 @@ use log::debug; use crate::components::gupax::FileWindow; use crate::disk::state::Node; -use crate::helper::Process; use crate::helper::node::PubNodeApi; +use crate::helper::{Process, ProcessName}; use crate::{P2POOL_IN, P2POOL_LOG, P2POOL_OUT, SPACE}; impl Node { @@ -56,7 +56,7 @@ impl Node { egui::ScrollArea::vertical().show(ui, |ui| { let text = &api.lock().unwrap().output; ui.group(|ui| { - console(ui, text); + console(ui, text, &mut self.console_height, ProcessName::Node); if !self.simple { ui.separator(); input_args_field( diff --git a/src/app/panels/middle/p2pool/mod.rs b/src/app/panels/middle/p2pool/mod.rs index b33067a..a04baaf 100644 --- a/src/app/panels/middle/p2pool/mod.rs +++ b/src/app/panels/middle/p2pool/mod.rs @@ -56,7 +56,7 @@ impl P2pool { egui::ScrollArea::vertical().show(ui, |ui| { let text = &api_lock.output; ui.group(|ui| { - console(ui, text); + console(ui, text, &mut self.console_height, ProcessName::P2pool); if !self.simple { ui.separator(); input_args_field( diff --git a/src/app/panels/middle/xmrig.rs b/src/app/panels/middle/xmrig.rs index dc6a043..5370094 100644 --- a/src/app/panels/middle/xmrig.rs +++ b/src/app/panels/middle/xmrig.rs @@ -23,8 +23,8 @@ use crate::app::panels::middle::common::state_edit_field::{ }; use crate::constants::*; use crate::disk::state::Xmrig; -use crate::helper::Process; use crate::helper::xrig::xmrig::PubXmrigApi; +use crate::helper::{Process, ProcessName}; use crate::miscs::height_txt_before_button; use crate::regex::REGEXES; use egui::{Checkbox, Ui, vec2}; @@ -58,7 +58,7 @@ impl Xmrig { egui::ScrollArea::vertical().show(ui, |ui| { ui.group(|ui| { let text = &api.lock().unwrap().output; - console(ui, text); + console(ui, text, &mut self.console_height, ProcessName::Xmrig); if !self.simple { ui.separator(); input_args_field( diff --git a/src/app/panels/middle/xmrig_proxy.rs b/src/app/panels/middle/xmrig_proxy.rs index 86f52a5..5e6c203 100644 --- a/src/app/panels/middle/xmrig_proxy.rs +++ b/src/app/panels/middle/xmrig_proxy.rs @@ -24,8 +24,8 @@ use crate::app::panels::middle::common::console::{console, input_args_field, sta use crate::app::panels::middle::common::header_tab::header_tab; use crate::app::panels::middle::common::list_poolnode::list_poolnode; use crate::disk::state::XmrigProxy; -use crate::helper::Process; use crate::helper::xrig::xmrig_proxy::PubXmrigProxyApi; +use crate::helper::{Process, ProcessName}; use crate::miscs::height_txt_before_button; use crate::regex::REGEXES; use crate::{ @@ -59,7 +59,7 @@ impl XmrigProxy { egui::ScrollArea::vertical().show(ui, |ui| { ui.group(|ui| { let text = &api.lock().unwrap().output; - console(ui, text); + console(ui, text, &mut self.console_height, ProcessName::XmrigProxy); //---------------------------------------------------------------------------------------------------- [Advanced] Console if !self.simple { ui.separator(); diff --git a/src/app/panels/middle/xvb.rs b/src/app/panels/middle/xvb.rs index 158dba3..41e3419 100644 --- a/src/app/panels/middle/xvb.rs +++ b/src/app/panels/middle/xvb.rs @@ -27,6 +27,7 @@ use crate::app::panels::middle::common::console::console; use crate::app::panels::middle::common::header_tab::header_tab; use crate::app::panels::middle::common::state_edit_field::StateTextEdit; use crate::disk::state::{ManualDonationLevel, ManualDonationMetric, XvbMode}; +use crate::helper::ProcessName; use crate::helper::xrig::xmrig::PubXmrigApi; use crate::helper::xrig::xmrig_proxy::PubXmrigProxyApi; use crate::helper::xvb::PubXvbApi; @@ -83,7 +84,7 @@ impl crate::disk::state::Xvb { debug!("XvB Tab | Rendering [Console]"); ui.group(|ui| { let text = &api.lock().unwrap().output; - console(ui, text); + console(ui, text, &mut self.console_height, ProcessName::Xvb); }); // input token ui.add_space(SPACE); diff --git a/src/disk/state.rs b/src/disk/state.rs index a4b356b..2e409fe 100644 --- a/src/disk/state.rs +++ b/src/disk/state.rs @@ -301,6 +301,7 @@ pub struct P2pool { pub zmq: String, pub selected_node: SelectedPoolNode, pub prefer_local_node: bool, + pub console_height: u32, } // compatible for P2Pool and Xmrig/Proxy @@ -328,6 +329,7 @@ pub struct Node { pub dns_blocklist: bool, pub disable_dns_checkpoint: bool, pub path_db: String, + pub console_height: u32, } impl Default for Node { @@ -346,6 +348,7 @@ impl Default for Node { dns_blocklist: true, disable_dns_checkpoint: true, path_db: String::new(), + console_height: APP_DEFAULT_CONSOLE_HEIGHT, } } } @@ -369,6 +372,7 @@ pub struct Xmrig { pub port: String, pub selected_pool: SelectedPoolNode, pub token: String, + pub console_height: u32, } // present for future. @@ -391,6 +395,7 @@ pub struct XmrigProxy { pub selected_pool: SelectedPoolNode, pub token: String, pub redirect_local_xmrig: bool, + pub console_height: u32, } impl Gupax { @@ -453,6 +458,7 @@ impl Default for XmrigProxy { api_port: "18089".to_string(), tls: false, keepalive: false, + console_height: APP_DEFAULT_CONSOLE_HEIGHT, } } } @@ -469,6 +475,7 @@ pub struct Xvb { pub manual_donation_metric: ManualDonationMetric, pub p2pool_buffer: i8, pub use_p2pool_sidechain_hr: bool, + pub console_height: u32, } #[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize, Default, EnumCount, EnumIter)] @@ -621,6 +628,7 @@ impl Default for P2pool { zmq_rig: "18083".to_string(), }, prefer_local_node: true, + console_height: APP_DEFAULT_CONSOLE_HEIGHT, } } } @@ -665,6 +673,7 @@ impl Default for Xmrig { .take(16) .map(char::from) .collect(), + console_height: APP_DEFAULT_CONSOLE_HEIGHT, } } } @@ -682,6 +691,7 @@ impl Default for Xvb { manual_donation_metric: Default::default(), p2pool_buffer: 25, use_p2pool_sidechain_hr: false, + console_height: APP_DEFAULT_CONSOLE_HEIGHT, } } } diff --git a/src/disk/tests.rs b/src/disk/tests.rs index 28de8b3..ec59edf 100644 --- a/src/disk/tests.rs +++ b/src/disk/tests.rs @@ -84,6 +84,7 @@ mod test { rpc = "18089" zmq = "18083" prefer_local_node = true + console_height = 360 [p2pool.selected_node] index = 0 @@ -109,6 +110,7 @@ mod test { ip = "192.168.1.122" port = "3333" token = "testtoken" + console_height = 360 [xmrig.selected_pool] @@ -136,6 +138,7 @@ mod test { p2pool_port = "18088" token = "testtoken" redirect_local_xmrig = true + console_height = 360 [xmrig_proxy.selected_pool] index = 0 @@ -157,6 +160,7 @@ mod test { node = "Europe" p2pool_buffer = 5 use_p2pool_sidechain_hr = false + console_height = 360 [node] simple = false @@ -172,6 +176,7 @@ mod test { dns_blocklist = true disable_dns_checkpoint = true path_db = "" + console_height = 360 [version] gupax = "v1.3.0" diff --git a/src/utils/constants.rs b/src/utils/constants.rs index 6e5f088..e03f02d 100644 --- a/src/utils/constants.rs +++ b/src/utils/constants.rs @@ -40,6 +40,7 @@ pub const APP_MAX_HEIGHT: f32 = 2160.0; // Default, 1280x960 pub const APP_DEFAULT_WIDTH: f32 = 1280.0; pub const APP_DEFAULT_HEIGHT: f32 = 960.0; +pub const APP_DEFAULT_CONSOLE_HEIGHT: u32 = 360; // App resolution scaling pub const APP_MIN_SCALE: f32 = 0.1; pub const APP_MAX_SCALE: f32 = 2.0;