diff --git a/crates/ui-egui/examples/color_picker_demo.rs b/crates/ui-egui/examples/color_picker_demo.rs index 9eae40c7ac..0d219f0d0b 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; @@ -37,12 +37,9 @@ 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(); - 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 1da130b754..d080b46090 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,46 +476,8 @@ pub(crate) mod live_preview; mod tests; #[cfg(test)] -#[path = "color_picker_swatch_name_tests.rs"] -mod swatch_name_tests; +mod screen_button_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); - } -} +#[path = "color_picker_swatch_name_tests.rs"] +mod swatch_name_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