From bf8c08e2a1f20aba0182985c08e37a6a21b5385d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 04:50:45 -0800 Subject: [PATCH] Recolor Artwork: the Edit tab's wheel can show brightness and hue A button under the Add Color and Remove Color tools switches both Edit tab wheels between hue with saturation and hue with brightness. On the brightness wheel a marker's distance from the center is its brightness (black at the center, full at the edge), a drag sets hue and brightness, the slider under the wheel edits saturation, and Add Color adds the hue and brightness clicked at the base color's saturation. The segmented wheel's five rings become brightness steps. Switching changes no color, the button is off for the color bars, and each opening shows hue and saturation. The dialog field is `wheelAxes` (`hueSaturation`, `hueBrightness`). --- crates/ui-egui/src/dialogs/recolor.rs | 83 +++++++++++--- crates/ui-egui/src/i18n/bg.tsv | 2 + crates/ui-egui/src/i18n/bs.tsv | 2 + crates/ui-egui/src/i18n/ca.tsv | 2 + crates/ui-egui/src/i18n/cs.tsv | 2 + crates/ui-egui/src/i18n/da.tsv | 2 + crates/ui-egui/src/i18n/de.tsv | 2 + crates/ui-egui/src/i18n/el.tsv | 2 + crates/ui-egui/src/i18n/es.tsv | 2 + crates/ui-egui/src/i18n/fi.tsv | 2 + crates/ui-egui/src/i18n/fr.tsv | 2 + crates/ui-egui/src/i18n/gu.tsv | 2 + crates/ui-egui/src/i18n/hi.tsv | 2 + crates/ui-egui/src/i18n/hu.tsv | 2 + crates/ui-egui/src/i18n/id.tsv | 2 + crates/ui-egui/src/i18n/it.tsv | 2 + crates/ui-egui/src/i18n/ja.tsv | 2 + crates/ui-egui/src/i18n/ka.tsv | 2 + crates/ui-egui/src/i18n/ko.tsv | 2 + crates/ui-egui/src/i18n/nl.tsv | 2 + crates/ui-egui/src/i18n/pl.tsv | 2 + crates/ui-egui/src/i18n/pt-br.tsv | 2 + crates/ui-egui/src/i18n/ru.tsv | 2 + crates/ui-egui/src/i18n/sv.tsv | 2 + crates/ui-egui/src/i18n/tr.tsv | 2 + crates/ui-egui/src/i18n/uk.tsv | 2 + crates/ui-egui/src/i18n/vi.tsv | 2 + crates/ui-egui/src/i18n/zh-hans.tsv | 2 + crates/ui-egui/src/i18n/zh-hant.tsv | 2 + crates/ui-egui/src/tests/recolor.rs | 156 +++++++++++++++++++++++++- crates/ui-egui/src/widgets.rs | 6 +- crates/ui-egui/src/widgets/color.rs | 137 ++++++++++++++++------ docs/control-protocol.md | 6 +- docs/target-app-parity.md | 1 + 34 files changed, 388 insertions(+), 57 deletions(-) diff --git a/crates/ui-egui/src/dialogs/recolor.rs b/crates/ui-egui/src/dialogs/recolor.rs index e617c1710f..ae49d90a87 100644 --- a/crates/ui-egui/src/dialogs/recolor.rs +++ b/crates/ui-egui/src/dialogs/recolor.rs @@ -30,7 +30,11 @@ //! Remove Color tool removes the color whose marker is clicked; a bar's right-click menu has Remove //! Color too. The base color can't be removed. A removed color's row goes, unless it has current //! colors and art or a group is open: it then keeps them, with no new color, so that art keeps its -//! colors and the group's swatch at that place goes. With art, the Prominent Colors bar under the wheel shows the new +//! colors and the group's swatch at that place goes. Under the tools, a button switches both wheels +//! to hue and brightness (black at the center, full brightness at the edge, at the base color's +//! saturation; a marker drag sets hue and brightness, Add Color adds the hue and brightness clicked +//! at the base color's saturation, and the slider under the wheel is a Saturation slider) and back; +//! switching changes no color, and the dialog opens on hue and saturation. With art, the Prominent Colors bar under the wheel shows the new //! colors, each part as wide as its row's share of the art's uses, the largest first; dragging the //! edge between two parts moves width between them, and when the drag ends the rows' current //! colors move toward those widths (`recolor.weigh`), and the art previews them. The New Color @@ -60,7 +64,8 @@ //! (`{saturation, brightness, temperature, luminosity}` in percent, sent as `recolor.apply`'s //! `globalAdjust` in every slider mode), `display` (the Edit tab's `smooth`, `segmented` or `bars`; //! unset: `smooth`), `wheelTool` (`add`: the Add Color tool, `remove`: the Remove Color tool; -//! unset: neither, a click on the wheel selects a marker), `themePicker` (the Color Theme Picker is on), `themePicks` (its picks, as +//! unset: neither, a click on the wheel selects a marker), `wheelAxes` (`hueBrightness`: the wheels +//! show hue and brightness; `hueSaturation`, unset or any other value: hue and saturation), `themePicker` (the Color Theme Picker is on), `themePicks` (its picks, as //! `recolor.pickTheme`'s `picks`; a new list recolors the rows), `weights` (one per row, as //! `recolor.weigh`'s; a new list moves the rows' current colors toward them), `findColors` (Find is //! on; it shows the art so on the Assign tab, with art and rows selected). Changing `colors`, a @@ -1446,12 +1451,27 @@ const DRAG: &str = "__drag"; /// The field of the Edit tab's wheel tools: `add` (Add Color) or `remove` (Remove Color). const WHEEL_TOOL: &str = "wheelTool"; -/// The new color the Add Color tool gives a click at hue `h` (degrees) and saturation `s`: at the -/// brightness of `base` (the base color, whose brightness the wheel shows; full without one), the -/// segmented wheel's patch color with `segmented`, in `base`'s model. -fn added_color(base: Option, h: f32, s: f32, segmented: bool) -> Color { - let v = base.map_or(1.0, |b| b.to_hsb()[2]); - let c = if segmented { widgets::segment_color(h, s, v) } else { Color::from_hsb(h, s, v) }; +/// The field of what the Edit tab's wheels show: `hueBrightness` (hue and brightness), or anything +/// else (hue and saturation). +const WHEEL_AXES: &str = "wheelAxes"; + +/// What the Edit tab's wheels show, from [`WHEEL_AXES`]. +fn wheel_axes(d: &Dialog) -> widgets::WheelAxes { + if d.str(WHEEL_AXES) == "hueBrightness" { widgets::WheelAxes::HueBrightness } else { widgets::WheelAxes::HueSaturation } +} + +/// The new color the Add Color tool gives a click at hue `h` (degrees) and `t`, the saturation (or +/// with [`widgets::WheelAxes::HueBrightness`] the brightness) clicked: with the other component of +/// `base` (the base color, whose other component the wheel shows; full without one), the segmented +/// wheel's patch color with `segmented`, in `base`'s model. +fn added_color(base: Option, h: f32, t: f32, segmented: bool, axes: widgets::WheelAxes) -> Color { + let o = base.map_or(1.0, |b| b.to_hsb()[axes.other()]); + let c = if segmented { + widgets::segment_color_on(axes, h, t, o) + } else { + let [h, s, v] = axes.hsb(h, t, o); + Color::from_hsb(h, s, v) + }; base.map_or(c, |b| keep_model(b, c)) } @@ -1552,6 +1572,7 @@ fn edit_tab(app: &VectorcraftApp, ui: &mut Ui, d: &mut Dialog, rows: &mut Vec w = widgets::segmented_wheel(ui, "recolor-wheel", WHEEL, &colors, marked), "bars" => changed |= color_bars(ui, d, rows, &active, base), - _ => w = widgets::harmony_wheel(ui, "recolor-wheel", WHEEL, &colors, marked), + _ => w = widgets::wheel_of(ui, "recolor-wheel", WHEEL, &colors, marked, display == "segmented", axes), }); }); // A click with a wheel tool adds a color there, or removes the color of the marker clicked. let clicked = w.clicked.filter(|_| on_wheel && matches!(tool.as_str(), "add" | "remove")); - if let Some((hit, [h, s])) = clicked { + if let Some((hit, [h, out])) = clicked { if tool == "add" { - let c = added_color(base.and_then(|b| to_color(&rows[b])), h, s, display == "segmented"); + let c = added_color(base.and_then(|b| to_color(&rows[b])), h, out, display == "segmented", axes); let i = add_color(rows, &c); d.fields.insert("__sel".into(), json!([i])); d.fields.remove(COMPS); @@ -1839,12 +1867,35 @@ mod tests { #[test] fn an_added_color_takes_the_base_colors_brightness_and_model() { let near = |a: [f32; 3], b: [f32; 3]| a.iter().zip(b).all(|(x, y)| (x - y).abs() < 1e-3); + let sat = widgets::WheelAxes::HueSaturation; let base = Color::from_hsb(10.0, 0.8, 0.6); - assert!(near(added_color(Some(base), 120.0, 0.5, false).to_hsb(), [120.0, 0.5, 0.6])); - assert!(near(added_color(None, 200.0, 0.25, false).to_hsb(), [200.0, 0.25, 1.0])); - assert!(near(added_color(None, 7.0, 0.95, true).to_hsb(), [0.0, 0.9, 1.0]), "the patch's color"); + assert!(near(added_color(Some(base), 120.0, 0.5, false, sat).to_hsb(), [120.0, 0.5, 0.6])); + assert!(near(added_color(None, 200.0, 0.25, false, sat).to_hsb(), [200.0, 0.25, 1.0])); + assert!(near(added_color(None, 7.0, 0.95, true, sat).to_hsb(), [0.0, 0.9, 1.0]), "the patch's color"); let cmyk = color_value(&json!("cmyk 0 100 100 0")).unwrap(); - assert!(matches!(added_color(Some(cmyk), 120.0, 0.5, false), Color::Cmyk { .. })); + assert!(matches!(added_color(Some(cmyk), 120.0, 0.5, false, sat), Color::Cmyk { .. })); + } + + /// On the hue and brightness wheel an added color is the hue and brightness clicked at the base + /// color's saturation (full without one), the patch's color on the segmented wheel (its ring is + /// a brightness step), in the base color's model. A black base adds a gray of the brightness + /// clicked, and the wheel's center is black. + #[test] + fn an_added_color_on_the_brightness_wheel_takes_the_base_colors_saturation() { + let near = |a: [f32; 3], b: [f32; 3]| a.iter().zip(b).all(|(x, y)| (x - y).abs() < 1e-3); + let bright = widgets::WheelAxes::HueBrightness; + let base = Color::from_hsb(10.0, 0.8, 0.6); + assert!(near(added_color(Some(base), 120.0, 0.5, false, bright).to_hsb(), [120.0, 0.8, 0.5])); + assert!(near(added_color(None, 200.0, 0.25, false, bright).to_hsb(), [200.0, 1.0, 0.25])); + assert!(near(added_color(Some(base), 7.0, 0.95, true, bright).to_hsb(), [0.0, 0.8, 0.9]), "the patch's color"); + assert!(near(added_color(Some(base), 7.0, 0.0, true, bright).to_hsb(), [0.0, 0.8, 0.1]), "the innermost ring"); + let black = Color::from_hsb(0.0, 0.0, 0.0); + let [_, s, v] = added_color(Some(black), 90.0, 0.4, false, bright).to_hsb(); + assert!(s.abs() < 1e-3 && (v - 0.4).abs() < 1e-3, "a gray: {s} {v}"); + let [_, _, v] = added_color(Some(base), 33.0, 0.0, false, bright).to_hsb(); + assert!(v.abs() < 1e-3, "black at the center"); + let cmyk = color_value(&json!("cmyk 0 100 100 0")).unwrap(); + assert!(matches!(added_color(Some(cmyk), 120.0, 0.5, false, bright), Color::Cmyk { .. })); } /// With a color group and art, a row without a new color removes its swatch in its place, the diff --git a/crates/ui-egui/src/i18n/bg.tsv b/crates/ui-egui/src/i18n/bg.tsv index 71e443a399..d578b5015a 100644 --- a/crates/ui-egui/src/i18n/bg.tsv +++ b/crates/ui-egui/src/i18n/bg.tsv @@ -1504,6 +1504,8 @@ font-technology Variable Променливи Show smooth color wheel Показване на плавно цветово колело Show segmented color wheel Показване на сегментирано цветово колело Show color bars Показване на цветни ленти + Show brightness and hue on wheel Показване на яркост и оттенък на колелото + Show saturation and hue on wheel Показване на насищане и оттенък на колелото Add Color Tool Инструмент „Добавяне на цвят“ Remove Color Tool Инструмент „Премахване на цвят“ Remove Color Премахване на цвят diff --git a/crates/ui-egui/src/i18n/bs.tsv b/crates/ui-egui/src/i18n/bs.tsv index 883d6dd387..b0db56e1b6 100644 --- a/crates/ui-egui/src/i18n/bs.tsv +++ b/crates/ui-egui/src/i18n/bs.tsv @@ -2927,6 +2927,8 @@ digits Malayalam Malajalam Show smooth color wheel Prikaži glatki kotač boja Show segmented color wheel Prikaži segmentirani kotač boja Show color bars Prikaži trake boja + Show brightness and hue on wheel Prikaži svjetlinu i nijansu na kotaču + Show saturation and hue on wheel Prikaži zasićenje i nijansu na kotaču Add Color Tool Alat za dodavanje boje Remove Color Tool Alat za uklanjanje boje Remove Color Ukloni boju diff --git a/crates/ui-egui/src/i18n/ca.tsv b/crates/ui-egui/src/i18n/ca.tsv index a8a63cbf55..0321757241 100644 --- a/crates/ui-egui/src/i18n/ca.tsv +++ b/crates/ui-egui/src/i18n/ca.tsv @@ -2044,6 +2044,8 @@ digits Malayalam Malaiàlam Show smooth color wheel Mostra la roda de color contínua Show segmented color wheel Mostra la roda de color segmentada Show color bars Mostra les barres de color + Show brightness and hue on wheel Mostra la lluentor i el to a la roda + Show saturation and hue on wheel Mostra la saturació i el to a la roda Add Color Tool Eina Afegeix color Remove Color Tool Eina Elimina color Remove Color Elimina el color diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index 569b1347ec..0378df7c53 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -3012,6 +3012,8 @@ digits Malayalam Malajálamské Show smooth color wheel Zobrazit plynulé barevné kolo Show segmented color wheel Zobrazit segmentované barevné kolo Show color bars Zobrazit barevné pruhy + Show brightness and hue on wheel Zobrazit jas a odstín na kole + Show saturation and hue on wheel Zobrazit sytost a odstín na kole Add Color Tool Nástroj Přidat barvu Remove Color Tool Nástroj Odstranit barvu Remove Color Odstranit barvu diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index 4578e4efc1..6e7ad5458f 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -5460,6 +5460,8 @@ digits Malayalam Malayalam Show smooth color wheel Vis glat farvehjul Show segmented color wheel Vis segmenteret farvehjul Show color bars Vis farvebjælker + Show brightness and hue on wheel Vis lysstyrke og farvetone på hjulet + Show saturation and hue on wheel Vis mætning og farvetone på hjulet Add Color Tool Værktøjet Tilføj farve Remove Color Tool Værktøjet Fjern farve Remove Color Fjern farve diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index c943c89dd2..a62d6e51ab 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -1554,6 +1554,8 @@ file-filter Templates Vorlagen Show smooth color wheel Stufenlosen Farbkreis anzeigen Show segmented color wheel Segmentierten Farbkreis anzeigen Show color bars Farbbalken anzeigen + Show brightness and hue on wheel Helligkeit und Farbton im Farbkreis anzeigen + Show saturation and hue on wheel Sättigung und Farbton im Farbkreis anzeigen Add Color Tool Farbe-hinzufügen-Werkzeug Remove Color Tool Farbe-entfernen-Werkzeug Remove Color Farbe entfernen diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index 906640aa0a..a3060a3d1d 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -1486,6 +1486,8 @@ font-technology Variable Μεταβλητές Show smooth color wheel Εμφάνιση ομαλού χρωματικού τροχού Show segmented color wheel Εμφάνιση τμηματοποιημένου χρωματικού τροχού Show color bars Εμφάνιση χρωματικών ράβδων + Show brightness and hue on wheel Εμφάνιση φωτεινότητας και απόχρωσης στον τροχό + Show saturation and hue on wheel Εμφάνιση κορεσμού και απόχρωσης στον τροχό Add Color Tool Εργαλείο προσθήκης χρώματος Remove Color Tool Εργαλείο αφαίρεσης χρώματος Remove Color Αφαίρεση χρώματος diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 9239c93a73..7d59e871c7 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -1569,6 +1569,8 @@ font-technology Variable Variables Show smooth color wheel Mostrar rueda de color continua Show segmented color wheel Mostrar rueda de color segmentada Show color bars Mostrar barras de color + Show brightness and hue on wheel Mostrar brillo y tono en la rueda + Show saturation and hue on wheel Mostrar saturación y tono en la rueda Add Color Tool Herramienta Añadir color Remove Color Tool Herramienta Eliminar color Remove Color Eliminar color diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index 423703e5c1..e75154859c 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -2956,6 +2956,8 @@ digits Malayalam Malajalam Show smooth color wheel Näytä liukuva väriympyrä Show segmented color wheel Näytä segmentoitu väriympyrä Show color bars Näytä väripalkit + Show brightness and hue on wheel Näytä kirkkaus ja sävy ympyrässä + Show saturation and hue on wheel Näytä kylläisyys ja sävy ympyrässä Add Color Tool Lisää väri -työkalu Remove Color Tool Poista väri -työkalu Remove Color Poista väri diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 1cff1c8ad0..52e05800f2 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -1558,6 +1558,8 @@ font-technology Variable Variables Show smooth color wheel Afficher la roue chromatique continue Show segmented color wheel Afficher la roue chromatique segmentée Show color bars Afficher les barres de couleur + Show brightness and hue on wheel Afficher la luminosité et la teinte sur la roue + Show saturation and hue on wheel Afficher la saturation et la teinte sur la roue Add Color Tool Outil Ajouter une couleur Remove Color Tool Outil Supprimer une couleur Remove Color Supprimer la couleur diff --git a/crates/ui-egui/src/i18n/gu.tsv b/crates/ui-egui/src/i18n/gu.tsv index 4eed343e3d..358c85c84a 100644 --- a/crates/ui-egui/src/i18n/gu.tsv +++ b/crates/ui-egui/src/i18n/gu.tsv @@ -3607,6 +3607,8 @@ Show all plates બધી પ્લેટ બતાવો Show axis અક્ષ બતાવો Show color bars રંગ બાર બતાવો + Show brightness and hue on wheel વ્હીલ પર તેજ અને હ્યૂ બતાવો + Show saturation and hue on wheel વ્હીલ પર સંતૃપ્તિ અને હ્યૂ બતાવો Add Color Tool રંગ ઉમેરો સાધન Remove Color Tool રંગ દૂર કરો સાધન Remove Color રંગ દૂર કરો diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index de33cdbd92..2eac73fb49 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -4687,6 +4687,8 @@ antiAlias Sharp शार्प Show Center Mark शो सेंटर मार्क Show Code कोड दिखाएं Show color bars रंग सलाखों दिखाएँ + Show brightness and hue on wheel व्हील पर ब्राइटनेस और ह्यू दिखाएँ + Show saturation and hue on wheel व्हील पर सैचुरेशन और ह्यू दिखाएँ Add Color Tool रंग जोड़ें टूल Remove Color Tool रंग हटाएँ टूल Remove Color रंग हटाएँ diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index f869e7d07b..29cc03b42c 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -1972,6 +1972,8 @@ file-filter Templates Sablonok Show smooth color wheel Folytonos színkör megjelenítése Show segmented color wheel Szegmentált színkör megjelenítése Show color bars Színsávok megjelenítése + Show brightness and hue on wheel Fényesség és színárnyalat megjelenítése a színkörön + Show saturation and hue on wheel Telítettség és színárnyalat megjelenítése a színkörön Add Color Tool Szín hozzáadása eszköz Remove Color Tool Szín eltávolítása eszköz Remove Color Szín eltávolítása diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index c5f865e69b..751872fed7 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -2737,6 +2737,8 @@ digits Malayalam Malayalam Show smooth color wheel Tampilkan roda warna halus Show segmented color wheel Tampilkan roda warna bersegmen Show color bars Tampilkan bilah warna + Show brightness and hue on wheel Tampilkan kecerahan dan rona pada roda + Show saturation and hue on wheel Tampilkan saturasi dan rona pada roda Add Color Tool Alat Tambah Warna Remove Color Tool Alat Hapus Warna Remove Color Hapus Warna diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 08cefdbed7..6b9f95466f 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -1588,6 +1588,8 @@ file-filter Templates Modelli Show smooth color wheel Mostra ruota dei colori continua Show segmented color wheel Mostra ruota dei colori segmentata Show color bars Mostra barre di colore + Show brightness and hue on wheel Mostra luminosità e tonalità sulla ruota + Show saturation and hue on wheel Mostra saturazione e tonalità sulla ruota Add Color Tool Strumento Aggiungi colore Remove Color Tool Strumento Rimuovi colore Remove Color Rimuovi colore diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 59c7628f40..ddab274aa5 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -1959,6 +1959,8 @@ antiAlias Sharp シャープ Show smooth color wheel 滑らかなカラーホイールを表示 Show segmented color wheel 分割カラーホイールを表示 Show color bars カラーバーを表示 + Show brightness and hue on wheel ホイールに明るさと色相を表示 + Show saturation and hue on wheel ホイールに彩度と色相を表示 Add Color Tool カラー追加ツール Remove Color Tool カラー削除ツール Remove Color カラーを削除 diff --git a/crates/ui-egui/src/i18n/ka.tsv b/crates/ui-egui/src/i18n/ka.tsv index 9393433cdb..fde3d6f292 100644 --- a/crates/ui-egui/src/i18n/ka.tsv +++ b/crates/ui-egui/src/i18n/ka.tsv @@ -4788,6 +4788,8 @@ digits Malayalam მალაიალამური Show smooth color wheel გლუვი ფერთა წრის ჩვენება Show segmented color wheel სეგმენტირებული ფერთა წრის ჩვენება Show color bars ფერთა ზოლების ჩვენება + Show brightness and hue on wheel სიკაშკაშისა და ფერის ტონის ჩვენება წრეზე + Show saturation and hue on wheel გაჯერებისა და ფერის ტონის ჩვენება წრეზე Add Color Tool ფერის დამატების ხელსაწყო Remove Color Tool ფერის წაშლის ხელსაწყო Remove Color ფერის წაშლა diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index 49d5e10dc1..cd27e23ecd 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -1949,6 +1949,8 @@ antiAlias Sharp 날카롭게 Show smooth color wheel 부드러운 색상환 표시 Show segmented color wheel 분할 색상환 표시 Show color bars 색상 막대 표시 + Show brightness and hue on wheel 색상환에 밝기 및 색조 표시 + Show saturation and hue on wheel 색상환에 채도 및 색조 표시 Add Color Tool 색상 추가 도구 Remove Color Tool 색상 제거 도구 Remove Color 색상 제거 diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index f071ebd0e2..58af2264ba 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -3354,6 +3354,8 @@ digits Malayalam Malayalam Show smooth color wheel Vloeiend kleurenwiel tonen Show segmented color wheel Gesegmenteerd kleurenwiel tonen Show color bars Kleurbalken tonen + Show brightness and hue on wheel Helderheid en tint op het wiel tonen + Show saturation and hue on wheel Verzadiging en tint op het wiel tonen Add Color Tool Gereedschap Kleur toevoegen Remove Color Tool Gereedschap Kleur verwijderen Remove Color Kleur verwijderen diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index 2477c73abd..93f3dccc30 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -2922,6 +2922,8 @@ digits Malayalam Malajalam Show smooth color wheel Pokaż płynne koło kolorów Show segmented color wheel Pokaż segmentowe koło kolorów Show color bars Pokaż paski kolorów + Show brightness and hue on wheel Pokaż jasność i barwę na kole + Show saturation and hue on wheel Pokaż nasycenie i barwę na kole Add Color Tool Narzędzie Dodaj kolor Remove Color Tool Narzędzie Usuń kolor Remove Color Usuń kolor diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index 333351b9af..be033e13cc 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -1354,6 +1354,8 @@ antiAlias Sharp Nítido Show smooth color wheel Mostrar roda de cores contínua Show segmented color wheel Mostrar roda de cores segmentada Show color bars Mostrar barras de cores + Show brightness and hue on wheel Mostrar brilho e tom na roda + Show saturation and hue on wheel Mostrar saturação e tom na roda Add Color Tool Ferramenta Adicionar cor Remove Color Tool Ferramenta Remover cor Remove Color Remover cor diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index ae33aa0d55..dad34e78c0 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -1579,6 +1579,8 @@ file-filter Templates Шаблоны Show smooth color wheel Показать плавный цветовой круг Show segmented color wheel Показать сегментированный цветовой круг Show color bars Показать цветовые полосы + Show brightness and hue on wheel Показать яркость и оттенок на круге + Show saturation and hue on wheel Показать насыщенность и оттенок на круге Add Color Tool Инструмент «Добавить цвет» Remove Color Tool Инструмент «Удалить цвет» Remove Color Удалить цвет diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index 1bd4fd0692..140c478265 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -1522,6 +1522,8 @@ font-technology Variable Variabla Show smooth color wheel Visa steglöst färghjul Show segmented color wheel Visa segmenterat färghjul Show color bars Visa färgstaplar + Show brightness and hue on wheel Visa ljusstyrka och nyans på hjulet + Show saturation and hue on wheel Visa mättnad och nyans på hjulet Add Color Tool Verktyget Lägg till färg Remove Color Tool Verktyget Ta bort färg Remove Color Ta bort färg diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index a2a38c679a..3437945ffe 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -1479,6 +1479,8 @@ font-technology Variable Değişken Show smooth color wheel Kesintisiz renk tekerleğini göster Show segmented color wheel Bölümlü renk tekerleğini göster Show color bars Renk çubuklarını göster + Show brightness and hue on wheel Tekerlekte parlaklık ve renk tonunu göster + Show saturation and hue on wheel Tekerlekte doygunluk ve renk tonunu göster Add Color Tool Renk Ekle aracı Remove Color Tool Renk Kaldır aracı Remove Color Rengi kaldır diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index 17c673885d..53d56eb1a8 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -1582,6 +1582,8 @@ file-filter Templates Шаблони Show smooth color wheel Показати плавне колірне коло Show segmented color wheel Показати сегментоване колірне коло Show color bars Показати колірні смуги + Show brightness and hue on wheel Показати яскравість і відтінок на колі + Show saturation and hue on wheel Показати насиченість і відтінок на колі Add Color Tool Інструмент «Додати колір» Remove Color Tool Інструмент «Вилучити колір» Remove Color Вилучити колір diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index da89525314..a1434deff4 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -1819,6 +1819,8 @@ file-filter Templates Mẫu Show smooth color wheel Hiện bánh xe màu liền mạch Show segmented color wheel Hiện bánh xe màu phân đoạn Show color bars Hiện các thanh màu + Show brightness and hue on wheel Hiện độ sáng và sắc độ trên bánh xe + Show saturation and hue on wheel Hiện độ bão hòa và sắc độ trên bánh xe Add Color Tool Công cụ Thêm màu Remove Color Tool Công cụ Xóa màu Remove Color Xóa màu diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index 5f612cb0d4..a57f43b4ef 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -1516,6 +1516,8 @@ file-filter Templates 模板 Show smooth color wheel 显示平滑色轮 Show segmented color wheel 显示分段色轮 Show color bars 显示颜色条 + Show brightness and hue on wheel 在色轮上显示亮度和色相 + Show saturation and hue on wheel 在色轮上显示饱和度和色相 Add Color Tool 添加颜色工具 Remove Color Tool 删除颜色工具 Remove Color 删除颜色 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index e0b5a13ee2..dad48cf74c 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -1553,6 +1553,8 @@ file-filter Templates 範本 Show smooth color wheel 顯示平滑色輪 Show segmented color wheel 顯示分段色輪 Show color bars 顯示顏色條 + Show brightness and hue on wheel 在色輪上顯示亮度和色相 + Show saturation and hue on wheel 在色輪上顯示飽和度和色相 Add Color Tool 新增顏色工具 Remove Color Tool 移除顏色工具 Remove Color 移除顏色 diff --git a/crates/ui-egui/src/tests/recolor.rs b/crates/ui-egui/src/tests/recolor.rs index ec6921500b..db8d298940 100644 --- a/crates/ui-egui/src/tests/recolor.rs +++ b/crates/ui-egui/src/tests/recolor.rs @@ -1059,6 +1059,159 @@ fn a_segmented_wheel_marker_moves_freely() { assert!((new_hsb(h.state())[red][2] - 0.25).abs() < 0.02, "the Brightness slider: {:?}", new_hsb(h.state())); } +/// The segmented hue and brightness wheel's patches: 24 hues by 5 brightness steps, at the +/// saturation asked; the innermost ring is the darkest. +#[test] +fn the_segmented_brightness_wheel_has_24_hues_by_5_brightnesses() { + let bright = crate::widgets::WheelAxes::HueBrightness; + let seg = |h, v, s| crate::widgets::segment_color_on(bright, h, v, s).to_hsb(); + let near = |a: [f32; 3], b: [f32; 3]| a.iter().zip(b).all(|(x, y)| (x - y).abs() < 1e-3); + assert!(near(seg(7.0, 0.95, 1.0), [0.0, 1.0, 0.9]), "{:?}", seg(7.0, 0.95, 1.0)); + assert!(near(seg(8.0, 0.0, 0.5), [15.0, 0.5, 0.1]), "{:?}", seg(8.0, 0.0, 0.5)); + assert!(near(seg(120.0, 0.5, 0.25), [120.0, 0.25, 0.5]), "{:?}", seg(120.0, 0.5, 0.25)); + let mut patches = std::collections::BTreeSet::new(); + for h in 0..360 { + for v in 0..=100 { + patches.insert(ColorKey::of(&crate::widgets::segment_color_on(bright, h as f32, v as f32 / 100.0, 1.0)).to_string()); + } + } + assert_eq!(patches.len(), 24 * 5); +} + +/// The button under the wheel tools switches the wheel to hue and brightness: its name says what a +/// click shows next, the slider under the wheel becomes a Saturation slider, and switching changes +/// no color, previews nothing and records no undo step. The choice holds for the segmented wheel and +/// across the color bars, where the button is off; the next opening shows hue and saturation again. +#[test] +fn the_brightness_and_hue_wheel_swaps_the_wheel_axis_and_the_slider() { + let mut h = edit_harness(&["#ff0000", "#0000ff", "#00ff00"]); + let (rows, height) = (field(h.state(), "rows"), dialog_height(&h)); + let doc = h.state().session.doc().unwrap().doc.clone(); + let undo = h.state().session.doc().unwrap().history.undo.len(); + let slider = |h: &egui_kittest::Harness<'_, VectorcraftApp>, name: &str| h.query_by_role_and_label(egui::accesskit::Role::Slider, name).is_some(); + assert_eq!(field(h.state(), "wheelAxes"), Value::Null, "hue and saturation first"); + assert!(slider(&h, "Brightness") && !slider(&h, "Saturation")); + click_button(&mut h, "Show brightness and hue on wheel"); + assert_eq!(field(h.state(), "wheelAxes"), json!("hueBrightness")); + assert!(slider(&h, "Saturation") && !slider(&h, "Brightness"), "the slider edits the component the wheel leaves out"); + assert!(h.query_by_role_and_label(egui::accesskit::Role::Button, "Show saturation and hue on wheel").is_some(), "the button names the way back"); + assert_eq!(field(h.state(), "rows"), rows, "switching changes no color"); + assert_eq!(h.state().session.doc().unwrap().doc, doc, "nor the art"); + assert_eq!(h.state().session.doc().unwrap().history.undo.len(), undo); + show_display(&mut h, "Show segmented color wheel"); + assert_eq!(field(h.state(), "wheelAxes"), json!("hueBrightness"), "the segmented wheel keeps the choice"); + assert!(slider(&h, "Saturation")); + show_display(&mut h, "Show color bars"); + let button = h.get_by_role_and_label(egui::accesskit::Role::Button, "Show saturation and hue on wheel"); + assert!(button.accesskit_node().is_disabled(), "the button is for the wheels"); + assert_eq!(dialog_height(&h), height, "the button keeps the dialog's height"); + show_display(&mut h, "Show smooth color wheel"); + assert!(slider(&h, "Saturation"), "the bars keep the choice"); + click_button(&mut h, "Show saturation and hue on wheel"); + assert_eq!(field(h.state(), "wheelAxes"), json!("hueSaturation")); + assert!(slider(&h, "Brightness") && !slider(&h, "Saturation")); + assert_eq!(field(h.state(), "rows"), rows); + assert_eq!(dialog_height(&h), height); + set(h.state_mut(), "wheelAxes", json!("sideways")); + h.run_steps(3); + assert!(slider(&h, "Brightness"), "an unknown value shows hue and saturation"); + set(h.state_mut(), "wheelAxes", json!("hueBrightness")); + h.run_steps(3); + let app = h.state_mut(); + dialogs::cancel(app); + app.run("select.all", json!({})).unwrap(); + app.run("ui.recolorDialog", json!({})).unwrap(); + assert_eq!(field(app, "wheelAxes"), Value::Null, "a new opening shows hue and saturation"); +} + +/// On the hue and brightness wheel a marker sits at its color's brightness, and a drag sets hue and +/// brightness and keeps saturation; linked colors turn and darken with it. The art previews the +/// drag, Cancel restores it and OK keeps it as one undo step. The Saturation slider sets the +/// selected color's saturation and keeps its brightness. +#[test] +fn a_marker_on_the_brightness_wheel_sets_hue_and_brightness() { + for confirm in [false, true] { + let mut h = edit_harness(&["rgb 200 100 100", "rgb 100 200 200"]); + set(h.state_mut(), "__sel", json!([0])); + h.run_steps(4); + let before = h.state().session.doc().unwrap().doc.clone(); + let undo = h.state().session.doc().unwrap().history.undo.len(); + click_button(&mut h, "Show brightness and hue on wheel"); + let start = new_hsb(h.state()); + let [hue, s, v] = start[0]; + // Around by 30° and in to 40% brightness, a few points at a time from the marker. + let from = wheel_at(&h, hue, v); + h.hover_at(from); + h.run_steps(1); + h.drag_at(from); + h.run_steps(1); + let c = widget_of_size(&h, vec2(220.0, 220.0)).center(); + let to = |k: f32| { + let a = (hue + 30.0 * k).to_radians(); + c + vec2(a.cos(), -a.sin()) * 100.0 * (v + (0.4 - v) * k) + }; + let end = to(1.0); + for k in 1..=10 { + let p = to(k as f32 / 10.0); + h.hover_at(p); + h.run_steps(1); + } + h.drop_at(end); + h.run_steps(2); + let moved = new_hsb(h.state()); + let gap = |a: f32, b: f32| (a - b).rem_euclid(360.0).min((b - a).rem_euclid(360.0)); + assert!(gap(moved[0][0], hue + 30.0) < 1.0, "hue: {start:?} -> {moved:?}"); + assert!((moved[0][2] - 0.4).abs() < 0.02, "brightness: {start:?} -> {moved:?}"); + assert!((moved[0][1] - s).abs() < 0.02, "saturation stays: {start:?} -> {moved:?}"); + assert!(gap(moved[1][0], start[1][0] + 30.0) < 1.5, "linked, it turns: {start:?} -> {moved:?}"); + assert!((moved[1][2] - (start[1][2] - (v - 0.4))).abs() < 0.02, "and darkens alike: {start:?} -> {moved:?}"); + click_slider(&mut h, "Saturation", 0.25); + let slid = new_hsb(h.state()); + assert!((slid[0][1] - 0.25).abs() < 0.02, "the Saturation slider: {slid:?}"); + assert!((slid[0][2] - 0.4).abs() < 0.02, "keeps the brightness: {slid:?}"); + let after = h.state().session.doc().unwrap().doc.clone(); + assert_ne!(after, before, "the art previews the edit"); + h.get_by_label(if confirm { "OK" } else { "Cancel" }).click(); + h.run_steps(2); + assert!(h.state().ui.dialog.is_none()); + if confirm { + assert_eq!(h.state().session.doc().unwrap().doc, after); + assert_eq!(h.state().session.doc().unwrap().history.undo.len(), undo + 1, "one undo step"); + h.state_mut().run("edit.undo", json!({})).unwrap(); + } else { + assert_eq!(h.state().session.doc().unwrap().history.undo.len(), undo, "Cancel records no undo step"); + } + assert_eq!(h.state().session.doc().unwrap().doc, before); + } +} + +/// On the hue and brightness wheels the Add Color tool adds the hue and brightness clicked at the +/// base color's saturation, the patch's color on the segmented wheel. +#[test] +fn the_add_color_tool_on_the_brightness_wheel_adds_the_brightness_clicked() { + let mut h = edit_harness(&["rgb 200 100 100", "rgb 100 200 200"]); + set(h.state_mut(), "__sel", json!([0])); + h.run_steps(4); + let s = new_hsb(h.state())[0][1]; + click_button(&mut h, "Show brightness and hue on wheel"); + click_button(&mut h, "Add Color Tool"); + let at = wheel_at(&h, 120.0, 0.5); + h.input_mut().events.extend(press(at, 1)); + h.run_steps(3); + let [hue, sat, b] = new_hsb(h.state())[2]; + assert!((hue - 120.0).abs() < 1.0 && (sat - s).abs() < 0.01 && (b - 0.5).abs() < 0.01, "{:?}", [hue, sat, b]); + assert_eq!(field(h.state(), "__sel"), json!([2])); + // The new color is now the base color; select the first one again. + set(h.state_mut(), "__sel", json!([0])); + h.run_steps(3); + show_display(&mut h, "Show segmented color wheel"); + let patch = wheel_at(&h, 187.0, 0.95); + h.input_mut().events.extend(press(patch, 1)); + h.run_steps(3); + let [hue, sat, b] = *new_hsb(h.state()).last().unwrap(); + assert!((hue - 180.0).abs() < 1.0 && (sat - s).abs() < 0.01 && (b - 0.9).abs() < 0.01, "the patch's color: {:?}", [hue, sat, b]); +} + /// The rows as `(current colors, new color)` pairs, sorted. fn row_pairs(app: &VectorcraftApp) -> Vec { let mut v: Vec = field(app, "rows").as_array().unwrap().iter().map(|r| format!("{} {}", r["from"], r["to"])).collect(); @@ -1173,7 +1326,8 @@ fn color_bars_scroll_and_show_when_nothing_is_recolored() { let _ = h.get_by_label("No colors to recolor (preserved colors are left out)."); } -/// Where the Edit tab's wheel draws a marker for hue `hue` and saturation `s`. +/// Where the Edit tab's wheel draws a marker for hue `hue` and saturation `s` (or brightness, on +/// the hue and brightness wheel). fn wheel_at(h: &egui_kittest::Harness<'_, VectorcraftApp>, hue: f32, s: f32) -> Pos2 { let c = widget_of_size(h, vec2(220.0, 220.0)).center(); c + vec2(hue.to_radians().cos(), -hue.to_radians().sin()) * 100.0 * s diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index d4d677a0a6..efc92e08e3 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -35,9 +35,9 @@ pub(crate) use buttons::{button_width, flat_button_fit_width, icon_button_info, use chips::gradient_chip_colors; pub use chips::{ProxyClicks, chip_button, chip_button_named, fill_stroke_proxy, gradient_chip, paint_chip, proxy_chip, swatch_tile}; pub use color::{ - FieldAxis, Live, RingResponse, SliderValue, WheelResponse, channel_slider, channel_slider_named, channel_slider_valued, color_field, color_mesh, - color_slider, color_slider_named, color_slider_stepped, color_slider_valued, harmony_wheel, hex_field, hex_field_named, hsb32, hue_ring, - region_texture, ring_square, segment_color, segmented_wheel, stepped_area, + FieldAxis, Live, RingResponse, SliderValue, WheelAxes, WheelResponse, channel_slider, channel_slider_named, channel_slider_valued, color_field, + color_mesh, color_slider, color_slider_named, color_slider_stepped, color_slider_valued, harmony_wheel, hex_field, hex_field_named, hsb32, + hue_ring, region_texture, ring_square, segment_color, segment_color_on, segmented_wheel, stepped_area, wheel_of, }; pub(crate) use color::{HEX_FIELD_CHARS, hex_text, pointer_phase}; pub use drag::{ diff --git a/crates/ui-egui/src/widgets/color.rs b/crates/ui-egui/src/widgets/color.rs index 04aae5be55..2c7711321d 100644 --- a/crates/ui-egui/src/widgets/color.rs +++ b/crates/ui-egui/src/widgets/color.rs @@ -700,17 +700,57 @@ fn wheel_pos(c: Pos2, r: f32, h: f32, s: f32) -> Pos2 { c + vec2(a.cos(), -a.sin()) * r * s } -/// The hue and saturation wheel at brightness `v`: hue around, saturation outwards. -fn wheel_shape(c: Pos2, r: f32, v: f32) -> egui::Shape { +/// Which HSB component the distance from a [`harmony_wheel`]'s center shows; hue is always the +/// angle. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub enum WheelAxes { + /// Saturation outwards (gray at the center), at the selected color's brightness. + #[default] + HueSaturation, + /// Brightness outwards (black at the center), at the selected color's saturation. + HueBrightness, +} + +impl WheelAxes { + /// The HSB index the distance from the center sets: 1 (saturation) or 2 (brightness). + pub fn radial(self) -> usize { + match self { + WheelAxes::HueSaturation => 1, + WheelAxes::HueBrightness => 2, + } + } + + /// The HSB index of the slider under the wheel: the component the wheel does not show. + pub fn other(self) -> usize { + 3 - self.radial() + } + + /// HSB `[h°, s, v]` of hue `h`, `t` for the component the distance from the center shows and + /// `o` for the other one. + pub fn hsb(self, h: f32, t: f32, o: f32) -> [f32; 3] { + match self { + WheelAxes::HueSaturation => [h, t, o], + WheelAxes::HueBrightness => [h, o, t], + } + } +} + +/// The wheel of `axes` with `o` for the component it does not show: hue around, the other +/// component outwards. +fn wheel_shape(c: Pos2, r: f32, axes: WheelAxes, o: f32) -> egui::Shape { const SEG: u32 = 72; const RINGS: u32 = 8; + let col = |h: f32, t: f32| { + let [h, s, v] = axes.hsb(h, t, o); + crate::panels::c32(&Color::from_hsb(h, s, v)) + }; let mut mesh = egui::Mesh::default(); - mesh.colored_vertex(c, crate::panels::c32(&Color::from_hsb(0.0, 0.0, v))); + mesh.colored_vertex(c, col(0.0, 0.0)); for ring in 1..=RINGS { - let s = ring as f32 / RINGS as f32; + let t = ring as f32 / RINGS as f32; for k in 0..SEG { let h = k as f32 * 360.0 / SEG as f32; - mesh.colored_vertex(wheel_pos(c, r, h, s), crate::panels::c32(&Color::from_hsb(h, s, v))); + mesh.colored_vertex(wheel_pos(c, r, h, t), col(h, t)); } } let at = |ring: u32, k: u32| if ring == 0 { 0 } else { 1 + (ring - 1) * SEG + k % SEG }; @@ -873,23 +913,31 @@ pub fn hue_ring(ui: &mut Ui, id: impl std::hash::Hash, name: &str, size: f32, hu out } -/// Hue sectors and saturation rings of the [`segmented_wheel`]: patches 15° of hue by 20% -/// saturation wide, the sectors centered on red at 0°. +/// Hue sectors and rings of the [`segmented_wheel`]: patches 15° of hue by 20% saturation (or +/// brightness) wide, the sectors centered on red at 0°. const WHEEL_SECTORS: u32 = 24; const WHEEL_RINGS: u32 = 5; /// The color of the [`segmented_wheel`] patch that holds hue `h` (degrees) and saturation `s` (0 to /// 1), at brightness `v`: the hue and saturation at the patch's center. pub fn segment_color(h: f32, s: f32, v: f32) -> Color { - let step = 360.0 / WHEEL_SECTORS as f32; - let sector = (h.rem_euclid(360.0) / step).round() % WHEEL_SECTORS as f32; - let ring = (s.clamp(0.0, 1.0) * WHEEL_RINGS as f32).floor().min((WHEEL_RINGS - 1) as f32); - Color::from_hsb(sector * step, (ring + 0.5) / WHEEL_RINGS as f32, v) + segment_color_on(WheelAxes::HueSaturation, h, s, v) } -/// The segmented hue and saturation wheel at brightness `v`: a solid patch per hue sector and -/// saturation ring, in its [`segment_color`]. -fn segmented_wheel_shape(c: Pos2, r: f32, v: f32) -> egui::Shape { +/// The color of the patch of the [`segmented_wheel`] of `axes` that holds hue `h` (degrees) and `t` +/// (0 to 1) for the component the wheel shows, with `o` for the other one: the hue and `t` at the +/// patch's center. +pub fn segment_color_on(axes: WheelAxes, h: f32, t: f32, o: f32) -> Color { + let step = 360.0 / WHEEL_SECTORS as f32; + let sector = (h.rem_euclid(360.0) / step).round() % WHEEL_SECTORS as f32; + let ring = (t.clamp(0.0, 1.0) * WHEEL_RINGS as f32).floor().min((WHEEL_RINGS - 1) as f32); + let [h, s, v] = axes.hsb(sector * step, (ring + 0.5) / WHEEL_RINGS as f32, o); + Color::from_hsb(h, s, v) +} + +/// The segmented wheel of `axes` with `o` for the component it does not show: a solid patch per +/// hue sector and ring, in its [`segment_color_on`]. +fn segmented_wheel_shape(c: Pos2, r: f32, axes: WheelAxes, o: f32) -> egui::Shape { // Points along each patch's arcs. const ARC: u32 = 4; let step = 360.0 / WHEEL_SECTORS as f32; @@ -898,7 +946,7 @@ fn segmented_wheel_shape(c: Pos2, r: f32, v: f32) -> egui::Shape { let (s0, s1) = (ring as f32 / WHEEL_RINGS as f32, (ring + 1) as f32 / WHEEL_RINGS as f32); for k in 0..WHEEL_SECTORS { let h = k as f32 * step; - let col = crate::panels::c32(&segment_color(h, (s0 + s1) / 2.0, v)); + let col = crate::panels::c32(&segment_color_on(axes, h, (s0 + s1) / 2.0, o)); let first = mesh.vertices.len() as u32; for j in 0..=ARC { let a = h - step / 2.0 + step * j as f32 / ARC as f32; @@ -920,11 +968,13 @@ fn segmented_wheel_shape(c: Pos2, r: f32, v: f32) -> egui::Shape { pub struct WheelResponse { /// The colour whose marker was pressed (it becomes the selected one). pub pressed: Option, - /// A colour moved by dragging its marker (a new hue and saturation) or, the selected colour, - /// the brightness slider (a new brightness): `[h°, s, v]`, `None` where the control kept it. + /// A colour moved by dragging its marker (a new hue and saturation, or with + /// [`WheelAxes::HueBrightness`] a new hue and brightness) or, the selected colour, the slider + /// under the wheel (a new brightness, or saturation): `[h°, s, v]`, `None` where the control + /// kept it. pub moved: Option<(usize, [Option; 3])>, /// A click on the wheel: the color whose marker is within reach of it (if any), and the hue - /// (degrees) and saturation under the pointer (1 for a marker past the wheel's edge). + /// (degrees) and the saturation (or brightness) under the pointer (1 past the wheel's edge). pub clicked: Option<(Option, [f32; 2])>, } @@ -933,32 +983,40 @@ pub struct WheelResponse { /// marker per colour joined to the centre (the selected colour, `base`, larger) and a Brightness /// slider for the selected colour below it. pub fn harmony_wheel(ui: &mut Ui, id: &str, size: f32, colors: &[Color], base: Option) -> WheelResponse { - wheel(ui, id, size, colors, base, false) + wheel_of(ui, id, size, colors, base, false, WheelAxes::HueSaturation) } /// [`harmony_wheel`] drawn as solid patches (24 hues by 5 saturations, each in its /// [`segment_color`]). The markers sit at their colors' own hue and /// saturation, and a drag moves them as freely as on the smooth wheel. pub fn segmented_wheel(ui: &mut Ui, id: &str, size: f32, colors: &[Color], base: Option) -> WheelResponse { - wheel(ui, id, size, colors, base, true) + wheel_of(ui, id, size, colors, base, true, WheelAxes::HueSaturation) } -/// [`harmony_wheel`], or with `segmented` [`segmented_wheel`]. -fn wheel(ui: &mut Ui, id: &str, size: f32, colors: &[Color], base: Option, segmented: bool) -> WheelResponse { +/// [`harmony_wheel`], or with `segmented` [`segmented_wheel`], showing `axes`. With +/// [`WheelAxes::HueBrightness`] the distance from the center is brightness (black at the center, +/// full brightness at the edge, a ring of patches per 20% on the segmented wheel), the wheel is drawn +/// at the selected colour's saturation (full without one), a marker drag sets hue and brightness, +/// and the slider under the wheel is a Saturation slider. +pub fn wheel_of(ui: &mut Ui, id: &str, size: f32, colors: &[Color], base: Option, segmented: bool, axes: WheelAxes) -> WheelResponse { let t = Tokens::get(ui.ctx()); let mut out = WheelResponse::default(); let base_hsb = base.and_then(|b| colors.get(b)).map(Color::to_hsb); - let v = base_hsb.map_or(1.0, |c| c[2]); + let (radial, other) = (axes.radial(), axes.other()); + // The component the wheel does not show: the slider's value, and the wheel's background at it. + let o = base_hsb.map_or(1.0, |c| c[other]); + // A dark wheel still shows its hues. + let shown = if axes == WheelAxes::HueSaturation { o.max(0.15) } else { o }; ui.horizontal(|ui| { ui.add_space(((ui.available_width() - size) / 2.0).max(0.0)); let (rect, resp) = ui.allocate_exact_size(vec2(size, size), Sense::click_and_drag()); let (c, r) = (rect.center(), size / 2.0 - 10.0); let painter = ui.painter_at(rect); - painter.add(if segmented { segmented_wheel_shape(c, r, v.max(0.15)) } else { wheel_shape(c, r, v.max(0.15)) }); + painter.add(if segmented { segmented_wheel_shape(c, r, axes, shown) } else { wheel_shape(c, r, axes, shown) }); painter.circle_stroke(c, r, Stroke::new(1.0, t.border)); let at = |col: &Color| { - let [h, s, _] = col.to_hsb(); - wheel_pos(c, r, h, s) + let hsb = col.to_hsb(); + wheel_pos(c, r, hsb[0], hsb[radial]) }; for (i, col) in colors.iter().enumerate() { let (p, big) = (at(col), Some(i) == base); @@ -974,7 +1032,8 @@ fn wheel(ui: &mut Ui, id: &str, size: f32, colors: &[Color], base: Option let near = colors.iter().map(at).enumerate().map(|(i, m)| (i, m.distance(p))).filter(|x| x.1 <= 14.0).min_by(|a, b| a.1.total_cmp(&b.1)); out.pressed = near.map(|x| x.0); ui.data_mut(|m| m.insert_temp(drag, out.pressed)); - // A click inside the wheel, or on a marker, gives the hue and saturation under it. + // A click inside the wheel, or on a marker, gives the hue and saturation (or + // brightness) under it. let dv = p - c; if resp.clicked() && (dv.length() <= r || out.pressed.is_some()) { let h = (-dv.y).atan2(dv.x).to_degrees().rem_euclid(360.0); @@ -986,8 +1045,10 @@ fn wheel(ui: &mut Ui, id: &str, size: f32, colors: &[Color], base: Option && i < colors.len() { let dv = p - c; - let h = (-dv.y).atan2(dv.x).to_degrees().rem_euclid(360.0); - out.moved = Some((i, [Some(h), Some((dv.length() / r).clamp(0.0, 1.0)), None])); + let mut set = [None; 3]; + set[0] = Some((-dv.y).atan2(dv.x).to_degrees().rem_euclid(360.0)); + set[radial] = Some((dv.length() / r).clamp(0.0, 1.0)); + out.moved = Some((i, set)); } let name = if segmented { tl!("Segmented color wheel") } else { tl!("Color wheel") }; resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Slider, ui.is_enabled(), name)); @@ -995,15 +1056,19 @@ fn wheel(ui: &mut Ui, id: &str, size: f32, colors: &[Color], base: Option ui.add_space(6.0); ui.horizontal(|ui| { ui.add_space(((ui.available_width() - size - 76.0) / 2.0).max(0.0)); - ui.add_sized([70.0, 22.0], egui::Label::new(egui::RichText::new(tl!("Brightness")).color(t.text_dim))); - // Screen readers get the brightness in percent, as the Color panel's HSB B field shows it. - let shown = SliderValue::field((f64::from(v) * 100.0).round(), 0.0..=100.0, "%", 0); - if let (Some(b), Some([h, s, _])) = (base, base_hsb) - && let (Some(nv), _) = color_slider_valued(ui, (id, "brightness"), tl!("Brightness"), Some(shown), v, size, &|x| { - crate::panels::c32(&Color::from_hsb(h, s, x)) + let (name, key) = if other == 2 { (tl!("Brightness"), "brightness") } else { (tl!("Saturation"), "saturation") }; + ui.add_sized([70.0, 22.0], egui::Label::new(egui::RichText::new(name).color(t.text_dim))); + // Screen readers get the value in percent, as the Color panel's HSB fields show it. + let shown = SliderValue::field((f64::from(o) * 100.0).round(), 0.0..=100.0, "%", 0); + if let (Some(b), Some(hsb)) = (base, base_hsb) + && let (Some(nv), _) = color_slider_valued(ui, (id, key), name, Some(shown), o, size, &|x| { + let [h, s, v] = axes.hsb(hsb[0], hsb[radial], x); + crate::panels::c32(&Color::from_hsb(h, s, v)) }) { - out.moved = Some((b, [None, None, Some(nv)])); + let mut set = [None; 3]; + set[other] = Some(nv); + out.moved = Some((b, set)); } }); out diff --git a/docs/control-protocol.md b/docs/control-protocol.md index df83c6eb04..275dbc569a 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -293,7 +293,11 @@ colors: `smooth` (the smooth wheel, also when unset; each opening starts there), selects its row for the sliders and a drag moves the row without changing a color). `wheelTool` turns on a wheel tool on either wheel: `add` (the Add Color tool) adds a click as a new color, the hue and saturation clicked at the base color's brightness (the patch's color on the segmented wheel), in a new row with no current colors (`from: []`) and -`added: true` that becomes the selected row; `remove` (the Remove Color tool) removes the color of the marker clicked. A color bar's +`added: true` that becomes the selected row; `remove` (the Remove Color tool) removes the color of the marker clicked. +`wheelAxes: "hueBrightness"` makes both wheels show hue and brightness: brightness runs from black at the center to +full at the edge, the wheel is drawn at the base color's saturation, a marker drag sets hue and brightness, the slider +under the wheel sets saturation, and Add Color adds the hue and brightness clicked at the base color's saturation. +`hueSaturation`, unset (each opening) or any other value shows hue and saturation; switching changes no color. A color bar's right-click menu has Remove Color too. The base color can't be removed. A removed color's row is dropped, unless it has current colors and art or a group is open: it then keeps them with `to: null`, that art keeps its colors, and the group's swatch at that place is removed. A row with no current colors recolors no art; with a group, the new color of diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 0782bacab9..abe834ba80 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1675,6 +1675,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Recolor Artwork layout (#3416):** the Edit chip list uses the modal scroll helper and its actual remaining height; the tab's minimum-height space scrolls with the chips. `tests_recolor` covers 5/20/200/400 colors, window resizing, 100/125/150/200% UI scaling, scrolling to and editing the final chip, Preview, Cancel, Confirm and Undo, alongside the existing #1733 drag regressions. Scores and estimates unchanged. - **Recolor Artwork Edit displays:** buttons beside the Edit tab's wheel show the colors on a smooth color wheel, a segmented color wheel or as color bars ([Edit colors using Recolor Artwork](https://helpx.adobe.com/illustrator/desktop/manage-colors/modify-colors/edit-colors-using-edit-colors-dialog.html)). The segmented wheel draws 24 hues by 5 saturations as solid patches, and its markers move freely as on the smooth wheel. The bars show one solid bar per recolored color in row order: a click selects a bar for the color sliders, and a drag moves its row without changing a color ([Advanced recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/edit-colors-dialog-overview.html)). The dialog opens on the smooth wheel; `display` (`smooth`, `segmented`, `bars`) is the dialog field. `tests_recolor` covers switching, the dialog height, segmented dragging and Brightness, and bar selection, editing, reordering, scrolling, Preview, Cancel and OK. Scores and estimates unchanged. - **Recolor Artwork Add Color and Remove Color tools:** under the display buttons beside the Edit tab's wheel, the Add Color tool adds the color clicked on either wheel to the color group, and the Remove Color tool removes the color whose marker is clicked; a color bar's right-click menu has Remove Color, and the base color can't be removed ([Advanced recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/edit-colors-dialog-overview.html), [Edit swatch groups using the color wheel](https://helpx.adobe.com/illustrator/desktop/manage-colors/modify-colors/edit-color-groups-using-the-color-wheel.html)). An added color is a new row with no current colors and `added: true`; unlike a row made with New Row, it adds its new color to a rewritten color group, after the group's other colors. VectorCraft's own rules: an added color takes the base color's brightness, and with art or a group a removed color's row stays with its current colors and no new color, so that art keeps its colors and the group's swatch at that place is removed. `wheelTool` (`add`, `remove`) is the dialog field. Tests: `the_add_color_tool_adds_a_row_with_no_current_colors`, `an_added_color_joins_the_color_group`, `the_remove_color_tool_removes_a_marker_but_not_the_base_colors` and `a_color_bars_menu_removes_its_color` in `crates/ui-egui/src/tests/recolor.rs`, `apply_params_give_the_group_added_colors_and_keep_its_other_colors` in `crates/ui-egui/src/dialogs/recolor.rs`, and `an_added_empty_row_gives_the_group_its_color_after_the_others` in `crates/engine/src/tests/recolor.rs`. Scores and estimates unchanged. + - **Recolor Artwork brightness and hue wheel:** a button under the Edit tab's wheel tools switches the wheel between hue with saturation and hue with brightness; a marker's angle sets its hue, and its distance from the center sets the component the wheel shows ([Recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/modify-colors/recolor-options-overview.html), [archived help, Edit colors](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=144)). VectorCraft's own rules: brightness runs from black at the center to full at the edge, the segmented wheel's five rings become brightness steps, the slider under the wheel edits the component the wheel leaves out (Saturation on the brightness wheel), Add Color takes the hue and brightness clicked at the base color's saturation, the choice holds for both wheels while the dialog is open and the button is off for the color bars, and each opening shows hue and saturation. `wheelAxes` (`hueSaturation`, `hueBrightness`) is the dialog field. Tests: `the_brightness_and_hue_wheel_swaps_the_wheel_axis_and_the_slider`, `a_marker_on_the_brightness_wheel_sets_hue_and_brightness`, `the_add_color_tool_on_the_brightness_wheel_adds_the_brightness_clicked` and `the_segmented_brightness_wheel_has_24_hues_by_5_brightnesses` in `crates/ui-egui/src/tests/recolor.rs`, and `an_added_color_on_the_brightness_wheel_takes_the_base_colors_saturation` in `crates/ui-egui/src/dialogs/recolor.rs`. Scores and estimates unchanged. - **Recolor Artwork Find:** the Assign tab's Find button finds the colors of the selected rows in the art ([Advanced recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/edit-colors-dialog-overview.html)): while it is on, their art shows as the preview shows it and the rest of the selected art shows dimmed, until a second click ([archived help, Recolor Artwork](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=149)). VectorCraft's own rules: a dimmed color is a 25% tint of its current color (or the nearest lighter tint when that one is a color a selected row lists), a color a selected row also lists is not dimmed, and Find records no undo step. `findColors` is the dialog field. Tests: `find_dims_the_colors_of_the_rows_not_selected` and `find_shows_the_selected_rows_art_and_dims_the_rest` in `crates/ui-egui/src/dialogs/recolor.rs`. Scores and estimates unchanged. - **Recolor Artwork New Row:** the Assign tab's New Row button adds a row with no current colors, so current colors can be moved into it and take its new color ([Advanced recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/edit-colors-dialog-overview.html), [Assign new colors to selected artworks](https://helpx.adobe.com/illustrator/desktop/manage-colors/modify-colors/assign-new-colors-to-selected-artwork.html)). VectorCraft's own rules: the row goes above the first selected row (at the top when none is selected) with that row's new color and becomes the selection, and Merge with it as the first selected row moves the other rows' colors into it. The button needs selected art. An empty row recolors nothing, does not count toward Colors, adds no library swatch and gives a rewritten color group no color. While it is empty, Save All Colors and a new color group saved from colors alone leave its new color out, the Edit tab's wheel, bars and chips do not show it and its sliders edit the base color instead, the harmony rules and linked moves leave its new color as it is, and the Color Theme Picker gives it no color. Tests: `a_new_row_goes_above_the_selection_and_takes_merged_colors`, `an_empty_row_gives_the_group_no_color`, `an_empty_row_gives_a_new_group_no_color`, `an_empty_row_takes_no_harmony_or_wheel_color`, `theme_picks_leave_an_empty_row_out`, `save_all_colors_leaves_an_empty_row_out` and `colors_merged_into_a_new_row_take_its_new_color` in `crates/ui-egui/src/dialogs/recolor.rs`, `an_empty_row_recolors_nothing` and `an_empty_row_adds_no_swatch_and_no_group_color` in `crates/engine/src/tests/recolor.rs`. - **Edit Colors parameters:** `edit.colors.saturate` needs a number `intensity`, the value from -100% to 100% that Saturate takes ([Adjusting colors](https://web.archive.org/web/20230128232631/https://helpx.adobe.com/illustrator/using/adjusting-colors.html)), and answers "missing number `intensity`" without one; a number outside the range counts as its nearest end. A value that is not a number, such as `"40"`, is refused with `` `intensity` must be a number, not "40" ``, as in every command that needs a number (`tests::params::a_malformed_required_number_is_not_reported_as_missing`). `edit.colors.adjustBalance` refuses a channel and `color.harmony` refuses `steps` or `amount` that is not a number; both read `null` as a value left out. `tests::editcolors` and `tests::colorguide` cover them.