PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Edit › Fill and Edit › Stroke: the colour opens the Color Picker (#2019)
kayrockscreenprinting1b8a68d45bc7
diff --git a/crates/ui-egui/src/color_picker_ui.rs b/crates/ui-egui/src/color_picker_ui.rsindex b8cfb98ab..c5b8b6fbe 100644--- a/crates/ui-egui/src/color_picker_ui.rs+++ b/crates/ui-egui/src/color_picker_ui.rs@@ -199,6 +199,42 @@ pub fn open_for_command(app: &mut PhotocraftApp, label: &str, rgb: [f32; 3], comapp.ui.open_dialog(DialogKind::Command, f)}+/// Open the picker on `rgb` for a colour field of another dialog (e.g. Edit › Fill's Color…): OK+/// writes `"#rrggbb"` into `field` of dialog `dialog`, which stays open; Cancel leaves it alone.+pub fn open_for_field(app: &mut PhotocraftApp, label: &str, rgb: [f32; 3], dialog: u64, field: &str) -> u64 {+ let hsv = rgb_to_hsv(rgb);+ let mut f = Map::new();+ f.insert("__colorPicker".into(), json!("field"));+ f.insert("__label".into(), json!(label));+ f.insert("__dialog".into(), json!(dialog));+ f.insert("__field".into(), json!(field));+ f.insert("color".into(), json!(hex(rgb)));+ f.insert("__orig".into(), json!(hex(rgb)));+ f.insert("__hsv".into(), json!(hsv));+ f.insert("__mode".into(), json!("h"));+ f.insert("__webOnly".into(), json!(false));+ app.ui.open_dialog(DialogKind::Command, f)+}++/// Set by a dialog body (to the picker's title) to open the Color Picker on its `color` field.+const REQUEST: &str = "__pickColor";++/// A dialog body asks for the Color Picker on its `color` field (Edit › Fill's Color… and colour+/// 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));+}++/// 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.+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");+}+pub fn owns(f: &Map<String, Value>) -> bool {f.contains_key("__colorPicker")}@@ -597,6 +633,14 @@ pub fn confirm(app: &mut PhotocraftApp, f: &Map<String, Value>) -> Result<Value,p["color"] = json!(color);return app.run(cmd, p);}+ if target == "field" {+ let (Some(dialog), Some(field)) = (f.get("__dialog").and_then(Value::as_u64), f.get("__field").and_then(Value::as_str)) else {+ 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));+ return Ok(json!({ "color": color }));+ }let r = app.run("tools.setColors", json!({ target: color }))?;if target == "foreground" {crate::type_tool::foreground_changed(app);diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 24e7ce0dc..6383115b6 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -298,6 +298,10 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {if let Some(dm) = app.ui.dialog_mut(d.id) {dm.fields = fields;}+ // A colour swatch (Edit › Fill, Edit › Stroke) opens the Color Picker over the dialog.+ if outcome.is_none() {+ crate::color_picker_ui::open_requested(app, d.id);+ }if apply_requested && outcome.is_none() {let _ = crate::prefs_ui::apply(app, d.id);}diff --git a/crates/ui-egui/src/fill_ui.rs b/crates/ui-egui/src/fill_ui.rsindex 284430bb4..c44c4b577 100644--- a/crates/ui-egui/src/fill_ui.rs+++ b/crates/ui-egui/src/fill_ui.rs@@ -138,15 +138,20 @@ pub fn body(app: &PhotocraftApp, ui: &mut egui::Ui, f: &mut Map<String, Value>)let opts: Vec<(String, &str)> = CONTENTS.iter().map(|(k, l)| (k.to_string(), *l)).collect();if crate::widgets::dropdown(ui, "fill-contents", &mut contents, &opts, 170.0) {f.insert("contents".into(), json!(contents));+ // Choosing Color… opens the Color Picker, as in Photoshop.+ if contents == "color" {+ crate::color_picker_ui::request(f, tl!("Color Picker (Fill Color)"));+ }}});match contents.as_str() {"color" => {ui.horizontal(|ui| {label(ui, tl!("Color:"));- let mut rgb = parse_hex(&get_str(f, "color", "#000000"));- if crate::widgets::color_edit_button_srgb(ui, &mut rgb).changed() {- f.insert("color".into(), json!(format!("#{:02x}{:02x}{:02x}", rgb[0], rgb[1], rgb[2])));+ // Photoshop shows no swatch; this one reopens the Color Picker on the colour.+ let rgb = parse_hex(&get_str(f, "color", "#000000"));+ if crate::widgets::color_swatch_button(ui, egui::Color32::from_rgb(rgb[0], rgb[1], rgb[2]), tl!("Fill color")).clicked() {+ crate::color_picker_ui::request(f, tl!("Color Picker (Fill Color)"));}});}diff --git a/crates/ui-egui/src/fill_ui_tests.rs b/crates/ui-egui/src/fill_ui_tests.rsindex 47dcd8f04..ce2582c3e 100644--- a/crates/ui-egui/src/fill_ui_tests.rs+++ b/crates/ui-egui/src/fill_ui_tests.rs@@ -161,6 +161,80 @@ fn menu_opens_the_dialog_and_params_skip_it() {assert!(empty.ui.dialogs.is_empty());}+/// The open Fill dialog's id and the top Color Picker, if one is open.+fn fill_and_picker(h: &Harness<'_, PhotocraftApp>) -> (u64, Option<u64>) {+ let app = h.state();+ let fill = app.ui.dialogs.iter().find(|d| owns(&d.fields)).map(|d| d.id).expect("the Fill dialog is open");+ (fill, crate::color_picker_ui::top(app))+}++fn field(h: &Harness<'_, PhotocraftApp>, id: u64, key: &str) -> Value {+ h.state().ui.dialogs.iter().find(|d| d.id == id).and_then(|d| d.fields.get(key).cloned()).unwrap_or(Value::Null)+}++/// Contents › Color… opens PhotoCraft's Color Picker on the dialog's colour (as Photoshop's Fill+/// does), and its OK sets the Fill colour, not the foreground; Fill then fills with it.+#[test]+fn choosing_color_opens_the_color_picker() {+ use egui_kittest::kittest::Queryable;+ let mut h = harness();+ h.state_mut().run("tools.setColors", json!({"foreground": "#ff0000", "background": "#0000ff"})).unwrap();+ let ctx = h.ctx.clone();+ crate::menus::invoke(h.state_mut(), &ctx, COMMAND, json!({})).unwrap();+ h.run_steps(3);+ assert_eq!(fill_and_picker(&h).1, None, "no picker before Color… is chosen");+ // The Contents dropdown shows its choice as the combo box's value.+ h.get_by_value("Foreground Color").click();+ h.run_steps(3);+ h.get_by_label("Color…").click();+ h.run_steps(4);+ let (fill, picker) = fill_and_picker(&h);+ assert_eq!(field(&h, fill, "contents"), json!("color"));+ let picker = picker.expect("Color… opens the Color Picker");+ assert_eq!(field(&h, picker, "color"), json!("#ff0000"), "on the dialog's colour (the foreground at first)");+ assert_eq!(field(&h, picker, "__label"), json!("Color Picker (Fill Color)"));+ // OK sets the Fill colour; the Fill dialog stays open and the tool colours are untouched.+ h.state_mut().ui.dialog_mut(picker).unwrap().fields.insert("color".into(), json!("#336699"));+ crate::dialogs::confirm(h.state_mut(), picker).unwrap();+ h.run_steps(3);+ assert_eq!(fill_and_picker(&h), (fill, None));+ assert_eq!(field(&h, fill, "color"), json!("#336699"));+ assert_eq!(h.state().session.tools.foreground, [1.0, 0.0, 0.0, 1.0]);+ crate::dialogs::confirm(h.state_mut(), fill).unwrap();+ let st = h.state().session.active().unwrap();+ let c = st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap().rgba(5, 5);+ assert!(close(c, [0x33 as f32 / 255.0, 0x66 as f32 / 255.0, 0x99 as f32 / 255.0, 1.0]), "{c:?}");+}++/// The Fill dialog keeps its colour swatch (Photoshop shows none), and clicking it opens the real+/// Color Picker, not a small popup. Cancel keeps Contents on Color… and the colour unchanged.+#[test]+fn the_color_swatch_opens_the_color_picker() {+ use egui_kittest::kittest::Queryable;+ let mut h = harness();+ let ctx = h.ctx.clone();+ let id = crate::menus::invoke(h.state_mut(), &ctx, COMMAND, json!({})).unwrap()["dialog"].as_u64().unwrap();+ {+ let f = &mut h.state_mut().ui.dialog_mut(id).unwrap().fields;+ f.insert("contents".into(), json!("color"));+ f.insert("color".into(), json!("#20a040"));+ }+ h.run_steps(3);+ assert_eq!(fill_and_picker(&h).1, None, "setting the field (automation) opens nothing");+ h.get_by_label("Fill color").click();+ h.run_steps(4);+ let picker = fill_and_picker(&h).1.expect("the swatch opens the Color Picker");+ assert_eq!(field(&h, picker, "color"), json!("#20a040"));+ assert!(!egui::Popup::is_any_open(&h.ctx), "no egui colour popup");+ // Cancel: the Fill dialog is unchanged.+ h.state_mut().ui.dialog_mut(picker).unwrap().fields.insert("color".into(), json!("#000000"));+ h.state_mut().ui.close_dialog(picker);+ h.run_steps(3);+ assert_eq!(fill_and_picker(&h), (id, None));+ assert_eq!(field(&h, id, "contents"), json!("color"));+ assert_eq!(field(&h, id, "color"), json!("#20a040"));+}+#[test]fn the_pattern_is_picked_from_its_swatches() {// The Custom Pattern was a dropdown of names; Photoshop shows the pattern itself and opens a griddiff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex 61af02a95..d15b3c27a 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -2182,6 +2182,10 @@ cameraRaw Color Barvy# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Výběr barvy (Barva textu)+ 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)+ Stroke color Barva tahuPick screen color Vybrat barvu obrazovkySample a pixel anywhere on the screen Vzorkovat pixel kdekoli na obrazovceClick to pick · Esc to cancel Kliknutí vybere · Esc zrušídiff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex 63a5db24a..6e05025b5 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -2220,6 +2220,10 @@# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Farbwähler (Textfarbe)+ Color Picker (Fill Color) Farbwähler (Füllfarbe)+ Fill color Füllfarbe+ Color Picker (Stroke Color) Farbwähler (Konturfarbe)+ Stroke color KonturfarbePick screen color Bildschirmfarbe auswählenSample a pixel anywhere on the screen Ein Pixel an beliebiger Stelle auf dem Bildschirm auswählenClick to pick · Esc to cancel Klicken zum Auswählen · Esc zum Abbrechendiff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsvindex 6beeed130..2ba8fcf1e 100644--- a/crates/ui-egui/src/i18n/el.tsv+++ b/crates/ui-egui/src/i18n/el.tsv@@ -269,6 +269,10 @@Foreground ΠροσκήνιοBackground ΦόντοColor Picker Επιλογέας χρώματος+ Color Picker (Fill Color) Επιλογέας χρώματος (Χρώμα γεμίσματος)+ Fill color Χρώμα γεμίσματος+ Color Picker (Stroke Color) Επιλογέας χρώματος (Χρώμα περιγράμματος)+ Stroke color Χρώμα περιγράμματοςColor Swatches Δείγματα χρωμάτωνAngle ΓωνίαScale Κλίμακαdiff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex 3c9cf28f7..8d47e2c87 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -2251,6 +2251,10 @@ cameraRaw Amount Cantidad# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Selector de color (Color del texto)+ Color Picker (Fill Color) Selector de color (Color de relleno)+ Fill color Color de relleno+ Color Picker (Stroke Color) Selector de color (Color del trazo)+ Stroke color Color del trazoPick screen color Elegir color de pantallaSample a pixel anywhere on the screen Tomar un píxel en cualquier lugar de la pantallaClick to pick · Esc to cancel Clic para elegir · Esc para cancelardiff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex d6e9056c0..d726d11ed 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -2608,6 +2608,10 @@ cameraRaw Blending Fusion# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Sélecteur de couleurs (Couleur du texte)+ Color Picker (Fill Color) Sélecteur de couleurs (Couleur de remplissage)+ Fill color Couleur de remplissage+ Color Picker (Stroke Color) Sélecteur de couleurs (Couleur du contour)+ Stroke color Couleur du contourPick screen color Choisir une couleur à l’écranSample a pixel anywhere on the screen Prélever un pixel n’importe où sur l’écranClick to pick · Esc to cancel Cliquer pour choisir · Échap pour annulerdiff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsvindex 63e687324..6a710ec17 100644--- a/crates/ui-egui/src/i18n/id.tsv+++ b/crates/ui-egui/src/i18n/id.tsv@@ -2595,6 +2595,10 @@ cameraRaw Blending Pembauran# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Pemilih Warna (Warna Teks)+ Color Picker (Fill Color) Pemilih Warna (Warna Isian)+ Fill color Warna isian+ Color Picker (Stroke Color) Pemilih Warna (Warna Stroke)+ Stroke color Warna strokePick screen color Pilih warna layarSample a pixel anywhere on the screen Ambil sampel piksel di mana saja pada layarClick to pick · Esc to cancel Klik untuk memilih · Esc untuk membatalkandiff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex 996b923aa..001319973 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -2254,6 +2254,10 @@ cameraRaw Amount Quantità# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Selettore colore (Colore del testo)+ Color Picker (Fill Color) Selettore colore (Colore di riempimento)+ Fill color Colore di riempimento+ Color Picker (Stroke Color) Selettore colore (Colore della traccia)+ Stroke color Colore della tracciaPick screen color Scegli colore dallo schermoSample a pixel anywhere on the screen Campiona un pixel in qualsiasi punto dello schermoClick to pick · Esc to cancel Clic per scegliere · Esc per annullarediff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex c6af57508..75266fd88 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -2163,6 +2163,10 @@ cameraRaw Color カラー# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) カラーピッカー(文字色)+ Color Picker (Fill Color) カラーピッカー(塗りつぶしカラー)+ Fill color 塗りつぶしカラー+ Color Picker (Stroke Color) カラーピッカー(線のカラー)+ Stroke color 線のカラーPick screen color 画面の色を選択Sample a pixel anywhere on the screen 画面上の任意のピクセルから色を取得Click to pick · Esc to cancel クリックで選択 · Escでキャンセルdiff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsvindex 3765ba584..5bd32ca91 100644--- a/crates/ui-egui/src/i18n/ko.tsv+++ b/crates/ui-egui/src/i18n/ko.tsv@@ -2768,6 +2768,10 @@ cameraRaw Color 색상# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) 색상 선택기 (텍스트 색상)+ Color Picker (Fill Color) 색상 선택기 (채우기 색상)+ Fill color 채우기 색상+ Color Picker (Stroke Color) 색상 선택기 (획 색상)+ Stroke color 획 색상Pick screen color 화면 색상 선택Sample a pixel anywhere on the screen 화면의 아무 픽셀에서 색상 추출Click to pick · Esc to cancel 클릭하여 선택 · Esc로 취소diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsvindex 5e0090469..120b8a599 100644--- a/crates/ui-egui/src/i18n/nl.tsv+++ b/crates/ui-egui/src/i18n/nl.tsv@@ -2200,6 +2200,10 @@Knockout UitsparingApply At Canvas Bounds Toepassen op canvasgrenzenColor Picker (Text Color) Kleurkiezer (tekstkleur)+ Color Picker (Fill Color) Kleurkiezer (vulkleur)+ Fill color Vulkleur+ Color Picker (Stroke Color) Kleurkiezer (lijnkleur)+ Stroke color LijnkleurPick screen color Schermkleur kiezenSample a pixel anywhere on the screen Een pixel ergens op het scherm bemonsterenClick to pick · Esc to cancel Klik om te kiezen · Esc om te annulerendiff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsvindex 9717c131e..f480c9a60 100644--- a/crates/ui-egui/src/i18n/pl.tsv+++ b/crates/ui-egui/src/i18n/pl.tsv@@ -3199,6 +3199,10 @@ cameraRaw Roughness Chropowatość# Text Color Picker and screen samplingColor Picker (Text Color) Próbnik kolorów (Kolor tekstu)+ Color Picker (Fill Color) Próbnik kolorów (Kolor wypełnienia)+ Fill color Kolor wypełnienia+ Color Picker (Stroke Color) Próbnik kolorów (Kolor obrysu)+ Stroke color Kolor obrysuPick screen color Wybierz kolor z ekranuSample a pixel anywhere on the screen Pobierz kolor piksela w dowolnym miejscu ekranuClick to pick · Esc to cancel Kliknij, aby wybrać · Esc, aby anulowaćdiff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex e396ef933..e6a6e27db 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -2615,6 +2615,10 @@ cameraRaw Whites Brancos# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Seletor de cores (Cor do texto)+ Color Picker (Fill Color) Seletor de cores (Cor de preenchimento)+ Fill color Cor de preenchimento+ Color Picker (Stroke Color) Seletor de cores (Cor do traçado)+ Stroke color Cor do traçadoPick screen color Escolher cor da telaSample a pixel anywhere on the screen Amostrar um pixel em qualquer lugar da telaClick to pick · Esc to cancel Clique para escolher · Esc para cancelardiff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex 57ee82a5c..7f6baef25 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -2457,6 +2457,10 @@ cameraRaw Roughness Неровность# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Палитра цветов (Цвет текста)+ Color Picker (Fill Color) Палитра цветов (Цвет заливки)+ Fill color Цвет заливки+ Color Picker (Stroke Color) Палитра цветов (Цвет обводки)+ Stroke color Цвет обводкиPick screen color Выбрать цвет на экранеSample a pixel anywhere on the screen Выберите пиксель в любом месте экранаClick to pick · Esc to cancel Щелчок — выбрать · Esc — отменитьdiff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsvindex a9af379f2..0e3ed88ef 100644--- a/crates/ui-egui/src/i18n/uk.tsv+++ b/crates/ui-egui/src/i18n/uk.tsv@@ -2445,6 +2445,10 @@ cameraRaw Roughness Шорсткість# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) Вибір кольору (колір тексту)+ Color Picker (Fill Color) Вибір кольору (колір заливки)+ Fill color Колір заливки+ Color Picker (Stroke Color) Вибір кольору (колір обведення)+ Stroke color Колір обведенняPick screen color Вибрати колір з екранаSample a pixel anywhere on the screen Взяти зразок пікселя будь-де на екраніClick to pick · Esc to cancel Клацніть для вибору · Esc для скасуванняdiff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex c79d4536b..9c04f9fb9 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -2190,6 +2190,10 @@ cameraRaw Blending 混合# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) 拾色器(文字颜色)+ Color Picker (Fill Color) 拾色器(填充颜色)+ Fill color 填充颜色+ Color Picker (Stroke Color) 拾色器(描边颜色)+ Stroke color 描边颜色Pick screen color 选取屏幕颜色Sample a pixel anywhere on the screen 在屏幕任意位置采样像素Click to pick · Esc to cancel 单击选取 · Esc 取消diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex c4b2308ef..7c6e52bf5 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -2159,6 +2159,10 @@ cameraRaw Blending 混合# Shared screen eyedropper and text Color Picker (#1128).Color Picker (Text Color) 檢色器(文字顏色)+ Color Picker (Fill Color) 檢色器(填滿顏色)+ Fill color 填滿顏色+ Color Picker (Stroke Color) 檢色器(筆畫顏色)+ Stroke color 筆畫顏色Pick screen color 選取螢幕顏色Sample a pixel anywhere on the screen 在螢幕任意位置取樣像素Click to pick · Esc to cancel 按一下選取 · Esc 取消diff --git a/crates/ui-egui/src/stroke_ui.rs b/crates/ui-egui/src/stroke_ui.rsindex 76acbbaad..e910887fc 100644--- a/crates/ui-egui/src/stroke_ui.rs+++ b/crates/ui-egui/src/stroke_ui.rs@@ -91,9 +91,10 @@ pub fn body(ui: &mut egui::Ui, f: &mut Map<String, Value>) {ui.horizontal(|ui| {label(ui, tl!("Color:"));let current = f.get("color").and_then(Value::as_str).unwrap_or("#000000");- let mut rgb = [1usize, 3, 5].map(|i| current.get(i..i + 2).and_then(|b| u8::from_str_radix(b, 16).ok()).unwrap_or(0));- if egui::color_picker::color_edit_button_srgb(ui, &mut rgb).changed() {- f.insert("color".into(), json!(format!("#{:02x}{:02x}{:02x}", rgb[0], rgb[1], rgb[2])));+ let rgb = [1usize, 3, 5].map(|i| current.get(i..i + 2).and_then(|b| u8::from_str_radix(b, 16).ok()).unwrap_or(0));+ // As in Photoshop, the swatch opens the Color Picker on the stroke colour.+ if crate::widgets::color_swatch_button(ui, egui::Color32::from_rgb(rgb[0], rgb[1], rgb[2]), tl!("Stroke color")).clicked() {+ crate::color_picker_ui::request(f, tl!("Color Picker (Stroke Color)"));}});diff --git a/crates/ui-egui/src/stroke_ui_tests.rs b/crates/ui-egui/src/stroke_ui_tests.rsindex 0d673d2a5..b79306c3a 100644--- a/crates/ui-egui/src/stroke_ui_tests.rs+++ b/crates/ui-egui/src/stroke_ui_tests.rs@@ -149,3 +149,39 @@ fn stroke_dialog_labels_are_translated_in_every_catalog() {}}}++/// The Stroke dialog's colour swatch opens PhotoCraft's Color Picker on the stroke colour (as in+/// Photoshop), not egui's compact popup; OK sets the stroke colour, not the foreground, and the+/// stroke is drawn in it.+#[test]+fn the_color_swatch_opens_the_color_picker() {+ use egui_kittest::Harness;+ use egui_kittest::kittest::Queryable;+ let mut h = Harness::builder().with_size(egui::vec2(1280.0, 800.0)).with_max_steps(64).build_eframe(|cc| {+ PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());+ app()+ });+ h.run_steps(6);+ h.state_mut().run("select.rect", json!({"x": 10, "y": 10, "width": 10, "height": 10})).unwrap();+ let ctx = h.ctx.clone();+ let id = crate::menus::invoke(h.state_mut(), &ctx, COMMAND, json!({})).unwrap()["dialog"].as_u64().unwrap();+ h.state_mut().ui.dialog_mut(id).unwrap().fields.insert("color".into(), json!("#20a040"));+ h.run_steps(3);+ assert_eq!(crate::color_picker_ui::top(h.state()), None);+ h.get_by_label("Stroke color").click();+ h.run_steps(4);+ let picker = crate::color_picker_ui::top(h.state()).expect("the swatch opens the Color Picker");+ let field = |h: &Harness<'_, PhotocraftApp>, d: u64, k: &str| h.state().ui.dialogs.iter().find(|x| x.id == d).and_then(|x| x.fields.get(k).cloned());+ assert_eq!(field(&h, picker, "color"), Some(json!("#20a040")));+ assert_eq!(field(&h, picker, "__label"), Some(json!("Color Picker (Stroke Color)")));+ assert!(!egui::Popup::is_any_open(&h.ctx), "no egui colour popup");+ h.state_mut().ui.dialog_mut(picker).unwrap().fields.insert("color".into(), json!("#0000ff"));+ crate::dialogs::confirm(h.state_mut(), picker).unwrap();+ h.run_steps(3);+ assert_eq!(crate::color_picker_ui::top(h.state()), None);+ assert_eq!(field(&h, id, "color"), Some(json!("#0000ff")));+ assert_eq!(h.state().session.tools.foreground, [1.0, 0.0, 0.0, 1.0], "the foreground is untouched");+ crate::dialogs::confirm(h.state_mut(), id).unwrap();+ let p = pixel(h.state(), 10, 15);+ assert!(p[2] > 0.98 && p[0] < 0.02, "stroked in the picked colour: {p:?}");+}diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rsindex f1371c888..dc9e38d57 100644--- a/crates/ui-egui/src/widgets.rs+++ b/crates/ui-egui/src/widgets.rs@@ -1500,6 +1500,17 @@ fn color_swatch(ui: &mut Ui, color: Color32) -> Response {ui.painter().rect_stroke(rect, t.radius_sm, Stroke::new(1.0, t.field_border), StrokeKind::Inside);response}+/// A colour swatch that only reports clicks (no popup): for colours edited in PhotoCraft's own+/// Color Picker dialog. `label` names it for hover text and accessibility.+pub fn color_swatch_button(ui: &mut Ui, color: Color32, label: &str) -> Response {+ let t = Tokens::get(ui.ctx());+ let (rect, response) = ui.allocate_exact_size(ui.spacing().interact_size, Sense::click());+ response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::ColorButton, true, label));+ checker(ui.painter(), rect, 4.0);+ ui.painter().rect_filled(rect.shrink(1.0), t.radius_sm, color);+ ui.painter().rect_stroke(rect, t.radius_sm, Stroke::new(1.0, t.field_border), StrokeKind::Inside);+ response.on_hover_text(label)+}fn color_edit_button(ui: &mut Ui, color: &mut Color32, alpha: egui::color_picker::Alpha) -> Response {let mut response = color_swatch(ui, *color);let id = response.id.with("screen-color");