From b650ea0f3d88d06ab68f9f4a86ab6aa75393331d Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 16 Nov 2026 16:21:21 +0100 Subject: [PATCH] Apply interface scaling after slider release --- crates/canvas-pilot/src/preferences_ui.rs | 74 +++++++++++++++++++++-- docs/canvas-pilot/changelog.md | 2 + docs/canvas-pilot/guide/preferences.md | 4 +- docs/interfaces/canvas-pilot-settings.md | 5 +- 4 files changed, 76 insertions(+), 9 deletions(-) diff --git a/crates/canvas-pilot/src/preferences_ui.rs b/crates/canvas-pilot/src/preferences_ui.rs index 13227f2..28850d0 100644 --- a/crates/canvas-pilot/src/preferences_ui.rs +++ b/crates/canvas-pilot/src/preferences_ui.rs @@ -1,6 +1,10 @@ use super::*; +#[derive(Clone)] +struct ScaleDraft(f32, f32); + pub(super) fn apply_scaling(ctx: &egui::Context, ui_scale: f32, text_scale: Option) { + ctx.data_mut(|data| data.remove_by_type::()); ctx.set_zoom_factor(ui_scale); // Derive from defaults each time: toggles and theme changes must not compound sizes. let mut fonts = egui::Style::default().text_styles; @@ -10,6 +14,28 @@ pub(super) fn apply_scaling(ctx: &egui::Context, ui_scale: f32, text_scale: Opti ctx.style_mut(|style| style.text_styles = fonts); } +// Keep the displayed draft separate from the saved size until interaction ends. +fn scale_slider(ui: &mut egui::Ui, scale: &mut f32, maximum: f32) -> egui::Response { + let id = ui.next_auto_id().with("scale-draft"); + let ScaleDraft(original, draft) = ui + .data(|data| data.get_temp::(id)) + .unwrap_or(ScaleDraft(*scale, *scale)); + let mut percent = if original == *scale { draft } else { *scale } * 100.0; + let response = ui.add( + egui::Slider::new(&mut percent, 50.0..=maximum) + .suffix(" %") + .step_by(5.0), + ); + let editing = ui.input(|input| input.pointer.any_down()) || ui.ctx().wants_keyboard_input(); + if editing { + ui.data_mut(|data| data.insert_temp(id, ScaleDraft(*scale, percent / 100.0))); + } else { + *scale = percent / 100.0; + ui.data_mut(|data| data.remove::(id)); + } + response +} + #[derive(Clone, Copy, Debug, Default, PartialEq)] pub(super) enum Section { #[default] @@ -169,18 +195,14 @@ impl Editor { Section::Appearance => { ui.heading(tr(ui.ctx(), "ui.appearance")); let scaling_before = (self.ui_scale, self.text_scale); - let mut percent = self.ui_scale * 100.0; ui.label(tr(ctx, "access.interface-scale")); - ui.add(egui::Slider::new(&mut percent, 50.0..=400.0).suffix(" %").step_by(5.0)); - self.ui_scale = percent / 100.0; + scale_slider(ui, &mut self.ui_scale, 400.0); let mut separate = self.text_scale.is_some(); if ui.checkbox(&mut separate, tr(ctx, "access.text-scale")).changed() { self.text_scale = separate.then_some(1.0); } if let Some(scale) = &mut self.text_scale { - let mut percent = *scale * 100.0; - ui.add(egui::Slider::new(&mut percent, 50.0..=200.0).suffix(" %").step_by(5.0)); - *scale = percent / 100.0; + scale_slider(ui, scale, 200.0); ui.weak(tr(ctx, "access.text-help")); } if scaling_before != (self.ui_scale, self.text_scale) { apply_scaling(ctx, self.ui_scale, self.text_scale); } @@ -307,6 +329,40 @@ mod tests { ); frame(app, ctx, vec![mouse(pos, false)]); } + #[test] + fn scale_slider_commits_only_after_pointer_release() { + for maximum in [200.0, 400.0] { + let ctx = egui::Context::default(); + let mut scale = 1.0; + let mut rect = egui::Rect::NOTHING; + let mut run = |events| { + let _ = ctx.run( + egui::RawInput { + events, + ..Default::default() + }, + |ctx| { + egui::CentralPanel::default().show(ctx, |ui| { + rect = scale_slider(ui, &mut scale, maximum).rect; + }); + }, + ); + (scale, rect) + }; + let (_, rect) = run(vec![]); + let start = rect.left_center() + egui::vec2(30.0, 0.0); + assert_eq!( + run(vec![egui::Event::PointerMoved(start), mouse(start, true)]).0, + 1.0 + ); + let end = rect.left_center() + egui::vec2(85.0, 0.0); + assert_eq!(run(vec![egui::Event::PointerMoved(end)]).0, 1.0); + let (committed, _) = run(vec![mouse(end, false)]); + assert!(committed > 1.0, "released value: {committed}"); + assert_eq!(run(vec![]).0, committed); + } + } + #[test] fn scaling_is_idempotent_and_preserves_project_and_theme() { let ctx = egui::Context::default(); @@ -331,7 +387,13 @@ mod tests { assert_eq!(app.application_settings(&ctx).ui_scale, 1.5); assert_eq!(app.application_settings(&ctx).text_scale, Some(1.25)); assert_eq!(app.project().to_json().unwrap(), project); + let draft_id = egui::Id::new("pending-scale"); + ctx.data_mut(|data| data.insert_temp(draft_id, ScaleDraft(1.0, 3.0))); apply_scaling(&ctx, 1.0, None); + assert!( + ctx.data(|data| data.get_temp::(draft_id)) + .is_none() + ); assert_eq!(ctx.style().text_styles[&egui::TextStyle::Body].size, base); } diff --git a/docs/canvas-pilot/changelog.md b/docs/canvas-pilot/changelog.md index 69bbacf..1998929 100644 --- a/docs/canvas-pilot/changelog.md +++ b/docs/canvas-pilot/changelog.md @@ -9,6 +9,8 @@ - Added Appearance controls for 50–400% interface zoom and optional 50–200% standard-widget text scaling, with a readily accessible size reset. Added a High Contrast theme with measured text contrast and stronger widget borders. + Scaling sliders keep the interface still while dragging and apply on release; + typed values apply after finishing text entry. Settings v11 migrates older preferences without changing projects or exports. Fixed-size artwork/labels follow interface zoom, not the additional text scale. diff --git a/docs/canvas-pilot/guide/preferences.md b/docs/canvas-pilot/guide/preferences.md index f111ce7..bd51831 100644 --- a/docs/canvas-pilot/guide/preferences.md +++ b/docs/canvas-pilot/guide/preferences.md @@ -60,7 +60,9 @@ Open **Menu → Open all settings… → Appearance**: - **Use high contrast:** select a black-based theme with white text, bright accents and stronger control borders. It also appears as **High Contrast** in the theme browser. -Changes apply immediately and are remembered on this computer. **Reset interface +Scale values update while dragging, but resizing applies only after releasing +the pointer. Typed values apply after finishing text entry. Preferences are +remembered on this computer. **Reset interface size**, near the top of Settings, restores 100% and disables separate text scaling. Smaller scales free up space on low-resolution displays; larger scales support high-resolution monitors. These ranges do not depend on monitor resolution. diff --git a/docs/interfaces/canvas-pilot-settings.md b/docs/interfaces/canvas-pilot-settings.md index a9279c9..5e5978b 100644 --- a/docs/interfaces/canvas-pilot-settings.md +++ b/docs/interfaces/canvas-pilot-settings.md @@ -40,7 +40,8 @@ unknown theme names are rejected. There are no numeric coordinates or units. | `show_source_pattern` | Boolean; default false. Shows source patterns on other layers only during crop editing; normal editing always hides patterns. | | `snapping` | Object with required boolean fields `enabled` (false), `pixels` (true), `screen_edges` (true; screen edges plus 25%, 50% and 75% guides on both axes), `layer_edges` (true), `grid` (false), `show_grid` (true), and `grid_divisions` ([8, 6]); unknown fields rejected | -Scale preferences apply on startup and save immediately when changed. UI controls +Scale preferences apply on startup. Slider drafts apply and save on pointer +release; typed values wait until text entry ends. UI controls use 5-percentage-point increments; the file accepts any finite in-range multiplier. Separate text scaling changes standard widget text styles without compounding on repeated application. Explicit-size artwork and labels follow interface zoom only. @@ -134,7 +135,7 @@ The cancel button uses the previously displayed locale, including resolved Syste default. Preview state and its deadline are not serialized; preview state adds no serialized fields. The Settings window and quick menus share the same settings. Changes apply -and save immediately, except for language confirmation described above; closing +and save immediately, except for scaling interaction and language confirmation described above; closing the window requires no general Apply step. Restore default preferences resets appearance and editing values, including theme history and snapping, without changing layer geometry or pending position/size text fields. Snapping uses a