PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Colour swatches open PhotoCraft's Color Picker: filter dialogs, Preferences, Note, Count, artboard (part of #2144) (#2571)
kayrockscreenprinting3a29be7f5eda
diff --git a/crates/ui-egui/src/analysis_ui.rs b/crates/ui-egui/src/analysis_ui.rsindex 5ac30a4ee..2359fd977 100644--- a/crates/ui-egui/src/analysis_ui.rs+++ b/crates/ui-egui/src/analysis_ui.rs@@ -456,9 +456,16 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> boif crate::icons::button(ui, eye, 22.0, false, tl!("Toggle count group visibility")).clicked() {let _ = app.run("count.setGroup", json!({"group": gi, "visible": !g.visible}));}- let mut rgb = g.color.to_rgb();- if crate::widgets::color_edit_button_rgb(ui, &mut rgb).changed() {- let _ = app.run("count.setGroup", json!({"group": gi, "color": [rgb[0], rgb[1], rgb[2]], "coalesce": "count-color"}));+ let rgb = g.color.to_rgb();+ // PhotoCraft's Color Picker (sRGB), as everywhere else (#2144).+ if crate::widgets::color_swatch_button(ui, color32(rgb), tl!("Color")).clicked() {+ crate::color_picker_ui::open_for_command(+ app,+ &crate::color_picker_ui::title_for(tl!("Color")),+ rgb,+ "count.setGroup",+ json!({"group": gi}),+ );}if crate::icons::button(ui, "trash", 22.0, false, tl!("Delete count group")).clicked() {let _ = app.run("count.deleteGroup", json!({"group": gi}));@@ -488,7 +495,10 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> boui.label(RichText::new(tl!("Author:")).color(t.text_dim).size(11.0));ui.add(egui::TextEdit::singleline(&mut app.ui.analysis.note_author).desired_width(120.0));ui.label(RichText::new(tl!("Color:")).color(t.text_dim).size(11.0));- crate::widgets::color_edit_button_rgb(ui, &mut app.ui.analysis.note_color);+ let rgb = app.ui.analysis.note_color;+ if crate::widgets::color_swatch_button(ui, color32(rgb), tl!("Color")).clicked() {+ crate::color_picker_ui::open_for_target(app, "noteColor", &crate::color_picker_ui::title_for(tl!("Color")), rgb);+ }if ui.add_enabled_ui(!doc.notes.is_empty(), |ui| crate::widgets::secondary_button(ui, tl!("Clear All"), 0.0)).inner.clicked() {let _ = app.run("notes.delete", json!({"all": true}));app.ui.analysis.note_selected = None;diff --git a/crates/ui-egui/src/artboard_ui.rs b/crates/ui-egui/src/artboard_ui.rsindex 3ea482c7c..c08a35205 100644--- a/crates/ui-egui/src/artboard_ui.rs+++ b/crates/ui-egui/src/artboard_ui.rs@@ -82,6 +82,8 @@ pub fn properties(app: &mut PhotocraftApp, ui: &mut egui::Ui, layer: &Layer) {let t = Tokens::get(ui.ctx());let key = |k: &str| format!("artboard-{}-{k}", layer.id.0);let mut edit: Option<Value> = None;+ // The custom background swatch was clicked: its colour, for the Color Picker.+ let mut pick: Option<[f32; 3]> = None;ui.label(egui::RichText::new(tl!("Artboard")).font(crate::theme::semibold(12.0)).color(t.text));ui.add_space(4.0);let mut preset = a.preset.clone();@@ -120,7 +122,12 @@ pub fn properties(app: &mut PhotocraftApp, ui: &mut egui::Ui, layer: &Layer) {});ui.horizontal(|ui| {let mut bg = a.background.name().to_string();- let opts = [("white".to_string(), tl!("White")), ("black".to_string(), tl!("Black")), ("transparent".to_string(), tl!("Transparent")), ("custom".to_string(), tl!("Other…"))];+ let opts = [+ ("white".to_string(), tl!("White")),+ ("black".to_string(), tl!("Black")),+ ("transparent".to_string(), tl!("Transparent")),+ ("custom".to_string(), tl!("Other…")),+ ];if crate::widgets::dropdown(ui, &key("bg"), &mut bg, &opts, 120.0) {let mut params = json!({"layer": layer.id.0, "background": bg});if bg == "custom" {@@ -137,9 +144,9 @@ pub fn properties(app: &mut PhotocraftApp, ui: &mut egui::Ui, layer: &Layer) {}if let ArtboardBackground::Custom(c) = a.background {let [r8, g8, b8, _] = c.to_rgba8();- let mut rgb = [r8, g8, b8];- if crate::widgets::color_edit_button_srgb(ui, &mut rgb).changed() {- edit = Some(json!({"layer": layer.id.0, "background": "custom", "color": format!("#{:02x}{:02x}{:02x}", rgb[0], rgb[1], rgb[2]), "coalesce": key("color")}));+ // PhotoCraft's Color Picker, as everywhere else (#2144): OK sets the background.+ if crate::widgets::color_swatch_button(ui, egui::Color32::from_rgb(r8, g8, b8), tl!("Color")).clicked() {+ pick = Some(c.to_rgb());}}});@@ -149,6 +156,10 @@ pub fn properties(app: &mut PhotocraftApp, ui: &mut egui::Ui, layer: &Layer) {app.ui.status = e;app.ui.status_error = true;}+ if let Some(rgb) = pick {+ let title = crate::color_picker_ui::title_for(tl!("Color"));+ crate::color_picker_ui::open_for_command(app, &title, rgb, "layer.artboard.set", json!({"layer": layer.id.0, "background": "custom"}));+ }}#[cfg(test)]diff --git a/crates/ui-egui/src/color_picker_ui.rs b/crates/ui-egui/src/color_picker_ui.rsindex bca981c23..c781b6b75 100644--- a/crates/ui-egui/src/color_picker_ui.rs+++ b/crates/ui-egui/src/color_picker_ui.rs@@ -235,16 +235,63 @@ const REQUEST: &str = "__pickColor";/// swatch, Edit › Stroke's swatch). The dialog loop opens it ([`open_requested`]), since that/// needs the dialog's id.pub fn request(f: &mut Map<String, Value>, title: &str) {- f.insert(REQUEST.into(), json!(title));+ request_field(f, "color", title);}-/// Opens the Color Picker dialog `id`'s body asked for ([`request`]), on its colour: OK sets that-/// dialog's `color` field (not the foreground), Cancel leaves it as it was.+/// [`request`] for another `"#rrggbb"` field of the dialog: a top-level key (`vineColor`), or a+/// JSON pointer into the fields (`/values/guidesGridAndSlices/guideColor`).+pub fn request_field(f: &mut Map<String, Value>, field: &str, title: &str) {+ f.insert(REQUEST.into(), json!({ "title": title, "field": field }));+}++/// The picker's title for the colour called `name`: "Color Picker (Vine Color)".+pub fn title_for(name: &str) -> String {+ crate::i18n::fmt(tl!("Color Picker ({name})"), &[("name", name)])+}++/// The `"#rrggbb"` at `field` of `f` (a key or a JSON pointer).+fn field_value<'a>(f: &'a Map<String, Value>, field: &str) -> Option<&'a str> {+ match field.strip_prefix('/') {+ Some(rest) => {+ let (first, tail) = rest.split_once('/').unwrap_or((rest, ""));+ let v = f.get(first)?;+ if tail.is_empty() { v.as_str() } else { v.pointer(&format!("/{tail}"))?.as_str() }+ }+ None => f.get(field)?.as_str(),+ }+}++/// Sets `field` of `f` (a key or a JSON pointer to an existing value) to `value`.+fn set_field(f: &mut Map<String, Value>, field: &str, value: Value) -> Result<(), String> {+ match field.strip_prefix('/') {+ Some(rest) => {+ let (first, tail) = rest.split_once('/').unwrap_or((rest, ""));+ let v = f.get_mut(first).ok_or("the dialog has no such colour")?;+ let slot = if tail.is_empty() { v } else { v.pointer_mut(&format!("/{tail}")).ok_or("the dialog has no such colour")? };+ *slot = value;+ }+ None => {+ f.insert(field.into(), value);+ }+ }+ Ok(())+}++/// Opens the Color Picker dialog `id`'s body asked for ([`request`], [`request_field`]), on its+/// colour: OK sets that field of the dialog (not the foreground), Cancel leaves it as it was.pub fn open_requested(app: &mut PhotocraftApp, id: u64) {let Some(d) = app.ui.dialog_mut(id) else { return };- let Some(title) = d.fields.remove(REQUEST).and_then(|v| v.as_str().map(str::to_string)) else { return };- let rgb = d.fields.get("color").and_then(Value::as_str).and_then(parse_hex).unwrap_or([0.0; 3]);- open_for_field(app, &title, rgb, id, "color");+ let (title, field) = match d.fields.remove(REQUEST) {+ Some(Value::String(title)) => (title, "color".to_string()),+ Some(Value::Object(o)) => {+ let get = |k: &str| o.get(k).and_then(Value::as_str).map(str::to_string);+ let (Some(title), Some(field)) = (get("title"), get("field")) else { return };+ (title, field)+ }+ _ => return,+ };+ let rgb = field_value(&d.fields, &field).and_then(parse_hex).unwrap_or([0.0; 3]);+ open_for_field(app, &title, rgb, id, &field);}pub fn owns(f: &Map<String, Value>) -> bool {@@ -659,13 +706,18 @@ pub fn confirm(app: &mut PhotocraftApp, f: &Map<String, Value>) -> Result<Value,return Err("the Color Picker has no field to set".into());};let d = app.ui.dialog_mut(dialog).ok_or("the dialog this colour was for is closed")?;- d.fields.insert(field.into(), json!(color));+ set_field(&mut d.fields, field, json!(color))?;return Ok(json!({ "color": color }));}if target == "cropShield" {crate::crop_shield::set_custom_color(app, color)?;return Ok(json!({ "color": color }));}+ // The Note tool's colour for new notes (#2144).+ if target == "noteColor" {+ app.ui.analysis.note_color = parse_hex(color).ok_or("not a colour")?;+ return Ok(json!({ "color": color }));+ }if target == "pasteboard" {// The pasteboard menu's Select Custom Color…: the custom colour, and use it.return app.run("prefs.set", json!({"values": {"interface.canvasColor": "custom", "interface.canvasCustomColor": color}}));diff --git a/crates/ui-egui/src/color_swatch_tests.rs b/crates/ui-egui/src/color_swatch_tests.rsnew file mode 100644index 000000000..6a8830185--- /dev/null+++ b/crates/ui-egui/src/color_swatch_tests.rs@@ -0,0 +1,117 @@+//! Colour swatches open PhotoCraft's Color Picker, not egui's compact popup (#2144: "use the same+//! color picker throughout the app"): filter dialog colours, Preferences colours, the Note and+//! Count tools' colours and an artboard's custom background. OK sets that colour (in sRGB, as+//! everywhere else); the foreground is untouched.++use egui::accesskit::Role;+use egui_kittest::Harness;+use egui_kittest::kittest::Queryable;+use serde_json::{Value, json};++use crate::PhotocraftApp;+use crate::state::Tool;++const PICKED: &str = "#336699";+const PICKED_RGB: [f32; 3] = [0x33 as f32 / 255.0, 0x66 as f32 / 255.0, 0x99 as f32 / 255.0];++fn harness(setup: impl FnOnce(&mut PhotocraftApp) + 'static) -> Harness<'static, PhotocraftApp> {+ let mut h = Harness::builder().with_size(egui::vec2(1400.0, 1800.0)).with_max_steps(64).build_eframe(|cc| {+ PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());+ app.run("file.new", json!({"width": 200, "height": 120})).unwrap();+ setup(&mut app);+ app+ });+ h.run_steps(6);+ h+}++/// Clicks the swatch called `label` (a colour button), answers the Color Picker it opens with+/// [`PICKED`], and returns the picker's title. Panics when no Color Picker opens.+fn pick(h: &mut Harness<'_, PhotocraftApp>, label: &str) -> String {+ // Panels scroll: bring the swatch into view first.+ h.get_by_role_and_label(Role::ColorWell, label).scroll_to_me();+ h.run_steps(2);+ h.get_by_role_and_label(Role::ColorWell, label).click();+ answer(h, label)+}++/// Answers the Color Picker a swatch click just opened with [`PICKED`]; returns its title.+fn answer(h: &mut Harness<'_, PhotocraftApp>, label: &str) -> String {+ let fg = h.state().session.tools.foreground;+ h.run_steps(4);+ let id = crate::color_picker_ui::top(h.state()).unwrap_or_else(|| panic!("the {label} swatch opens the Color Picker"));+ assert!(!egui::Popup::is_any_open(&h.ctx), "{label}: no egui colour popup");+ let title = h.state().ui.dialogs.iter().find(|d| d.id == id).and_then(|d| d.fields.get("__label")).and_then(Value::as_str).unwrap_or("").to_string();+ h.state_mut().ui.dialog_mut(id).unwrap().fields.insert("color".into(), json!(PICKED));+ crate::dialogs::confirm(h.state_mut(), id).unwrap();+ h.run_steps(3);+ assert!(crate::color_picker_ui::top(h.state()).is_none(), "{label}: OK closes the picker");+ assert_eq!(h.state().session.tools.foreground, fg, "{label}: the foreground is untouched");+ title+}++fn close(a: [f32; 3], b: [f32; 3]) -> bool {+ a.iter().zip(b).all(|(x, y)| (x - y).abs() < 1.0 / 255.0)+}++#[test]+fn filter_dialog_colours_open_the_color_picker() {+ for (cmd, key, label) in [("filter.other.colorToAlpha", "color", "Color"), ("filter.render.pictureFrame", "vineColor", "Vine Color")] {+ let mut h = harness(|_| {});+ let ctx = h.ctx.clone();+ let id = crate::menus::invoke(h.state_mut(), &ctx, cmd, json!({})).unwrap()["dialog"].as_u64().unwrap();+ h.run_steps(4);+ let title = pick(&mut h, label);+ assert_eq!(title, format!("Color Picker ({label})"), "{cmd}");+ let d = h.state().ui.dialogs.iter().find(|d| d.id == id).expect("the filter dialog stays open");+ assert_eq!(d.fields.get(key), Some(&json!(PICKED)), "{cmd}: {key}");+ }+}++#[test]+fn preferences_colours_open_the_color_picker() {+ let mut h = harness(|_| {});+ let id = crate::prefs_ui::open_preferences(h.state_mut(), "guidesGridAndSlices");+ h.run_steps(4);+ let values = |h: &Harness<'_, PhotocraftApp>| h.state().ui.dialogs.iter().find(|d| d.id == id).unwrap().fields["values"]["guidesGridAndSlices"].clone();+ let before = values(&h);+ h.get_all_by_role(Role::ColorWell).next().expect("a colour swatch").click();+ answer(&mut h, "the first Preferences colour");+ let after = values(&h);+ let changed: Vec<&str> = after.as_object().unwrap().iter().filter(|(k, v)| before.get(k.as_str()) != Some(v)).map(|(k, _)| k.as_str()).collect();+ assert_eq!(changed.len(), 1, "one colour changed: {changed:?}");+ assert_eq!(after[changed[0]], json!(PICKED));+}++#[test]+fn note_and_count_colours_open_the_color_picker() {+ let mut h = harness(|app| app.ui.tool = Tool::Note);+ pick(&mut h, "Color");+ assert!(close(h.state().ui.analysis.note_color, PICKED_RGB), "note colour {:?}", h.state().ui.analysis.note_color);++ let mut h = harness(|app| {+ app.ui.tool = Tool::Count;+ app.run("count.newGroup", json!({})).unwrap();+ });+ pick(&mut h, "Color");+ let st = h.state().session.active().unwrap();+ let m = &st.doc.measurement;+ let g = &m.count_groups[m.active_count_group];+ assert!(close(g.color.to_rgb(), PICKED_RGB), "count group colour {:?}", g.color.to_rgb());+}++#[test]+fn an_artboard_background_opens_the_color_picker() {+ let mut h = harness(|app| {+ app.run("layer.new.artboard", json!({"x": 10, "y": 10, "width": 100, "height": 80})).unwrap();+ app.run("layer.artboard.set", json!({"background": "custom", "color": "#ff0000"})).unwrap();+ });+ pick(&mut h, "Color");+ let st = h.state().session.active().unwrap();+ let l = st.doc.layer(st.active_layer.unwrap()).unwrap();+ let photocraft_doc::LayerContent::Group(g) = &l.content else { panic!("an artboard") };+ let bg = g.artboard.as_ref().expect("an artboard").background;+ let photocraft_doc::ArtboardBackground::Custom(c) = bg else { panic!("custom background: {bg:?}") };+ assert!(close(c.to_rgb(), PICKED_RGB), "artboard background {:?}", c.to_rgb());+}diff --git a/crates/ui-egui/src/filter_dialog.rs b/crates/ui-egui/src/filter_dialog.rsindex c53fd8139..d0c79d4fa 100644--- a/crates/ui-egui/src/filter_dialog.rs+++ b/crates/ui-egui/src/filter_dialog.rs@@ -557,19 +557,25 @@ pub fn body(ui: &mut egui::Ui, f: &mut Map<String, Value>) {let set = f.get(&p.key).and_then(Value::as_str).and_then(crate::color_picker_ui::parse_hex);let rgb = set.or(default).unwrap_or([0.0; 3]);let q = |v: f32| (v.clamp(0.0, 1.0) * 255.0).round() as u8;- let mut bytes = rgb.map(q);- let mut changed = false;+ let bytes = rgb.map(q);+ let name = label(&p.key);+ let mut clicked = false;ui.horizontal(|ui| {- ui.label(egui::RichText::new(label(&p.key)).color(t.text_dim));+ ui.label(egui::RichText::new(&name).color(t.text_dim));ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {- changed = crate::widgets::color_edit_button_srgb(ui, &mut bytes).changed();+ // PhotoCraft's Color Picker, as everywhere else (#2144).+ clicked = crate::widgets::color_swatch_button(ui, egui::Color32::from_rgb(bytes[0], bytes[1], bytes[2]), &name).clicked();ui.label(egui::RichText::new(crate::color_picker_ui::hex(rgb)).color(t.text_dim).monospace());});});- if changed {- f.insert(p.key, json!(crate::color_picker_ui::hex(bytes.map(|b| f32::from(b) / 255.0))));- } else if set.is_none() && default.is_some() {- f.insert(p.key, json!(crate::color_picker_ui::hex(rgb)));+ if set.is_none() && default.is_some() {+ f.insert(p.key.clone(), json!(crate::color_picker_ui::hex(rgb)));+ }+ if clicked {+ if !f.contains_key(&p.key) {+ f.insert(p.key.clone(), json!(crate::color_picker_ui::hex(rgb)));+ }+ crate::color_picker_ui::request_field(f, &p.key, &crate::color_picker_ui::title_for(&name));}}Kind::Int { default } => {diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex 517d135fd..5e0510dcd 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -2228,6 +2228,7 @@ cameraRaw Color Barvy# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Výběr barvy (Barva textu)+ Color Picker ({name}) Výběr barvy ({name})Color Picker (Fill Color) Výběr barvy (Barva výplně)Fill color Barva výplněColor Picker (Stroke Color) Výběr barvy (Barva tahu)diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex 148c8293d..62d01bd14 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -2267,6 +2267,7 @@# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Farbwähler (Textfarbe)+ Color Picker ({name}) Farbwähler ({name})Color Picker (Fill Color) Farbwähler (Füllfarbe)Fill color FüllfarbeColor Picker (Stroke Color) Farbwähler (Konturfarbe)diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsvindex b162476b7..41af7e933 100644--- a/crates/ui-egui/src/i18n/el.tsv+++ b/crates/ui-egui/src/i18n/el.tsv@@ -3457,6 +3457,7 @@ fontWeight Thin Πολύ λεπτά# Shared text style Color Picker (#2015)Color Picker (Text Color) Επιλογέας χρώματος (χρώμα κειμένου)+ Color Picker ({name}) Επιλογέας χρώματος ({name})Auto Hide Notifications Αυτόματη απόκρυψη ειδοποιήσεωνNotification Duration (seconds) Διάρκεια ειδοποίησης (δευτερόλεπτα)Appearance Mode Λειτουργία εμφάνισηςdiff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex 7f8393468..9290db49c 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -2297,6 +2297,7 @@ cameraRaw Amount Cantidad# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Selector de color (Color del texto)+ Color Picker ({name}) Selector de color ({name})Color Picker (Fill Color) Selector de color (Color de relleno)Fill color Color de rellenoColor Picker (Stroke Color) Selector de color (Color del trazo)diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex d4c9f7475..36d945371 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -2653,6 +2653,7 @@ cameraRaw Blending Fusion# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Sélecteur de couleurs (Couleur du texte)+ Color Picker ({name}) Sélecteur de couleurs ({name})Color Picker (Fill Color) Sélecteur de couleurs (Couleur de remplissage)Fill color Couleur de remplissageColor Picker (Stroke Color) Sélecteur de couleurs (Couleur du contour)diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsvindex 819cbc28e..828d65531 100644--- a/crates/ui-egui/src/i18n/id.tsv+++ b/crates/ui-egui/src/i18n/id.tsv@@ -2640,6 +2640,7 @@ cameraRaw Blending Pembauran# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Pemilih Warna (Warna Teks)+ Color Picker ({name}) Pemilih Warna ({name})Color Picker (Fill Color) Pemilih Warna (Warna Isian)Fill color Warna isianColor Picker (Stroke Color) Pemilih Warna (Warna Stroke)diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex 827a0ad22..b6c359208 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -2301,6 +2301,7 @@ cameraRaw Amount Quantità# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Selettore colore (Colore del testo)+ Color Picker ({name}) Selettore colore ({name})Color Picker (Fill Color) Selettore colore (Colore di riempimento)Fill color Colore di riempimentoColor Picker (Stroke Color) Selettore colore (Colore della traccia)diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 830030b61..d0b0674f6 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -2206,6 +2206,7 @@ cameraRaw Color カラー# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) カラーピッカー(文字色)+ Color Picker ({name}) カラーピッカー({name})Color Picker (Fill Color) カラーピッカー(塗りつぶしカラー)Fill color 塗りつぶしカラーColor Picker (Stroke Color) カラーピッカー(線のカラー)diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsvindex ee578dd2f..a93f1a543 100644--- a/crates/ui-egui/src/i18n/ko.tsv+++ b/crates/ui-egui/src/i18n/ko.tsv@@ -2815,6 +2815,7 @@ cameraRaw Color 색상# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) 색상 선택기 (텍스트 색상)+ Color Picker ({name}) 색상 선택기 ({name})Color Picker (Fill Color) 색상 선택기 (채우기 색상)Fill color 채우기 색상Color Picker (Stroke Color) 색상 선택기 (획 색상)diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsvindex 0a910321e..e1f786227 100644--- a/crates/ui-egui/src/i18n/nl.tsv+++ b/crates/ui-egui/src/i18n/nl.tsv@@ -2244,6 +2244,7 @@Knockout UitsparingApply At Canvas Bounds Toepassen op canvasgrenzenColor Picker (Text Color) Kleurkiezer (tekstkleur)+ Color Picker ({name}) Kleurkiezer ({name})Color Picker (Fill Color) Kleurkiezer (vulkleur)Fill color VulkleurColor Picker (Stroke Color) Kleurkiezer (lijnkleur)diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsvindex a1a27d3c1..9cf709947 100644--- a/crates/ui-egui/src/i18n/pl.tsv+++ b/crates/ui-egui/src/i18n/pl.tsv@@ -3245,6 +3245,7 @@ cameraRaw Roughness Chropowatość# Text Color Picker and screen samplingColor Picker (Text Color) Próbnik kolorów (Kolor tekstu)+ Color Picker ({name}) Próbnik kolorów ({name})Color Picker (Fill Color) Próbnik kolorów (Kolor wypełnienia)Fill color Kolor wypełnieniaColor Picker (Stroke Color) Próbnik kolorów (Kolor obrysu)diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex 67f7c89e2..eb5d4a8ba 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -2661,6 +2661,7 @@ cameraRaw Whites Brancos# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Seletor de cores (Cor do texto)+ Color Picker ({name}) Seletor de cores ({name})Color Picker (Fill Color) Seletor de cores (Cor de preenchimento)Fill color Cor de preenchimentoColor Picker (Stroke Color) Seletor de cores (Cor do traçado)diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex 07062d05a..118effef7 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -2502,6 +2502,7 @@ cameraRaw Roughness Неровность# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Палитра цветов (Цвет текста)+ Color Picker ({name}) Палитра цветов ({name})Color Picker (Fill Color) Палитра цветов (Цвет заливки)Fill color Цвет заливкиColor Picker (Stroke Color) Палитра цветов (Цвет обводки)diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsvindex 78992b326..b822050d5 100644--- a/crates/ui-egui/src/i18n/uk.tsv+++ b/crates/ui-egui/src/i18n/uk.tsv@@ -2478,6 +2478,7 @@ cameraRaw Roughness Шорсткість# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Вибір кольору (колір тексту)+ Color Picker ({name}) Вибір кольору ({name})Color Picker (Fill Color) Вибір кольору (колір заливки)Fill color Колір заливкиColor Picker (Stroke Color) Вибір кольору (колір обведення)diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex d180b17f3..f89dc8a25 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -2236,6 +2236,7 @@ cameraRaw Blending 混合# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) 拾色器(文字颜色)+ Color Picker ({name}) 拾色器({name})Color Picker (Fill Color) 拾色器(填充颜色)Fill color 填充颜色Color Picker (Stroke Color) 拾色器(描边颜色)diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex 231b39cce..d82d854de 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -2205,6 +2205,7 @@ cameraRaw Blending 混合# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) 檢色器(文字顏色)+ Color Picker ({name}) 檢色器({name})Color Picker (Fill Color) 檢色器(填滿顏色)Fill color 填滿顏色Color Picker (Stroke Color) 檢色器(筆畫顏色)diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex e5e3c43b1..2395cf636 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1920,6 +1920,9 @@ impl PhotocraftApp {}}+#[cfg(test)]+mod color_swatch_tests;+#[cfg(test)]mod input_tests;diff --git a/crates/ui-egui/src/prefs_ui.rs b/crates/ui-egui/src/prefs_ui.rsindex ee0bb22f8..23649e728 100644--- a/crates/ui-egui/src/prefs_ui.rs+++ b/crates/ui-egui/src/prefs_ui.rs@@ -1047,6 +1047,10 @@ fn prefs_body(ui: &mut egui::Ui, f: &mut Map<String, Value>, system: Option<egui});f.insert("section".into(), json!(section));f.insert("values".into(), values);+ // A colour swatch was clicked: open the Color Picker on that value (#2144).+ if let Some((path, name)) = ctx_take_pick(ui) {+ crate::color_picker_ui::request_field(f, &format!("/values/{}", path.replace('.', "/")), &crate::color_picker_ui::title_for(&name));+ }}/// Preferences › Performance: what the app renders with now, and a reset of the GPU backend@@ -1234,6 +1238,15 @@ fn appearance_rows(ui: &mut egui::Ui, obj: &mut Map<String, Value>, system: Optiui.add_space(12.0);}+/// Where a clicked colour swatch leaves its preference path and label for the dialog body, which+/// holds the fields the Color Picker request goes in.+const PICK_ID: &str = "prefs-pick-color";++/// The colour swatch clicked this frame, if any: (preference path, label).+fn ctx_take_pick(ui: &egui::Ui) -> Option<(String, String)> {+ ui.ctx().data_mut(|d| d.remove_temp::<(String, String)>(egui::Id::new(PICK_ID)))+}+/// Generic editor for a section's fields: checkboxes, dropdowns for choices, colour swatches,/// number fields with the preference's range, text fields.fn section_fields(ui: &mut egui::Ui, section: &str, obj: &mut Map<String, Value>, order: &[String], lang: crate::i18n::Lang, system: Option<egui::Theme>) {@@ -1297,7 +1310,10 @@ fn section_fields(ui: &mut egui::Ui, section: &str, obj: &mut Map<String, Value>let c = prefs::parse_hex(s).unwrap_or([128, 128, 128]);let mut rgb = c;ui.horizontal(|ui| {- crate::widgets::color_edit_button_srgb(ui, &mut rgb);+ // PhotoCraft's Color Picker, as everywhere else (#2144).+ if crate::widgets::color_swatch_button(ui, egui::Color32::from_rgb(rgb[0], rgb[1], rgb[2]), &label).clicked() {+ ui.ctx().data_mut(|d| d.insert_temp(egui::Id::new(PICK_ID), (path.clone(), label.clone())));+ }hex_field(ui, &path, &mut rgb);});obj.insert(k, json!(format!("#{:02x}{:02x}{:02x}", rgb[0], rgb[1], rgb[2])));