diff --git a/crates/color/src/harmony.rs b/crates/color/src/harmony.rs index 2cca6e264d..87e1c54548 100644 --- a/crates/color/src/harmony.rs +++ b/crates/color/src/harmony.rs @@ -176,18 +176,33 @@ impl Harmony { /// The rule's colours in the base colour's model, the base colour itself first. pub fn apply(self, base: Color) -> Vec { - let [h, s, v] = base.to_hsb(); - std::iter::once(base) - .chain(self.tones()[1..].iter().map(|tone| { + let rest = self.apply_hsb(base.to_hsb()).into_iter().skip(1); + std::iter::once(base).chain(rest.map(|[h, s, v]| keep_model(base, Color::from_hsb(h, s, v)))).collect() + } + + /// The rule's colours as HSB from base HSB `hsb`, the base first: hue in degrees from 0 to 360, + /// saturation and brightness from 0 to 1. A gray base keeps its hue, so the colours keep their + /// places around a hue wheel. + pub fn apply_hsb(self, [h, s, v]: [f32; 3]) -> Vec<[f32; 3]> { + self.tones() + .iter() + .map(|tone| { let b = match tone.bright { Bright::Times(f) => v * f, Bright::Contrast => contrast(v), }; - keep_model(base, Color::from_hsb(h + tone.turn, (s * tone.sat).clamp(0.0, 1.0), b.clamp(0.0, 1.0))) - })) + [(h + tone.turn).rem_euclid(360.0), (s * tone.sat).clamp(0.0, 1.0), b.clamp(0.0, 1.0)] + }) .collect() } + /// Whether every colour of the rule has a hue of its own (Triad, but not Triad 2 or + /// Monochromatic), so that each can sit on a hue ring apart from the others. + pub fn hues_differ(self) -> bool { + let turns: Vec = self.tones().iter().map(|t| t.turn.rem_euclid(360.0)).collect(); + turns.iter().enumerate().all(|(i, a)| turns[..i].iter().all(|b| a != b)) + } + /// A [`THEME_SIZE`]-colour theme from `base`: the rule's colours, each followed by the lighter or /// darker variations of it that fill the remaining places (the rule's first colours get them /// first). The base colour comes first, every colour in its model. @@ -409,6 +424,34 @@ mod tests { assert_eq!(Harmony::parse("square"), None); } + /// A rule's HSB colours match the colours `apply` gives, and a gray base keeps its hue, so its + /// colours turn around the hue ring from it. + #[test] + fn hsb_colours_match_and_keep_a_grays_hue() { + for h in Harmony::ALL { + let base = Color::rgb8(230, 120, 40); + let hsb = h.apply_hsb(base.to_hsb()); + let colors = h.apply(base); + assert_eq!(hsb.len(), colors.len(), "{}", h.label()); + for (a, c) in hsb.iter().zip(&colors).skip(1) { + assert_eq!(Color::from_hsb(a[0], a[1], a[2]).to_hex(), c.to_hex(), "{}", h.label()); + } + } + let gray = Harmony::Triad.apply_hsb([40.0, 0.0, 0.5]); + assert_eq!(gray.iter().map(|c| c[0]).collect::>(), [40.0, 160.0, 280.0]); + assert_eq!(Harmony::Analogous.apply_hsb([10.0, 1.0, 1.0])[2][0], 340.0, "hues wrap to 0..360"); + } + + /// Fifteen rules give every colour its own hue; the six that repeat a hue are left out. + #[test] + fn rules_whose_colours_all_have_their_own_hue() { + let differ: Vec = Harmony::ALL.into_iter().filter(|h| h.hues_differ()).collect(); + assert_eq!(differ.len(), 15); + for h in [Harmony::Complementary2, Harmony::Monochromatic, Harmony::Shades, Harmony::Triad2, Harmony::Triad3, Harmony::HighContrast2] { + assert!(!h.hues_differ(), "{}", h.label()); + } + } + #[test] fn high_contrast_flips_brightness() { let light = Harmony::HighContrast.apply(Color::rgb(0.9, 0.8, 0.2)); diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index 8e1da7dcf2..97c1dc7f13 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1495,7 +1495,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.colorWheel", "Color Wheel Options", "", - "{view?: wheel|box, channel?: hue|saturation|brightness|red|green|blue, vision?: bool} show the Color Wheel panel's wheel or its box, as the panel menu's Wheel View and Box View do, and pick the box's channel, as Box Channel does: the box is a color field with the channel's strip at its right, and the field shows the other two components (hue: saturation across and brightness up; saturation: hue across and brightness up; brightness: hue across and saturation up; red: blue across and green up; green: blue across and red up; blue: red across and green up); vision shows Show Color Vision Preview's row under the wheel or the box, four chips with the current color as simulated for protanopia, deuteranopia and tritanopia (the simulations of view.proofSetup's protanopia, deuteranopia and tritanopia targets) and for achromatopsia (the gray with the color's CIE L*), each named with its hex value in its tooltip and to screen readers, and taking the keyboard focus; a click or a key on a chip does not apply its color; keys left out or null keep their values ({} reads them), params that are not an object, another key or a value off the list are an error and change nothing, the settings are kept with the preferences, and the command does not open the panel (window.panel {panel: \"colorWheel\"} does) (ui.inspect: ui.color_wheel) → {view, channel, vision}", + "{view?: wheel|box, channel?: hue|saturation|brightness|red|green|blue, harmony?: bool, harmonyRule?: complementary|splitComplementary|leftComplement|rightComplement|analogous|analogous2|triad|tetrad|tetrad2|tetrad3|compound|compound2|highContrast|highContrast3|pentagram, vision?: bool} show the Color Wheel panel's wheel or its box, as the panel menu's Wheel View and Box View do, and pick the box's channel, as Box Channel does: the box is a color field with the channel's strip at its right, and the field shows the other two components (hue: saturation across and brightness up; saturation: hue across and brightness up; brightness: hue across and saturation up; red: blue across and green up; green: blue across and red up; blue: red across and green up); harmony shows a marker on the wheel's ring for each other color of harmonyRule (the Color Guide's rule of that id; a rule's label is taken too), as Show Harmony and Harmony Rule do, and a click on a marker applies its color; vision shows Show Color Vision Preview's row under the wheel or the box, four chips with the current color as simulated for protanopia, deuteranopia and tritanopia (the simulations of view.proofSetup's protanopia, deuteranopia and tritanopia targets) and for achromatopsia (the gray with the color's CIE L*), each named with its hex value in its tooltip and to screen readers, and taking the keyboard focus; a click or a key on a chip does not apply its color; keys left out or null keep their values ({} reads them), params that are not an object, another key or a value off the list are an error and change nothing, the settings are kept with the preferences, and the command does not open the panel (window.panel {panel: \"colorWheel\"} does) (ui.inspect: ui.color_wheel) → {view, channel, harmony, harmonyRule, vision}", ), ( "ui.savePdfDialog", diff --git a/crates/ui-egui/src/i18n/bg.tsv b/crates/ui-egui/src/i18n/bg.tsv index cd947b5195..c3df4ae11b 100644 --- a/crates/ui-egui/src/i18n/bg.tsv +++ b/crates/ui-egui/src/i18n/bg.tsv @@ -581,6 +581,9 @@ font-technology Variable Променливи Box Channel Канал на квадрата Color box Цветови квадрат Color Wheel Options Опции на цветното колело + Show Harmony Показване на хармонията + Harmony Rule Правило за хармония + Harmony color Цвят от хармонията Color Type: Цветен тип: Color: Цвят: Colorize Оцветяване diff --git a/crates/ui-egui/src/i18n/bs.tsv b/crates/ui-egui/src/i18n/bs.tsv index 0624a6301c..c3b3e1b615 100644 --- a/crates/ui-egui/src/i18n/bs.tsv +++ b/crates/ui-egui/src/i18n/bs.tsv @@ -793,6 +793,9 @@ Box Channel Kanal kvadrata Color box Kvadrat boje Color Wheel Options Opcije kotača boja + Show Harmony Prikaži harmoniju + Harmony Rule Pravilo harmonije + Harmony color Boja harmonije CSS Properties CSS svojstva Document Info Informacije o dokumentu Flattener Preview Pregled spljoštavanja diff --git a/crates/ui-egui/src/i18n/ca.tsv b/crates/ui-egui/src/i18n/ca.tsv index 2530d31e44..cd7463d060 100644 --- a/crates/ui-egui/src/i18n/ca.tsv +++ b/crates/ui-egui/src/i18n/ca.tsv @@ -860,6 +860,9 @@ antiAlias Sharp Nítid Box Channel Canal del quadre Color box Quadre de color Color Wheel Options Opcions de la roda de colors + Show Harmony Mostra l’harmonia + Harmony Rule Regla d’harmonia + Harmony color Color de l’harmonia Color Type: Tipus de color: Color wheel Roda de color Color: Color: diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index ba15176e71..f39e5a5cfd 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -807,6 +807,9 @@ Box Channel Kanál čtverce Color box Barevný čtverec Color Wheel Options Možnosti barevného kola + Show Harmony Zobrazit harmonii + Harmony Rule Pravidlo harmonie + Harmony color Barva harmonie CSS Properties Vlastnosti CSS Document Info Informace o dokumentu Flattener Preview Náhled sloučení diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index 4d8a6e759a..aff2b81401 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -3482,6 +3482,9 @@ liquify-list-end {0}, {1} {0} og {1} Box Channel Kvadratets kanal Color box Farvekvadrat Color Wheel Options Indstillinger for farvehjul + Show Harmony Vis harmoni + Harmony Rule Harmoniregel + Harmony color Harmonifarve CSS Properties CSS-egenskaber Document Info Dokumentoplysninger Flattener Preview Udjævningsforhåndsvisning diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index 2b4a0c916a..652f11c489 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -585,6 +585,9 @@ font-technology Variable Variabel Box Channel Kanal des Quadrats Color box Farbquadrat Color Wheel Options Optionen für den Farbkreis + Show Harmony Harmonie einblenden + Harmony Rule Harmonieregel + Harmony color Harmoniefarbe Color Type: Farbart: Color: Farbe: Colorize Einfärben diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index 93206112b9..a9fb4cef3f 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -560,6 +560,9 @@ font-technology Variable Μεταβλητές Box Channel Κανάλι τετραγώνου Color box Τετράγωνο χρώματος Color Wheel Options Επιλογές χρωματικού τροχού + Show Harmony Εμφάνιση αρμονίας + Harmony Rule Κανόνας χρωματικής αρμονίας + Harmony color Χρώμα αρμονίας Color Type: Τύπος χρώματος: Color: Χρώμα: Colorize Χρωματισμός diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 577a63080d..eb4ee115c2 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -605,6 +605,9 @@ font-technology Variable Variables Box Channel Canal del cuadro Color box Cuadro de color Color Wheel Options Opciones de la rueda de color + Show Harmony Mostrar armonía + Harmony Rule Regla de armonía + Harmony color Color de la armonía Color Type: Tipo de color: Color: Color: Colorize Colorear diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index e9a8a3e345..72bf9a2efd 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -793,6 +793,9 @@ Box Channel Ruudun kanava Color box Väriruutu Color Wheel Options Väriympyrän asetukset + Show Harmony Näytä harmonia + Harmony Rule Harmoniasääntö + Harmony color Harmonian väri CSS Properties CSS-ominaisuudet Document Info Asiakirjan tiedot Flattener Preview Litistyksen esikatselu diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index fe58b4cd86..dea7fb606e 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -606,6 +606,9 @@ font-technology Variable Variables Box Channel Couche du carré Color box Carré de couleur Color Wheel Options Options de la roue chromatique + Show Harmony Afficher l’harmonie + Harmony Rule Règle d’harmonie + Harmony color Couleur de l’harmonie Color Type: Type de couleur : Color: Couleur : Colorize Coloriser diff --git a/crates/ui-egui/src/i18n/gu.tsv b/crates/ui-egui/src/i18n/gu.tsv index 0236ef7aa1..313e31b3c5 100644 --- a/crates/ui-egui/src/i18n/gu.tsv +++ b/crates/ui-egui/src/i18n/gu.tsv @@ -4613,6 +4613,9 @@ Box Channel બૉક્સ ચેનલ Color box રંગ બૉક્સ Color Wheel Options રંગ વ્હીલ વિકલ્પો + Show Harmony હાર્મની બતાવો + Harmony Rule હાર્મની નિયમ + Harmony color હાર્મની રંગ {name} (spot) {name} (સ્પૉટ) {pages} in all, {count} per copy કુલ {pages}, પ્રતિ નકલ {count} {page} of {count} {count} માંથી {page} diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index 119374a7d7..cdce21a569 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -1243,6 +1243,9 @@ antiAlias Sharp शार्प Box Channel बॉक्स चैनल Color box कलर बॉक्स Color Wheel Options कलर व्हील ऑप्शन्स + Show Harmony सद्भाव दिखाएँ + Harmony Rule सद्भाव नियम + Harmony color सद्भाव रंग Color Type: रंग का प्रकार: Color wheel कलर व्हील Color: रंग: diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index 570294b038..513e52f893 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -788,6 +788,9 @@ font-technology Variable Változó Box Channel Négyzet csatornája Color box Színnégyzet Color Wheel Options Színkör beállításai + Show Harmony Harmónia megjelenítése + Harmony Rule Harmóniaszabály + Harmony color Harmóniaszín Color Type: Színtípus: Color: Szín: Colorization Színezés diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index d13f74d5d2..871fdf3ca6 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -746,6 +746,9 @@ Box Channel Saluran kotak Color box Kotak warna Color Wheel Options Opsi roda warna + Show Harmony Tampilkan harmoni + Harmony Rule Aturan harmoni + Harmony color Warna harmoni CSS Properties Properti CSS Document Info Info dokumen Flattener Preview Pratinjau perata diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 40b24ceeef..dcfcd146c5 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -607,6 +607,9 @@ font-technology Variable Variabili Box Channel Canale del riquadro Color box Riquadro colore Color Wheel Options Opzioni ruota dei colori + Show Harmony Mostra armonia + Harmony Rule Regola di armonia + Harmony color Colore dell’armonia Color Type: Tipo di colore: Color: Colore: Colorize Colora diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 15c5f86e03..cee526e9ab 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -835,6 +835,9 @@ digits Malayalam マラヤーラム数字 Box Channel ボックスのチャンネル Color box カラーボックス Color Wheel Options カラーホイールオプション + Show Harmony ハーモニーを表示 + Harmony Rule ハーモニールール + Harmony color ハーモニーカラー CSS Properties CSS プロパティ Document Info ドキュメント情報 Flattener Preview 分割・統合プレビュー diff --git a/crates/ui-egui/src/i18n/ka.tsv b/crates/ui-egui/src/i18n/ka.tsv index 8d31c1ef46..257050e8c4 100644 --- a/crates/ui-egui/src/i18n/ka.tsv +++ b/crates/ui-egui/src/i18n/ka.tsv @@ -2916,6 +2916,9 @@ Box Channel კვადრატის არხი Color box ფერის კვადრატი Color Wheel Options ფერთა წრის პარამეტრები + Show Harmony ჰარმონიის ჩვენება + Harmony Rule ჰარმონიის წესი + Harmony color ჰარმონიის ფერი CSS Properties CSS თვისებები Document Info დოკუმენტის ინფორმაცია Flattener Preview გაბრტყელების წინასწარი ნახვა diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index e2712559b7..7aec2b6739 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -828,6 +828,9 @@ digits Malayalam 말라얄람어 Box Channel 상자 채널 Color box 색상 상자 Color Wheel Options 색상환 옵션 + Show Harmony 하모니 표시 + Harmony Rule 하모니 규칙 + Harmony color 하모니 색상 CSS Properties CSS 속성 Document Info 문서 정보 Flattener Preview 병합 미리 보기 diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index 2e0851db2d..64204c6be9 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -1351,6 +1351,9 @@ liquify-list-end {0}, {1} {0} en {1} Box Channel Kanaal van het vak Color box Kleurvak Color Wheel Options Opties voor kleurenwiel + Show Harmony Harmonie tonen + Harmony Rule Harmonieregel + Harmony color Harmoniekleur CSS Properties CSS-eigenschappen Document Info Documentinfo Flattener Preview Afvlakvoorbeeld diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index 2d0bb59d80..265d645813 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -756,6 +756,9 @@ Box Channel Kanał kwadratu Color box Kwadrat koloru Color Wheel Options Opcje koła kolorów + Show Harmony Pokaż harmonię + Harmony Rule Reguła harmonii + Harmony color Kolor harmonii CSS Properties Właściwości CSS Document Info Informacje o dokumencie Flattener Preview Podgląd spłaszczania diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index 1d3fa5cbd5..4004a06051 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -544,6 +544,9 @@ antiAlias Sharp Nítido Box Channel Canal da Caixa Color box Caixa de cor Color Wheel Options Opções da Roda de Cores + Show Harmony Mostrar Harmonia + Harmony Rule Regra de Harmonia + Harmony color Cor da harmonia Color Type: Tipo de Cor: Color blindness – Deuteranopia-type Daltonismo – tipo deuteranopia Color blindness – Protanopia-type Daltonismo – tipo protanopia diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index f97d34eddd..c47ea12848 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -603,6 +603,9 @@ font-technology Variable Вариативные Box Channel Канал квадрата Color box Цветовой квадрат Color Wheel Options Параметры цветового круга + Show Harmony Показать гармонию + Harmony Rule Правило гармонии + Harmony color Цвет гармонии Color Type: Тип цвета: Color: Цвет: Colorize Тонировать diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index 51d1c92a32..99339b2b5d 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -588,6 +588,9 @@ font-technology Variable Variabla Box Channel Rutans kanal Color box Färgruta Color Wheel Options Alternativ för färghjulet + Show Harmony Visa harmoni + Harmony Rule Harmoniregel + Harmony color Harmonifärg Color Type: Färgtyp: Color: Färg: Colorize Färglägg diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index 2774ca3e57..91abbb82f4 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -586,6 +586,9 @@ font-technology Variable Değişken Box Channel Kutu Kanalı Color box Renk kutusu Color Wheel Options Renk Tekerleği Seçenekleri + Show Harmony Uyumu Göster + Harmony Rule Uyum Kuralı + Harmony color Uyum rengi Color Type: Renk Türü: Color: Renk: Colorize Renklendir diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index dd9f711b88..521288445c 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -601,6 +601,9 @@ font-technology Variable Варіативні Box Channel Канал квадрата Color box Колірний квадрат Color Wheel Options Параметри колірного кола + Show Harmony Показати гармонію + Harmony Rule Правило гармонії + Harmony color Колір гармонії Color Type: Тип кольору: Color: Колір: Colorize Тонувати diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index d5ec2245e0..5951c4691e 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -701,6 +701,9 @@ font-technology Variable Biến thiên Box Channel Kênh của hộp Color box Hộp màu Color Wheel Options Tùy chọn bánh xe màu + Show Harmony Hiện hài hòa màu + Harmony Rule Quy tắc hài hòa màu + Harmony color Màu hài hòa Color Type: Loại màu: Color: Màu: Colorization Tô màu diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index e0cfc44b95..4df686ff69 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -552,6 +552,9 @@ antiAlias Sharp 锐利 Box Channel 方块色版 Color box 颜色方块 Color Wheel Options 色轮选项 + Show Harmony 显示协调 + Harmony Rule 协调规则 + Harmony color 协调颜色 Color Type: 颜色类型: Color: 颜色: Colorize 上色 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index 17aabe42e3..a17daad164 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -569,6 +569,9 @@ font-technology Variable 可變 Box Channel 方塊色版 Color box 顏色方塊 Color Wheel Options 色輪選項 + Show Harmony 顯示色彩調和 + Harmony Rule 色彩調和規則 + Harmony color 調和色彩 Color Type: 顏色類型: Color: 顏色: Colorize 上色 diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 60d1f811f9..abcc27138f 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1496,7 +1496,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.colorWheel", "Color Wheel Options", "", - "{view?: wheel|box, channel?: hue|saturation|brightness|red|green|blue, vision?: bool} show the Color Wheel panel's wheel or its box, as the panel menu's Wheel View and Box View do, and pick the box's channel, as Box Channel does: the box is a color field with the channel's strip at its right, and the field shows the other two components (hue: saturation across and brightness up; saturation: hue across and brightness up; brightness: hue across and saturation up; red: blue across and green up; green: blue across and red up; blue: red across and green up); vision shows Show Color Vision Preview's row under the wheel or the box, four chips with the current color as simulated for protanopia, deuteranopia and tritanopia (the simulations of view.proofSetup's protanopia, deuteranopia and tritanopia targets) and for achromatopsia (the gray with the color's CIE L*), each named with its hex value in its tooltip and to screen readers, and taking the keyboard focus; a click or a key on a chip does not apply its color; keys left out or null keep their values ({} reads them), params that are not an object, another key or a value off the list are an error and change nothing, the settings are kept with the preferences, and the command does not open the panel (window.panel {panel: \"colorWheel\"} does) (ui.inspect: ui.color_wheel) → {view, channel, vision}", + "{view?: wheel|box, channel?: hue|saturation|brightness|red|green|blue, harmony?: bool, harmonyRule?: complementary|splitComplementary|leftComplement|rightComplement|analogous|analogous2|triad|tetrad|tetrad2|tetrad3|compound|compound2|highContrast|highContrast3|pentagram, vision?: bool} show the Color Wheel panel's wheel or its box, as the panel menu's Wheel View and Box View do, and pick the box's channel, as Box Channel does: the box is a color field with the channel's strip at its right, and the field shows the other two components (hue: saturation across and brightness up; saturation: hue across and brightness up; brightness: hue across and saturation up; red: blue across and green up; green: blue across and red up; blue: red across and green up); harmony shows a marker on the wheel's ring for each other color of harmonyRule (the Color Guide's rule of that id; a rule's label is taken too), as Show Harmony and Harmony Rule do, and a click on a marker applies its color; vision shows Show Color Vision Preview's row under the wheel or the box, four chips with the current color as simulated for protanopia, deuteranopia and tritanopia (the simulations of view.proofSetup's protanopia, deuteranopia and tritanopia targets) and for achromatopsia (the gray with the color's CIE L*), each named with its hex value in its tooltip and to screen readers, and taking the keyboard focus; a click or a key on a chip does not apply its color; keys left out or null keep their values ({} reads them), params that are not an object, another key or a value off the list are an error and change nothing, the settings are kept with the preferences, and the command does not open the panel (window.panel {panel: \"colorWheel\"} does) (ui.inspect: ui.color_wheel) → {view, channel, harmony, harmonyRule, vision}", ), ( "ui.savePdfDialog", diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index f0005662c7..b59e44949e 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -810,6 +810,8 @@ mod tests_color_wheel; #[cfg(test)] mod tests_color_wheel_box; #[cfg(test)] +mod tests_color_wheel_harmony; +#[cfg(test)] mod tests_color_wheel_vision; #[cfg(test)] mod tests_constrain; diff --git a/crates/ui-egui/src/panels/color_wheel.rs b/crates/ui-egui/src/panels/color_wheel.rs index bbc2b588c5..028652c9bb 100644 --- a/crates/ui-egui/src/panels/color_wheel.rs +++ b/crates/ui-egui/src/panels/color_wheel.rs @@ -12,18 +12,24 @@ //! Brightness, Red, Green or Blue). The field shows the other two components on the Color //! Picker's axes. //! +//! Show Harmony puts a marker on the ring for each other color of the harmony rule picked under +//! Harmony Rule (the Color Guide's rules whose colors each have a hue of their own), filled with +//! that color. The markers follow the current color, and a click on one applies its color as a +//! pick does. +//! //! Panel menu › Show Color Vision Preview adds a row under the wheel or the box with the color as //! simulated for protanopia, deuteranopia and tritanopia, through the simulations View › Proof //! Setup uses, and for achromatopsia as the gray with the color's CIE L*. The chips only show the //! simulation. //! -//! The view, the channel and Show Color Vision Preview are kept with the preferences -//! (`ui.colorWheel`). +//! The view, the channel, Show Harmony, Harmony Rule and Show Color Vision Preview are kept with +//! the preferences (`ui.colorWheel`). use egui::{Rect, Sense, Stroke, StrokeKind, Ui, UiBuilder, vec2}; use serde::{Deserialize, Serialize}; use serde_json::{Value, json}; use vectorcraft_color::cms::{self, Cms, ProofSetup, ProofTarget}; +use vectorcraft_color::harmony::Harmony; use vectorcraft_color::{Color, Paint, hsb_to_rgb, rgb_to_hsb}; use vectorcraft_doc::{ColorMode, NodeId}; @@ -69,19 +75,56 @@ impl View { /// The panel's settings, kept with the preferences (`UiState::color_wheel`, `ui.colorWheel`). /// Each key reads on its own, and a value this build does not know reads as the key's default. -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase", default)] pub struct Settings { #[serde(deserialize_with = "deserialize_view")] pub view: View, #[serde(serialize_with = "serialize_channel", deserialize_with = "deserialize_channel")] pub channel: Channel, + /// Show Harmony: markers on the ring for the other colors of `harmony_rule`. + #[serde(deserialize_with = "deserialize_flag")] + pub harmony: bool, + /// The rule of Show Harmony, one of [`harmony_rules`]. + #[serde(serialize_with = "serialize_rule", deserialize_with = "deserialize_rule")] + pub harmony_rule: Harmony, /// Show Color Vision Preview: the row of simulated colors under the wheel or the box. A saved /// `true` shows the row and any other value hides it. #[serde(deserialize_with = "crate::panels::color::deserialize_rgb_percent")] pub vision: bool, } +impl Default for Settings { + fn default() -> Self { + Self { view: View::default(), channel: Channel::default(), harmony: false, harmony_rule: Harmony::Complementary, vision: false } + } +} + +/// The harmony rules the wheel shows: those whose colors each have a hue of their own, so that no +/// two markers sit at the same place on the ring. +pub fn harmony_rules() -> impl Iterator { + Harmony::ALL.into_iter().filter(|h| h.hues_differ()) +} + +/// The wheel's harmony rule named by `s`, its id or its label. +fn parse_rule(s: &str) -> Option { + Harmony::parse(s).filter(|h| h.hues_differ()) +} + +fn deserialize_flag<'de, D: serde::Deserializer<'de>>(d: D) -> Result { + let v = ::deserialize(d)?; + Ok(v.as_bool().unwrap_or_default()) +} + +fn serialize_rule(h: &Harmony, s: S) -> Result { + s.serialize_str(&h.id()) +} + +fn deserialize_rule<'de, D: serde::Deserializer<'de>>(d: D) -> Result { + let v = ::deserialize(d)?; + Ok(v.as_str().and_then(parse_rule).unwrap_or(Harmony::Complementary)) +} + fn deserialize_view<'de, D: serde::Deserializer<'de>>(d: D) -> Result { let v = ::deserialize(d)?; Ok(v.as_str().and_then(View::parse).unwrap_or_default()) @@ -103,12 +146,12 @@ pub fn deserialize_settings<'de, D: serde::Deserializer<'de>>(d: D) -> Result Result { - const KEYS: [&str; 3] = ["view", "channel", "vision"]; + const KEYS: [&str; 5] = ["view", "channel", "harmony", "harmonyRule", "vision"]; match p { Value::Null => {} Value::Object(o) => { @@ -127,6 +170,21 @@ pub(crate) fn command(app: &mut VectorcraftApp, p: &Value) -> Result {} Some(v) => set.channel = v.as_str().and_then(Channel::parse).ok_or("`channel` must be hue, saturation, brightness, red, green or blue")?, } + let key = "harmony"; + match p.get(key) { + None | Some(Value::Null) => {} + Some(v) => set.harmony = v.as_bool().ok_or_else(|| format!("`{key}` must be true or false"))?, + } + let key = "harmonyRule"; + match p.get(key) { + None | Some(Value::Null) => {} + Some(v) => { + set.harmony_rule = v.as_str().and_then(parse_rule).ok_or_else(|| { + let ids: Vec = harmony_rules().map(Harmony::id).collect(); + format!("`{key}` must be one of {}", ids.join(", ")) + })? + } + } if let Some(on) = crate::menus::opt_bool(p, "vision")? { set.vision = on; } @@ -134,8 +192,8 @@ pub(crate) fn command(app: &mut VectorcraftApp, p: &Value) -> Result = set.harmony_rule.apply_hsb(hsb).into_iter().skip(1).collect(); + let markers = widgets::ring_markers(ui, "color-wheel-harmony", ring.rect, &others, tl!("Harmony color")); + held = markers.held; + if let Some(i) = markers.picked + && let Some(&c) = others.get(i) + { + pick = Some((c, Live::Released)); + } + } + if let Some((h, phase)) = ring.hue + && !held + && pick.is_none() + { pick = Some(([h, hsb[1], hsb[2]], phase)); } // A press between the square and the ring picks the closest point of the square, which diff --git a/crates/ui-egui/src/panels/tests_color_wheel_box.rs b/crates/ui-egui/src/panels/tests_color_wheel_box.rs index d527bf1fa8..3b55f52ac2 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel_box.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel_box.rs @@ -167,16 +167,22 @@ fn the_strip_takes_the_arrow_keys_and_screen_readers_actions() { #[test] fn ui_color_wheel_sets_and_reads_the_view_and_the_channel() { let mut app = VectorcraftApp::new(Session::new(), Default::default()); - assert_eq!(app.run("ui.colorWheel", json!({})).unwrap(), json!({"view": "wheel", "channel": "hue", "vision": false})); - assert_eq!(app.run("ui.colorWheel", json!({"view": "box"})).unwrap(), json!({"view": "box", "channel": "hue", "vision": false})); - assert_eq!(app.run("ui.colorWheel", json!({"channel": "green"})).unwrap(), json!({"view": "box", "channel": "green", "vision": false})); + let harmony = json!({"harmony": false, "harmonyRule": "complementary", "vision": false}); + let with = |v: serde_json::Value| { + let mut v = v; + v.as_object_mut().unwrap().extend(harmony.as_object().unwrap().clone()); + v + }; + assert_eq!(app.run("ui.colorWheel", json!({})).unwrap(), with(json!({"view": "wheel", "channel": "hue"}))); + assert_eq!(app.run("ui.colorWheel", json!({"view": "box"})).unwrap(), with(json!({"view": "box", "channel": "hue"}))); + assert_eq!(app.run("ui.colorWheel", json!({"channel": "green"})).unwrap(), with(json!({"view": "box", "channel": "green"}))); let e = app.run("ui.colorWheel", json!({"view": "triangle"})).unwrap_err(); assert_eq!(e, "`view` must be wheel or box"); let e = app.run("ui.colorWheel", json!({"view": "wheel", "channel": 7})).unwrap_err(); assert_eq!(e, "`channel` must be hue, saturation, brightness, red, green or blue"); - assert_eq!(app.ui.color_wheel, Settings { view: View::Box, channel: Channel::Green, vision: false }, "an error changes nothing"); + assert_eq!(app.ui.color_wheel, Settings { view: View::Box, channel: Channel::Green, ..Default::default() }, "an error changes nothing"); let ui = crate::control::inspect(&app, &egui::Context::default()); - assert_eq!(ui["ui"]["color_wheel"], json!({"view": "box", "channel": "green", "vision": false})); + assert_eq!(ui["ui"]["color_wheel"], with(json!({"view": "box", "channel": "green"}))); } /// The command's errors are translated in the catalogs that translate status and error messages, @@ -211,10 +217,10 @@ fn ui_color_wheel_rejects_other_params() { let e = app.run("ui.colorWheel", json!([1])).unwrap_err(); assert_eq!(e, "the params must be an object, not [1]"); let e = app.run("ui.colorWheel", json!({"veiw": "wheel"})).unwrap_err(); - assert_eq!(e, "unknown parameter `veiw`; the command takes: view, channel, vision"); + assert_eq!(e, "unknown parameter `veiw`; the command takes: view, channel, harmony, harmonyRule, vision"); let e = app.run("ui.colorWheel", json!({"view": "wheel", "chanel": "blue"})).unwrap_err(); - assert_eq!(e, "unknown parameter `chanel`; the command takes: view, channel, vision"); - assert_eq!(app.ui.color_wheel, Settings { view: View::Box, channel: Channel::Red, vision: false }, "an error changes nothing"); + assert_eq!(e, "unknown parameter `chanel`; the command takes: view, channel, harmony, harmonyRule, vision"); + assert_eq!(app.ui.color_wheel, Settings { view: View::Box, channel: Channel::Red, ..Default::default() }, "an error changes nothing"); } /// With None there is no color to edit: the strip reads 0 to screen readers, as the hue ring does, @@ -271,7 +277,7 @@ fn ui_color_wheel_answers_junk_params_without_a_panic() { #[test] fn the_settings_are_kept_and_read_leniently() { let ui = crate::UiState { - color_wheel: Settings { view: View::Box, channel: Channel::Blue, vision: true }, + color_wheel: Settings { view: View::Box, channel: Channel::Blue, vision: true, ..Default::default() }, color_rgb_percent: true, ..Default::default() }; @@ -287,11 +293,11 @@ fn the_settings_are_kept_and_read_leniently() { let mut odd = saved.clone(); odd["color_wheel"] = json!({"view": "box", "channel": 7}); let back: crate::UiState = serde_json::from_value(odd).unwrap(); - assert_eq!(back.color_wheel, Settings { view: View::Box, channel: Channel::default(), vision: false }); + assert_eq!(back.color_wheel, Settings { view: View::Box, channel: Channel::default(), ..Default::default() }); let mut odd = saved.clone(); odd["color_wheel"] = json!({"view": "triangle", "channel": "blue"}); let back: crate::UiState = serde_json::from_value(odd).unwrap(); - assert_eq!(back.color_wheel, Settings { view: View::Wheel, channel: Channel::Blue, vision: false }); + assert_eq!(back.color_wheel, Settings { view: View::Wheel, channel: Channel::Blue, ..Default::default() }); let mut odd = saved; odd["color_wheel"] = json!("box"); let back: crate::UiState = serde_json::from_value(odd).unwrap(); diff --git a/crates/ui-egui/src/panels/tests_color_wheel_harmony.rs b/crates/ui-egui/src/panels/tests_color_wheel_harmony.rs new file mode 100644 index 0000000000..454e43ec49 --- /dev/null +++ b/crates/ui-egui/src/panels/tests_color_wheel_harmony.rs @@ -0,0 +1,351 @@ +//! The Color Wheel panel's Show Harmony drawn headless: the markers of a rule's other colors on the +//! ring, what a click, Alt, Enter and a screen reader do with them, `ui.colorWheel`'s `harmony` and +//! `harmonyRule`, the panel menu and the saved settings. + +use egui::{Event, Modifiers, PointerButton, Pos2, Rect, vec2}; +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; +use serde_json::json; +use vectorcraft_color::Color; +use vectorcraft_color::cms; +use vectorcraft_color::harmony::Harmony; +use vectorcraft_engine::Session; + +use super::color_wheel::{Settings, View, display_hsb, harmony_rules, show}; +use crate::VectorcraftApp; + +/// An app with a selected rectangle filled with `fill`, its Color Wheel panel showing `rule`. +fn app(fill: serde_json::Value, rule: &str) -> VectorcraftApp { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap(); + app.run("paint.setFill", json!({"color": fill})).unwrap(); + app.run("ui.colorWheel", json!({"harmony": true, "harmonyRule": rule})).unwrap(); + app +} + +/// The panel in a 260-point-wide flyout, with the app's shortcuts after it as in a frame of the app. +fn harness(app: VectorcraftApp) -> Harness<'static, VectorcraftApp> { + let mut h = Harness::builder().with_size(vec2(260.0, 320.0)).build_ui_state( + |ui, app: &mut VectorcraftApp| { + show(app, ui); + crate::shortcuts::handle(app, ui.ctx()); + }, + app, + ); + h.run_steps(2); + h +} + +/// The hue (degrees counterclockwise from 3 o'clock) of point `p` on the ring drawn in `ring`. +fn hue_at(ring: Rect, p: Pos2) -> f32 { + let v = p - ring.center(); + (-v.y).atan2(v.x).to_degrees().rem_euclid(360.0) +} + +/// The point at hue `deg` in the middle of the band of the ring drawn in `ring`. +fn on_ring(ring: Rect, deg: f32) -> Pos2 { + let r = ring.width() / 2.0 - 4.0 - 7.0; + let a = deg.to_radians(); + ring.center() + vec2(a.cos(), -a.sin()) * r +} + +/// The centers of the harmony markers, in the rule's order. +fn markers(h: &Harness<'static, VectorcraftApp>) -> Vec { + h.query_all_by_label("Harmony color").map(|n| n.rect().center()).collect() +} + +fn ring(h: &Harness<'static, VectorcraftApp>) -> Rect { + h.get_by_label("Hue ring").rect() +} + +fn press(h: &mut Harness<'static, VectorcraftApp>, pos: Pos2, pressed: bool, modifiers: Modifiers) { + h.event(Event::ModifiersChanged(modifiers)); + h.event(Event::PointerMoved(pos)); + h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers }); + h.run_steps(1); +} + +fn click(h: &mut Harness<'static, VectorcraftApp>, pos: Pos2, modifiers: Modifiers) { + press(h, pos, true, modifiers); + press(h, pos, false, modifiers); + h.event(Event::ModifiersChanged(Modifiers::NONE)); + h.run_steps(1); +} + +/// A drag through `points`, pressed at the first and released at the last. +fn drag(h: &mut Harness<'static, VectorcraftApp>, points: &[Pos2]) { + let (Some(first), Some(last)) = (points.first(), points.last()) else { return }; + press(h, *first, true, Modifiers::NONE); + for p in points { + for _ in 0..2 { + h.event(Event::PointerMoved(*p)); + h.run_steps(1); + } + } + press(h, *last, false, Modifiers::NONE); + h.run_steps(1); +} + +fn fill(app: &VectorcraftApp) -> Color { + crate::panels::current_paints(app).0.color().expect("a solid fill") +} + +fn hsb(c: &Color) -> [f32; 3] { + display_hsb(&cms::active(), c) +} + +fn undo_len(app: &VectorcraftApp) -> usize { + app.session.doc().unwrap().history.undo.len() +} + +/// With the complementary rule and a red fill, a marker sits at 180° on the ring, and a click on it +/// sets the fill to the complement that the rule gives, as one undo step. +#[test] +fn a_complementary_marker_sits_opposite_and_a_click_applies_it() { + let mut h = harness(app(json!("#ff0000"), "complementary")); + let at = markers(&h); + assert_eq!(at.len(), 1, "one other color"); + assert!((hue_at(ring(&h), at[0]) - 180.0).abs() < 1.0, "{}", hue_at(ring(&h), at[0])); + assert_eq!(h.get_by_label("Harmony color").value().as_deref(), Some("#00ffff")); + let undo = undo_len(h.state()); + click(&mut h, at[0], Modifiers::NONE); + let want = Harmony::Complementary.apply(Color::rgb(1.0, 0.0, 0.0))[1]; + assert_eq!(fill(h.state()).to_hex(), want.to_hex()); + assert_eq!(undo_len(h.state()), undo + 1); +} + +/// A click on a High Contrast marker applies the rule's color, whose brightness differs from the +/// current one, and not the hue under the pointer at the current brightness. +#[test] +fn a_click_on_a_marker_applies_the_rules_color_not_the_hue_under_it() { + let mut h = harness(app(json!([0.9, 0.8, 0.2]), "highContrast")); + let base = hsb(&fill(h.state())); + let at = markers(&h); + assert_eq!(at.len(), 1); + click(&mut h, at[0], Modifiers::NONE); + let want = Harmony::HighContrast.apply_hsb(base)[1]; + let got = hsb(&fill(h.state())); + assert!((got[2] - want[2]).abs() < 0.01 && got[2] < 0.5, "{got:?} {want:?}"); + assert!((got[0] - want[0]).abs() < 1.0, "{got:?} {want:?}"); +} + +/// Dragging the current color around the ring moves the other markers by the same angle. +#[test] +fn the_markers_follow_the_current_color() { + let mut h = harness(app(json!("#ff0000"), "triad")); + let r = ring(&h); + let before: Vec = markers(&h).iter().map(|p| hue_at(r, *p)).collect(); + assert_eq!(before.len(), 2); + assert!((before[0] - 120.0).abs() < 1.0 && (before[1] - 240.0).abs() < 1.0, "{before:?}"); + drag(&mut h, &[on_ring(r, 0.0), on_ring(r, 30.0), on_ring(r, 60.0)]); + assert!((hsb(&fill(h.state()))[0] - 60.0).abs() < 1.0, "{:?}", hsb(&fill(h.state()))); + let after: Vec = markers(&h).iter().map(|p| hue_at(r, *p)).collect(); + assert!((after[0] - 180.0).abs() < 1.0 && (after[1] - 300.0).abs() < 1.0, "{after:?}"); +} + +/// A drag that starts on a harmony marker moves the ring's hue as a drag on the band does, as one +/// undo step. +#[test] +fn a_drag_from_a_marker_moves_the_hue() { + let mut h = harness(app(json!("#ff0000"), "triad")); + let r = ring(&h); + let at = markers(&h); + assert!((hue_at(r, at[0]) - 120.0).abs() < 1.0); + let undo = undo_len(h.state()); + drag(&mut h, &[at[0], on_ring(r, 135.0), on_ring(r, 150.0)]); + assert!((hsb(&fill(h.state()))[0] - 150.0).abs() < 1.0, "{:?}", hsb(&fill(h.state()))); + assert_eq!(undo_len(h.state()), undo + 1); +} + +/// A press held on a High Contrast marker past the length of a click, without moving, applies the +/// rule's color on release, and the hue under the pointer is not previewed while it is held. +#[test] +fn a_press_held_on_a_marker_applies_the_rules_color() { + let mut h = harness(app(json!([0.9, 0.8, 0.2]), "highContrast")); + let base = hsb(&fill(h.state())); + let at = markers(&h); + assert_eq!(at.len(), 1); + let undo = undo_len(h.state()); + press(&mut h, at[0], true, Modifiers::NONE); + h.run_steps(6); + assert_eq!(hsb(&fill(h.state())), base, "nothing changes while the press is held"); + press(&mut h, at[0], false, Modifiers::NONE); + h.run_steps(1); + let want = Harmony::HighContrast.apply_hsb(base)[1]; + let got = hsb(&fill(h.state())); + assert!((got[2] - want[2]).abs() < 0.01 && (got[0] - want[0]).abs() < 1.0, "{got:?} {want:?}"); + assert_eq!(undo_len(h.state()), undo + 1); +} + +/// Alt-click on a marker paints the stroke, and the fill stays in front. +#[test] +fn alt_click_on_a_marker_paints_the_stroke() { + let mut app = app(json!("#ff0000"), "complementary"); + app.run("paint.setStroke", json!({"color": "#808080", "focus": false})).unwrap(); + let mut h = harness(app); + let at = markers(&h); + click(&mut h, at[0], Modifiers::ALT); + let (f, s) = crate::panels::current_paints(h.state()); + assert_eq!((f.color().unwrap().to_hex(), s.color().unwrap().to_hex()), ("#ff0000".into(), "#00ffff".into())); + assert!(h.state().session.fill_active); +} + +/// A click gives a marker the keyboard focus, and Enter or Space then applies its color; a screen +/// reader's click applies it too. +#[test] +fn the_markers_take_enter_space_and_a_screen_readers_click() { + let mut h = harness(app(json!("#ff0000"), "splitComplementary")); + let at = markers(&h); + assert_eq!(at.len(), 2); + click(&mut h, at[0], Modifiers::NONE); + assert!((hsb(&fill(h.state()))[0] - 150.0).abs() < 1.0, "{:?}", hsb(&fill(h.state()))); + // The markers moved with the color: from 150°, the focused first one is at 300°. + let undo = undo_len(h.state()); + h.key_press_modifiers(Modifiers::NONE, egui::Key::Enter); + h.run_steps(1); + assert!((hsb(&fill(h.state()))[0] - 300.0).abs() < 1.0, "{:?}", hsb(&fill(h.state()))); + h.key_press_modifiers(Modifiers::NONE, egui::Key::Space); + h.run_steps(1); + assert!((hsb(&fill(h.state()))[0] - 90.0).abs() < 1.0, "{:?}", hsb(&fill(h.state()))); + assert_eq!(undo_len(h.state()), undo + 2, "one undo step a key"); + let node = h.get_all_by_label("Harmony color").nth(1).unwrap(); + assert!(node.accesskit_node().data().supports_action(egui::accesskit::Action::Click)); + node.click_accesskit(); + h.run_steps(2); + assert!((hsb(&fill(h.state()))[0] - 300.0).abs() < 1.0, "{:?}", hsb(&fill(h.state()))); +} + +/// No markers show with Show Harmony off, in the box view, or with no color to edit. +#[test] +fn markers_show_only_on_the_wheel_with_a_color() { + let mut a = app(json!("#ff0000"), "triad"); + a.run("ui.colorWheel", json!({"harmony": false})).unwrap(); + assert!(markers(&harness(a)).is_empty()); + let mut a = app(json!("#ff0000"), "triad"); + a.run("ui.colorWheel", json!({"view": "box"})).unwrap(); + assert!(markers(&harness(a)).is_empty()); + let mut a = app(json!("#ff0000"), "triad"); + a.run("paint.setFill", json!({"none": true})).unwrap(); + assert!(markers(&harness(a)).is_empty()); +} + +/// A gray keeps the hue it was picked at, and its markers stay apart around the ring. +#[test] +fn a_gray_markers_turn_from_its_hue() { + let mut h = harness(app(json!([0.3, 0.6, 0.9]), "tetrad2")); + let r = ring(&h); + let hue = hsb(&fill(h.state()))[0]; + let sq = h.get_by_label("Saturation and brightness").rect(); + // A press between the square and the ring picks the square's left edge: no saturation. + click(&mut h, Pos2::new(sq.left() - 3.0, sq.center().y), Modifiers::NONE); + assert_eq!(hsb(&fill(h.state()))[1], 0.0, "a gray"); + let hues: Vec = markers(&h).iter().map(|p| hue_at(r, *p)).collect(); + assert_eq!(hues.len(), 3); + for (got, turn) in hues.iter().zip([90.0, 180.0, 270.0]) { + assert!(((got - hue - turn).rem_euclid(360.0) + 0.5).rem_euclid(360.0) < 2.0, "{hue} {hues:?}"); + } +} + +/// `ui.colorWheel` sets and answers `harmony` and `harmonyRule`, takes a rule's label as well as its +/// id, and answers an error that changes nothing for a value that is not a boolean or a rule +/// outside the wheel's list. +#[test] +fn ui_color_wheel_sets_the_harmony_and_its_rule() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let got = app.run("ui.colorWheel", json!({"harmony": true, "harmonyRule": "Split Complementary"})).unwrap(); + assert_eq!((got["harmony"].clone(), got["harmonyRule"].clone()), (json!(true), json!("splitComplementary"))); + let e = app.run("ui.colorWheel", json!({"harmony": "yes"})).unwrap_err(); + assert_eq!(e, "`harmony` must be true or false"); + let e = app.run("ui.colorWheel", json!({"view": "box", "harmonyRule": "monochromatic"})).unwrap_err(); + assert_eq!( + e, + "`harmonyRule` must be one of complementary, splitComplementary, leftComplement, rightComplement, analogous, analogous2, triad, \ + tetrad, tetrad2, tetrad3, compound, compound2, highContrast, highContrast3, pentagram" + ); + assert_eq!(app.ui.color_wheel, Settings { harmony: true, harmony_rule: Harmony::SplitComplementary, ..Default::default() }, "nothing changed"); + // Turning Show Harmony off and on keeps the rule. + app.run("ui.colorWheel", json!({"harmony": false})).unwrap(); + let got = app.run("ui.colorWheel", json!({"harmony": true})).unwrap(); + assert_eq!(got["harmonyRule"], json!("splitComplementary")); +} + +/// The errors are translated in the catalogs that translate status and error messages, and each +/// translation keeps the key and the accepted values. +#[test] +fn ui_color_wheel_harmony_errors_are_translated() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let flag = app.run("ui.colorWheel", json!({"harmony": 1})).unwrap_err(); + let rule = app.run("ui.colorWheel", json!({"harmonyRule": "shades"})).unwrap_err(); + for code in [ + "cs", "de", "el", "es", "fr", "hi", "hu", "it", "ja", "ka", "ko", "pl", "pt-br", "ru", "sv", "uk", "vi", "zh-hans", "zh-hant", "fi", "tr", + "ca", "nl", "bs", "da", "id", + ] { + let lang = crate::i18n::Lang::from_code(code).expect("registered"); + let shown = crate::i18n::message(lang, &flag); + assert!(shown != flag && shown.contains("`harmony`"), "{code}: {shown}"); + let shown = crate::i18n::message(lang, &rule); + assert!(shown != rule && shown.contains("`harmonyRule`") && shown.contains("highContrast3"), "{code}: {shown}"); + } +} + +/// The wheel offers the fifteen rules whose colors each have a hue of their own. +#[test] +fn the_wheel_offers_fifteen_rules_without_monochromatic() { + let rules: Vec = harmony_rules().collect(); + assert_eq!(rules.len(), 15); + assert!(!rules.contains(&Harmony::Monochromatic) && !rules.contains(&Harmony::Triad2)); + assert!(rules.contains(&Harmony::Pentagram) && rules.contains(&Harmony::HighContrast3)); +} + +/// The settings survive a JSON round trip of the preferences, and a saved value this build does +/// not know, or a rule the wheel leaves out, reads as the key's default. +#[test] +fn the_harmony_settings_are_kept_and_read_leniently() { + let set = Settings { view: View::Wheel, harmony: true, harmony_rule: Harmony::Pentagram, ..Default::default() }; + let ui = crate::UiState { color_wheel: set.clone(), color_rgb_percent: true, ..Default::default() }; + let saved = serde_json::to_value(&ui).unwrap(); + assert_eq!(saved["color_wheel"]["harmonyRule"], json!("pentagram")); + let back: crate::UiState = serde_json::from_value(saved.clone()).unwrap(); + assert_eq!(back.color_wheel, set); + let mut odd = saved; + odd["color_wheel"]["harmony"] = json!("yes"); + odd["color_wheel"]["harmonyRule"] = json!("monochromatic"); + let back: crate::UiState = serde_json::from_value(odd).unwrap(); + assert_eq!((back.color_wheel.harmony, back.color_wheel.harmony_rule), (false, Harmony::Complementary)); + assert!(back.color_rgb_percent, "the other preferences are kept"); +} + +/// The panel menu's Show Harmony is checked while on and gray while the box shows, and Harmony Rule +/// lists the wheel's rules with the current one checked; its items set the rule. +#[test] +fn the_panel_menu_shows_the_harmony_and_picks_the_rule() { + let a = app(json!("#ff0000"), "triad"); + let mut fonts = false; + let mut h = Harness::builder().with_size(vec2(260.0, 600.0)).build_ui_state( + move |ui, app: &mut VectorcraftApp| { + // The fonts, which draw the check mark, take effect from the next frame. + if !fonts { + crate::theme::install_fonts(ui.ctx()); + fonts = true; + return; + } + assert!(super::panel_menu_items(app, ui, super::color_wheel::ID)); + }, + a, + ); + h.run_steps(3); + assert!(!h.get_by_label("✓ Show Harmony").accesskit_node().data().is_disabled()); + h.get_by_label(" Harmony Rule").click(); + h.run_steps(2); + assert!(h.query_by_label("✓ Triad").is_some()); + assert!(h.query_by_label(" Pentagram").is_some()); + assert!(h.query_by_label(" Monochromatic").is_none() && h.query_by_label(" Shades").is_none()); + h.get_by_label(" Pentagram").click(); + h.run_steps(2); + assert_eq!(h.state().ui.color_wheel.harmony_rule, Harmony::Pentagram); + h.state_mut().run("ui.colorWheel", json!({"view": "box"})).unwrap(); + h.run_steps(2); + assert!(h.get_by_label("✓ Show Harmony").accesskit_node().data().is_disabled(), "gray while the box shows"); + assert!(h.get_by_label(" Harmony Rule").accesskit_node().data().is_disabled(), "gray while the box shows"); +} diff --git a/crates/ui-egui/src/panels/tests_color_wheel_vision.rs b/crates/ui-egui/src/panels/tests_color_wheel_vision.rs index 5c73496642..7c07b71f90 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel_vision.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel_vision.rs @@ -225,24 +225,26 @@ fn the_panel_menu_turns_the_row_on_and_off() { #[test] fn ui_color_wheel_sets_and_reads_the_settings() { let mut app = VectorcraftApp::new(Session::new(), Default::default()); - assert_eq!(app.run("ui.colorWheel", json!({})).unwrap(), json!({"view": "wheel", "channel": "hue", "vision": false})); - assert_eq!(app.run("ui.colorWheel", json!({"vision": true})).unwrap(), json!({"view": "wheel", "channel": "hue", "vision": true})); + let settings = + |view: &str, vision: bool| json!({"view": view, "channel": "hue", "harmony": false, "harmonyRule": "complementary", "vision": vision}); + assert_eq!(app.run("ui.colorWheel", json!({})).unwrap(), settings("wheel", false)); + assert_eq!(app.run("ui.colorWheel", json!({"vision": true})).unwrap(), settings("wheel", true)); assert_eq!(crate::control::inspect(&app, &egui::Context::default())["ui"]["color_wheel"]["vision"], true); assert_eq!(app.run("ui.colorWheel", json!({"vision": "no"})).unwrap_err(), "`vision` must be true or false"); assert_eq!(app.run("ui.colorWheel", json!({"view": "box", "channel": "red", "vision": 1})).unwrap_err(), "`vision` must be true or false"); - assert_eq!(app.run("ui.colorWheel", json!({})).unwrap(), json!({"view": "wheel", "channel": "hue", "vision": true})); + assert_eq!(app.run("ui.colorWheel", json!({})).unwrap(), settings("wheel", true)); assert_eq!(app.run("ui.colorWheel", json!("junk")).unwrap_err(), "the params must be an object, not \"junk\""); assert_eq!(app.run("ui.colorWheel", json!(5)).unwrap_err(), "the params must be an object, not 5"); assert_eq!( app.run("ui.colorWheel", json!({"visoin": false})).unwrap_err(), - "unknown parameter `visoin`; the command takes: view, channel, vision" + "unknown parameter `visoin`; the command takes: view, channel, harmony, harmonyRule, vision" ); assert!(app.ui.color_wheel.vision); assert_eq!(app.run("ui.colorWheel", json!({"vision": null})).unwrap()["vision"], true); assert_eq!(app.run("ui.colorWheel", Value::Null).unwrap()["vision"], true); // Setting the view or the channel keeps the row, and setting the row keeps them. assert_eq!(app.run("ui.colorWheel", json!({"view": "box"})).unwrap()["vision"], true); - assert_eq!(app.run("ui.colorWheel", json!({"vision": false})).unwrap(), json!({"view": "box", "channel": "hue", "vision": false})); + assert_eq!(app.run("ui.colorWheel", json!({"vision": false})).unwrap(), settings("box", false)); } /// `ui.colorWheel` answers every junk parameter, with and without a document, without a panic. diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index d6a0f7c50e..3ec5d25613 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -37,10 +37,10 @@ pub(crate) use buttons::{ 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, WheelAxes, WheelResponse, channel_slider, channel_slider_named, channel_slider_stepped, - 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, + FieldAxis, Live, MarkerResponse, RingResponse, SliderValue, WheelAxes, WheelResponse, channel_slider, channel_slider_named, + channel_slider_stepped, 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_markers, ring_square, segment_color, + segment_color_on, segmented_wheel, stepped_area, wheel_of, }; pub(crate) use color::{HEX_FIELD_CHARS, focus_by_pointer, 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 54d52a6ccf..882e236363 100644 --- a/crates/ui-egui/src/widgets/color.rs +++ b/crates/ui-egui/src/widgets/color.rs @@ -972,6 +972,68 @@ pub fn hue_ring(ui: &mut Ui, id: impl std::hash::Hash, name: &str, size: f32, hu out } +/// What [`ring_markers`] did this frame. +#[derive(Clone, Copy, Debug, Default)] +pub struct MarkerResponse { + /// The index of the marker that was picked. + pub picked: Option, + /// A press on a marker is held with the pointer still on the marker. The caller then ignores + /// the drag that the ring under it reports. + pub held: bool, +} + +/// Markers on a [`hue_ring`] drawn in `rect`, one for each HSB of `colors` at its hue, filled with +/// its color and smaller than the ring's own marker. Each marker is a button that screen readers +/// read as `name` with the color's hex value. A click gives it the keyboard focus. A click, a +/// press released on the marker however long it was held, Enter or Space on the focused marker, +/// or a screen reader's click picks it. A drag that leaves the marker moves the ring's hue as a +/// drag on the band does. +pub fn ring_markers(ui: &mut Ui, id: &str, rect: Rect, colors: &[[f32; 3]], name: &str) -> MarkerResponse { + let t = Tokens::get(ui.ctx()); + let c = rect.center(); + let mid = rect.width().min(rect.height()) / 2.0 - RING_MARGIN - RING_WIDTH / 2.0; + let radius = RING_WIDTH / 2.0 - 2.0; + let painter = ui.painter_at(rect); + let press_id = id_with(ui.scope_id(), (id, "press")); + let (pos, down, pressed, released) = + ui.input(|i| (i.pointer.latest_pos(), i.pointer.primary_down(), i.pointer.primary_pressed(), i.pointer.primary_released())); + let mut held_on: Option = ui.data(|d| d.get_temp(press_id)).flatten(); + let mut picked = None; + for (i, hsb) in colors.iter().enumerate() { + let p = wheel_pos(c, mid, hsb[0], 1.0); + let area = Rect::from_center_size(p, Vec2::splat(RING_WIDTH)); + let resp = ui.interact(area, id_with(ui.scope_id(), (id, i)), Sense::click()); + focus_on_press(&resp); + if pressed && resp.is_pointer_button_down_on() { + held_on = Some(i); + } + let on = pos.is_some_and(|p| area.contains(p)); + if held_on == Some(i) && !on { + held_on = None; + } + let fill = hsb32(*hsb); + painter.circle(p, radius, fill, Stroke::new(1.0, Color32::WHITE)); + painter.circle_stroke(p, radius + 1.0, Stroke::new(1.0, Color32::BLACK)); + if ui.memory(|m| m.has_focus(resp.id)) { + painter.circle_stroke(p, radius + 3.0, Stroke::new(1.0, t.accent)); + } + let hex = format!("#{:02x}{:02x}{:02x}", fill.r(), fill.g(), fill.b()); + resp.widget_info(|| egui::WidgetInfo { + current_text_value: Some(hex.clone()), + ..egui::WidgetInfo::labeled(egui::Role::Button, ui.is_enabled(), name) + }); + if resp.clicked() || (held_on == Some(i) && released && on) { + picked = Some(i); + } + } + if held_on.is_some_and(|i| i >= colors.len()) { + held_on = None; + } + let held = down && held_on.is_some(); + ui.data_mut(|d| d.insert_temp(press_id, if down { held_on } else { None })); + MarkerResponse { picked, held } +} + /// 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; diff --git a/docs/control-protocol.md b/docs/control-protocol.md index b3ab28fb7c..8773cad601 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -268,9 +268,10 @@ My Themes tab lists the saved themes; every action runs a command (`colorTheme.s Color Wheel panel (`window.panel {panel: "colorWheel"}`): a hue ring around a saturation and brightness square. A pick runs the commands the Color panel's sliders run: `paint.setFill` or `paint.setStroke` with `keepModel`, `paint.editGradient` for a gradient's selected stop, and `paint.freeform.setPoint` for a freeform gradient's selected -point (the first stop or point when none is selected). `ui.colorWheel {view?, channel?, vision?}` shows the wheel or -the box (a color field with a channel strip at its right), picks the box's channel and shows or hides the color vision -row; it returns the settings, and `ui.inspect` reports them as `ui.color_wheel`. +point (the first stop or point when none is selected). `ui.colorWheel {view?, channel?, harmony?, harmonyRule?, vision?}` +shows the wheel or the box (a color field with a channel strip at its right), picks the box's channel, shows the +other colors of a harmony rule as markers on the wheel's ring, and shows or hides the color vision row; it returns +the settings, and `ui.inspect` reports them as `ui.color_wheel`. Edit Colors dialogs: `ui.colorBalanceDialog` opens Adjust Colors (`colorBalance`: fields `mode` `gray`/`rgb`/`cmyk`/ `global`, the channels `r` `g` `b` / `c` `m` `y` `k` / `gray` / `tint` (global mode) from −100 to 100, `convert`, `fill`, `stroke`, diff --git a/docs/mcp.md b/docs/mcp.md index aef85b8a45..5cbec862b8 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -683,9 +683,12 @@ RGB fields in percent, as a double-click right of an RGB field does, and `false` and answers true when the fields show in percent. `ui.colorWheel {"view": "box", "channel": "red"}` shows the Color Wheel panel's box (a color field with the channel's strip at its right) in place of the wheel, as the panel menu's Box View and Box Channel do, and `"view": "wheel"` -shows the wheel again. Keys left out keep their values. Params that are not an object, another key or a value off -the list return an error and change nothing. The command returns `{view, channel, vision}`, and the settings are -kept with the preferences. +shows the wheel again. `{"harmony": true, "harmonyRule": "triad"}` puts a marker on the wheel's ring for each other +color of a Color Guide harmony rule, as Show Harmony and Harmony Rule do; the wheel takes the 15 rules whose colors +each have a hue of their own (not `monochromatic`, `shades`, `complementary2`, `triad2`, `triad3` or +`highContrast2`). Keys left out keep their values. Params that are not an object, another key or a value off +the list return an error and change nothing. The command returns `{view, channel, harmony, harmonyRule, vision}`, +and the settings are kept with the preferences. `ui.colorWheel {"vision": true}` turns on the Color Wheel panel's Show Color Vision Preview, as its panel menu does: a row of four chips under the wheel or the box shows the current color through the protanopia, deuteranopia and tritanopia simulations of `view.proofSetup`, and for achromatopsia as the gray with the color's CIE L*. Each diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 167e60e06b..1d08309500 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1886,7 +1886,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Colorized images (#1466):** a fill color applied to a selected grayscale or 1-bit image (`paint.setFill`) colorizes it with black, white, a process color or a spot color, and refuses a process color when the image has an alpha channel ([Convert color modes](https://web.archive.org/web/20251220223850/https://helpx.adobe.com/illustrator/desktop/manage-colors/select-and-adjust-colors/convert-color-modes.html), "Colorize Grayscale or 1-bit images"); black and white are accepted there too. The canvas draws each pixel in the color as far as the pixel is dark, with white pixels transparent; PDF export writes the image in the color (a spot color as its ink, Registration in every ink) with the image as its soft mask; Separations Preview and printed separations show it on its color's plates; native files keep the color. EPS and SVG write the image's own pixels. - **Missing library files:** a persistent swatch or graphic style library panel whose file is gone at startup reopens and stays in the preferences, showing the file's path with Locate Library… (`ui.libraryPanel.locate`), which reads the file from where it is now into the same panel. - **Swatch library and Recolor Artwork parameters:** the `swatch.library.*` commands, `swatch.resetDefaults`, the graphic style library save, load and add, the `recolor.*` commands and `color.harmony`'s `limitTo` refuse parameters of the wrong form, such as `names: "Grays"`, `limitTo: 5` or `includeImages: "false"`. Errors name the parameter, except that a `limitTo` that is not a string, such as `5`, gets an unknown-library error. A `null` counts as left out except for `recolor.apply`'s `model`, which must be a string when given. - - **Color Wheel panel (part of #978):** Window › Color Wheel shows the Fill and Stroke proxy beside a hue ring around a square with saturation across and brightness up. It edits what the Color panel's sliders edit (the active proxy's color, the selected gradient stop or freeform point) through the same paint commands, and a drag is one undo step. Alt paints the other proxy, and Shift steps the ring by 45°. A pick goes from display sRGB into the working RGB space; an RGB, CMYK or Lab color keeps its model, and a Gray color or a tint of a global swatch becomes a process color in the document's color mode. A click gives the ring or the square the keyboard focus, and the arrow keys then step the color; both report their names and values to screen readers, and the Color Picker's color field takes the same keys. The panel menu's Box View puts a box in the wheel's place: a color field with a channel strip at its right for Hue, Saturation, Brightness, Red, Green or Blue (Box Channel), on the Color Picker's axes, kept with the preferences (`ui.colorWheel`); the strip and the Color Picker's channel slider take the arrow keys after a click. Scores and estimates are unchanged. + - **Color Wheel panel (part of #978):** Window › Color Wheel shows the Fill and Stroke proxy beside a hue ring around a square with saturation across and brightness up. It edits what the Color panel's sliders edit (the active proxy's color, the selected gradient stop or freeform point) through the same paint commands, and a drag is one undo step. Alt paints the other proxy, and Shift steps the ring by 45°. A pick goes from display sRGB into the working RGB space; an RGB, CMYK or Lab color keeps its model, and a Gray color or a tint of a global swatch becomes a process color in the document's color mode. A click gives the ring or the square the keyboard focus, and the arrow keys then step the color; both report their names and values to screen readers, and the Color Picker's color field takes the same keys. The panel menu's Box View puts a box in the wheel's place: a color field with a channel strip at its right for Hue, Saturation, Brightness, Red, Green or Blue (Box Channel), on the Color Picker's axes, kept with the preferences (`ui.colorWheel`); the strip and the Color Picker's channel slider take the arrow keys after a click. The panel menu's Show Harmony marks the other colors of a harmony rule (Harmony Rule) on the ring; the markers follow the current color, and a click on a marker applies its color (`ui.colorWheel {harmony, harmonyRule}`). Scores and estimates are unchanged. - **Colour:** a Color Picker (colour field, H/S/B/R/G/B channel slider, HSB/RGB/Lab/CMYK fields, hex, web-only snapping, out-of-gamut correction); the Color panel shows a selected colour in its own model and, with nothing selected, the new-art defaults in the mode picked last, which it keeps between sessions; Alt-click paints the other proxy; proxies look through groups and show "?" for mixed paint; Invert, Complement, Apply Last Color (`,`) and Apply Last Gradient (`.`) keep the colour model; every paint command feeds the recent colours. The Color Guide has 21 harmony rules, Steps and Variation options and Limit to Library. Adjust Color Balance (its Global mode shifts tints) and Saturate preview live; Edit Colors and Recolor also reach meshes, images and patterns. Recolor Artwork has colour reduction, five recolour methods, presets, Limit to Library, a colour-wheel Edit tab and Edit Color Group; a local Color Themes panel saves five-colour themes. Fill/Stroke chips open swatch and mixer popovers (the Properties panel has the Control bar's Fill and Stroke chips, Stroke link and weight spinner, with nothing selected too), panels have Illustrator's Window menu keys (Align Shift+F7, Transform Shift+F8, Pathfinder Cmd+Shift+F9, Layers F7, Character Cmd+T…; every panel can be given one in Edit › Keyboard Shortcuts), and Eyedropper Options pick up and apply chosen attributes (Alt and Shift+Alt, image pixels). An ICC CMYK profile converts straight into the RGB working space (not through sRGB, so a wider space such as Wide Gamut RGB keeps colours sRGB can't hold) with the colour settings' black-point compensation, on the canvas and in RGB exports alike (the built-in Generic CMYK compensates both ways, so RGB black separated to a rich black displays as black again). Fills and strokes can overprint (Attributes panel, Overprint Black options), and CMYK documents blend in inks on screen, in PDF and when flattening. Document Color Mode converts the art, symbols, pattern tiles and swatches through the colour settings: Gray stays Gray, RGB grays separate into light grays in cyan, magenta and yellow only, darker four-color grays and a rich black, or go on the black plate only with `grays: "black"` (also for `document.open {colorMode}`). **Color panel spectrum mode tooltip (part of #7235):** hovering the spectrum names the displayed mode (Grayscale, RGB, HSB, CMYK, Web Safe RGB or Lab), including after Shift-clicking to switch modes and with Show Options or Hide Options. Hovering changes no paint or undo history. Spectrum rendering and vertical resizing remain open. Evidence: `spectrum_tooltip_names_its_displayed_mode` and `spectrum_tooltip_follows_shift_cycle_without_painting` in `crates/ui-egui/tests/color_working_components.rs`. Scores and estimates unchanged.