From d1b26e5a7ef881f0fa1686fb5c3d640876b927e9 Mon Sep 17 00:00:00 2001 From: David Mann Date: Tue, 1 Dec 2026 02:02:40 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Fill:=20Color=E2=80=A6=20opens=20the=20colo?= =?UTF-8?q?ur=20picker=20on=20every=20choice=20(#17470)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contents reads Color… and each choice of it, also while it is the current entry, opens Color Picker (Fill Color) at the remembered fill colour (the foreground until a colour fill was confirmed). The Color: swatch row is gone; agents still set the colour with ui.dialog.set on color, and choosing Color… through automation opens no picker. Needs storytold/craft-libs#4596 (Param::option_picks_color) in the craft-libs pin. Co-Authored-By: Claude Opus 5.5 --- .../src/dialogs/fill_history_greyed_tests.rs | 6 +- .../dialogs/fill_quick_mask_greyed_tests.rs | 2 +- crates/ui-egui/src/dialogs/fill_ui.rs | 16 +- .../src/dialogs/fill_ui/color_entry_tests.rs | 165 ++++++++++++++++++ .../fill_ui/content_aware_greyed_tests.rs | 2 +- crates/ui-egui/src/dialogs/fill_ui/tests.rs | 2 +- 6 files changed, 182 insertions(+), 11 deletions(-) create mode 100644 crates/ui-egui/src/dialogs/fill_ui/color_entry_tests.rs diff --git a/crates/ui-egui/src/dialogs/fill_history_greyed_tests.rs b/crates/ui-egui/src/dialogs/fill_history_greyed_tests.rs index 454c3d3e3e..c8b2979ce6 100644 --- a/crates/ui-egui/src/dialogs/fill_history_greyed_tests.rs +++ b/crates/ui-egui/src/dialogs/fill_history_greyed_tests.rs @@ -50,7 +50,7 @@ fn resized(cmd: &str, p: Value) -> Box { } fn contents_row(app: &PhotocraftApp) -> Param { - rows(app, [0.0; 3], None, None).into_iter().find(|r| r.key == "contents").expect("a Contents row") + rows(app, None, None).into_iter().find(|r| r.key == "contents").expect("a Contents row") } fn keys(row: &Param) -> Vec { @@ -135,9 +135,9 @@ fn the_dropdown_and_the_command_agree() { fn a_remembered_history_choice_keeps_todays_fallback_once_greyed() { let mut saved = DialogFields::new(); saved.set("contents", "history"); - let unchanged = ParamDialog::remembered(&rows(&app(), [0.0; 3], None, None), &saved); + let unchanged = ParamDialog::remembered(&rows(&app(), None, None), &saved); assert_eq!(unchanged.text("contents"), Some("history"), "kept while usable"); let app = resized("image.imageSize", json!({"width": 20, "height": 15})); - let greyed = ParamDialog::remembered(&rows(&app, [0.0; 3], None, None), &saved); + let greyed = ParamDialog::remembered(&rows(&app, None, None), &saved); assert_eq!(greyed.text("contents"), None, "dropped once greyed: the row opens on Foreground Color"); } diff --git a/crates/ui-egui/src/dialogs/fill_quick_mask_greyed_tests.rs b/crates/ui-egui/src/dialogs/fill_quick_mask_greyed_tests.rs index 72a9746407..b8103d5fa5 100644 --- a/crates/ui-egui/src/dialogs/fill_quick_mask_greyed_tests.rs +++ b/crates/ui-egui/src/dialogs/fill_quick_mask_greyed_tests.rs @@ -24,7 +24,7 @@ fn quick_mask_on(app: &mut PhotocraftApp, on: bool) { } fn row(app: &PhotocraftApp, key: &str) -> Param { - rows(app, [0.0; 3], None, None).into_iter().find(|r| r.key == key).unwrap_or_else(|| panic!("a {key} row")) + rows(app, None, None).into_iter().find(|r| r.key == key).unwrap_or_else(|| panic!("a {key} row")) } /// A field of the open dialog `id`, and whether it takes `value`. diff --git a/crates/ui-egui/src/dialogs/fill_ui.rs b/crates/ui-egui/src/dialogs/fill_ui.rs index 36f4b65738..564723645c 100644 --- a/crates/ui-egui/src/dialogs/fill_ui.rs +++ b/crates/ui-egui/src/dialogs/fill_ui.rs @@ -21,11 +21,11 @@ pub const COMMAND: &str = "edit.fill"; const REMEMBER: &str = "photocraft.dialog.edit.fill"; const REMEMBER_INKS: &str = "photocraft.dialog.edit.fill.inks"; -/// The Contents menu: (param, label), in Photoshop's order. Color reads without an ellipsis: choosing it opens nothing. +/// The Contents menu: (param, label), in Photoshop's order. Color… opens the Color Picker on every choice (#17470). pub const CONTENTS: [(&str, &str); 9] = [ ("foreground", "Foreground Color"), ("background", "Background Color"), - ("color", "Color"), + ("color", "Color…"), ("contentAware", "Content-Aware"), ("pattern", "Pattern"), ("history", "History"), @@ -79,7 +79,7 @@ fn quick_mask_greyed_keys() -> impl Iterator { } /// The dialog's rows, with the Preserve Transparency the target forces. -fn rows(app: &PhotocraftApp, foreground: [f32; 3], first_pattern: Option, preserve: Option) -> Vec { +fn rows(app: &PhotocraftApp, first_pattern: Option, preserve: Option) -> Vec { let quick_mask = quick_mask(app); let contents = CONTENTS.iter().map(|(k, l)| (k.to_string(), Label::from(tl!(l)))).collect(); let mut contents = Param::new("contents", tl!("Contents:"), ParamKind::choice(contents, Some(opening_contents(app).into()))); @@ -91,9 +91,11 @@ fn rows(app: &PhotocraftApp, foreground: [f32; 3], first_pattern: Option ("history", quick_mask || app.session.active().is_none_or(|st| !photocraft_engine::history_source::fill_source_usable(st))), ]; contents = contents.disabled_options(greyed.into_iter().filter(|(_, off)| *off).map(|(key, _)| key)); + // Each choice of Color…, also while it is the current one, opens "Color Picker (Fill Color)" at the colour under + // `color`, which has no row of its own (#17470). + contents = contents.option_picks_color("color", "color", tl!("Fill Color")); let mut rows = vec![ contents, - Param::new("color", tl!("Color:"), ParamKind::color(Some(foreground))).visible_when("contents", "color"), Param::new("pattern", tl!("Custom Pattern:"), ParamKind::pattern(first_pattern)).visible_when("contents", "pattern"), // Script lays the pattern out tile by tile in the chosen script's own dialog, opened by OK (#17428). Param::new("script", tl!("Script"), ParamKind::bool(false)).visible_when("contents", "pattern"), @@ -150,11 +152,13 @@ pub fn open(app: &mut PhotocraftApp) -> DialogId { let [r, g, b, _] = app.session.tools.foreground; let first = app.session.patterns.items.first().map(|p| p.id.clone()); let patterns = crate::panels::preset_browser::pattern_swatches(app); - let rows = rows(app, [r, g, b], first.clone(), preserve); + let rows = rows(app, first.clone(), preserve); let inks = crate::color_picker_ui::ink_value(craft::theme::Srgba::rgb(r, g, b), app.session.tools.picked_role_cmyk(0)); let mut reset = defaults([r, g, b], first, app.session.tools.picked_role_cmyk(0), preserve); reset.set("contents", opening_contents(app)); let mut fields = opening_fields(app.ctx(), COMMAND); + // The picker starts on the remembered fill colour, which the dialog keeps over this one; the foreground until then. + fields.set("color", FieldValue::Color([r, g, b])); let remembered: Option = MemoryStage::peek_saved(app.ctx(), &SaveKey::named(REMEMBER_INKS)); let remembered_inks = remembered.as_ref().and_then(|saved| saved.get(&crate::color_picker_ui::ink_field("color"))).cloned(); fields.set(crate::color_picker_ui::ink_field("color"), remembered_inks.unwrap_or(inks)); @@ -276,6 +280,8 @@ fn keep_mode(ctx: &egui::Context, key: &str, mode: String) { } } +#[cfg(test)] +mod color_entry_tests; #[cfg(test)] mod content_aware_greyed_tests; #[cfg(test)] diff --git a/crates/ui-egui/src/dialogs/fill_ui/color_entry_tests.rs b/crates/ui-egui/src/dialogs/fill_ui/color_entry_tests.rs new file mode 100644 index 0000000000..3ef20bddab --- /dev/null +++ b/crates/ui-egui/src/dialogs/fill_ui/color_entry_tests.rs @@ -0,0 +1,165 @@ +//! #17470: Color… in Fill's Contents opens "Color Picker (Fill Color)" on the remembered fill colour each time it is +//! chosen, also when it is already the current entry; the dialog shows no swatch of the colour, and agents still set it. + +use craft::ui::patterns::form_dialogs::HostedParamDialog; +use egui::accesskit::Role; +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; +use serde_json::json; + +use super::*; +use crate::color_picker_ui::{parse_hex, testing as picker, title_for}; +use crate::dialogs::testing::{cancel, confirm}; + +const GREEN: &str = "#33cc66"; +const BLUE: &str = "#3366ff"; + +type H = Harness<'static, Box>; + +/// A transparent 20×20 document with a red foreground, drawn through `dialogs::run` as the window shows its dialogs. +fn harness() -> H { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 20, "height": 20, "background": "transparent"})).unwrap(); + app.run("tools.setColors", json!({"foreground": "#ff0000"})).unwrap(); + let h = Harness::builder() + .with_context(app.ctx().clone()) + .with_size(egui::vec2(900.0, 900.0)) + .build_ui_state(|ui, app: &mut Box| crate::dialogs::run(app, ui), app); + PhotocraftApp::setup_context(&h.ctx, crate::theme::AppTheme::pro()); + h +} + +fn open_fill(h: &mut H) -> DialogId { + let id = open(h.state_mut()); + h.run_steps(3); + id +} + +fn fields(h: &H, id: DialogId) -> DialogFields { + h.state().framework.dialogs.get_by_id::(id).expect("Fill is open").fields().clone() +} + +fn set(h: &mut H, id: DialogId, key: &str, value: Value) { + let ctx = h.ctx.clone(); + h.state_mut().framework.dialogs.set_json_field(&ctx, id, key, value).unwrap_or_else(|e| panic!("{key}: {e}")); + h.run_steps(2); +} + +fn close(a: [f32; 3], b: [f32; 3]) -> bool { + a.iter().zip(b).all(|(x, y)| (x - y).abs() < 1.5 / 255.0) +} + +fn rgb(hex: &str) -> [f32; 3] { + parse_hex(hex).expect("a colour") +} + +/// Opens the Contents list and chooses Color… in it, as a click does; returns the Color Picker that opened. +fn choose_color(h: &mut H) -> Option { + h.get_by_role_and_label(Role::ComboBox, "Contents").click(); + h.run_steps(2); + h.get_by_label("Color…").click(); + h.run_steps(4); + crate::color_picker_ui::top(h.state()) +} + +/// The colour the open picker `id` shows. +fn shown(h: &H, id: DialogId) -> [f32; 3] { + picker::current(h.state(), id).expect("the picker shows a colour").color.to_rgb_array() +} + +fn pixel(h: &H) -> [f32; 4] { + let st = h.state().session.active().unwrap(); + st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap().rgba(10, 10) +} + +/// Choosing Color… opens the titled picker on top of Fill at the colour Fill holds, and choosing it again while it is +/// the current entry opens the picker again; Cancel leaves Contents on Color… and the colour as it was. +#[test] +fn choosing_color_opens_the_fill_color_picker_every_time() { + let mut h = harness(); + let fill = open_fill(&mut h); + set(&mut h, fill, "color", json!(rgb(GREEN))); + + let first = choose_color(&mut h).expect("choosing Color… opens the Color Picker"); + assert!(h.query_all_by_label(&title_for(tl!("Fill Color"))).next().is_some(), "the picker is titled Color Picker (Fill Color)"); + assert!(close(shown(&h, first), rgb(GREEN)), "the picker starts on the colour Fill holds"); + assert_eq!(fields(&h, fill).text("contents"), Some("color")); + + cancel(h.state_mut(), first).unwrap(); + h.run_steps(3); + assert!(crate::color_picker_ui::top(h.state()).is_none(), "Cancel closes the picker"); + assert_eq!(fields(&h, fill).text("contents"), Some("color"), "Cancel leaves Contents on Color…"); + assert!(close(fields(&h, fill).color("color").unwrap(), rgb(GREEN)), "Cancel keeps the colour"); + + let again = choose_color(&mut h).expect("choosing the current Color… opens the picker again"); + assert!(close(shown(&h, again), rgb(GREEN))); +} + +/// Picker OK sets the colour, Fill OK fills with it and remembers it: Fill reopens on Color… with no picker and no +/// swatch row, and the next picker starts on that colour. +#[test] +fn picker_ok_then_fill_ok_fills_with_the_colour_and_remembers_it() { + let mut h = harness(); + let fill = open_fill(&mut h); + let id = choose_color(&mut h).expect("the picker opens"); + assert!(close(shown(&h, id), [1.0, 0.0, 0.0]), "with nothing remembered the picker starts on the foreground"); + picker::set_color(h.state_mut(), id, GREEN); + confirm(h.state_mut(), id).unwrap(); + h.run_steps(3); + assert!(close(fields(&h, fill).color("color").unwrap(), rgb(GREEN)), "picker OK sets the colour for this fill"); + confirm(h.state_mut(), fill).unwrap(); + h.run_steps(3); + let [r, g, b, a] = pixel(&h); + assert!(close([r, g, b], rgb(GREEN)) && a == 1.0, "Fill OK fills with the picked colour: {:?}", pixel(&h)); + + let reopened = open_fill(&mut h); + assert!(crate::color_picker_ui::top(h.state()).is_none(), "reopening on Color… opens no picker by itself"); + assert_eq!(fields(&h, reopened).text("contents"), Some("color")); + assert!(h.query_all_by_label("Color:").next().is_none(), "Fill has no colour swatch row"); + let id = choose_color(&mut h).expect("the picker opens"); + assert!(close(shown(&h, id), rgb(GREEN)), "the remembered colour is the next start colour"); +} + +/// Fill Cancel forgets a colour picked in that session: the next picker starts on the last committed one. +#[test] +fn fill_cancel_forgets_the_picked_colour() { + let mut h = harness(); + let fill = open_fill(&mut h); + let id = choose_color(&mut h).expect("the picker opens"); + picker::set_color(h.state_mut(), id, GREEN); + confirm(h.state_mut(), id).unwrap(); + h.run_steps(3); + cancel(h.state_mut(), fill).unwrap(); + h.run_steps(3); + assert_eq!(pixel(&h)[3], 0.0, "nothing is filled"); + + open_fill(&mut h); + let id = choose_color(&mut h).expect("the picker opens"); + assert!(close(shown(&h, id), [1.0, 0.0, 0.0]), "the picked colour is forgotten"); +} + +/// From Foreground Color, a cancelled picker still leaves Contents on Color…, and Fill OK fills with the remembered +/// colour; an agent sets the colour without the picker. +#[test] +fn picker_cancel_from_foreground_fills_with_the_remembered_colour() { + let mut h = harness(); + let fill = open_fill(&mut h); + set(&mut h, fill, "contents", json!("color")); + assert!(crate::color_picker_ui::top(h.state()).is_none(), "an agent's choice of Color… opens no picker"); + set(&mut h, fill, "color", json!(rgb(BLUE))); + confirm(h.state_mut(), fill).unwrap(); + h.run_steps(3); + h.state_mut().run("edit.undo", json!({})).unwrap(); + + let fill = open_fill(&mut h); + set(&mut h, fill, "contents", json!("foreground")); + let id = choose_color(&mut h).expect("the picker opens"); + assert!(close(shown(&h, id), rgb(BLUE)), "the picker starts on the remembered colour"); + cancel(h.state_mut(), id).unwrap(); + h.run_steps(3); + assert_eq!(fields(&h, fill).text("contents"), Some("color"), "Contents stays Color… after Cancel"); + confirm(h.state_mut(), fill).unwrap(); + h.run_steps(3); + let [r, g, b, _] = pixel(&h); + assert!(close([r, g, b], rgb(BLUE)), "Fill OK fills with the remembered colour: {:?}", pixel(&h)); +} diff --git a/crates/ui-egui/src/dialogs/fill_ui/content_aware_greyed_tests.rs b/crates/ui-egui/src/dialogs/fill_ui/content_aware_greyed_tests.rs index 9ee00589ff..dc2bf23092 100644 --- a/crates/ui-egui/src/dialogs/fill_ui/content_aware_greyed_tests.rs +++ b/crates/ui-egui/src/dialogs/fill_ui/content_aware_greyed_tests.rs @@ -20,7 +20,7 @@ fn app(selected: bool) -> Box { /// The Contents row of the dialog `app` would open. fn contents_row(app: &PhotocraftApp) -> Param { - rows(app, [0.0; 3], None, None).into_iter().find(|r| r.key == "contents").expect("a Contents row") + rows(app, None, None).into_iter().find(|r| r.key == "contents").expect("a Contents row") } /// The keys of a choice row, in order. diff --git a/crates/ui-egui/src/dialogs/fill_ui/tests.rs b/crates/ui-egui/src/dialogs/fill_ui/tests.rs index 517417cbf8..7fe3072e40 100644 --- a/crates/ui-egui/src/dialogs/fill_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/fill_ui/tests.rs @@ -314,7 +314,7 @@ fn reset_fill_restores_the_original_native_inks_for_the_same_rgb() { use std::{cell::RefCell, rc::Rc}; let original = [0., 0., 0., 1.]; let reset = defaults([0.; 3], None, Some(original), None); - let rows = rows(&app(), [0.; 3], None, None); + let rows = rows(&app(), None, None); let fields = Rc::new(RefCell::new(reset.clone())); let shown = fields.clone(); let mut fixture = Fixture::new(move |ui| { From f75a0f98432f7087850934b4b8987410b4289cc6 Mon Sep 17 00:00:00 2001 From: David Mann Date: Tue, 1 Dec 2026 10:14:54 +0100 Subject: [PATCH 2/3] Fill: the threshold-mode test calls rows() without the foreground (#17470) Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs/fill_ui/fill_threshold_mode_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/fill_ui/fill_threshold_mode_tests.rs b/crates/ui-egui/src/dialogs/fill_ui/fill_threshold_mode_tests.rs index a6f0eaa01e..2e78f5dbf3 100644 --- a/crates/ui-egui/src/dialogs/fill_ui/fill_threshold_mode_tests.rs +++ b/crates/ui-egui/src/dialogs/fill_ui/fill_threshold_mode_tests.rs @@ -25,7 +25,7 @@ fn app(mode: &str) -> Box { } fn row(app: &PhotocraftApp, key: &str) -> Param { - rows(app, [0.0; 3], None, None).into_iter().find(|r| r.key == key).expect("the row") + rows(app, None, None).into_iter().find(|r| r.key == key).expect("the row") } /// The Mode row's entries as (key, label), and the labels of the enabled ones. From e6fe79fe3c01cca6cac08a2ab97cfd78f060692c Mon Sep 17 00:00:00 2001 From: David Mann Date: Tue, 1 Dec 2026 12:31:34 +0100 Subject: [PATCH 3/3] Fill: picker OK writes the colour into Fill at once (#17470) Without a Color row, the picker's answer reached Fill only in the next dialog pass, so a Fill OK right after the picker's OK (an agent's next request, or framework_dialog_dropper_keeps_native_model_values) filled with the old colour and the new inks did not match it. The picker's OK now writes the colour into its parent's field with the inks, keeping a row's opacity. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs/color_picker_ui.rs | 8 ++++++++ .../src/dialogs/fill_ui/color_entry_tests.rs | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/crates/ui-egui/src/dialogs/color_picker_ui.rs b/crates/ui-egui/src/dialogs/color_picker_ui.rs index ec1f6bc8cd..3723900a9d 100644 --- a/crates/ui-egui/src/dialogs/color_picker_ui.rs +++ b/crates/ui-egui/src/dialogs/color_picker_ui.rs @@ -424,6 +424,14 @@ fn commit(app: &mut PhotocraftApp, _id: DialogId, target: PickTarget, picked: &P PickTarget::NewSolidFill { document } => crate::solid_fill_ui::confirm_new(app, *document, picked), PickTarget::Request { parent, key } => { if let Some(dialog) = app.framework.dialogs.get_mut_by_id::(*parent) { + // The colour goes in with its inks at once, so an OK of the parent right after this one (an agent's next + // request, before a dialog pass has taken the answer) fills with it; a row with opacity keeps its own. + let [r, g, b] = picked.color.to_rgb_array(); + let value = match dialog.fields().get(key) { + Some(FieldValue::Rgba([.., a])) => FieldValue::Rgba([r, g, b, *a]), + _ => FieldValue::Color([r, g, b]), + }; + dialog.set_field(key.clone(), value); dialog.set_field(ink_field(key), ink_value(picked.color, inks_of(picked))); } app.color_answers.push((*parent, key.clone(), picked.color)); diff --git a/crates/ui-egui/src/dialogs/fill_ui/color_entry_tests.rs b/crates/ui-egui/src/dialogs/fill_ui/color_entry_tests.rs index 3ef20bddab..6f32ae7ff3 100644 --- a/crates/ui-egui/src/dialogs/fill_ui/color_entry_tests.rs +++ b/crates/ui-egui/src/dialogs/fill_ui/color_entry_tests.rs @@ -163,3 +163,18 @@ fn picker_cancel_from_foreground_fills_with_the_remembered_colour() { let [r, g, b, _] = pixel(&h); assert!(close([r, g, b], rgb(BLUE)), "Fill OK fills with the remembered colour: {:?}", pixel(&h)); } + +/// Fill OK straight after picker OK, with no dialog pass between them (an agent's two requests), fills with the picked +/// colour: the picker writes it into Fill at once. +#[test] +fn fill_ok_right_after_picker_ok_fills_with_the_picked_colour() { + let mut h = harness(); + let fill = open_fill(&mut h); + let id = choose_color(&mut h).expect("the picker opens"); + picker::set_color(h.state_mut(), id, GREEN); + confirm(h.state_mut(), id).unwrap(); + confirm(h.state_mut(), fill).unwrap(); + h.run_steps(3); + let [r, g, b, _] = pixel(&h); + assert!(close([r, g, b], rgb(GREEN)), "Fill OK fills with the picked colour: {:?}", pixel(&h)); +}