mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-12-22 22:59:27 +00:00
feat: optmize console output to render only what is visible
egui TextEdit::multiligne will render everything. Use show_rows insteead of show_viewport for AreaScroll to fix this.
This commit is contained in:
parent
bddc507a83
commit
9f91f88689
5 changed files with 102 additions and 87 deletions
|
@ -45,13 +45,17 @@
|
|||
- [x] output log to console in XvB tab
|
||||
- [x] fix some overlapping from upstream
|
||||
- [ ] edit metadata of project
|
||||
- [ ] adapt README for XvB
|
||||
- [ ] adapt README for XvB
|
||||
- [ ] beta release
|
||||
- [ ] stable release
|
||||
- [ ] video tutorial to set up XvB Tab
|
||||
- [ ] adapt doc for new code
|
||||
- [ ] cargo package metadata
|
||||
- [ ] pgp signatures
|
||||
- [x] fix clippy
|
||||
- [ ] optimizations
|
||||
- [x] benchmarks table render only what is visible
|
||||
- [x] console output render only what is visible
|
||||
- [ ] migrate to hyper stable
|
||||
- [ ] use tor socks proxy instead of creating one
|
||||
- [ ] better organize new code
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::disk::node::Node;
|
||||
use crate::disk::state::{P2pool, State};
|
||||
use crate::helper::p2pool::PubP2poolApi;
|
||||
use crate::regex::num_lines;
|
||||
// Gupax - GUI Uniting P2Pool And XMRig
|
||||
//
|
||||
// Copyright (c) 2022-2023 hinto-janai
|
||||
|
@ -18,7 +19,11 @@ use crate::helper::p2pool::PubP2poolApi;
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
use crate::{components::node::*, constants::*, helper::*, macros::*, utils::regex::Regexes};
|
||||
use egui::{vec2, Color32, Label, RichText, TextEdit, TextStyle::*, Vec2};
|
||||
use egui::{
|
||||
vec2, Color32, Label, RichText, TextEdit,
|
||||
TextStyle::{self, *},
|
||||
Vec2,
|
||||
};
|
||||
use log::*;
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
@ -45,49 +50,45 @@ impl P2pool {
|
|||
let width = size.x;
|
||||
let text_edit = size.y / 25.0;
|
||||
//---------------------------------------------------------------------------------------------------- [Simple] Console
|
||||
debug!("P2Pool Tab | Rendering [Console]");
|
||||
// debug!("P2Pool Tab | Rendering [Console]");
|
||||
ui.group(|ui| {
|
||||
if self.simple {
|
||||
// height of console = height - address - simple(dropmenu, select_bar, buttons, warning)
|
||||
let height = (size.y * 0.38) - SPACE;
|
||||
let width = size.x - SPACE;
|
||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||
egui::ScrollArea::vertical()
|
||||
.stick_to_bottom(true)
|
||||
.max_width(width)
|
||||
.max_height(height)
|
||||
.auto_shrink([false; 2])
|
||||
.show_viewport(ui, |ui, _| {
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
TextEdit::multiline(&mut lock!(api).output.as_str()),
|
||||
);
|
||||
});
|
||||
});
|
||||
//---------------------------------------------------------------------------------------------------- [Advanced] Console
|
||||
let text = &lock!(api).output;
|
||||
let nb_lines = num_lines(text);
|
||||
let (height, width) = if self.simple {
|
||||
((size.y * 0.38) - SPACE, size.x - SPACE)
|
||||
} else {
|
||||
// fix for advanced submenu overlap on bottom when small window
|
||||
let height = if size.y < 600.0 {
|
||||
size.y * 0.22 - SPACE
|
||||
} else {
|
||||
size.y * 0.36 - SPACE
|
||||
};
|
||||
let width = width - SPACE;
|
||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||
egui::ScrollArea::vertical()
|
||||
.stick_to_bottom(true)
|
||||
.max_width(width)
|
||||
.max_height(height)
|
||||
.auto_shrink([false; 2])
|
||||
.show_viewport(ui, |ui, _| {
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
TextEdit::multiline(&mut lock!(api).output.as_str()),
|
||||
);
|
||||
});
|
||||
});
|
||||
(
|
||||
if size.y < 600.0 {
|
||||
size.y * 0.22 - SPACE
|
||||
} else {
|
||||
size.y * 0.36 - SPACE
|
||||
},
|
||||
width - SPACE,
|
||||
)
|
||||
};
|
||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||
egui::ScrollArea::vertical()
|
||||
.stick_to_bottom(true)
|
||||
.max_width(width)
|
||||
.max_height(height)
|
||||
.auto_shrink([false; 2])
|
||||
// .show_viewport(ui, |ui, _| {
|
||||
.show_rows(
|
||||
ui,
|
||||
ui.text_style_height(&TextStyle::Name("MonospaceSmall".into())),
|
||||
nb_lines,
|
||||
|ui, row_range| {
|
||||
for i in row_range {
|
||||
if let Some(line) = text.lines().nth(i) {
|
||||
ui.label(line);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
if !self.simple {
|
||||
//---------------------------------------------------------------------------------------------------- [Advanced] Console
|
||||
ui.separator();
|
||||
let response = ui
|
||||
.add_sized(
|
||||
|
|
|
@ -19,12 +19,13 @@ use crate::disk::pool::Pool;
|
|||
use crate::disk::state::Xmrig;
|
||||
use crate::helper::xmrig::PubXmrigApi;
|
||||
use crate::helper::Process;
|
||||
use crate::regex::REGEXES;
|
||||
use crate::regex::{num_lines, REGEXES};
|
||||
use crate::utils::regex::Regexes;
|
||||
use crate::{constants::*, macros::*};
|
||||
use egui::{
|
||||
vec2, Button, Checkbox, ComboBox, Label, RichText, SelectableLabel, Slider, TextEdit,
|
||||
TextStyle::*, Vec2,
|
||||
TextStyle::{self, *},
|
||||
Vec2,
|
||||
};
|
||||
use log::*;
|
||||
|
||||
|
@ -47,43 +48,36 @@ impl Xmrig {
|
|||
//---------------------------------------------------------------------------------------------------- [Simple] Console
|
||||
debug!("XMRig Tab | Rendering [Console]");
|
||||
ui.group(|ui| {
|
||||
if self.simple {
|
||||
let height = size.y / 1.5;
|
||||
let width = size.x - SPACE;
|
||||
let size = vec2(width, height);
|
||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||
egui::ScrollArea::vertical()
|
||||
.stick_to_bottom(true)
|
||||
.max_width(width)
|
||||
.max_height(height)
|
||||
.auto_shrink([false; 2])
|
||||
.show_viewport(ui, |ui, _| {
|
||||
ui.add_sized(
|
||||
size,
|
||||
TextEdit::multiline(&mut lock!(api).output.as_str()),
|
||||
);
|
||||
});
|
||||
});
|
||||
//---------------------------------------------------------------------------------------------------- [Advanced] Console
|
||||
let text = &lock!(api).output;
|
||||
let nb_lines = num_lines(text);
|
||||
let (height, width) = if self.simple {
|
||||
(size.y / 1.5, size.x - SPACE)
|
||||
} else {
|
||||
let height = size.y / 2.8;
|
||||
let width = size.x - SPACE;
|
||||
let size = vec2(width, height);
|
||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||
egui::ScrollArea::vertical()
|
||||
.stick_to_bottom(true)
|
||||
.max_width(width)
|
||||
.max_height(height)
|
||||
.auto_shrink([false; 2])
|
||||
.show_viewport(ui, |ui, _| {
|
||||
ui.add_sized(
|
||||
size,
|
||||
TextEdit::multiline(&mut lock!(api).output.as_str()),
|
||||
);
|
||||
});
|
||||
});
|
||||
(size.y / 2.8, size.x - SPACE)
|
||||
};
|
||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
|
||||
egui::ScrollArea::vertical()
|
||||
.stick_to_bottom(true)
|
||||
.max_width(width)
|
||||
.max_height(height)
|
||||
.auto_shrink([false; 2])
|
||||
// .show_viewport(ui, |ui, _| {
|
||||
.show_rows(
|
||||
ui,
|
||||
ui.text_style_height(&TextStyle::Name("MonospaceSmall".into())),
|
||||
nb_lines,
|
||||
|ui, row_range| {
|
||||
for i in row_range {
|
||||
if let Some(line) = text.lines().nth(i) {
|
||||
ui.label(line);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
//---------------------------------------------------------------------------------------------------- [Advanced] Console
|
||||
if !self.simple {
|
||||
ui.separator();
|
||||
let response = ui
|
||||
.add_sized(
|
||||
|
|
|
@ -6,6 +6,7 @@ use log::debug;
|
|||
use readable::num::Float;
|
||||
|
||||
use crate::helper::xvb::PubXvbApi;
|
||||
use crate::regex::num_lines;
|
||||
use crate::utils::constants::{
|
||||
GREEN, LIGHT_GRAY, ORANGE, RED, XVB_DONATED_1H_FIELD, XVB_DONATED_24H_FIELD, XVB_FAILURE_FIELD,
|
||||
XVB_HELP, XVB_HERO_SELECT, XVB_ROUND_TYPE_FIELD, XVB_TOKEN_FIELD, XVB_TOKEN_LEN, XVB_URL_RULES,
|
||||
|
@ -47,6 +48,8 @@ impl crate::disk::state::Xvb {
|
|||
// console output for log
|
||||
debug!("XvB Tab | Rendering [Console]");
|
||||
ui.group(|ui| {
|
||||
let text = &lock!(api).output;
|
||||
let nb_lines = num_lines(text);
|
||||
let height = size.y / 2.8;
|
||||
let width = size.x - (space_h / 2.0);
|
||||
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
|
||||
|
@ -56,12 +59,19 @@ impl crate::disk::state::Xvb {
|
|||
.max_width(width)
|
||||
.max_height(height)
|
||||
.auto_shrink([false; 2])
|
||||
.show_viewport(ui, |ui, _| {
|
||||
ui.add_sized(
|
||||
[width, height],
|
||||
TextEdit::multiline(&mut lock!(api).output.as_str()),
|
||||
);
|
||||
});
|
||||
// .show_viewport(ui, |ui, _| {
|
||||
.show_rows(
|
||||
ui,
|
||||
ui.text_style_height(&TextStyle::Name("MonospaceSmall".into())),
|
||||
nb_lines,
|
||||
|ui, row_range| {
|
||||
for i in row_range {
|
||||
if let Some(line) = text.lines().nth(i) {
|
||||
ui.label(line);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
// input token
|
||||
|
|
|
@ -123,6 +123,12 @@ impl XmrigRegex {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// count the lines without consuming.
|
||||
pub fn num_lines(s: &str) -> usize {
|
||||
static LINE_BREAKS: Lazy<Regex> = Lazy::new(|| Regex::new(r"\r?\n").unwrap());
|
||||
LINE_BREAKS.captures_iter(s).count() + 1
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------- TEST
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
|
Loading…
Reference in a new issue