mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Edit › Fill and Edit › Stroke: the colour opens the Color Picker (#2019)
* Edit > Fill: Color... and its swatch open the Color Picker Choosing Contents: Color... opens PhotoCraft's Color Picker (as Photoshop's Fill does), and the colour swatch opens it too instead of egui's compact popup. OK sets the Fill colour, not the foreground; Cancel leaves it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Edit > Stroke: the colour swatch opens the Color Picker A dialog body asks for the Color Picker on its colour field with color_picker_ui::request; Fill and Stroke share it. OK sets the dialog's colour, not the foreground. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude <[email protected]>
This commit is contained in:
1 parent
51f9abaad7
commit
1b8a68d45b
23 files changed
+245
-6
No files matched your search
@@ -199,6 +199,42 @@ pub fn open_for_command(app: &mut PhotocraftApp, label: &str, rgb: [f32; 3], com
|
||||
app.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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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 grid
|
||||
|
||||
@@ -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 tahu
|
||||
Pick screen color Vybrat barvu obrazovky
|
||||
Sample a pixel anywhere on the screen Vzorkovat pixel kdekoli na obrazovce
|
||||
Click to pick · Esc to cancel Kliknutí vybere · Esc zruší
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -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 Konturfarbe
|
||||
Pick screen color Bildschirmfarbe auswählen
|
||||
Sample a pixel anywhere on the screen Ein Pixel an beliebiger Stelle auf dem Bildschirm auswählen
|
||||
Click to pick · Esc to cancel Klicken zum Auswählen · Esc zum Abbrechen
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -269,6 +269,10 @@
|
||||
Foreground Προσκήνιο
|
||||
Background Φόντο
|
||||
Color Picker Επιλογέας χρώματος
|
||||
Color Picker (Fill Color) Επιλογέας χρώματος (Χρώμα γεμίσματος)
|
||||
Fill color Χρώμα γεμίσματος
|
||||
Color Picker (Stroke Color) Επιλογέας χρώματος (Χρώμα περιγράμματος)
|
||||
Stroke color Χρώμα περιγράμματος
|
||||
Color Swatches Δείγματα χρωμάτων
|
||||
Angle Γωνία
|
||||
Scale Κλίμακα
|
||||
|
||||
|
@@ -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 trazo
|
||||
Pick screen color Elegir color de pantalla
|
||||
Sample a pixel anywhere on the screen Tomar un píxel en cualquier lugar de la pantalla
|
||||
Click to pick · Esc to cancel Clic para elegir · Esc para cancelar
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 4 and column 47.
|
@@ -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 contour
|
||||
Pick screen color Choisir une couleur à l’écran
|
||||
Sample a pixel anywhere on the screen Prélever un pixel n’importe où sur l’écran
|
||||
Click to pick · Esc to cancel Cliquer pour choisir · Échap pour annuler
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -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 stroke
|
||||
Pick screen color Pilih warna layar
|
||||
Sample a pixel anywhere on the screen Ambil sampel piksel di mana saja pada layar
|
||||
Click to pick · Esc to cancel Klik untuk memilih · Esc untuk membatalkan
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 4 and column 47.
|
@@ -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 traccia
|
||||
Pick screen color Scegli colore dallo schermo
|
||||
Sample a pixel anywhere on the screen Campiona un pixel in qualsiasi punto dello schermo
|
||||
Click to pick · Esc to cancel Clic per scegliere · Esc per annullare
|
||||
|
||||
|
@@ -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でキャンセル
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -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로 취소
|
||||
|
||||
|
@@ -2200,6 +2200,10 @@
|
||||
Knockout Uitsparing
|
||||
Apply At Canvas Bounds Toepassen op canvasgrenzen
|
||||
Color Picker (Text Color) Kleurkiezer (tekstkleur)
|
||||
Color Picker (Fill Color) Kleurkiezer (vulkleur)
|
||||
Fill color Vulkleur
|
||||
Color Picker (Stroke Color) Kleurkiezer (lijnkleur)
|
||||
Stroke color Lijnkleur
|
||||
Pick screen color Schermkleur kiezen
|
||||
Sample a pixel anywhere on the screen Een pixel ergens op het scherm bemonsteren
|
||||
Click to pick · Esc to cancel Klik om te kiezen · Esc om te annuleren
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 8 and column 34.
|
@@ -3199,6 +3199,10 @@ cameraRaw Roughness Chropowatość
|
||||
|
||||
# Text Color Picker and screen sampling
|
||||
Color 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 obrysu
|
||||
Pick screen color Wybierz kolor z ekranu
|
||||
Sample a pixel anywhere on the screen Pobierz kolor piksela w dowolnym miejscu ekranu
|
||||
Click to pick · Esc to cancel Kliknij, aby wybrać · Esc, aby anulować
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -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çado
|
||||
Pick screen color Escolher cor da tela
|
||||
Sample a pixel anywhere on the screen Amostrar um pixel em qualquer lugar da tela
|
||||
Click to pick · Esc to cancel Clique para escolher · Esc para cancelar
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -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 — отменить
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -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 для скасування
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 1305 and column 18.
|
@@ -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 取消
|
||||
|
||||
|
@@ -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 取消
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -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)"));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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:?}");
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
Reference in new issue
Block a user