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.
This commit is contained in:
RickiNano committed 2026-11-15 14:39:12 +01:00
1 parent 5697cdfc48
commit 85630ee441
2 files changed
+73 -11

No files matched your search

+16 -5
View File
@@ -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<String, Value>, 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<String, Value>, 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<Strin
let mut artboard = f.get("artboard").and_then(Value::as_bool).unwrap_or(false);
if widgets::checkbox(ui, &mut artboard, tl!("Artboards")).changed() {
f.insert("artboard".into(), json!(artboard));
// Now the user's choice: another tab's preset leaves it alone.
f.remove(PRESET_ARTBOARD);
}
ui.add_space(4.0);
small_label(ui, tl!("Resolution"));
@@ -1,6 +1,6 @@
//! #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.
//! the Photo, Print, Art & Illustration or Film & Video tab turns that back off, and leaves a box
//! ticked by hand as it is. Recent and Saved cards keep restoring their own settings.
use egui_kittest::Harness;
use egui_kittest::kittest::{NodeT, Queryable};
@@ -43,16 +43,46 @@ fn web_and_mobile_presets_turn_artboards_on() {
}
}
const OTHER_TABS: [&str; 4] = ["Photo", "Print", "Art & Illustration", "Film & Video"];
#[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}");
fn presets_of_the_other_tabs_turn_a_web_or_mobile_presets_artboards_off() {
for from in ["Web", "Mobile"] {
for tab in OTHER_TABS {
assert!(!presets(tab).is_empty(), "{tab}");
for p in presets(tab) {
let mut f = on_tab(from, false);
apply_preset(&mut f, &presets(from)[0], &Default::default());
assert!(artboard(&f));
f.insert("__category".into(), json!(tab));
apply_preset(&mut f, p, &Default::default());
assert!(!artboard(&f), "{from} then {tab} › {}", p.0);
assert!(command_params(&f).get("artboard").is_none(), "Create makes a plain document: {tab} › {}", p.0);
}
}
}
}
/// Ticking Artboards by hand and then picking a preset of another tab wasn't measured: the box
/// keeps the user's choice, as before this change.
#[test]
fn presets_of_the_other_tabs_leave_a_box_ticked_by_hand() {
for tab in OTHER_TABS {
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_eq!(command_params(&f)["artboard"], json!(true), "{tab} › {}", p.0);
let mut f = on_tab(tab, false);
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);
}
// Ticked by hand before a Web preset (which keeps it on): still the user's choice.
let mut f = on_tab("Web", true);
apply_preset(&mut f, &presets("Web")[0], &Default::default());
f.insert("__category".into(), json!(tab));
apply_preset(&mut f, &presets(tab)[0], &Default::default());
assert!(artboard(&f), "Web then {tab}");
}
}
@@ -164,4 +194,25 @@ mod dialog {
let doc = &h.state().session.active().expect("a new document").doc;
assert!(doc.artboards().is_empty(), "a plain document");
}
#[test]
fn a_photo_preset_keeps_artboards_ticked_by_hand_after_a_web_one() {
let mut h = harness();
open_tab(&mut h, "Web");
click_preset(&mut h, "Web Most Common");
assert!(artboards_ticked(&h));
// Untick and tick again by hand: the box now holds the user's choice.
for _ in 0..2 {
h.get_by_label("Artboards").click();
h.run_steps(2);
}
assert!(artboards_ticked(&h));
open_tab(&mut h, "Photo");
click_preset(&mut h, presets("Photo")[0].0);
assert!(artboards_ticked(&h), "a box ticked by hand stays ticked");
h.get_by_label("Create").click();
h.run_steps(3);
let doc = &h.state().session.active().expect("a new document").doc;
assert_eq!(doc.artboards().len(), 1, "made as an artboard");
}
}