From 1ff2e978b24ef0a1617ffbee9b1ca6ae7fb9958c Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 12 Oct 2026 22:17:14 +0000 Subject: [PATCH] Integration (colour-entry x #552): the Tools panel's Fill/Stroke double-click opens the Color Picker with picker_fields (CMYK stays CMYK); the Formatting Affects Text picker test fills the fields the picker writes for a typed colour --- crates/ui-egui/src/panels/swatches.rs | 2 +- crates/ui-egui/src/toolbar.rs | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/panels/swatches.rs b/crates/ui-egui/src/panels/swatches.rs index 0592e75e1..fe078cf8f 100644 --- a/crates/ui-egui/src/panels/swatches.rs +++ b/crates/ui-egui/src/panels/swatches.rs @@ -347,7 +347,7 @@ pub fn color_panel(app: &mut DesignApp, ui: &mut egui::Ui) { /// The Color Picker's fields for `color` (`None`: black): its values in its own model, so OK /// keeps a CMYK colour CMYK. -fn picker_fields(color: Option, stroke: bool) -> serde_json::Value { +pub(crate) fn picker_fields(color: Option, stroke: bool) -> serde_json::Value { let color = color.unwrap_or(designcraft_color::Color::BLACK); let mut f = json!({"target": if stroke { "stroke" } else { "fill" }, "hex": color.to_hex()}); match color { diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index 7be5a27b6..7676ad8ea 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -285,12 +285,9 @@ fn fill_stroke_proxy(app: &mut DesignApp, ui: &mut egui::Ui, width: f32) { let on_fill = fresp.double_clicked() && (!stroke_front || !sresp.double_clicked()); let stroke = !on_fill; let current = if stroke { &stroke_sw } else { &fill_sw }; - let rgb = doc.as_ref().and_then(|d| d.resolve_color(current, 1.0)).map_or([0.0; 3], |c| c.to_rgb()); - let byte = |v: f32| (v.clamp(0.0, 1.0) * 255.0).round() as u8; - let hex = format!("#{:02x}{:02x}{:02x}", byte(rgb[0]), byte(rgb[1]), byte(rgb[2])); - let text = crate::panels::colors_affect_text(app); - app.ui.dialog = - Some(crate::dialogs::Dialog::new("colorPicker", json!({"target": if stroke { "stroke" } else { "fill" }, "hex": hex, "text": text}))); + let mut fields = crate::panels::swatches::picker_fields(doc.as_ref().and_then(|d| d.resolve_color(current, 1.0)), stroke); + fields["text"] = json!(crate::panels::colors_affect_text(app)); + app.ui.dialog = Some(crate::dialogs::Dialog::new("colorPicker", fields)); } ui.add_space(3.0); // Formatting affects container / text. @@ -563,7 +560,11 @@ mod tests { let app = h.state_mut(); let d = app.ui.dialog.as_mut().expect("the Color Picker opened"); assert_eq!(d.fields["text"], true, "{:?}", d.fields); - d.fields.insert("hex".into(), serde_json::json!("#456daf")); + // What the picker's fields hold after #456daf is typed. + for (k, v) in [("hex", serde_json::json!("#456daf")), ("rgb", serde_json::json!([0x45, 0x6d, 0xaf])), ("model", serde_json::json!("rgb"))] { + d.fields.insert(k.into(), v); + } + d.fields.insert("edited".into(), serde_json::json!(true)); crate::dialogs::confirm(app).unwrap(); let st = app.session.active().unwrap(); let it = st.doc.item(id).unwrap();