diff --git a/Cargo.lock b/Cargo.lock index a9b4c96..4628241 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -582,7 +582,7 @@ dependencies = [ [[package]] name = "canvas-pilot" -version = "0.9.0" +version = "0.9.1" dependencies = [ "base64", "craft-dwg", diff --git a/Cargo.toml b/Cargo.toml index 651ff32..9b6b835 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ default-members = ["crates/canvas-pilot"] resolver = "3" [workspace.package] -version = "0.9.0" +version = "0.9.1" edition = "2024" license = "MIT" repository = "https://proxy.dandaedre.com/gitea/idle-org/canvas-pilot" diff --git a/crates/canvas-pilot/locales/en.json b/crates/canvas-pilot/locales/en.json index 6bd24a4..39e68fe 100644 --- a/crates/canvas-pilot/locales/en.json +++ b/crates/canvas-pilot/locales/en.json @@ -456,5 +456,10 @@ "language.keep": "Yes", "language.rollback": "Your previous language returns in %{seconds} seconds unless you confirm.", "language.cancel": "No, I clicked on this language by accident", - "ui.mask-properties": "Mask properties…" + "ui.mask-properties": "Mask properties…", + "access.interface-scale": "Interface scale", + "access.text-scale": "Adjust text separately", + "access.text-help": "Additional scaling for standard controls. Canvas artwork and fixed-size labels follow interface scale.", + "access.contrast": "Use high contrast", + "access.reset": "Reset interface size" } diff --git a/crates/canvas-pilot/locales/eo.json b/crates/canvas-pilot/locales/eo.json index 8f811b8..874509a 100644 --- a/crates/canvas-pilot/locales/eo.json +++ b/crates/canvas-pilot/locales/eo.json @@ -456,5 +456,10 @@ "language.keep": "Jes", "language.rollback": "Sen konfirmo, la antaŭa lingvo revenos post %{seconds} sekundoj.", "language.cancel": "Ne, mi elektis ĉi tiun lingvon erare", - "ui.mask-properties": "Ecoj de la masko…" + "ui.mask-properties": "Ecoj de la masko…", + "access.interface-scale": "Interfaca skalo", + "access.text-scale": "Alĝustigi tekston aparte", + "access.text-help": "Plia skalo por normaj regiloj. La kanvaso kaj fiksgrandaj etikedoj sekvas la interfacan skalon.", + "access.contrast": "Uzi altan kontraston", + "access.reset": "Restarigi la interfacan grandecon" } diff --git a/crates/canvas-pilot/locales/es.json b/crates/canvas-pilot/locales/es.json index a7f46f5..6f7f50f 100644 --- a/crates/canvas-pilot/locales/es.json +++ b/crates/canvas-pilot/locales/es.json @@ -456,5 +456,10 @@ "language.keep": "Sí", "language.rollback": "Si no confirmas, se volverá al idioma anterior en %{seconds} segundos.", "language.cancel": "No, elegí este idioma por accidente", - "ui.mask-properties": "Propiedades de la máscara…" + "ui.mask-properties": "Propiedades de la máscara…", + "access.interface-scale": "Escala de la interfaz", + "access.text-scale": "Ajustar el texto por separado", + "access.text-help": "Escala adicional para controles estándar. El lienzo y las etiquetas de tamaño fijo siguen la escala de la interfaz.", + "access.contrast": "Usar alto contraste", + "access.reset": "Restablecer el tamaño de la interfaz" } diff --git a/crates/canvas-pilot/locales/fr.json b/crates/canvas-pilot/locales/fr.json index c285b03..7d1b097 100644 --- a/crates/canvas-pilot/locales/fr.json +++ b/crates/canvas-pilot/locales/fr.json @@ -456,5 +456,10 @@ "language.keep": "Oui", "language.rollback": "Sans confirmation, la langue précédente sera rétablie dans %{seconds} secondes.", "language.cancel": "Non, j’ai choisi cette langue par erreur", - "ui.mask-properties": "Propriétés du masque…" + "ui.mask-properties": "Propriétés du masque…", + "access.interface-scale": "Échelle de l’interface", + "access.text-scale": "Ajuster le texte séparément", + "access.text-help": "Agrandissement supplémentaire des commandes standard. Le canevas et les libellés à taille fixe suivent l’échelle de l’interface.", + "access.contrast": "Utiliser le contraste élevé", + "access.reset": "Réinitialiser la taille de l’interface" } diff --git a/crates/canvas-pilot/locales/grc.json b/crates/canvas-pilot/locales/grc.json index 149fd3a..f5e6907 100644 --- a/crates/canvas-pilot/locales/grc.json +++ b/crates/canvas-pilot/locales/grc.json @@ -456,5 +456,10 @@ "language.keep": "Ναί", "language.rollback": "Ἡ προτέρα γλῶττα ἐπανήξει μετὰ %{seconds} δευτερόλεπτα, ἐὰν μὴ βεβαιώσῃς.", "language.cancel": "Οὔ, κατὰ τύχην ταύτην τὴν γλῶτταν εἱλόμην", - "ui.mask-properties": "Ἰδιότητες τοῦ καλύμματος…" + "ui.mask-properties": "Ἰδιότητες τοῦ καλύμματος…", + "access.interface-scale": "Μέγεθος τῆς διεπαφῆς", + "access.text-scale": "Τὰ γράμματα χωρὶς αὔξειν", + "access.text-help": "Αὔξησις τῶν γραμμάτων τῶν συνήθων ὀργάνων. Ὁ πίναξ καὶ αἱ σταθεραὶ ἐπιγραφαὶ ἕπονται τῷ μεγέθει τῆς διεπαφῆς.", + "access.contrast": "Ἰσχυρὰν ἀντίθεσιν χρῆσθαι", + "access.reset": "Τὸ μέγεθος ἀποκαθιστάναι" } diff --git a/crates/canvas-pilot/locales/ja.json b/crates/canvas-pilot/locales/ja.json index cbfe0bf..6be5d1f 100644 --- a/crates/canvas-pilot/locales/ja.json +++ b/crates/canvas-pilot/locales/ja.json @@ -456,5 +456,10 @@ "language.keep": "はい", "language.rollback": "確認しない場合、%{seconds} 秒後に元の言語に戻ります。", "language.cancel": "いいえ、間違えてこの言語を選びました", - "ui.mask-properties": "マスクのプロパティ…" + "ui.mask-properties": "マスクのプロパティ…", + "access.interface-scale": "インターフェースの拡大率", + "access.text-scale": "文字サイズを個別に調整", + "access.text-help": "標準コントロールの文字を拡大します。キャンバスと固定サイズのラベルはインターフェースの拡大率に従います。", + "access.contrast": "高コントラストを使用", + "access.reset": "インターフェースのサイズをリセット" } diff --git a/crates/canvas-pilot/locales/zh-CN.json b/crates/canvas-pilot/locales/zh-CN.json index 9b13f13..e14b152 100644 --- a/crates/canvas-pilot/locales/zh-CN.json +++ b/crates/canvas-pilot/locales/zh-CN.json @@ -456,5 +456,10 @@ "language.keep": "是", "language.rollback": "如果不确认,将在 %{seconds} 秒后恢复原来的语言。", "language.cancel": "不,我不小心选错了语言", - "ui.mask-properties": "遮罩属性…" + "ui.mask-properties": "遮罩属性…", + "access.interface-scale": "界面缩放", + "access.text-scale": "单独调整文字", + "access.text-help": "额外缩放标准控件文字。画布和固定大小的标签遵循界面缩放。", + "access.contrast": "使用高对比度", + "access.reset": "重置界面大小" } diff --git a/crates/canvas-pilot/src/gui.rs b/crates/canvas-pilot/src/gui.rs index b5b3835..7c8297d 100644 --- a/crates/canvas-pilot/src/gui.rs +++ b/crates/canvas-pilot/src/gui.rs @@ -44,6 +44,8 @@ pub struct Editor { capture: capture_ui::CaptureUi, layer_ui: layers_ui::LayerUi, settings: settings::Store, + ui_scale: f32, + text_scale: Option, language: localization::Language, language_preview: Option, recovery: recovery_ui::Recovery, @@ -364,6 +366,8 @@ impl Default for Editor { device: Default::default(), capture: Default::default(), layer_ui: Default::default(), + ui_scale: 1.0, + text_scale: None, language: localization::Language::default(), language_preview: None, settings: settings::Store::default(), @@ -523,6 +527,7 @@ impl Editor { theme::Theme::restore_recent(ctx, saved.recent_themes.clone()); saved.theme.apply(ctx); saved.language.apply(ctx); + preferences_ui::apply_scaling(ctx, saved.ui_scale, saved.text_scale); let mut device = device_ui::DeviceUi::with_connection_preferences( saved.midra_host, saved.allow_sending_to_program, @@ -533,6 +538,8 @@ impl Editor { device, settings: store, language: saved.language, + ui_scale: saved.ui_scale, + text_scale: saved.text_scale, snapping: saved.snapping, keep_aspect_ratio: saved.keep_aspect_ratio, show_pattern: saved.show_source_pattern, @@ -542,6 +549,8 @@ impl Editor { } fn application_settings(&self, ctx: &egui::Context) -> settings::Settings { settings::Settings { + ui_scale: self.ui_scale, + text_scale: self.text_scale, language: self .language_preview .as_ref() diff --git a/crates/canvas-pilot/src/preferences_ui.rs b/crates/canvas-pilot/src/preferences_ui.rs index 9fa28f8..b9cae63 100644 --- a/crates/canvas-pilot/src/preferences_ui.rs +++ b/crates/canvas-pilot/src/preferences_ui.rs @@ -1,6 +1,16 @@ use super::*; -#[derive(Clone, Copy, Default, PartialEq)] +pub(super) fn apply_scaling(ctx: &egui::Context, ui_scale: f32, text_scale: Option) { + 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; + for font in fonts.values_mut() { + font.size *= text_scale.unwrap_or(1.0); + } + ctx.style_mut(|style| style.text_styles = fonts); +} + +#[derive(Clone, Copy, Debug, Default, PartialEq)] pub(super) enum Section { #[default] Appearance, @@ -115,8 +125,8 @@ impl Editor { let mut open = self.preferences_open; egui::Window::new(tr(ctx, "ui.settings")).id(egui::Id::new("Settings")) .open(&mut open) - .default_width(660.0) - .min_width(540.0) + .default_width(660.0_f32.min(ctx.screen_rect().width() - 32.0)) + .min_width(320.0_f32.min(ctx.screen_rect().width() - 32.0)) .collapsible(false) .show(ctx, |ui| { ui.horizontal(|ui| { @@ -132,8 +142,19 @@ impl Editor { } }); }); + ui.horizontal_wrapped(|ui| { + if ui.button(tr(ui.ctx(), "ui.close")).clicked() { self.preferences_open = false; } + if ui.small_button(tr(ctx, "access.reset")).clicked() { + self.ui_scale = 1.0; + self.text_scale = None; + apply_scaling(ctx, self.ui_scale, self.text_scale); + } + }); ui.weak(tr(ctx, "language.preview")); ui.separator(); + egui::ScrollArea::vertical().id_salt("settings-body") + .max_height((ctx.screen_rect().height() - ui.cursor().min.y - 120.0).max(40.0)) + .show(ui, |ui| { ui.horizontal(|ui| { ui.vertical(|ui| { ui.set_width(145.0); @@ -142,15 +163,29 @@ impl Editor { } }); ui.separator(); - egui::ScrollArea::vertical().id_salt("settings-content") - .max_height((ctx.screen_rect().height() - 260.0).max(180.0)) - .min_scrolled_height((ctx.screen_rect().height() - 260.0).clamp(265.0, 540.0)) - .show(ui, |ui| { ui.vertical(|ui| { - ui.set_min_height(265.0); + ui.set_min_height(60.0); match self.preferences_section { 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, 100.0..=200.0).suffix(" %").step_by(5.0)); + self.ui_scale = percent / 100.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, 100.0..=150.0).suffix(" %").step_by(5.0)); + *scale = percent / 100.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); } + if ui.button(tr(ctx, "access.contrast")).clicked() { theme::Theme::HighContrast.apply(ctx); } + ui.separator(); ui.label(rust_i18n::t!("theme.current", locale = localization::locale(ctx), name = theme::Theme::current(ctx).name()).into_owned()); if ui.button(tr(ui.ctx(), "ui.browse-all-themes")).clicked() { self.themes_open = true; } ui.label(tr(ui.ctx(), "ui.recently-used")); @@ -205,6 +240,9 @@ impl Editor { ui.weak(tr(ui.ctx(), "ui.opening-a-project-may-restore-its-viewport-options-without-rewriting-your-startup-def")); if ui.button(tr(ui.ctx(), "ui.restore-default-settings")).clicked() { let defaults = settings::Settings::default(); + self.ui_scale = defaults.ui_scale; + self.text_scale = defaults.text_scale; + apply_scaling(ctx, self.ui_scale, self.text_scale); self.language = defaults.language; self.language.apply(ctx); theme::Theme::restore_recent(ctx, defaults.recent_themes); @@ -227,7 +265,7 @@ impl Editor { } } }); - }); + }); }); ui.separator(); ui.label(tr(ui.ctx(), "ui.changes-take-effect-immediately-and-save-automatically")); @@ -235,7 +273,6 @@ impl Editor { if self.settings.can_retry() && ui.button(tr(ui.ctx(), "ui.retry-saving-settings")).clicked() { self.settings.save(&self.application_settings(ctx)); } - if ui.button(tr(ui.ctx(), "ui.close")).clicked() { self.preferences_open = false; } }); self.preferences_open &= open; let after = self.application_settings(ctx); @@ -270,6 +307,34 @@ mod tests { ); frame(app, ctx, vec![mouse(pos, false)]); } + #[test] + fn scaling_is_idempotent_and_preserves_project_and_theme() { + let ctx = egui::Context::default(); + let mut app = Editor::default(); + let project = app.project().to_json().unwrap(); + let base = ctx.style().text_styles[&egui::TextStyle::Body].size; + apply_scaling(&ctx, 1.5, Some(1.25)); + apply_scaling(&ctx, 1.5, Some(1.25)); + let _ = ctx.run(egui::RawInput::default(), |_| {}); + assert_eq!(ctx.zoom_factor(), 1.5); + assert_eq!( + ctx.style().text_styles[&egui::TextStyle::Body].size, + base * 1.25 + ); + theme::Theme::HighContrast.apply(&ctx); + assert_eq!( + ctx.style().text_styles[&egui::TextStyle::Body].size, + base * 1.25 + ); + app.ui_scale = 1.5; + app.text_scale = Some(1.25); + 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); + apply_scaling(&ctx, 1.0, None); + assert_eq!(ctx.style().text_styles[&egui::TextStyle::Body].size, base); + } + #[test] fn preferences_edit_and_persist_without_touching_document_or_drafts() { let dir = tempfile::tempdir().unwrap(); @@ -391,6 +456,47 @@ mod tests { assert_eq!(app.project().to_json().unwrap(), project); } + #[test] + fn enlarged_settings_keep_recovery_controls_visible() { + for language in localization::Language::ALL { + let ctx = egui::Context::default(); + language.apply(&ctx); + apply_scaling(&ctx, 1.0, Some(1.5)); + let screen = Rect::from_min_size(Pos2::ZERO, Vec2::new(500.0, 360.0)); + let mut app = Editor { + language, + ui_scale: 2.0, + text_scale: Some(1.5), + preferences_open: true, + ..Default::default() + }; + let mut output = egui::FullOutput::default(); + for _ in 0..5 { + output = ctx.run( + egui::RawInput { + screen_rect: Some(screen), + ..Default::default() + }, + |ctx| app.preferences_window(ctx), + ); + } + for key in ["ui.close", "access.reset"] { + let label = tr(&ctx, key); + let rect = output + .shapes + .iter() + .find_map(|s| match &s.shape { + egui::Shape::Text(t) if t.galley.text() == label => { + Some(Rect::from_min_size(t.pos, t.galley.size())) + } + _ => None, + }) + .unwrap_or_else(|| panic!("Missing {key} in {language:?}")); + assert!(screen.contains_rect(rect), "{language:?}: {key}: {rect:?}"); + } + } + } + #[test] fn settings_language_and_close_stay_visible_at_minimum_window_size() { let screen = Rect::from_min_size(Pos2::ZERO, Vec2::new(1000.0, 720.0)); @@ -424,7 +530,7 @@ mod tests { } _ => None, }) - .unwrap_or_else(|| panic!("Missing {label}")); + .unwrap_or_else(|| panic!("Missing {label}: {language:?} / {section:?}")); assert!( screen.contains_rect(rect), "Control outside window: {label}: {rect:?}" diff --git a/crates/canvas-pilot/src/settings.rs b/crates/canvas-pilot/src/settings.rs index 8a9d02b..ae13429 100644 --- a/crates/canvas-pilot/src/settings.rs +++ b/crates/canvas-pilot/src/settings.rs @@ -7,6 +7,8 @@ use std::{io::Read, path::PathBuf}; #[serde(deny_unknown_fields)] pub struct Settings { pub version: u32, + pub ui_scale: f32, + pub text_scale: Option, pub language: crate::localization::Language, pub midra_host: String, pub recent_midra_hosts: Vec, @@ -22,7 +24,9 @@ pub struct Settings { impl Default for Settings { fn default() -> Self { Self { - version: 10, + version: 11, + ui_scale: 1.0, + text_scale: None, language: Default::default(), autoconnect_at_startup: false, allow_sending_to_program: false, @@ -123,14 +127,35 @@ impl Settings { } value["version"] = 10.into(); } + if value["version"] == 10 { + for field in ["ui_scale", "text_scale"] { + if value.get(field).is_some() { + return Err(format!("Unexpected {field} in version 10 settings")); + } + } + value["ui_scale"] = serde_json::json!(1.0); + value["text_scale"] = serde_json::Value::Null; + value["version"] = 11.into(); + } + if value["version"] == 11 && value.get("text_scale").is_none() { + return Err("Missing text_scale in version 11 settings".into()); + } let settings: Self = serde_json::from_value(value).map_err(|e| e.to_string())?; settings.validate()?; Ok(settings) } fn validate(&self) -> Result<(), String> { - if self.version != 10 { + if self.version != 11 { return Err(format!("unsupported settings version {}", self.version)); } + if !self.ui_scale.is_finite() + || !(1.0..=2.0).contains(&self.ui_scale) + || self + .text_scale + .is_some_and(|scale| !scale.is_finite() || !(1.0..=1.5).contains(&scale)) + { + return Err("Interface scale must be 100–200%; text scale must be 100–150%".into()); + } if self.recent_midra_hosts.len() > 4 || self.recent_midra_hosts.iter().enumerate().any(|(i, host)| { canvas_pilot::device::address(host) @@ -257,13 +282,65 @@ impl Store { #[cfg(test)] mod tests { use super::*; + #[test] + fn scaling_migrates_and_round_trips_with_strict_limits() { + let old = include_str!("../../../docs/interfaces/canvas-pilot-settings-v10.example.json"); + let migrated = Settings::parse(old).unwrap(); + assert_eq!(migrated.ui_scale, 1.0); + assert_eq!(migrated.text_scale, None); + assert_eq!( + migrated, + Settings::parse(include_str!( + "../../../docs/interfaces/canvas-pilot-settings-v11.example.json" + )) + .unwrap() + ); + let saved = Settings { + ui_scale: 2.0, + text_scale: Some(1.5), + theme: Theme::HighContrast, + recent_themes: vec![Theme::HighContrast], + ..migrated + }; + assert_eq!( + Settings::parse(&serde_json::to_string(&saved).unwrap()).unwrap(), + saved + ); + for scale in [0.5, 2.1, f32::NAN, f32::INFINITY] { + assert!( + Settings { + ui_scale: scale, + ..saved.clone() + } + .validate() + .is_err() + ); + } + for scale in [0.5, 1.6, f32::NAN] { + assert!( + Settings { + text_scale: Some(scale), + ..saved.clone() + } + .validate() + .is_err() + ); + } + let mut missing = serde_json::to_value(&saved).unwrap(); + missing.as_object_mut().unwrap().remove("text_scale"); + assert!(Settings::parse(&missing.to_string()).is_err()); + let mut malformed: serde_json::Value = serde_json::from_str(old).unwrap(); + malformed["ui_scale"] = serde_json::json!(1.5); + assert!(Settings::parse(&malformed.to_string()).is_err()); + } + #[test] fn language_settings_migrate_and_validate_without_touching_other_preferences() { use crate::localization::Language; let old = include_str!("../../../docs/interfaces/canvas-pilot-settings-v8.example.json"); let migrated = Settings::parse(old).unwrap(); assert_eq!(migrated.language, Language::System); - assert_eq!(migrated.version, 10); + assert_eq!(migrated.version, 11); let current = include_str!("../../../docs/interfaces/canvas-pilot-settings-v10.example.json"); assert_eq!(Settings::parse(current).unwrap(), migrated); @@ -272,12 +349,14 @@ mod tests { let mut old: serde_json::Value = serde_json::from_str(v9).unwrap(); old["language"] = old_language.into(); let upgraded = Settings::parse(&old.to_string()).unwrap(); - assert_eq!(upgraded.version, 10); + assert_eq!(upgraded.version, 11); assert_eq!( serde_json::to_value(upgraded.language).unwrap(), old["language"] ); - old["version"] = 10.into(); + old["version"] = 11.into(); + old["ui_scale"] = serde_json::json!(1.0); + old["text_scale"] = serde_json::Value::Null; assert_eq!(serde_json::to_value(upgraded).unwrap(), old); } let mut invalid_v9: serde_json::Value = serde_json::from_str(v9).unwrap(); @@ -371,7 +450,7 @@ mod tests { for text in [ "broken".to_string(), serde_json::to_string(&Settings { - version: 11, + version: 12, ..Default::default() }) .unwrap(), diff --git a/crates/canvas-pilot/src/theme.rs b/crates/canvas-pilot/src/theme.rs index fd6e7ca..9493399 100644 --- a/crates/canvas-pilot/src/theme.rs +++ b/crates/canvas-pilot/src/theme.rs @@ -6,6 +6,7 @@ use super::*; pub enum Theme { #[default] Midra, + HighContrast, FoxifiedDark, CorporateLight, Bluecore, @@ -45,8 +46,9 @@ pub struct Palette { } impl Theme { - pub const ALL: [Self; 19] = [ + pub const ALL: [Self; 20] = [ Self::Midra, + Self::HighContrast, Self::FoxifiedDark, Self::CorporateLight, Self::Bluecore, @@ -69,6 +71,7 @@ impl Theme { pub fn name(self) -> &'static str { match self { Self::Midra => "Midra Dark", + Self::HighContrast => "High Contrast", Self::FoxifiedDark => "Foxified Dark", Self::CorporateLight => "Corporate Light", Self::Bluecore => "Bluecore", @@ -115,6 +118,22 @@ impl Theme { pub fn palette(self) -> Palette { let rgb = |hex: u32| Color32::from_rgb((hex >> 16) as u8, (hex >> 8) as u8, hex as u8); match self { + Self::HighContrast => Palette { + canvas: rgb(0x000000), + banner: rgb(0x101010), + grid: rgb(0x777777), + layer: rgb(0x101010), + pattern: [rgb(0x000000), rgb(0xffffff)], + bg: rgb(0x000000), + panel: rgb(0x000000), + field: rgb(0x101010), + line: rgb(0xaaaaaa), + text: rgb(0xffffff), + muted: rgb(0xdddddd), + cyan: rgb(0x00ffff), + amber: rgb(0xffff00), + purple: rgb(0x202080), + }, Self::Bluecore => sotv_palette( [ 0x1a222d, 0x232f3a, 0x111922, 0x2b3948, 0xd0e4ff, 0xaaccee, 0x3399ff, 0x4488cc, @@ -301,6 +320,19 @@ impl Theme { widget.bg_stroke = Stroke::new(1.0_f32, border); widget.fg_stroke = Stroke::new(1.0_f32, p.text); } + if self == Self::HighContrast { + v.window_stroke.width = 2.0; + for widget in [ + &mut v.widgets.noninteractive, + &mut v.widgets.inactive, + &mut v.widgets.hovered, + &mut v.widgets.active, + &mut v.widgets.open, + ] { + widget.bg_stroke.width = 2.0; + widget.fg_stroke.width = 2.0; + } + } ctx.set_visuals(v); ctx.data_mut(|d| d.insert_temp(egui::Id::new("application-theme"), self)); ctx.request_repaint(); @@ -348,6 +380,36 @@ fn sotv_palette(colors: [u32; 8], light: bool) -> Palette { #[cfg(test)] mod tests { use super::*; + #[test] + fn high_contrast_text_and_borders_have_strong_luminance_separation() { + fn luminance(c: Color32) -> f64 { + let channel = |v: u8| { + let s = v as f64 / 255.0; + if s <= 0.04045 { + s / 12.92 + } else { + ((s + 0.055) / 1.055).powf(2.4) + } + }; + 0.2126 * channel(c.r()) + 0.7152 * channel(c.g()) + 0.0722 * channel(c.b()) + } + let contrast = |a: Color32, b: Color32| { + let (a, b) = (luminance(a), luminance(b)); + (a.max(b) + 0.05) / (a.min(b) + 0.05) + }; + let p = Theme::HighContrast.palette(); + for bg in [p.bg, p.panel, p.field, p.purple] { + for text in [p.text, p.muted] { + assert!(contrast(text, bg) >= 7.0); + } + assert!(contrast(p.line, bg) >= 3.0); + } + let ctx = egui::Context::default(); + Theme::HighContrast.apply(&ctx); + assert!(contrast(ctx.style().visuals.weak_text_color(), p.panel) >= 4.5); + assert_eq!(ctx.style().visuals.window_stroke.width, 2.0); + } + #[test] fn recent_themes_are_unique_newest_first_and_bounded() { let ctx = egui::Context::default(); diff --git a/docs/canvas-pilot/changelog.md b/docs/canvas-pilot/changelog.md index d2d9aa6..dd37290 100644 --- a/docs/canvas-pilot/changelog.md +++ b/docs/canvas-pilot/changelog.md @@ -4,6 +4,14 @@ ## Unreleased +### v0.9.1 + +- Added Appearance controls for 100–200% interface zoom and optional 100–150% + standard-widget text scaling, with a readily accessible size reset. Added a + High Contrast theme with measured text contrast and stronger widget borders. + Settings v11 migrates older preferences without changing projects or exports. + Fixed-size artwork/labels follow interface zoom, not the additional text scale. + ### v0.9.0 This minor version brings interface localization, French quick-start screenshots, diff --git a/docs/canvas-pilot/guide/preferences.md b/docs/canvas-pilot/guide/preferences.md index ca1f8b5..09fcca5 100644 --- a/docs/canvas-pilot/guide/preferences.md +++ b/docs/canvas-pilot/guide/preferences.md @@ -49,6 +49,27 @@ It does not rename layers, change file contents or send device commands. Numeric fields continue to use a decimal point in every language. Projects do not carry language preferences to another workstation. +### Interface size and high contrast + +Open **Menu → Open all settings… → Appearance**: + +- **Interface scale:** enlarge the entire interface from **100% to 200%**, on top + of the operating system's display scale. This also enlarges icons and hit targets. +- **Adjust text separately:** optionally enlarge standard control text by a further + **100% to 150%**. Canvas artwork and fixed-size labels follow interface scale only. +- **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 +size**, near the top of Settings, restores 100% and disables separate text scaling. +The settings content scrolls at smaller window sizes. Larger windows provide more +working space at high zoom. Project dimensions, exported artwork, clipboard data +and device values stay unchanged; imported pictures retain their original colors. + +![Appearance settings with high contrast, 150% interface scale and 125% text scale](../images/09-accessibility.png) + +*Enlarged controls with High Contrast. Close and Reset interface size remain above the scrolling settings.* + ### Application themes **Menu → Options → Theme** (also in the toolbar cog) shows up to three recently diff --git a/docs/canvas-pilot/images/09-accessibility.png b/docs/canvas-pilot/images/09-accessibility.png new file mode 100644 index 0000000..dd32eb5 Binary files /dev/null and b/docs/canvas-pilot/images/09-accessibility.png differ diff --git a/docs/canvas-pilot/images/capture.md b/docs/canvas-pilot/images/capture.md index 81163f9..abbd3b8 100644 --- a/docs/canvas-pilot/images/capture.md +++ b/docs/canvas-pilot/images/capture.md @@ -152,3 +152,10 @@ Verify the French control names against the chapter, keep the whole client area, and close only the temporary app after capture. Rebuild the book and inspect the French chapter's images and print view. Screenshot refreshes do not imply that other languages or the rest of the manual have received an editorial review. + +## Accessibility settings capture + +`09-accessibility.png` shows version 0.9.1 on Linux/X11 in an isolated offline +profile, at 1440 × 940 physical pixels. Use English, High Contrast, 150% interface +scale and separate 125% text scale; open Settings → Appearance. The PNG is an +unedited native capture. Project names and example artwork remain unchanged. diff --git a/docs/interfaces/canvas-pilot-settings-v11.example.json b/docs/interfaces/canvas-pilot-settings-v11.example.json new file mode 100644 index 0000000..c5bc99e --- /dev/null +++ b/docs/interfaces/canvas-pilot-settings-v11.example.json @@ -0,0 +1,29 @@ +{ + "version": 11, + "theme": "midra", + "recent_themes": [ + "midra" + ], + "show_toolbar_icon_names": false, + "keep_aspect_ratio": true, + "show_source_pattern": false, + "snapping": { + "enabled": false, + "pixels": true, + "screen_edges": true, + "layer_edges": true, + "grid": false, + "show_grid": true, + "grid_divisions": [ + 8, + 6 + ] + }, + "midra_host": "", + "allow_sending_to_program": false, + "autoconnect_at_startup": false, + "recent_midra_hosts": [], + "language": "system", + "ui_scale": 1.0, + "text_scale": null +} diff --git a/docs/interfaces/canvas-pilot-settings.md b/docs/interfaces/canvas-pilot-settings.md index 56f4099..03a404b 100644 --- a/docs/interfaces/canvas-pilot-settings.md +++ b/docs/interfaces/canvas-pilot-settings.md @@ -1,15 +1,15 @@ -# Canvas Pilot application settings, version 10 +# Canvas Pilot application settings, version 11 Canvas Pilot was formerly named Midra Layout. The rename preserves existing wire-format identifiers, `.midra.json` projects, settings/recovery locations and `MIDRA_VECTORCRAFT_CLI` configuration. No schema version changes are needed. New exports use Canvas Pilot in human-readable titles; legacy files remain readable. Implementation: `crates/canvas-pilot/src/settings.rs`. This per-user JSON file is independent of the [project JSON and SVG contracts](canvas-pilot.md). -[Complete default example](canvas-pilot-settings-v10.example.json). +[Complete default example](canvas-pilot-settings-v11.example.json). Version 1 files migrate automatically: the saved theme becomes the only entry in `recent_themes`, with all other preferences preserved. The [version 1 example](canvas-pilot-settings-v1.example.json) remains a migration fixture. Version 2 files then migrate by adding disabled snapping with all target types enabled. The [version 2 example](canvas-pilot-settings-v2.example.json) -remains a migration fixture too. Version 3 files migrate by adding an empty `midra_host`; the [version 3 example](canvas-pilot-settings-v3.example.json) remains a migration fixture. Version 4 files migrate by adding `allow_sending_to_program: false`; the [version 4 example](canvas-pilot-settings-v4.example.json) remains a migration fixture. Version 5 files migrate with `autoconnect_at_startup: false`; the [version 5 example](canvas-pilot-settings-v5.example.json) remains a migration fixture. Version 6 files migrate with the overlay grid visible, snapping to it disabled, and `grid_divisions: [8, 6]`; the [version 6 example](canvas-pilot-settings-v6.example.json) remains a migration fixture. Version 7 migrates with an empty `recent_midra_hosts` list; the [version 7 example](canvas-pilot-settings-v7.example.json) remains a migration fixture. Version 8 migrates with `language: "system"`; the [version 8 example](canvas-pilot-settings-v8.example.json) remains a migration fixture. Version 9 migrates without changing any preferences; its `system`, `en` and `fr` values remain valid. The [version 9 example](canvas-pilot-settings-v9.example.json) remains a migration fixture. Version 10 adds language choices; saving writes version 10, which old applications reject. +remains a migration fixture too. Version 3 files migrate by adding an empty `midra_host`; the [version 3 example](canvas-pilot-settings-v3.example.json) remains a migration fixture. Version 4 files migrate by adding `allow_sending_to_program: false`; the [version 4 example](canvas-pilot-settings-v4.example.json) remains a migration fixture. Version 5 files migrate with `autoconnect_at_startup: false`; the [version 5 example](canvas-pilot-settings-v5.example.json) remains a migration fixture. Version 6 files migrate with the overlay grid visible, snapping to it disabled, and `grid_divisions: [8, 6]`; the [version 6 example](canvas-pilot-settings-v6.example.json) remains a migration fixture. Version 7 migrates with an empty `recent_midra_hosts` list; the [version 7 example](canvas-pilot-settings-v7.example.json) remains a migration fixture. Version 8 migrates with `language: "system"`; the [version 8 example](canvas-pilot-settings-v8.example.json) remains a migration fixture. Version 9 migrates without changing any preferences; its `system`, `en` and `fr` values remain valid. The [version 9 example](canvas-pilot-settings-v9.example.json) remains a migration fixture. Version 10 adds language choices. Version 11 adds `ui_scale` and `text_scale`; v1–v10 settings migrate to 100% interface scale with separate text scaling disabled, preserving all existing preferences. The [version 10 example](canvas-pilot-settings-v10.example.json) remains a migration fixture. Saving writes version 11, which older applications reject. The `directories` 6 crate resolves `ProjectDirs::from("org", "beffroi", "midra-layout")`. The filename is `settings.json` beneath `config_dir()`: @@ -26,7 +26,9 @@ unknown theme names are rejected. There are no numeric coordinates or units. | Field | Values / default | | --- | --- | -| `version` | Integer `10` | +| `version` | Integer `11` | +| `ui_scale` | Finite number, 1.0–2.0 inclusive; default 1.0. egui interface zoom relative to the OS display scale. | +| `text_scale` | `null` (default, disabled) or finite number 1.0–1.5 inclusive. Additional standard-widget text multiplier. | | `language` | `"system"` (default), `"en"`, `"fr"`, `"ja"`, `"zh-CN"`, `"es"`, `"grc"`, `"eo"`. Unknown values are rejected. | | `autoconnect_at_startup` | Boolean; default false. Try one background connection at application startup if the saved address is nonblank. | | `allow_sending_to_program` | Boolean; default false. Enables the Program destination in the exporter. Turning it off restores Preview; applies to quick Apply too. | @@ -38,6 +40,14 @@ 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 +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. +Neither scale changes project dimensions, export text, clipboard bytes or device +coordinates. Restore defaults and Reset interface size restore 1.0 / null. +`high_contrast` is the new theme identifier, also valid in `recent_themes`. + Language is a workstation preference, never a project field or exchange value. Changing **Settings → Language / Langue** previews immediately and saves after confirmation, without restarting or reinstalling the project. It preserves selections, undo, numeric @@ -96,6 +106,7 @@ The picker includes both light and dark themes with color swatches. | Theme | Settings ID | Source CSS | | --- | --- | --- | | Midra Dark | `midra` | Original editor palette | +| High Contrast | `high_contrast` | Original accessibility palette; black surfaces, bright text, stronger borders | | Corporate Light | `corporate_light` | `theme-corporate.css` and `../base/variables.css` | | Foxified Dark | `foxified_dark` | `theme-foxified-dark.css` | | Bluecore | `bluecore` | `theme-bluecore.css` | @@ -120,7 +131,7 @@ the new `language` value. Cancellation, Escape or timeout restores the previous choice. While a preview is pending, all settings writes retain the previous confirmed language, so quitting or crashing cannot persist an accidental selection. The cancel button uses the previously displayed locale, including resolved System -default. Preview state and its deadline are not serialized; the v10 schema is unchanged. +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