Merge pull request #9440 from dotCooCoo/fix/saved-ui-scale

Preferences: keep Actual Size correct with out-of-range UI Scaling
This commit is contained in:
BFlat
2026-11-27 00:46:27 +07:00
committed by GitHub
3 changed files with 24 additions and 3 deletions
+6 -2
View File
@@ -707,14 +707,18 @@ impl VectorcraftApp {
}
}
/// Use the same supported scale for the interface and the canvas. Invalid saved values fall back to 100%.
fn applied_ui_scaling(saved: f64) -> f32 {
if saved.is_finite() && saved > 0.0 { saved.clamp(0.75, 2.0) as f32 } else { 1.0 }
}
/// The root values the preferences give every frame: the theme, the interface scale (UI Scaling
/// over the display's `native_ppp`), Show Tool Tips, the zoom stops (100% at `print` screen points
/// to an inch, [`crate::state::print_ppi`]) and which drags scrub a value (Scrub Numeric Fields: the
/// side label only, or nothing).
pub(crate) fn root_env(prefs: &vectorcraft_engine::Prefs, native_ppp: f32, print: Option<f64>) -> RootEnv {
let (theme, mode, accent) = theme::root_theme(prefs);
// A hand-edited preferences file must not scale the interface to nothing.
let scaling = if prefs.ui_scaling.is_finite() && prefs.ui_scaling > 0.0 { prefs.ui_scaling as f32 } else { 1.0 };
let scaling = applied_ui_scaling(prefs.ui_scaling);
let mut root = RootEnv::new().theme(theme).mode(mode).accent(accent).scale(Scale::new(scaling)).tooltips(prefs.show_tool_tips);
root.sizes = theme::app_sizes();
root.values.set(view::zoom_scheme(print, native_ppp));
+1 -1
View File
@@ -327,7 +327,7 @@ impl VectorcraftApp {
/// Preferences › User Interface › UI Scaling, as the interface applies it.
pub(crate) fn ui_scaling(&self) -> f32 {
self.session.prefs.ui_scaling.clamp(0.75, 2.0) as f32
super::applied_ui_scaling(self.session.prefs.ui_scaling)
}
/// Ask the active view's canvas to run `request` in its next pass; `bounds` are the layers' bounds
@@ -92,3 +92,20 @@ fn pixel_preview_compares_a_document_pixel_with_a_device_pixel() {
}
}
}
#[test]
fn out_of_range_saved_ui_scaling_keeps_actual_size_correct() {
let (a, b) = (Point::new(100.0, 100.0), Point::new(228.0, 100.0));
for (saved, expected) in [(0.5, 0.75), (3.0, 2.0), (0.0, 1.0), (f64::NAN, 1.0)] {
let (mut app, ctx, jobs) = shown(1.0, 1.5);
app.run("view.actualSize", json!({})).unwrap();
frame(&mut app, &ctx, (1.0, 1.5), vec![]);
let before = device_length(rendered(&jobs), a, b);
app.session.prefs.ui_scaling = saved;
let scale = crate::app::root_env(&app.session.prefs, 1.0, None).scale.0;
assert_eq!(scale, expected, "interface scale from saved value {saved}");
frame(&mut app, &ctx, (1.0, scale), vec![]);
let length = device_length(rendered(&jobs), a, b);
assert!((length - before).abs() < 1e-4, "saved scale {saved} changes 128 pt from {before} to {length} pixels");
}
}