mirror of
https://github.com/hinto-janai/gupax.git
synced 2024-12-23 03:19:21 +00:00
app: resize only once on width diff, set static button size at init
A [must_resize] and [ctx.is_pointer_over_area()] is now used to indicate we need a resizing. This makes it so when a user is resizing the width of Gupax, the heavy [init_text_styles()] func will only get called once when the user hovers over the GUI. The button size is also now set in that function so it doesn't have to be called in every separate tab.
This commit is contained in:
parent
4d4d2f1a42
commit
29a62f638a
5 changed files with 49 additions and 36 deletions
|
@ -1,4 +1,4 @@
|
|||
# Gupax - WORK IN PROGRESS
|
||||
# WORK IN PROGRESS - ETA: December 25th, 2022
|
||||
![banner.png](https://github.com/hinto-janaiyo/gupax/blob/main/images/banner.png)
|
||||
**Gupax** (*guh-picks*) is a cross-platform GUI for mining [**Monero**](https://github.com/monero-project/monero) on [**P2Pool**](https://github.com/SChernykh/p2pool), using [**XMRig**](https://github.com/xmrig/xmrig).
|
||||
|
||||
|
|
10
src/gupax.rs
10
src/gupax.rs
|
@ -113,11 +113,11 @@ impl Gupax {
|
|||
ui.group(|ui| {
|
||||
let width = (width - SPACE*7.5)/4.0;
|
||||
let height = height/8.0;
|
||||
let mut style = (*ctx.style()).clone();
|
||||
style.spacing.icon_width_inner = width / 8.0;
|
||||
style.spacing.icon_width = width / 6.0;
|
||||
style.spacing.icon_spacing = 20.0;
|
||||
ctx.set_style(style);
|
||||
// let mut style = (*ctx.style()).clone();
|
||||
// style.spacing.icon_width_inner = width / 8.0;
|
||||
// style.spacing.icon_width = width / 6.0;
|
||||
// style.spacing.icon_spacing = 20.0;
|
||||
// ctx.set_style(style);
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.auto_update, "Auto-update")).on_hover_text(GUPAX_AUTO_UPDATE);
|
||||
ui.separator();
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.update_via_tor, "Update via Tor")).on_hover_text(GUPAX_UPDATE_VIA_TOR);
|
||||
|
|
49
src/main.rs
49
src/main.rs
|
@ -71,6 +71,12 @@ pub struct App {
|
|||
tab: Tab, // What tab are we on?
|
||||
width: f32, // Top-level width
|
||||
height: f32, // Top-level height
|
||||
// This is a one time trigger so [init_text_styles()] isn't
|
||||
// called 60x a second when resizing the window. Instead,
|
||||
// it only gets called if this bool is true and the user
|
||||
// is hovering over egui (ctx.is_pointer_over_area()).
|
||||
must_resize: bool,
|
||||
first_frame: bool, // Is this the very first frame?
|
||||
// State
|
||||
og: Arc<Mutex<State>>, // og = Old state to compare against
|
||||
state: State, // state = Working state (current settings)
|
||||
|
@ -127,6 +133,8 @@ impl App {
|
|||
ping: Arc::new(Mutex::new(Ping::new())),
|
||||
width: APP_DEFAULT_WIDTH,
|
||||
height: APP_DEFAULT_HEIGHT,
|
||||
must_resize: false,
|
||||
first_frame: true,
|
||||
og: Arc::new(Mutex::new(State::new())),
|
||||
state: State::new(),
|
||||
update: Arc::new(Mutex::new(Update::new(String::new(), PathBuf::new(), PathBuf::new(), true))),
|
||||
|
@ -420,23 +428,14 @@ fn init_text_styles(ctx: &egui::Context, width: f32) {
|
|||
(Name("MonospaceSmall".into()), FontId::new(scale/2.5, egui::FontFamily::Monospace)),
|
||||
(Name("MonospaceLarge".into()), FontId::new(scale/1.5, egui::FontFamily::Monospace)),
|
||||
].into();
|
||||
// style.visuals.selection.stroke = Stroke { width: 5.0, color: Color32::from_rgb(255, 255, 255) };
|
||||
// style.spacing.slider_width = scale;
|
||||
// style.spacing.text_edit_width = scale;
|
||||
// style.spacing.button_padding = Vec2::new(scale/2.0, scale/2.0);
|
||||
style.spacing.icon_width_inner = width / 35.0;
|
||||
style.spacing.icon_width = width / 25.0;
|
||||
style.spacing.icon_spacing = 20.0;
|
||||
ctx.set_style(style);
|
||||
ctx.set_pixels_per_point(1.0);
|
||||
ctx.request_repaint();
|
||||
}
|
||||
|
||||
//fn init_color(ctx: &egui::Context) {
|
||||
// let mut style = (*ctx.style()).clone();
|
||||
// style.visuals.widgets.inactive.fg_stroke.color = Color32::from_rgb(100, 100, 100);
|
||||
// style.visuals.selection.bg_fill = Color32::from_rgb(255, 125, 50);
|
||||
// style.visuals.selection.stroke = Stroke { width: 5.0, color: Color32::from_rgb(255, 255, 255) };
|
||||
// ctx.set_style(style);
|
||||
//}
|
||||
|
||||
fn init_logger(now: Instant) {
|
||||
use env_logger::fmt::Color;
|
||||
Builder::new().format(move |buf, record| {
|
||||
|
@ -508,6 +507,7 @@ fn init_auto(app: &mut App) {
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Reset functions
|
||||
fn reset_state(path: &PathBuf) -> Result<(), TomlError> {
|
||||
match State::create_new(path) {
|
||||
Ok(_) => { info!("Resetting [state.toml] ... OK"); Ok(()) },
|
||||
|
@ -676,15 +676,28 @@ impl eframe::App for App {
|
|||
// *-------*
|
||||
// | DEBUG |
|
||||
// *-------*
|
||||
// crate::node::ping();
|
||||
// std::process::exit(0);
|
||||
// init_color(ctx);
|
||||
|
||||
// This sets the top level Ui dimensions.
|
||||
// Used as a reference for other uis.
|
||||
CentralPanel::default().show(ctx, |ui| { self.width = ui.available_width(); self.height = ui.available_height(); });
|
||||
// This sets fonts globally depending on the width.
|
||||
init_text_styles(ctx, self.width);
|
||||
CentralPanel::default().show(ctx, |ui| {
|
||||
let available_width = ui.available_width();
|
||||
if self.width != available_width {
|
||||
self.width = available_width;
|
||||
self.must_resize = true;
|
||||
};
|
||||
self.height = ui.available_height();
|
||||
});
|
||||
// This resizes fonts/buttons/etc globally depending on the width.
|
||||
// This is separate from the [self.width != available_width] logic above
|
||||
// because placing [init_text_styles()] above would mean calling it 60x a second
|
||||
// while the user was readjusting the frame. It's a pretty heavy operation and looks
|
||||
// buggy when calling it that many times. Looking for a [must_resize] in addtion to
|
||||
// checking if the user is hovering over the app means that we only have call it once.
|
||||
if self.must_resize && ctx.is_pointer_over_area(){
|
||||
info!("App | Resizing frame to match new internal resolution: [{}x{}]", self.width, self.height);
|
||||
init_text_styles(ctx, self.width);
|
||||
self.must_resize = false;
|
||||
}
|
||||
|
||||
// If [F11] was pressed, reverse [fullscreen] bool
|
||||
if ctx.input_mut().consume_key(Modifiers::NONE, Key::F11) {
|
||||
|
|
|
@ -166,11 +166,11 @@ impl P2pool {
|
|||
ui.horizontal(|ui| {
|
||||
let width = (width/2.0)-(SPACE*1.75);
|
||||
// [Auto-node] + [Auto-select]
|
||||
let mut style = (*ctx.style()).clone();
|
||||
style.spacing.icon_width_inner = width / 16.0;
|
||||
style.spacing.icon_width = width / 6.0;
|
||||
style.spacing.icon_spacing = 20.0;
|
||||
ctx.set_style(style);
|
||||
// let mut style = (*ctx.style()).clone();
|
||||
// style.spacing.icon_width_inner = width / 16.0;
|
||||
// style.spacing.icon_width = width / 6.0;
|
||||
// style.spacing.icon_spacing = 20.0;
|
||||
// ctx.set_style(style);
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.auto_select, "Auto-select")).on_hover_text(P2POOL_AUTO_SELECT);
|
||||
ui.separator();
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.auto_node, "Auto-node")).on_hover_text(P2POOL_AUTO_NODE);
|
||||
|
|
14
src/xmrig.rs
14
src/xmrig.rs
|
@ -341,7 +341,7 @@ impl Xmrig {
|
|||
ui.horizontal(|ui| {
|
||||
let text;
|
||||
let color;
|
||||
let len = self.port.len();
|
||||
let len = self.api_port.len();
|
||||
if self.api_port.is_empty() {
|
||||
text = format!("HTTP API Port [ {}/5 ]➖", len);
|
||||
color = LIGHT_GRAY;
|
||||
|
@ -350,7 +350,7 @@ impl Xmrig {
|
|||
text = format!("HTTP API Port [ {}/5 ]✔", len);
|
||||
color = GREEN;
|
||||
} else {
|
||||
text = format!(" Port [ {}/5 ]❌", len);
|
||||
text = format!("HTTP API Port [ {}/5 ]❌", len);
|
||||
color = RED;
|
||||
incorrect_input = true;
|
||||
}
|
||||
|
@ -367,11 +367,11 @@ impl Xmrig {
|
|||
ui.horizontal(|ui| {
|
||||
let width = (ui.available_width()/2.0)-11.0;
|
||||
let height = text_edit*2.0;
|
||||
let mut style = (*ctx.style()).clone();
|
||||
style.spacing.icon_width_inner = width / 8.0;
|
||||
style.spacing.icon_width = width / 6.0;
|
||||
style.spacing.icon_spacing = 20.0;
|
||||
ctx.set_style(style);
|
||||
// let mut style = (*ctx.style()).clone();
|
||||
// style.spacing.icon_width_inner = width / 8.0;
|
||||
// style.spacing.icon_width = width / 6.0;
|
||||
// style.spacing.icon_spacing = 20.0;
|
||||
// ctx.set_style(style);
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.tls, "TLS Connection")).on_hover_text(XMRIG_TLS);
|
||||
ui.separator();
|
||||
ui.add_sized([width, height], Checkbox::new(&mut self.keepalive, "Keepalive")).on_hover_text(XMRIG_KEEPALIVE);
|
||||
|
|
Loading…
Reference in a new issue