PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge PR #6335: Replace Color: the sample eyedropper is armed when the dialog opens (fixes #6279)
aionggb5fed83c7991
diff --cc crates/ui-egui/src/filter_dialog.rsindex 868c920cb,83944a1b0..3290dacee--- a/crates/ui-egui/src/filter_dialog.rs+++ b/crates/ui-egui/src/filter_dialog.rs@@@ -2452,53 -2379,15 +2456,54 @@@ mod testsPhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);open(h.state_mut(), REPLACE_COLOR).unwrap();h.run_steps(3);+ assert!(color_eyedropper_armed(h.state()), "armed as the dialog opens");h.get_by_label("Pick Color From Image").click();h.run_steps(2);- assert!(color_eyedropper_armed(h.state()));+ assert!(!color_eyedropper_armed(h.state()));h.get_by_label("Pick Color From Image").click();h.run_steps(2);- assert!(!color_eyedropper_armed(h.state()));+ assert!(color_eyedropper_armed(h.state()));}+ /// #6278: the Result swatch shows the sampled colour after the shift, and a colour picked for+ /// it sets Hue, Saturation and Lightness so the sampled colour becomes it.+ #[test]+ fn replace_color_result_swatch_sets_the_sliders() {+ use egui_kittest::Harness;+ use egui_kittest::kittest::Queryable;++ let mut s = photocraft_engine::Session::new();+ s.execute("file.new", json!({"width": 16, "height": 16})).unwrap();+ let mut app = PhotocraftApp::new(s, crate::Services::default());+ app.run("tools.setColors", json!({"foreground": "#cc3333"})).unwrap();+ let mut h = Harness::builder().with_size(egui::vec2(900.0, 900.0)).build_ui_state(|ui, app| crate::dialogs::show(app, ui.ctx()), &mut app);+ PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);+ let id = open(h.state_mut(), REPLACE_COLOR).unwrap();+ h.run_steps(3);+ // No shift yet: the Result is the sampled colour.+ assert_eq!(h.get_all_by_label("#cc3333").count(), 2, "the sampled colour and the Result both read #cc3333");+ h.get_by_role_and_label(egui::accesskit::Role::ColorWell, "Result").click();+ h.run_steps(3);+ let picker = h.state().ui.dialogs.last().unwrap();+ assert_ne!(picker.id, id, "the Color Picker opened over the dialog");+ assert_eq!(picker.fields["color"], json!("#cc3333"), "on the current Result");+ let picker = picker.id;+ h.state_mut().ui.dialog_mut(picker).unwrap().fields.insert("color".into(), json!("#3355cc"));+ crate::dialogs::confirm(h.state_mut(), picker).unwrap();+ h.state_mut().ui.dialogs.retain(|d| d.id != picker);+ h.run_steps(3);+ let f = h.state_mut().ui.dialog_mut(id).unwrap().fields.clone();+ let n = |k: &str| f[k].as_f64().unwrap() as f32;+ let got = photocraft_algo::tone::replace_color_result([0.8, 0.2, 0.2], n("hue"), n("saturation"), n("lightness"));+ let want = crate::color_picker_ui::parse_hex("#3355cc").unwrap();+ assert!(got.iter().zip(want).all(|(a, b)| (a - b).abs() < 0.02), "the sliders turn the sampled colour into the pick: {got:?}");+ assert!(n("hue") != 0.0, "the hue moved");+ // Moving a slider afterwards is not mistaken for another pick.+ h.state_mut().ui.dialog_mut(id).unwrap().fields.insert("lightness".into(), json!(10.0));+ h.run_steps(2);+ assert_eq!(h.state_mut().ui.dialog_mut(id).unwrap().fields["lightness"], json!(10.0));+ }+/// #4457: Localized Color Clusters and its Range, as in Photoshop's dialog; the sampled point/// and both settings reach the command.#[test]