From 5697cdfc4883cb8605ab6c922e26e680ba41617a Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Sat, 14 Nov 2026 12:27:05 +0100 Subject: [PATCH 1/2] New Document: Web and Mobile presets turn Artboards on (#14042) A preset picked on the Web or Mobile tab of File > New ticks Artboards, so Create makes the document as an artboard; a preset of the Photo, Print, Art & Illustration or Film & Video tab unticks it. Recent's built-in cards, the Clipboard preset and Recent/Saved cards keep today's behaviour. --- crates/ui-egui/src/dialogs/new_doc_ui.rs | 19 +- crates/ui-egui/src/lib.rs | 3 + .../src/new_doc_web_artboards_tests.rs | 167 ++++++++++++++++++ 3 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 crates/ui-egui/src/new_doc_web_artboards_tests.rs diff --git a/crates/ui-egui/src/dialogs/new_doc_ui.rs b/crates/ui-egui/src/dialogs/new_doc_ui.rs index 2cba2a6af3..7c4aad1e68 100644 --- a/crates/ui-egui/src/dialogs/new_doc_ui.rs +++ b/crates/ui-egui/src/dialogs/new_doc_ui.rs @@ -218,17 +218,34 @@ pub fn at_pref_resolutions(p: &Preset, units: &UnitsAndRulers) -> Preset { (p.0, px(p.1), px(p.2), ppi) } +/// The category tabs whose presets start the document as an artboard, as in Photoshop (#14042). +const ARTBOARD_CATEGORIES: &[&str] = &["Web", "Mobile"]; + /// Apply a built-in preset (at the preference resolutions, see [`at_pref_resolutions`]) to the -/// dialog fields. +/// dialog fields. A preset of the category tab picked in `__category` also sets Artboards: on for +/// Web and Mobile, off for the other tabs (#14042). Recent's built-in cards and the Clipboard +/// preset leave it as it is. pub fn apply_preset(f: &mut Map, p: &Preset, units: &UnitsAndRulers) { let (name, w, h, ppi) = at_pref_resolutions(p, units); let unit = preset_unit(p, f); + let cat = get_s(f, "__category", CATEGORIES[0].0); + let tab = CATEGORIES.iter().find(|c| c.0 == cat && c.0 != CATEGORIES[0].0 && c.1.iter().any(|q| q.0 == name)); f.remove("__savedPreset"); f.insert("width".into(), json!(w)); f.insert("height".into(), json!(h)); f.insert("resolution".into(), json!(ppi)); f.insert("__preset".into(), json!(name)); f.insert("__unit".into(), json!(unit)); + match tab { + Some((tab, _)) if ARTBOARD_CATEGORIES.contains(tab) => { + f.insert("artboard".into(), json!(true)); + } + // Off is the checkbox's and `file.new`'s default. + Some(_) => { + f.remove("artboard"); + } + None => {} + } } /// The colour mode of the dialog's `mode` value. diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 7928bf442c..907988221d 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -987,6 +987,9 @@ mod blend_dropdown_keys_tests; #[cfg(test)] mod warp_text_dialog_tests; +#[cfg(test)] +mod new_doc_web_artboards_tests; + #[cfg(test)] mod blend_dropdown_wheel_tests; #[cfg(test)] diff --git a/crates/ui-egui/src/new_doc_web_artboards_tests.rs b/crates/ui-egui/src/new_doc_web_artboards_tests.rs new file mode 100644 index 0000000000..76988ea8a5 --- /dev/null +++ b/crates/ui-egui/src/new_doc_web_artboards_tests.rs @@ -0,0 +1,167 @@ +//! #14042: a Web or Mobile preset in File › New turns Artboards on, as in Photoshop; a preset of +//! the Photo, Print, Art & Illustration or Film & Video tab turns it off. Recent and Saved cards keep +//! restoring their own settings. + +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; +use serde_json::{Map, Value, json}; + +use crate::PhotocraftApp; +use crate::new_doc_ui::{CATEGORIES, CLIPBOARD, Preset, apply_preset, apply_settings, command_params}; +use crate::state::{DialogKind, UiState}; + +fn presets(tab: &str) -> &'static [Preset] { + CATEGORIES.iter().find(|c| c.0 == tab).unwrap().1 +} + +/// The dialog's fields on `tab`, with Artboards ticked by hand or not. +fn on_tab(tab: &str, artboard: bool) -> Map { + let mut f = UiState::new_document_fields(); + f.insert("__category".into(), json!(tab)); + if artboard { + f.insert("artboard".into(), json!(true)); + } + f +} + +fn artboard(f: &Map) -> bool { + f.get("artboard").and_then(Value::as_bool).unwrap_or(false) +} + +#[test] +fn web_and_mobile_presets_turn_artboards_on() { + for tab in ["Web", "Mobile"] { + assert!(!presets(tab).is_empty(), "{tab}"); + for p in presets(tab) { + for ticked in [false, true] { + let mut f = on_tab(tab, ticked); + apply_preset(&mut f, p, &Default::default()); + assert!(artboard(&f), "{tab} › {}", p.0); + assert_eq!(command_params(&f)["artboard"], json!(true), "Create sends it: {tab} › {}", p.0); + } + } + } +} + +#[test] +fn presets_of_the_other_tabs_turn_artboards_off() { + for tab in ["Photo", "Print", "Art & Illustration", "Film & Video"] { + assert!(!presets(tab).is_empty(), "{tab}"); + for p in presets(tab) { + let mut f = on_tab(tab, true); + apply_preset(&mut f, p, &Default::default()); + assert!(!artboard(&f), "{tab} › {}", p.0); + assert!(command_params(&f).get("artboard").is_none(), "Create makes a plain document: {tab} › {}", p.0); + } + } +} + +/// Recent's built-in cards and the Clipboard preset weren't measured: they keep today's behaviour. +#[test] +fn recent_presets_and_the_clipboard_leave_artboards_as_it_is() { + for ticked in [false, true] { + for p in presets(CATEGORIES[0].0) { + let mut f = on_tab(CATEGORIES[0].0, ticked); + apply_preset(&mut f, p, &Default::default()); + assert_eq!(artboard(&f), ticked, "Recent › {}", p.0); + } + let mut f = on_tab(CATEGORIES[0].0, ticked); + crate::new_doc_ui::set_clipboard(&mut f, 640, 360); + assert_eq!(artboard(&f), ticked, "{CLIPBOARD}"); + // Applied without a tab (a script, or a preset no tab lists) changes nothing either. + let mut f = on_tab("Web", ticked); + apply_preset(&mut f, &("Not a Web preset", 640, 360, 72.0), &Default::default()); + assert_eq!(artboard(&f), ticked); + } +} + +#[test] +fn recent_cards_keep_restoring_their_own_settings() { + let mut f = on_tab("Web", false); + apply_preset(&mut f, &presets("Web")[0], &Default::default()); + let mut settings_from = f.clone(); + settings_from.remove("artboard"); + let settings = serde_json::from_value(crate::new_doc_ui::document_settings(&settings_from)).unwrap(); + let before = f.get("artboard").cloned(); + apply_settings(&mut f, &settings); + assert_eq!(f.get("artboard").cloned(), before, "the stored settings hold no Artboards value"); +} + +mod dialog { + use super::*; + + fn harness() -> Harness<'static, PhotocraftApp> { + let app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + let mut h = + Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(|ui, app| crate::dialogs::show(app, ui.ctx()), app); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]); + h.state_mut().ui.open_dialog(DialogKind::NewDocument, UiState::new_document_fields()); + h.run_steps(3); + h + } + + fn fields(h: &Harness<'static, PhotocraftApp>) -> Map { + h.state().ui.dialogs.first().map(|d| d.fields.clone()).expect("the dialog is open") + } + + fn open_tab(h: &mut Harness<'static, PhotocraftApp>, tab: &str) { + h.get_by_label(tab).click(); + h.run_steps(2); + } + + /// Preset cards paint their titles directly, without an accessibility label. + fn click_preset(h: &mut Harness<'static, PhotocraftApp>, title: &str) { + fn find(shape: &egui::Shape, title: &str) -> Option { + match shape { + egui::Shape::Text(text) if text.galley.job.text == title => Some(text.visual_bounding_rect().center()), + egui::Shape::Vec(shapes) => shapes.iter().find_map(|shape| find(shape, title)), + _ => None, + } + } + let at = h.output().shapes.iter().find_map(|shape| find(&shape.shape, title)).expect("visible preset title"); + // Let a previous card click age past the double-click interval, so this one only selects. + h.run_steps(60); + h.hover_at(at); + h.run_steps(1); + h.drag_at(at); + h.run_steps(1); + h.drop_at(at); + h.run_steps(2); + } + + fn artboards_ticked(h: &Harness<'static, PhotocraftApp>) -> bool { + h.get_by_label("Artboards").accesskit_node().toggled() == Some(egui::accesskit::Toggled::True) + } + + #[test] + fn a_web_preset_ticks_artboards_and_create_makes_an_artboard() { + let mut h = harness(); + assert!(!artboards_ticked(&h)); + open_tab(&mut h, "Web"); + click_preset(&mut h, "Web Most Common"); + assert_eq!(fields(&h)["__preset"], "Web Most Common"); + assert!(artboards_ticked(&h), "the checkbox shows it"); + h.get_by_label("Create").click(); + h.run_steps(3); + assert!(h.state().ui.dialogs.is_empty(), "the dialog closed"); + let doc = &h.state().session.active().expect("a new document").doc; + assert_eq!((doc.size.width, doc.size.height), (1366, 768)); + assert_eq!(doc.artboards().len(), 1, "made as an artboard"); + } + + #[test] + fn a_photo_preset_after_a_mobile_one_unticks_artboards() { + let mut h = harness(); + open_tab(&mut h, "Mobile"); + click_preset(&mut h, presets("Mobile")[0].0); + assert!(artboards_ticked(&h)); + open_tab(&mut h, "Photo"); + click_preset(&mut h, presets("Photo")[0].0); + assert_eq!(h.state().ui.dialogs.len(), 1, "a single click only selects"); + assert!(!artboards_ticked(&h)); + h.get_by_label("Create").click(); + h.run_steps(3); + let doc = &h.state().session.active().expect("a new document").doc; + assert!(doc.artboards().is_empty(), "a plain document"); + } +} From 85630ee441e308f8914cc834c9b9cdcb28ab403e Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Sat, 14 Nov 2026 20:59:01 +0100 Subject: [PATCH 2/2] New Document: another tab's preset unticks only Artboards a preset ticked (#14042) A Photo, Print, Art & Illustration or Film & Video preset turned Artboards off even when the user had ticked it by hand. That case wasn't measured, so it keeps today's behaviour: the dialog now remembers when a Web or Mobile preset ticked the box and turns off only that. --- crates/ui-egui/src/dialogs/new_doc_ui.rs | 21 +++++-- .../src/new_doc_web_artboards_tests.rs | 63 +++++++++++++++++-- 2 files changed, 73 insertions(+), 11 deletions(-) diff --git a/crates/ui-egui/src/dialogs/new_doc_ui.rs b/crates/ui-egui/src/dialogs/new_doc_ui.rs index 7c4aad1e68..49c6acd485 100644 --- a/crates/ui-egui/src/dialogs/new_doc_ui.rs +++ b/crates/ui-egui/src/dialogs/new_doc_ui.rs @@ -221,10 +221,15 @@ pub fn at_pref_resolutions(p: &Preset, units: &UnitsAndRulers) -> Preset { /// The category tabs whose presets start the document as an artboard, as in Photoshop (#14042). const ARTBOARD_CATEGORIES: &[&str] = &["Web", "Mobile"]; +/// Set when a Web or Mobile preset ticked Artboards, so a preset of another tab unticks only that +/// and never a box ticked by hand (#14042). +const PRESET_ARTBOARD: &str = "__presetArtboard"; + /// Apply a built-in preset (at the preference resolutions, see [`at_pref_resolutions`]) to the /// dialog fields. A preset of the category tab picked in `__category` also sets Artboards: on for -/// Web and Mobile, off for the other tabs (#14042). Recent's built-in cards and the Clipboard -/// preset leave it as it is. +/// Web and Mobile; the other tabs turn it back off when a Web or Mobile preset turned it on, and +/// leave a box ticked by hand as it is (#14042). Recent's built-in cards and the Clipboard preset +/// leave it as it is. pub fn apply_preset(f: &mut Map, p: &Preset, units: &UnitsAndRulers) { let (name, w, h, ppi) = at_pref_resolutions(p, units); let unit = preset_unit(p, f); @@ -238,13 +243,17 @@ pub fn apply_preset(f: &mut Map, p: &Preset, units: &UnitsAndRule f.insert("__unit".into(), json!(unit)); match tab { Some((tab, _)) if ARTBOARD_CATEGORIES.contains(tab) => { - f.insert("artboard".into(), json!(true)); + if f.get("artboard").and_then(Value::as_bool) != Some(true) { + f.insert("artboard".into(), json!(true)); + f.insert(PRESET_ARTBOARD.into(), json!(true)); + } } // Off is the checkbox's and `file.new`'s default. - Some(_) => { + Some(_) if f.contains_key(PRESET_ARTBOARD) => { + f.remove(PRESET_ARTBOARD); f.remove("artboard"); } - None => {} + _ => {} } } @@ -722,6 +731,8 @@ pub fn body(app: &mut crate::PhotocraftApp, ui: &mut egui::Ui, f: &mut Map