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.
This commit is contained in:
dotCooCoo
2026-11-16 16:26:24 -08:00
parent d6dacbd0a2
commit 086810b9aa
2 changed files with 56 additions and 2 deletions
+8 -2
View File
@@ -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));
+48
View File
@@ -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};