From 32d7141bc165394cf8104d3c0663a206d13cc043 Mon Sep 17 00:00:00 2001 From: David Mann Date: Wed, 25 Nov 2026 23:19:21 +0100 Subject: [PATCH 1/4] WIP: Color Picker without the screen eyedropper button (#17017) Co-Authored-By: Claude Opus 5.5 From 0202f45ddc9df9217ddba8d32f517ad16cadfac3 Mon Sep 17 00:00:00 2001 From: David Mann Date: Thu, 26 Nov 2026 00:17:53 +0100 Subject: [PATCH 2/4] Color Picker: no screen eyedropper button, as in the reference application (#17017) The reference application's Color Picker has no eyedropper button; it samples by a click on the canvas while the dialog is open, which PhotoCraft already does. Build every full Color Picker dialog with eyedropper(false): the shared launcher, the Layer Style picker and the text style picker (the last two never served the button's press). Remove the dialog's unused screen-pick wiring, update docs/color-picker.md and the color_picker_demo example. Compact popovers keep their own screen eyedropper. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/examples/color_picker_demo.rs | 13 +-- crates/ui-egui/src/dialogs/color_picker_ui.rs | 64 ++----------- .../color_picker_ui/screen_button_tests.rs | 92 +++++++++++++++++++ .../src/dialogs/layer_style/color_picker.rs | 5 +- .../src/panels/type_panels_ui/color_picker.rs | 7 +- docs/color-picker.md | 6 +- 6 files changed, 115 insertions(+), 72 deletions(-) create mode 100644 crates/ui-egui/src/dialogs/color_picker_ui/screen_button_tests.rs diff --git a/crates/ui-egui/examples/color_picker_demo.rs b/crates/ui-egui/examples/color_picker_demo.rs index 9eae40c7ac..e6b2ec60e3 100644 --- a/crates/ui-egui/examples/color_picker_demo.rs +++ b/crates/ui-egui/examples/color_picker_demo.rs @@ -1,10 +1,10 @@ //! Render synthetic color-picker evidence without capturing the user's desktop. //! cargo run -p photocraft-ui-egui --example color_picker_demo -- /tmp/color-picker -use craft::color_ui::ui::{CaptureSource, StillCapture}; +use craft::color_ui::ui::{CaptureSource, ScreenPickGesture, StillCapture}; use craft::platform::screen::{Capture, ScreenImage}; use craft::theme::Srgba; use egui_kittest::{Harness, kittest::Queryable}; -use photocraft_ui_egui::{PhotocraftApp, Services, color_picker_ui, screen_picker}; +use photocraft_ui_egui::{PhotocraftApp, Services, screen_picker}; use serde_json::json; use std::sync::Arc; @@ -40,9 +40,6 @@ fn main() { text.get_by_label("Set the text color").click(); text.run_steps(6); text.render().unwrap().save(format!("{output}/text-color-picker.png")).unwrap(); - text.get_by_label("Sample color from the screen").click(); - text.run_steps(6); - text.render().unwrap().save(format!("{output}/text-color-picked.png")).unwrap(); // PLAN: the loupe renders through the app's own frame, which calls `screen_picker::tick` and // `show` once per pass (frame.rs, hub-w1); calling them again here would run the pick twice a pass. @@ -57,9 +54,9 @@ fn main() { PhotocraftApp::with_context(cc.egui_ctx.clone(), session, services) }); loupe.run_steps(8); - color_picker_ui::open(loupe.state_mut(), "foreground"); - loupe.run_steps(6); - loupe.get_by_label("Sample color from the screen").click(); + // The Color Picker dialog has no screen button (#17017); the compact popovers start the same pick. + let ctx = loupe.ctx.clone(); + screen_picker::hold(loupe.state_mut(), &ctx, "color-picker-demo", ScreenPickGesture::Clicked); loupe.run_steps(3); loupe.input_mut().events.push(egui::Event::PointerMoved(egui::pos2(360.0, 220.0))); loupe.run_steps(2); diff --git a/crates/ui-egui/src/dialogs/color_picker_ui.rs b/crates/ui-egui/src/dialogs/color_picker_ui.rs index 2a0b4c8e95..9bb0631ecb 100644 --- a/crates/ui-egui/src/dialogs/color_picker_ui.rs +++ b/crates/ui-egui/src/dialogs/color_picker_ui.rs @@ -2,7 +2,7 @@ //! //! Every opener builds the dialog, opens it on the dialog host and records what it is for in //! `app.color_targets` ([`PickTarget`]). [`take`] runs once per pass from `dialogs::TAKERS`: it -//! serves the dialog's screen pick, Add to Swatches and canvas eyedropper, previews the picked +//! serves the dialog's Add to Swatches and canvas eyedropper, previews the picked //! colour in its parent ([`live_preview`]) and commits an OK to the target ([`commit`]). A hosted //! dialog's colour row opens a child with [`open_for_request`] and pulls the answer with //! [`answer_for`]; a window the app holds itself opens one with [`open_for_window`] and pulls the @@ -169,9 +169,10 @@ fn converter(app: &PhotocraftApp) -> CmykConverter { CmykConverter::new(app.session.color().working(photocraft_doc::ColorMode::Cmyk)).ok().unwrap_or_else(|| CmykConverter::coated().clone()) } -/// Opens `dialog` for `target` with the app's picker features, under `parent` when it has one. +/// Opens `dialog` for `target` with the app's picker features, under `parent` when it has one. No screen eyedropper +/// button: the reference application's picker has none and samples by a click on the canvas (#17017). fn launch(app: &mut PhotocraftApp, dialog: ColorPickerDialog, parent: Option, target: PickTarget) -> DialogId { - let mut dialog = dialog.cmyk(&converter(app)).canvas_samples(true).eyedropper(true).add_to_swatches(true).instance(target.identity()); + let mut dialog = dialog.cmyk(&converter(app)).canvas_samples(true).eyedropper(false).add_to_swatches(true).instance(target.identity()); if let Some(idx) = app.session.active_index() { dialog = dialog.canvas(crate::canvas::document_display::CanvasHost::primary(app, idx).canvas_id()); } @@ -335,31 +336,18 @@ pub(crate) fn find(app: &PhotocraftApp, matches: impl Fn(&PickTarget) -> bool) - .last() } -/// Once per pass: serves each open picker's screen pick, Add to Swatches and canvas eyedropper request, +/// Once per pass: serves each open picker's Add to Swatches and canvas eyedropper request, /// previews the picked colours in their parents, and commits the pickers that finished. A second pass in /// one frame finds nothing new: every request is taken from the dialog once. -pub(crate) fn take(app: &mut PhotocraftApp, ctx: &egui::Context) { +pub(crate) fn take(app: &mut PhotocraftApp, _ctx: &egui::Context) { if app.color_targets.is_empty() { return; } let ids: Vec = app.color_targets.keys().copied().collect(); - // PLAN: assumed `screen_picker::busy(app: &PhotocraftApp) -> bool` and `hold(app, ctx, id, gesture)` (dialogs-w39). - let busy = crate::screen_picker::busy(app); for &id in &ids { let Some(d) = app.framework.dialogs.get_mut_by_id::(id) else { continue }; - d.screen_busy(busy); - let gesture = d.take_screen_pick(); let swatch = d.take_add_to_swatches(); let dropper = d.requests().take_eyedropper(); - if let Some(gesture) = gesture { - crate::screen_picker::hold(app, ctx, id, gesture); - } - // PLAN: assumed `screen_picker::take(app, id) -> Option` (dialogs-w39). - if let Some(color) = crate::screen_picker::take(app, id) - && let Some(d) = app.framework.dialogs.get_mut_by_id::(id) - { - d.set_color(PickedColor::rgb(color)); - } if let Some(picked) = swatch { crate::swatches_ui::add_from_picker(app, picked); } @@ -488,42 +476,4 @@ pub(crate) mod live_preview; mod tests; #[cfg(test)] -mod screen_integration_tests { - use super::*; - use craft::color_ui::ui::StillCapture; - use egui::vec2; - use egui_kittest::{Harness, kittest::Queryable}; - - #[test] - fn text_swatch_opens_full_dialog_and_screen_pick_waits_for_ok() { - let mut session = photocraft_engine::Session::new(); - session.execute("file.new", json!({"width":160,"height":120})).unwrap(); - let id = session.execute("type.create", json!({"text":"Hello world","color":"#000000","size":24,"x":10,"y":60})).unwrap()["layer"].as_u64().unwrap(); - let mut h = Harness::builder().with_size(vec2(1440.0, 900.0)).with_max_steps(64).build_eframe(move |cc| { - PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); - let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), session, Default::default()); - app.ui.tool = crate::state::Tool::Type; - app.services.screen_capture = Some(std::sync::Arc::new(|| Box::new(StillCapture::color(Srgba::rgb(1.0, 136.0 / 255.0, 0.0))))); - app - }); - h.run_steps(8); - let before = h.state().session.active().unwrap().history.entries().len(); - let fg = h.state().session.tools.foreground; - h.get_all_by_role_and_label(egui::accesskit::Role::ColorWell, "Text color").next().expect("the text swatch").click(); - h.run_steps(6); - let picker = top(h.state()).expect("the text swatch opens the Color Picker"); - assert!(matches!(target(h.state(), picker), Some(PickTarget::Command { command, .. }) if command == "type.setStyle")); - h.get_by_label("Sample color from the screen").click(); - h.run_steps(6); - assert_eq!(rgb_hex(testing::current(h.state(), picker).unwrap().color), "#ff8800"); - assert_eq!(h.state().session.active().unwrap().history.entries().len(), before, "sampling only changes the picker's colour"); - assert_eq!(h.state().session.tools.foreground, fg); - h.get_by_label("OK").click(); - h.run_steps(4); - let doc = &h.state().session.active().unwrap().doc; - let layer = doc.layer(photocraft_doc::LayerId(id)).unwrap(); - let photocraft_doc::LayerContent::Text(text) = &layer.content else { panic!("not text") }; - assert_eq!(text.color.to_rgba8(), [255, 136, 0, 255]); - assert_eq!(h.state().session.active().unwrap().history.entries().len(), before + 1); - } -} +mod screen_button_tests; diff --git a/crates/ui-egui/src/dialogs/color_picker_ui/screen_button_tests.rs b/crates/ui-egui/src/dialogs/color_picker_ui/screen_button_tests.rs new file mode 100644 index 0000000000..3b8a72cfc4 --- /dev/null +++ b/crates/ui-egui/src/dialogs/color_picker_ui/screen_button_tests.rs @@ -0,0 +1,92 @@ +//! The Color Picker dialog has no screen eyedropper button, as in the reference application (#17017): whichever chip +//! opens it, it samples by a click on the canvas only. + +use craft::color_ui::ui::StillCapture; +use egui::vec2; +use egui_kittest::{Harness, kittest::Queryable}; + +use super::*; + +const SCREEN_BUTTON: &str = "Sample color from the screen"; + +/// The whole app with a screen capture service, so the platform could sample the screen and the button would show. +fn app_harness(setup: impl FnOnce(&mut photocraft_engine::Session) + 'static) -> Harness<'static, Box> { + let mut session = photocraft_engine::Session::new(); + session.execute("file.new", json!({"width":160,"height":120})).unwrap(); + setup(&mut session); + let mut h = Harness::builder().with_size(vec2(1440.0, 900.0)).with_max_steps(64).build_eframe(move |cc| { + PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); + let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), session, Default::default()); + app.services.screen_capture = Some(std::sync::Arc::new(|| Box::new(StillCapture::color(Srgba::rgb(1.0, 136.0 / 255.0, 0.0))))); + app + }); + h.run_steps(8); + h +} + +/// The picker is drawn in its full layout (Only Web Colors under the field) and has no screen eyedropper button. +fn assert_no_screen_button(h: &Harness<'static, Box>, opener: &str) { + assert!(h.query_by_label("Only Web Colors").is_some(), "{opener}: the full Color Picker is shown"); + assert!(h.query_by_label(SCREEN_BUTTON).is_none(), "{opener}: the Color Picker shows a screen eyedropper button"); +} + +#[test] +fn foreground_and_background_pickers_have_no_screen_button() { + for target in ["foreground", "background"] { + let mut h = app_harness(|_| {}); + open(h.state_mut(), target); + h.run_steps(6); + assert_no_screen_button(&h, target); + } +} + +/// The Type options bar's swatch opens the full picker for `type.setStyle`; OK still applies the picked colour. +#[test] +fn text_swatch_picker_has_no_screen_button_and_ok_applies() { + let layer = std::rc::Rc::new(std::cell::Cell::new(0)); + let created = layer.clone(); + let mut h = app_harness(move |session| { + let reply = session.execute("type.create", json!({"text":"Hello world","color":"#000000","size":24,"x":10,"y":60})).unwrap(); + created.set(reply["layer"].as_u64().unwrap()); + }); + h.state_mut().ui.tool = crate::state::Tool::Type; + h.run_steps(4); + h.get_all_by_role_and_label(egui::accesskit::Role::ColorWell, "Text color").next().expect("the text swatch").click(); + h.run_steps(6); + let picker = top(h.state()).expect("the text swatch opens the Color Picker"); + assert!(matches!(target(h.state(), picker), Some(PickTarget::Command { command, .. }) if command == "type.setStyle")); + assert_no_screen_button(&h, "text swatch"); + testing::set_color(h.state_mut(), picker, "#ff8800"); + h.run_steps(2); + h.get_by_label("OK").click(); + h.run_steps(4); + let doc = &h.state().session.active().unwrap().doc; + let photocraft_doc::LayerContent::Text(text) = &doc.layer(photocraft_doc::LayerId(layer.get())).unwrap().content else { panic!("not text") }; + assert_eq!(text.color.to_rgba8(), [255, 136, 0, 255]); +} + +#[test] +fn layer_style_picker_has_no_screen_button() { + let mut h = app_harness(|_| {}); + let parent = crate::layer_style::open(h.state_mut(), Some("colorOverlay")).expect("the Layer Style dialog opens"); + h.run_steps(4); + crate::dialogs::layer_style::color_picker::open(h.state_mut(), parent.value(), "fx1", "color", None).expect("the picker opens"); + h.run_steps(6); + assert_no_screen_button(&h, "Layer Style"); +} + +#[test] +fn text_style_picker_has_no_screen_button() { + let style = std::rc::Rc::new(std::cell::Cell::new(0)); + let created = style.clone(); + let mut h = app_harness(move |session| { + let layer = session.execute("type.create", json!({"x":10,"y":55,"text":"Shared color","size":30})).unwrap()["layer"].as_u64().unwrap(); + let id = session.execute("type.characterStyle.new", json!({"fromSelection":false,"attrs":{"color":"#ff0000"}})).unwrap()["id"].as_u64().unwrap(); + session.execute("type.characterStyle.apply", json!({"id":id,"layer":layer})).unwrap(); + created.set(u32::try_from(id).unwrap()); + }); + let kind = crate::type_panels_ui::color_picker::Kind::Character; + crate::type_panels_ui::color_picker::open(h.state_mut(), kind, style.get()).expect("the text style picker opens"); + h.run_steps(6); + assert_no_screen_button(&h, "Character Style Options"); +} diff --git a/crates/ui-egui/src/dialogs/layer_style/color_picker.rs b/crates/ui-egui/src/dialogs/layer_style/color_picker.rs index 825738a5b9..f86627cbe2 100644 --- a/crates/ui-egui/src/dialogs/layer_style/color_picker.rs +++ b/crates/ui-egui/src/dialogs/layer_style/color_picker.rs @@ -48,8 +48,9 @@ pub(super) fn open_request(app: &mut PhotocraftApp, parent: DialogId, request: C } let opening = color_at(app, parent, &request.key)?; let key = request.key.clone(); - // An instance keeps the picker's result apart from the other pickers' (`take_by_id` only). - let picker = ColorPickerDialog::from_request(request).instance(parent); + // An instance keeps the picker's result apart from the other pickers' (`take_by_id` only). No screen eyedropper + // button, as in the reference application (#17017). + let picker = ColorPickerDialog::from_request(request).eyedropper(false).instance(parent); let id = app.framework.dialogs.open_child(picker, parent); app.layer_style_child = Some((parent, Child::Picker { id, key, opening })); Ok(id) diff --git a/crates/ui-egui/src/panels/type_panels_ui/color_picker.rs b/crates/ui-egui/src/panels/type_panels_ui/color_picker.rs index b0d57d5d32..0bf2a0bd9f 100644 --- a/crates/ui-egui/src/panels/type_panels_ui/color_picker.rs +++ b/crates/ui-egui/src/panels/type_panels_ui/color_picker.rs @@ -88,8 +88,11 @@ pub(crate) fn open(app: &mut PhotocraftApp, kind: Kind, id: u32) -> Result Date: Thu, 26 Nov 2026 00:24:57 +0100 Subject: [PATCH 3/4] color_picker_demo: open the text swatch by its current name The Type options bar swatch is the "Text color" colour well now; the demo still asked for "Set the text color" and panicked before its first image. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/examples/color_picker_demo.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/examples/color_picker_demo.rs b/crates/ui-egui/examples/color_picker_demo.rs index e6b2ec60e3..0d219f0d0b 100644 --- a/crates/ui-egui/examples/color_picker_demo.rs +++ b/crates/ui-egui/examples/color_picker_demo.rs @@ -37,7 +37,7 @@ fn main() { app }); text.run_steps(8); - text.get_by_label("Set the text color").click(); + text.get_all_by_role_and_label(egui::accesskit::Role::ColorWell, "Text color").next().expect("the text swatch").click(); text.run_steps(6); text.render().unwrap().save(format!("{output}/text-color-picker.png")).unwrap(); From 45b84b64b52429a7dad32b329eeee7507fac4c75 Mon Sep 17 00:00:00 2001 From: David Mann Date: Thu, 26 Nov 2026 00:25:17 +0100 Subject: [PATCH 4/4] docs: color-picker wording Co-Authored-By: Claude Opus 5.5 --- docs/color-picker.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/color-picker.md b/docs/color-picker.md index 207733e30b..c9a06cbf45 100644 --- a/docs/color-picker.md +++ b/docs/color-picker.md @@ -28,7 +28,7 @@ Screen snapshots are held in memory, are never written or transmitted by the pic - **macOS:** safe CoreGraphics bindings capture the composed screen and use the snapshot's own ICC profile when available. Screen Recording permission may be required. The existing macOS 11 deployment target is preserved. The window-list capture API is deprecated by Apple, so current macOS releases require explicit manual validation; migration to modern native sampling must also preserve older-app compatibility. - **Web:** browsers exposing the standard EyeDropper API use the browser's native sampling/magnification UI. Browser support and zoom controls vary. Unsupported browsers retain document sampling and color fields; external screen sampling is unavailable. -The implementation follows publicly documented Photoshop behavior for the full Type Color Picker and outside-image sampling. PhotoCraft's popups use an explicit screen-pick action and frozen snapshots rather than Photoshop's press-and-drag gesture; dragging from the canvas to outside the document is tracked in #11755. +The implementation follows publicly documented Photoshop behavior for the full Type Color Picker and outside-image sampling. PhotoCraft's popups use an explicit screen-pick action and frozen snapshots rather than the reference application's press-and-drag gesture; dragging from the canvas to outside the document is tracked in #11755. ## Verification