From b85d119ceb6dc53a492802f6ab8259f8e42fdedd Mon Sep 17 00:00:00 2001 From: moppeeer Date: Sun, 25 Oct 2026 19:43:30 +0100 Subject: [PATCH] Color Picker: typed C/M/Y/K are kept even when the colour shown doesn't change At 100% K a device CMYK conversion is black whatever C, M and Y are, so the picked RGB stayed the same and the `p != before` guard dropped the typed percentages. They are stored (and the colour marked edited) whenever a C/M/Y/K field was typed in; the rest still only when the colour changes. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index c3c99ec44..2404a7032 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -7416,9 +7416,12 @@ fn color_picker(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialog) { ); if p != before { store_picked(d, &p); - if let Some(c) = exact_cmyk { - d.fields.insert("cmyk".into(), json!(c)); - } + } + // Typed C/M/Y/K are kept as typed, even when the colour shown stays the same (at 100% K, a + // device conversion is black whatever C, M and Y are). + if let Some(c) = exact_cmyk { + d.fields.insert("cmyk".into(), json!(c)); + d.fields.insert("edited".into(), json!(true)); } } @@ -11113,6 +11116,19 @@ mod tests { panic!("a CMYK swatch") }; assert_eq!([c, m, y, k].map(|v| (v * 100.0).round()), [0.0, 50.0, 100.0, 0.0]); + // A C typed at 100% K is kept, whether or not the colour shown changes with it. + let rgb = h.state().app.ui.dialog.as_ref().unwrap().fields["rgb"].clone(); + h.state_mut().app.ui.dialog.as_mut().unwrap().fields.insert("cmyk".into(), json!([0.0, 0.0, 0.0, 100.0])); + h.run_steps(2); + h.get_by_label("C").focus(); + h.run_steps(1); + h.event(egui::Event::Text("50".into())); + h.run_steps(2); + let d = h.state().app.ui.dialog.as_ref().unwrap(); + assert_eq!(d.fields["cmyk"], json!([50.0, 0.0, 0.0, 100.0]), "rgb {} (was {rgb})", d.fields["rgb"]); + assert!(d.b("edited")); + store_picked(h.state_mut().app.ui.dialog.as_mut().unwrap(), &Picked::from_rgb([124.0 / 255.0, 19.0 / 255.0, 21.0 / 255.0], 0.0)); + h.run_steps(2); // Its own OK, at the top right, applies it. h.get_by_label("OK").click(); h.run_steps(3);