add 0.1..=2.0 window pixel_per_point scaling

This commit is contained in:
hinto.janai 2023-10-22 17:14:02 -04:00
parent 008c0def34
commit 874f11cb3e
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
7 changed files with 42 additions and 8 deletions

2
Cargo.lock generated
View file

@ -2208,7 +2208,7 @@ dependencies = [
[[package]] [[package]]
name = "gupax" name = "gupax"
version = "1.3.0" version = "1.3.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"arti-client", "arti-client",

View file

@ -38,6 +38,10 @@ pub const APP_MAX_HEIGHT: f32 = 2160.0;
// Default, 1280x960 // Default, 1280x960
pub const APP_DEFAULT_WIDTH: f32 = 1280.0; pub const APP_DEFAULT_WIDTH: f32 = 1280.0;
pub const APP_DEFAULT_HEIGHT: f32 = 960.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 // Constants specific for Linux distro packaging of Gupax
#[cfg(feature = "distro")] #[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_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_WIDTH: &str = "Set the width of the Gupax window";
pub const GUPAX_HEIGHT: &str = "Set the height 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_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_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"; pub const GUPAX_NO_LOCK: &str = "Allow individual selection of width and height";

View file

@ -991,7 +991,7 @@ pub struct Status {
pub hash_metric: Hash, pub hash_metric: Hash,
} }
#[derive(Clone,Eq,PartialEq,Debug,Deserialize,Serialize)] #[derive(Clone,PartialEq,Debug,Deserialize,Serialize)]
pub struct Gupax { pub struct Gupax {
pub simple: bool, pub simple: bool,
pub auto_update: bool, pub auto_update: bool,
@ -1007,6 +1007,7 @@ pub struct Gupax {
pub absolute_xmrig_path: PathBuf, pub absolute_xmrig_path: PathBuf,
pub selected_width: u16, pub selected_width: u16,
pub selected_height: u16, pub selected_height: u16,
pub selected_scale: f32,
pub tab: Tab, pub tab: Tab,
pub ratio: Ratio, pub ratio: Ratio,
} }
@ -1096,6 +1097,7 @@ impl Default for Gupax {
absolute_xmrig_path: into_absolute_path(DEFAULT_XMRIG_PATH.to_string()).unwrap(), absolute_xmrig_path: into_absolute_path(DEFAULT_XMRIG_PATH.to_string()).unwrap(),
selected_width: APP_DEFAULT_WIDTH as u16, selected_width: APP_DEFAULT_WIDTH as u16,
selected_height: APP_DEFAULT_HEIGHT as u16, selected_height: APP_DEFAULT_HEIGHT as u16,
selected_scale: APP_DEFAULT_SCALE,
ratio: Ratio::Width, ratio: Ratio::Width,
tab: Tab::About, tab: Tab::About,
} }

17
src/free.rs Normal file
View file

@ -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)
}

View file

@ -231,7 +231,7 @@ impl crate::disk::Gupax {
self.selected_width = width as u16; self.selected_width = width as u16;
}, },
} }
let height = height/2.5; let height = height/3.5;
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.set_enabled(self.ratio != Ratio::Height); 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))); 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], 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.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.style_mut().override_text_style = Some(egui::TextStyle::Button);
ui.separator(); ui.separator();

View file

@ -79,6 +79,7 @@ mod human;
mod regex; mod regex;
mod xmr; mod xmr;
mod macros; mod macros;
mod free;
use {macros::*,crate::regex::*,ferris::*,constants::*,node::*,disk::*,update::*,gupax::*,helper::*}; use {macros::*,crate::regex::*,ferris::*,constants::*,node::*,disk::*,update::*,gupax::*,helper::*};
// Sudo (dummy values for Windows) // Sudo (dummy values for Windows)
@ -174,7 +175,7 @@ pub struct App {
impl App { impl App {
fn cc(cc: &eframe::CreationContext<'_>, app: Self) -> Self { fn cc(cc: &eframe::CreationContext<'_>, app: Self) -> Self {
let resolution = cc.integration_info.window_info.size; 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()); cc.egui_ctx.set_visuals(VISUALS.clone());
Self { Self {
resolution, resolution,
@ -335,6 +336,9 @@ impl App {
State::new() 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()); app.og = arc_mut!(app.state.clone());
// Read node list // Read node list
info!("App Init | Reading node list..."); info!("App Init | Reading node list...");
@ -777,7 +781,7 @@ impl KeyPressed {
//---------------------------------------------------------------------------------------------------- Init functions //---------------------------------------------------------------------------------------------------- Init functions
#[inline(always)] #[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 scale = width / 30.0;
let mut style = (*ctx.style()).clone(); let mut style = (*ctx.style()).clone();
style.text_styles = [ style.text_styles = [
@ -796,7 +800,9 @@ fn init_text_styles(ctx: &egui::Context, width: f32) {
style.spacing.icon_spacing = 20.0; style.spacing.icon_spacing = 20.0;
style.spacing.scroll_bar_width = width / 150.0; style.spacing.scroll_bar_width = width / 150.0;
ctx.set_style(style); 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(); ctx.request_repaint();
} }
@ -1308,7 +1314,7 @@ impl eframe::App for App {
}); });
ctx.request_repaint(); ctx.request_repaint();
info!("App | Resizing frame to match new internal resolution: [{}x{}]", self.width, self.height); 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; self.resizing = false;
} }
}); });

View file

@ -112,7 +112,7 @@ impl crate::disk::P2pool {
let height = ui.available_height(); let height = ui.available_height();
if self.simple { if self.simple {
// [Node] // [Node]
let height = height / 6.0; let height = height / 6.5;
ui.spacing_mut().slider_width = width - 8.0; ui.spacing_mut().slider_width = width - 8.0;
ui.spacing_mut().icon_width = width / 25.0; ui.spacing_mut().icon_width = width / 25.0;