From 086810b9aaedadf64d87db1c5f59af927e24c605 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 16:26:24 -0800 Subject: [PATCH] Print: a typed Scale W or H is the base for the next linked change With the link on, a W or H typed in the dialog sets both fields, but the values the link compares a later change against stayed at the ones from before the edit. A height set through ui.dialog.set before the next frame then matched neither, so W and H stayed apart and Done refused them. The dialog now remembers W and H after a typed edit. --- crates/ui-egui/src/dialogs/print.rs | 10 ++++- crates/ui-egui/src/dialogs/tests_print.rs | 48 +++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/dialogs/print.rs b/crates/ui-egui/src/dialogs/print.rs index 369a953780..ebaad1749a 100644 --- a/crates/ui-egui/src/dialogs/print.rs +++ b/crates/ui-egui/src/dialogs/print.rs @@ -746,13 +746,19 @@ fn general(app: &VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) { let on = scaling == PrintScaling::Custom || tiles; let linked = get(d, SCALE_LINKED).as_bool() == Some(true); ui.label(tl!("W:")); - if let Some(w) = percent(ui, d, "scale.width", on).filter(|_| linked) { + let w = percent(ui, d, "scale.width", on); + if let Some(w) = w.filter(|_| linked) { set(d, "scale.height", json!(w)); } ui.label(tl!("H:")); - if let Some(h) = percent(ui, d, "scale.height", on).filter(|_| linked) { + let h = percent(ui, d, "scale.height", on); + if let Some(h) = h.filter(|_| linked) { set(d, "scale.width", json!(h)); } + // A typed W or H is what the next `ui.dialog.set` changes from. + if w.is_some() || h.is_some() { + see_scale(&mut d.fields); + } ui.add_enabled_ui(on, |ui| scale_link(ui, d, linked)); }); row(ui, tl!("Overlap:"), |ui| length(ui, d, "overlap", unit, tiles)); diff --git a/crates/ui-egui/src/dialogs/tests_print.rs b/crates/ui-egui/src/dialogs/tests_print.rs index 9153471ebd..cad38bb984 100644 --- a/crates/ui-egui/src/dialogs/tests_print.rs +++ b/crates/ui-egui/src/dialogs/tests_print.rs @@ -422,6 +422,54 @@ fn a_scale_set_through_the_dialog_keeps_the_percentage_it_changes() { assert_eq!(saved["scale"], json!({"width": 250.0, "height": 250.0, "linked": true})); } +/// An accessibility action on the node `target_node`. +fn request(action: egui::accesskit::Action, target_node: egui::accesskit::NodeId) -> egui::Event { + use egui::accesskit::{ActionRequest, TreeId}; + egui::Event::AccessKitActionRequest(ActionRequest { action, target_node, target_tree: TreeId::ROOT, data: None }) +} + +/// Type `typed` into Scale W, which shows `shown` (the first field that does, before H), and Tab out. +fn type_w(screen: &mut Screen, app: &mut VectorcraftApp, shown: &str, typed: &str) { + let key = |key, modifiers| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }; + screen.run(app, vec![]); + let out = screen.run(app, vec![]); + let nodes = &out.platform_output.accesskit_update.as_ref().expect("an accessibility tree").nodes; + let w = nodes.iter().find(|(_, n)| n.role() == egui::accesskit::Role::TextInput && n.value().is_some_and(|v| v.starts_with(shown))); + screen.run(app, vec![request(egui::accesskit::Action::Focus, w.expect("the Scale W field").0)]); + screen.run(app, vec![key(egui::Key::A, egui::Modifiers::COMMAND), egui::Event::Text(typed.into())]); + screen.run(app, vec![key(egui::Key::Tab, egui::Modifiers::NONE)]); +} + +#[test] +fn a_scale_set_after_a_typed_percentage_follows_the_link() { + let (mut app, _) = app(); + app.run("file.print", json!({})).unwrap(); + let mut screen = Screen::new(); + set(&mut app, "scaling", json!("custom")); + dialog(&mut app).fields["scale"]["width"] = json!(40); + screen.run(&mut app, vec![]); + assert_eq!(scale(&mut app), (40.0, 40.0, true)); + // W typed with the link on sets H as well. + type_w(&mut screen, &mut app, "40", "60"); + assert_eq!(scale(&mut app), (60.0, 60.0, true)); + // A new H set before the next frame: W follows it, and Done saves both. + dialog(&mut app).fields["scale"]["height"] = json!(50); + set(&mut app, "discard", json!(true)); + super::confirm(&mut app).unwrap(); + let saved = app.session.active().unwrap().doc.print_setup.clone().unwrap(); + assert_eq!(saved["scale"], json!({"width": 50.0, "height": 50.0, "linked": true})); + // W typed with the link off changes W alone; turning the link on then sets H to W. + app.run("file.print", json!({})).unwrap(); + let (link, _, _) = screen.link(&mut app); + screen.run(&mut app, vec![request(egui::accesskit::Action::Click, link)]); + assert_eq!(scale(&mut app), (50.0, 50.0, false)); + type_w(&mut screen, &mut app, "50", "70"); + assert_eq!(scale(&mut app), (70.0, 50.0, false)); + screen.run(&mut app, vec![request(egui::accesskit::Action::Click, link)]); + screen.run(&mut app, vec![]); + assert_eq!(scale(&mut app), (70.0, 70.0, true)); +} + #[test] fn the_dimmed_scale_link_ignores_the_keyboard() { use egui::accesskit::{Action, ActionRequest, TreeId};