From 874f11cb3eeb1108dfb587048cbfda6382d21e17 Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Sun, 22 Oct 2023 17:14:02 -0400 Subject: [PATCH] add `0.1..=2.0` window pixel_per_point scaling --- Cargo.lock | 2 +- src/constants.rs | 5 +++++ src/disk.rs | 4 +++- src/free.rs | 17 +++++++++++++++++ src/gupax.rs | 6 +++++- src/main.rs | 14 ++++++++++---- src/p2pool.rs | 2 +- 7 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 src/free.rs diff --git a/Cargo.lock b/Cargo.lock index b1bfc89..736b653 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2208,7 +2208,7 @@ dependencies = [ [[package]] name = "gupax" -version = "1.3.0" +version = "1.3.1" dependencies = [ "anyhow", "arti-client", diff --git a/src/constants.rs b/src/constants.rs index edf61c3..3c8cfc3 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -38,6 +38,10 @@ 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; +// App resolution scaling +pub const APP_MIN_SCALE: f32 = 0.1; +pub const APP_MAX_SCALE: f32 = 2.0; +pub const APP_DEFAULT_SCALE: f32 = 1.0; // Constants specific for Linux distro packaging of Gupax #[cfg(feature = "distro")] @@ -237,6 +241,7 @@ pub const GUPAX_AUTO_XMRIG: &str = "Automatically start XMRig on Gupax sta pub const GUPAX_ADJUST: &str = "Adjust and set the width/height of the Gupax window"; pub const GUPAX_WIDTH: &str = "Set the width of the Gupax window"; pub const GUPAX_HEIGHT: &str = "Set the height of the Gupax window"; +pub const GUPAX_SCALE: &str = "Set the resolution scaling of the Gupax window (resize window to re-apply scaling)"; pub const GUPAX_LOCK_WIDTH: &str = "Automatically match the HEIGHT against the WIDTH in a 4:3 ratio"; pub const GUPAX_LOCK_HEIGHT: &str = "Automatically match the WIDTH against the HEIGHT in a 4:3 ratio"; pub const GUPAX_NO_LOCK: &str = "Allow individual selection of width and height"; diff --git a/src/disk.rs b/src/disk.rs index 2056849..f7c53b2 100644 --- a/src/disk.rs +++ b/src/disk.rs @@ -991,7 +991,7 @@ pub struct Status { pub hash_metric: Hash, } -#[derive(Clone,Eq,PartialEq,Debug,Deserialize,Serialize)] +#[derive(Clone,PartialEq,Debug,Deserialize,Serialize)] pub struct Gupax { pub simple: bool, pub auto_update: bool, @@ -1007,6 +1007,7 @@ pub struct Gupax { pub absolute_xmrig_path: PathBuf, pub selected_width: u16, pub selected_height: u16, + pub selected_scale: f32, pub tab: Tab, pub ratio: Ratio, } @@ -1096,6 +1097,7 @@ impl Default for Gupax { absolute_xmrig_path: into_absolute_path(DEFAULT_XMRIG_PATH.to_string()).unwrap(), selected_width: APP_DEFAULT_WIDTH as u16, selected_height: APP_DEFAULT_HEIGHT as u16, + selected_scale: APP_DEFAULT_SCALE, ratio: Ratio::Width, tab: Tab::About, } diff --git a/src/free.rs b/src/free.rs new file mode 100644 index 0000000..e0e58a2 --- /dev/null +++ b/src/free.rs @@ -0,0 +1,17 @@ +// Free functions. + +//---------------------------------------------------------------------------------------------------- Use +use crate::constants::*; + +//---------------------------------------------------------------------------------------------------- +#[inline] +// Clamp the scaling resolution `f32` to a known good `f32`. +pub fn clamp_scale(scale: f32) -> f32 { + // Make sure it is finite. + if !scale.is_finite() { + return APP_DEFAULT_SCALE; + } + + // Clamp between valid range. + scale.clamp(APP_MIN_SCALE, APP_MAX_SCALE) +} \ No newline at end of file diff --git a/src/gupax.rs b/src/gupax.rs index 421d2fb..ea75333 100644 --- a/src/gupax.rs +++ b/src/gupax.rs @@ -231,7 +231,7 @@ impl crate::disk::Gupax { self.selected_width = width as u16; }, } - let height = height/2.5; + let height = height/3.5; ui.horizontal(|ui| { ui.set_enabled(self.ratio != Ratio::Height); ui.add_sized([width, height], Label::new(format!(" Width [{}-{}]:", APP_MIN_WIDTH as u16, APP_MAX_WIDTH as u16))); @@ -242,6 +242,10 @@ impl crate::disk::Gupax { ui.add_sized([width, height], Label::new(format!("Height [{}-{}]:", APP_MIN_HEIGHT as u16, APP_MAX_HEIGHT as u16))); ui.add_sized([width, height], Slider::new(&mut self.selected_height, APP_MIN_HEIGHT as u16..=APP_MAX_HEIGHT as u16)).on_hover_text(GUPAX_HEIGHT); }); + ui.horizontal(|ui| { + ui.add_sized([width, height], Label::new(format!("Scaling [{APP_MIN_SCALE}..{APP_MAX_SCALE}]:"))); + ui.add_sized([width, height], Slider::new(&mut self.selected_scale, APP_MIN_SCALE..=APP_MAX_SCALE).step_by(0.1)).on_hover_text(GUPAX_SCALE); + }); }); ui.style_mut().override_text_style = Some(egui::TextStyle::Button); ui.separator(); diff --git a/src/main.rs b/src/main.rs index a635436..4896604 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,6 +79,7 @@ mod human; mod regex; mod xmr; mod macros; +mod free; use {macros::*,crate::regex::*,ferris::*,constants::*,node::*,disk::*,update::*,gupax::*,helper::*}; // Sudo (dummy values for Windows) @@ -174,7 +175,7 @@ pub struct App { impl App { fn cc(cc: &eframe::CreationContext<'_>, app: Self) -> Self { let resolution = cc.integration_info.window_info.size; - init_text_styles(&cc.egui_ctx, resolution[0]); + init_text_styles(&cc.egui_ctx, resolution[0], crate::free::clamp_scale(app.state.gupax.selected_scale)); cc.egui_ctx.set_visuals(VISUALS.clone()); Self { resolution, @@ -335,6 +336,9 @@ impl App { State::new() }, }; + // Clamp window resolution scaling values. + app.state.gupax.selected_scale = crate::free::clamp_scale(app.state.gupax.selected_scale); + app.og = arc_mut!(app.state.clone()); // Read node list info!("App Init | Reading node list..."); @@ -777,7 +781,7 @@ impl KeyPressed { //---------------------------------------------------------------------------------------------------- Init functions #[inline(always)] -fn init_text_styles(ctx: &egui::Context, width: f32) { +fn init_text_styles(ctx: &egui::Context, width: f32, pixels_per_point: f32) { let scale = width / 30.0; let mut style = (*ctx.style()).clone(); style.text_styles = [ @@ -796,7 +800,9 @@ fn init_text_styles(ctx: &egui::Context, width: f32) { style.spacing.icon_spacing = 20.0; style.spacing.scroll_bar_width = width / 150.0; ctx.set_style(style); - ctx.set_pixels_per_point(1.0); + // Make sure scale f32 is a regular number. + let pixels_per_point = crate::free::clamp_scale(pixels_per_point); + ctx.set_pixels_per_point(pixels_per_point); ctx.request_repaint(); } @@ -1308,7 +1314,7 @@ impl eframe::App for App { }); ctx.request_repaint(); info!("App | Resizing frame to match new internal resolution: [{}x{}]", self.width, self.height); - init_text_styles(ctx, self.width); + init_text_styles(ctx, self.width, self.state.gupax.selected_scale); self.resizing = false; } }); diff --git a/src/p2pool.rs b/src/p2pool.rs index 5420546..c8dfaea 100644 --- a/src/p2pool.rs +++ b/src/p2pool.rs @@ -112,7 +112,7 @@ impl crate::disk::P2pool { let height = ui.available_height(); if self.simple { // [Node] - let height = height / 6.0; + let height = height / 6.5; ui.spacing_mut().slider_width = width - 8.0; ui.spacing_mut().icon_width = width / 25.0;