From 7292350010aeb0c297af3efd07da648f40b981e3 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 07:45:12 -0800 Subject: [PATCH 1/2] Color Wheel: Show Color Vision Preview shows the color through four color vision simulations The Color Wheel panel's menu gains Show Color Vision Preview, which adds a row of four chips under the wheel or the box: the current color through the protanopia, deuteranopia and tritanopia simulations that View > Proof Setup uses (Cms::proof_srgb), and an achromatopsia chip that shows the gray with the color's CIE L*, a rule of VectorCraft's own. Each chip takes the keyboard focus, reports its name and its hex value to screen readers and shows both in its tooltip. A click or a key on a chip does not apply its color. With no solid color the chips are empty and keep their names. ui.colorWheel takes a vision key next to view and channel and returns all three. A value that is not true, false or null is an error and changes nothing. The setting is kept with the preferences, and a saved value the build does not read falls back to the default without losing the other settings. New strings have rows in the complete catalogs. Docs: docs/mcp.md, docs/control-protocol.md, docs/target-app-parity.md. --- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/i18n/bg.tsv | 5 + crates/ui-egui/src/i18n/bs.tsv | 5 + crates/ui-egui/src/i18n/ca.tsv | 5 + crates/ui-egui/src/i18n/cs.tsv | 5 + crates/ui-egui/src/i18n/da.tsv | 5 + crates/ui-egui/src/i18n/de.tsv | 5 + crates/ui-egui/src/i18n/el.tsv | 5 + crates/ui-egui/src/i18n/es.tsv | 5 + crates/ui-egui/src/i18n/fi.tsv | 5 + crates/ui-egui/src/i18n/fr.tsv | 5 + crates/ui-egui/src/i18n/gu.tsv | 5 + crates/ui-egui/src/i18n/hi.tsv | 5 + crates/ui-egui/src/i18n/hu.tsv | 5 + crates/ui-egui/src/i18n/id.tsv | 5 + crates/ui-egui/src/i18n/it.tsv | 5 + crates/ui-egui/src/i18n/ja.tsv | 5 + crates/ui-egui/src/i18n/ka.tsv | 5 + crates/ui-egui/src/i18n/ko.tsv | 5 + crates/ui-egui/src/i18n/nl.tsv | 5 + crates/ui-egui/src/i18n/pl.tsv | 5 + crates/ui-egui/src/i18n/pt-br.tsv | 5 + crates/ui-egui/src/i18n/ru.tsv | 5 + crates/ui-egui/src/i18n/sv.tsv | 5 + crates/ui-egui/src/i18n/tr.tsv | 5 + crates/ui-egui/src/i18n/uk.tsv | 5 + crates/ui-egui/src/i18n/vi.tsv | 5 + crates/ui-egui/src/i18n/zh-hans.tsv | 5 + crates/ui-egui/src/i18n/zh-hant.tsv | 5 + crates/ui-egui/src/menus/ui_commands.rs | 2 +- crates/ui-egui/src/panels.rs | 2 + crates/ui-egui/src/panels/color_wheel.rs | 97 ++++++- .../src/panels/tests_color_wheel_box.rs | 26 +- .../src/panels/tests_color_wheel_vision.rs | 258 ++++++++++++++++++ crates/ui-egui/src/state.rs | 3 +- docs/control-protocol.md | 6 +- docs/mcp.md | 6 + docs/target-app-parity.md | 1 + 38 files changed, 519 insertions(+), 24 deletions(-) create mode 100644 crates/ui-egui/src/panels/tests_color_wheel_vision.rs diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index 943faa4782..0af5289bd9 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1324,7 +1324,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.colorWheel", "Color Wheel Options", "", - "{view?: wheel|box, channel?: hue|saturation|brightness|red|green|blue} 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); keys left out keep their values, params that are not an object, another key or a value off the list are an error and change nothing, both 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}", + "{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}", ), ( "ui.savePdfDialog", diff --git a/crates/ui-egui/src/i18n/bg.tsv b/crates/ui-egui/src/i18n/bg.tsv index 348ac7b881..7017ac7bd3 100644 --- a/crates/ui-egui/src/i18n/bg.tsv +++ b/crates/ui-egui/src/i18n/bg.tsv @@ -5810,6 +5810,11 @@ theme Appearance Външен вид The active document changed while the screen color sampler was open Активният документ се промени, докато взимането на цвят от екрана беше отворено This system has no screen color sampler Тази система няма инструмент за взимане на цвят от екрана Color blindness – Tritanopia-type Цветна слепота – тип тританопия + Show Color Vision Preview Показване на преглед на цветовото зрение + Protanopia Протанопия + Deuteranopia Девтеранопия + Tritanopia Тританопия + Achromatopsia Ахроматопсия Panels Except Tools and Control Панели без инструменти и контрол # Type › Reset Tracking and Kerning diff --git a/crates/ui-egui/src/i18n/bs.tsv b/crates/ui-egui/src/i18n/bs.tsv index 3b1a9e001c..a1af907e0c 100644 --- a/crates/ui-egui/src/i18n/bs.tsv +++ b/crates/ui-egui/src/i18n/bs.tsv @@ -592,6 +592,11 @@ Color blindness – Protanopia-type Daltonizam – tip protanopije Color blindness – Deuteranopia-type Daltonizam – tip deuteranopije Color blindness – Tritanopia-type Daltonizam – tip tritanopije + Show Color Vision Preview Prikaži pregled vida boja + Protanopia Protanopija + Deuteranopia Deuteranopija + Tritanopia Tritanopija + Achromatopsia Ahromatopsija Customize… Prilagodi… Proof Colors Probne boje Zoom In Uvećaj diff --git a/crates/ui-egui/src/i18n/ca.tsv b/crates/ui-egui/src/i18n/ca.tsv index 488b46c4f5..de7451339b 100644 --- a/crates/ui-egui/src/i18n/ca.tsv +++ b/crates/ui-egui/src/i18n/ca.tsv @@ -779,6 +779,11 @@ antiAlias Sharp Nítid Color blindness – Deuteranopia-type Daltonisme – tipus deuteranòpsia Color blindness – Protanopia-type Daltonisme – tipus protanòpsia Color blindness – Tritanopia-type Daltonisme – tipus tritanòpsia + Show Color Vision Preview Mostra la previsualització de la visió del color + Protanopia Protanòpsia + Deuteranopia Deuteranòpsia + Tritanopia Tritanòpsia + Achromatopsia Acromatòpsia Color Burn Subexposa el color Color conversion: Conversió de color: Color Dodge Sobreexposició de color diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index 6a57e90e37..32402c3583 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -605,6 +605,11 @@ Color blindness – Protanopia-type Barvoslepost – protanopie Color blindness – Deuteranopia-type Barvoslepost – deuteranopie Color blindness – Tritanopia-type Barvoslepost – tritanopie + Show Color Vision Preview Zobrazit náhled barevného vidění + Protanopia Protanopie + Deuteranopia Deuteranopie + Tritanopia Tritanopie + Achromatopsia Achromatopsie Customize… Vlastní… Proof Colors Barvy nátisku Zoom In Zvětšit diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index 54a79e38e5..bc5550c8d5 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -5565,6 +5565,11 @@ mark-style Japanese Japansk The active document changed while the screen color sampler was open Det aktive dokument ændrede sig, mens skærmfarvesampleren var åben This system has no screen color sampler Dette system har ingen skærmfarvesampler Color blindness – Tritanopia-type Farveblindhed – tritanopitype + Show Color Vision Preview Vis eksempel på farvesyn + Protanopia Protanopi + Deuteranopia Deuteranopi + Tritanopia Tritanopi + Achromatopsia Akromatopsi Panels Except Tools and Control Paneler undtagen værktøjer og kontrol Reset Tracking and Kerning Nulstil sporing og kerning Reset Horizontal Scale Nulstil vandret skalering diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index ab77cb0dd7..aa1d9e9534 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -514,6 +514,11 @@ font-technology Variable Variabel Color blindness – Deuteranopia-type Farbenblindheit – Deuteranopie Color blindness – Protanopia-type Farbenblindheit – Protanopie Color blindness – Tritanopia-type Farbenblindheit – Tritanopie + Show Color Vision Preview Farbsehvorschau einblenden + Protanopia Protanopie + Deuteranopia Deuteranopie + Tritanopia Tritanopie + Achromatopsia Achromatopsie Color Burn Farbig nachbelichten Color conversion: Farbkonvertierung: Color Dodge Farbig abwedeln diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index a1a203a257..fee3b3b5f4 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -5998,6 +5998,11 @@ effect Points Σημεία Close the circular ends of open profiles. Partial sweeps keep their cut sides open. Κλείσιμο των κυκλικών άκρων των ανοιχτών προφίλ. Οι μερικές περιστροφές κρατούν ανοιχτές τις πλευρές τομής τους. Color Panel Options Επιλογές πίνακα χρώματος Color blindness – Tritanopia-type Αχρωματοψία – τύπου τριτανοπίας + Show Color Vision Preview Εμφάνιση προεπισκόπησης χρωματικής όρασης + Protanopia Πρωτανοπία + Deuteranopia Δευτερανοπία + Tritanopia Τριτανοπία + Achromatopsia Ολική αχρωματοψία Create Dimension Δημιουργία διάστασης Darkness Σκουρότητα Destination Folder: Φάκελος προορισμού: diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 45fd0d8235..60511775ec 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -536,6 +536,11 @@ font-technology Variable Variables Color blindness – Deuteranopia-type Daltonismo – tipo deuteranopía Color blindness – Protanopia-type Daltonismo – tipo protanopía Color blindness – Tritanopia-type Daltonismo – tipo tritanopía + Show Color Vision Preview Mostrar vista previa de visión del color + Protanopia Protanopía + Deuteranopia Deuteranopía + Tritanopia Tritanopía + Achromatopsia Acromatopsia Color Burn Subexponer color Color conversion: Conversión de color: Color Dodge Sobreexponer color diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index f6db5b8ee1..83e137334a 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -6009,6 +6009,11 @@ mark-style Japanese Japanilainen Close the circular ends of open profiles. Partial sweeps keep their cut sides open. Sulje avointen profiilien pyöreät päät. Osittaiset pyöräytykset jättävät leikkauspintansa auki. Color Panel Options Väri-paneelin asetukset Color blindness – Tritanopia-type Värisokeus – tritanopia + Show Color Vision Preview Näytä värinäön esikatselu + Protanopia Protanopia + Deuteranopia Deuteranopia + Tritanopia Tritanopia + Achromatopsia Akromatopsia Create Dimension Luo mitta Darkness Tummuus Destination Folder: Kohdekansio: diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index ae0bf3b436..88a8ae8af6 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -537,6 +537,11 @@ font-technology Variable Variables Color blindness – Deuteranopia-type Daltonisme – type deutéranopie Color blindness – Protanopia-type Daltonisme – type protanopie Color blindness – Tritanopia-type Daltonisme – type tritanopie + Show Color Vision Preview Afficher un aperçu de la vision des couleurs + Protanopia Protanopie + Deuteranopia Deutéranopie + Tritanopia Tritanopie + Achromatopsia Achromatopsie Color Burn Densité couleur + Color conversion: Conversion des couleurs : Color Dodge Densité couleur - diff --git a/crates/ui-egui/src/i18n/gu.tsv b/crates/ui-egui/src/i18n/gu.tsv index f38612601c..07dfda4cf0 100644 --- a/crates/ui-egui/src/i18n/gu.tsv +++ b/crates/ui-egui/src/i18n/gu.tsv @@ -643,6 +643,11 @@ Color blindness – Deuteranopia-type રંગ અંધત્વ – ડ્યુટેરેનોપિયા પ્રકાર Color blindness – Protanopia-type રંગ અંધત્વ – પ્રોટેનોપિયા પ્રકાર Color blindness – Tritanopia-type રંગ અંધત્વ – ટ્રિટેનોપિયા પ્રકાર + Show Color Vision Preview રંગ દ્રષ્ટિ પૂર્વાવલોકન બતાવો + Protanopia પ્રોટેનોપિયા + Deuteranopia ડ્યુટેરેનોપિયા + Tritanopia ટ્રિટેનોપિયા + Achromatopsia એક્રોમેટોપ્સિયા Color conversion: રંગ રૂપાંતર: Color field રંગ ક્ષેત્ર Color images રંગીન ઇમેજ diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index 624671acca..e2af7c75b6 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -901,6 +901,11 @@ antiAlias Sharp शार्प Color blindness – Deuteranopia-type कलर ब्लाइंडनेस – ड्यूटेरानोपिया प्रकार Color blindness – Protanopia-type रंग अंधापन - प्रोटानोपिया प्रकार Color blindness – Tritanopia-type कलर ब्लाइंडनेस – ट्राइटेनोपिया प्रकार + Show Color Vision Preview कलर विज़न प्रीव्यू दिखाएँ + Protanopia प्रोटानोपिया + Deuteranopia ड्यूटेरानोपिया + Tritanopia ट्राइटेनोपिया + Achromatopsia एक्रोमैटोप्सिया Color Burn कलर बर्न Color conversion: रंग रूपांतरण: Color Dodge कलर डॉज diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index 3e8a200697..1a80d791b4 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -709,6 +709,11 @@ font-technology Variable Változó Color blindness – Deuteranopia-type Színvakság – deuteranópia Color blindness – Protanopia-type Színvakság – protanópia Color blindness – Tritanopia-type Színvakság – tritanópia + Show Color Vision Preview Színlátás-előnézet megjelenítése + Protanopia Protanópia + Deuteranopia Deuteranópia + Tritanopia Tritanópia + Achromatopsia Akromatopszia Color Burn Színsötétítés Color conversion: Színátalakítás: Color Dodge Színvilágosítás diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index 2107a23bf0..d2b04685e3 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -5565,6 +5565,11 @@ mark-style Japanese Jepang The active document changed while the screen color sampler was open Dokumen aktif berubah saat pengambil warna layar terbuka This system has no screen color sampler Sistem ini tidak memiliki pengambil warna layar Color blindness – Tritanopia-type Buta warna – tipe Tritanopia + Show Color Vision Preview Tampilkan pratinjau penglihatan warna + Protanopia Protanopia + Deuteranopia Deuteranopia + Tritanopia Tritanopia + Achromatopsia Akromatopsia Panels Except Tools and Control Semua panel kecuali Alat dan Kontrol Reset Tracking and Kerning Atur ulang tracking dan kerning Reset Horizontal Scale Atur ulang skala horizontal diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index f75dc629db..53449c5606 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -536,6 +536,11 @@ font-technology Variable Variabili Color blindness – Deuteranopia-type Daltonismo – tipo deuteranopia Color blindness – Protanopia-type Daltonismo – tipo protanopia Color blindness – Tritanopia-type Daltonismo – tipo tritanopia + Show Color Vision Preview Mostra anteprima della visione dei colori + Protanopia Protanopia + Deuteranopia Deuteranopia + Tritanopia Tritanopia + Achromatopsia Acromatopsia Color Burn Brucia colore Color conversion: Conversione colore: Color Dodge Scherma colore diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 67072cc8b3..17b0e35d0e 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -640,6 +640,11 @@ digits Malayalam マラヤーラム数字 Color blindness – Protanopia-type P 型(1 型)色覚 Color blindness – Deuteranopia-type D 型(2 型)色覚 Color blindness – Tritanopia-type T 型(3 型)色覚 + Show Color Vision Preview 色覚のプレビューを表示 + Protanopia P 型色覚 + Deuteranopia D 型色覚 + Tritanopia T 型色覚 + Achromatopsia 1 色覚 Customize… カスタマイズ… Proof Colors 色の校正 Zoom In ズームイン diff --git a/crates/ui-egui/src/i18n/ka.tsv b/crates/ui-egui/src/i18n/ka.tsv index c8513b84c3..122e501b09 100644 --- a/crates/ui-egui/src/i18n/ka.tsv +++ b/crates/ui-egui/src/i18n/ka.tsv @@ -5686,6 +5686,11 @@ imageTrace Outline კონტური @plural {n} part of the file wasn't read|{n} parts of the file weren't read ფაილის წაუკითხავი ნაწილები: {n}|ფაილის წაუკითხავი ნაწილები: {n} # Upstream sync 2026-10-16: legacy .ai export, screen color sampler, Hidden Objects, Dimension tool. Color blindness – Tritanopia-type დალტონიზმი – ტრიტანოპიის ტიპი + Show Color Vision Preview ფერთა აღქმის გადახედვის ჩვენება + Protanopia პროტანოპია + Deuteranopia დეიტერანოპია + Tritanopia ტრიტანოპია + Achromatopsia აქრომატოფსია Darkness სიმუქე Sample Color from Screen ფერის აღება ეკრანიდან This system has no screen color sampler ამ სისტემას ეკრანიდან ფერის აღების საშუალება არ აქვს diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index 8aa0bc41ca..91256df9eb 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -633,6 +633,11 @@ digits Malayalam 말라얄람어 Color blindness – Protanopia-type 색맹 – 적색맹 유형 Color blindness – Deuteranopia-type 색맹 – 녹색맹 유형 Color blindness – Tritanopia-type 색맹 – 청색맹 유형 + Show Color Vision Preview 색각 미리 보기 표시 + Protanopia 적색맹 + Deuteranopia 녹색맹 + Tritanopia 청색맹 + Achromatopsia 전색맹 Customize… 사용자 지정… Proof Colors 교정 색상 Zoom In 확대 diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index de5b7a3cf6..7ac537614a 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -6146,6 +6146,11 @@ mark-style Japanese Japans The active document changed while the screen color sampler was open Het actieve document is gewijzigd terwijl de schermkleurkiezer open was This system has no screen color sampler Dit systeem heeft geen schermkleurkiezer Color blindness – Tritanopia-type Kleurenblindheid – type tritanopie + Show Color Vision Preview Voorvertoning van kleurwaarneming tonen + Protanopia Protanopie + Deuteranopia Deuteranopie + Tritanopia Tritanopie + Achromatopsia Achromatopsie Panels Except Tools and Control Alle panelen behalve Gereedschap en Bediening Reset Tracking and Kerning Tracking en kerning herstellen Reset Horizontal Scale Horizontale schaal herstellen diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index f9bdc664f1..b7748b9579 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -561,6 +561,11 @@ Color blindness – Protanopia-type Daltonizm – typu protanopia Color blindness – Deuteranopia-type Daltonizm – typu deuteranopia Color blindness – Tritanopia-type Daltonizm – typu tritanopia + Show Color Vision Preview Pokaż podgląd widzenia barw + Protanopia Protanopia + Deuteranopia Deuteranopia + Tritanopia Tritanopia + Achromatopsia Achromatopsja Customize… Dostosuj… Proof Colors Próba kolorów Zoom In Powiększ diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index 07cd9c6fd6..29551e9855 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -526,6 +526,11 @@ antiAlias Sharp Nítido Color blindness – Deuteranopia-type Daltonismo – tipo deuteranopia Color blindness – Protanopia-type Daltonismo – tipo protanopia Color blindness – Tritanopia-type Daltonismo – tipo tritanopia + Show Color Vision Preview Mostrar Visualização da Visão de Cores + Protanopia Protanopia + Deuteranopia Deuteranopia + Tritanopia Tritanopia + Achromatopsia Acromatopsia Color conversion: Conversão de cor: Color images Imagens coloridas Color: Cor: diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index fcf44192cd..d5fc09295a 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -534,6 +534,11 @@ font-technology Variable Вариативные Color blindness – Deuteranopia-type Дальтонизм — дейтеранопия Color blindness – Protanopia-type Дальтонизм — протанопия Color blindness – Tritanopia-type Дальтонизм — тританопия + Show Color Vision Preview Показать имитацию цветового зрения + Protanopia Протанопия + Deuteranopia Дейтеранопия + Tritanopia Тританопия + Achromatopsia Ахроматопсия Color Burn Затемнение основы Color conversion: Преобразование цвета: Color Dodge Осветление основы diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index d68878734e..0f0bb4a01a 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -5999,6 +5999,11 @@ theme Appearance Utseende Close the circular ends of open profiles. Partial sweeps keep their cut sides open. Stäng de cirkulära ändarna på öppna profiler. Partiella svep behåller sina snittsidor öppna. Color Panel Options Alternativ för panelen Färg Color blindness – Tritanopia-type Färgblindhet – tritanopi + Show Color Vision Preview Visa förhandsvisning av färgseende + Protanopia Protanopi + Deuteranopia Deuteranopi + Tritanopia Tritanopi + Achromatopsia Akromatopsi Create Dimension Skapa mått Darkness Mörkhet Destination Folder: Målmapp: diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index b3c88cc563..ca333d6ac5 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -518,6 +518,11 @@ font-technology Variable Değişken Color blindness – Deuteranopia-type Renk körlüğü – Döteranopi tipi Color blindness – Protanopia-type Renk körlüğü – Protanopi tipi Color blindness – Tritanopia-type Renk körlüğü – Tritanopia tipi + Show Color Vision Preview Renk Görme Önizlemesini Göster + Protanopia Protanopi + Deuteranopia Döteranopi + Tritanopia Tritanopi + Achromatopsia Akromatopsi Color Burn Renkli Yanık Color conversion: Renk dönüşümü: Color Dodge Renk Soldurma diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index 0ab6257df4..1f906688ae 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -530,6 +530,11 @@ font-technology Variable Варіативні Color blindness – Deuteranopia-type Дальтонізм - дейтеранопія Color blindness – Protanopia-type Дальтонізм - протанопія Color blindness – Tritanopia-type Дальтонізм - тританопія + Show Color Vision Preview Показати імітацію колірного зору + Protanopia Протанопія + Deuteranopia Дейтеранопія + Tritanopia Тританопія + Achromatopsia Ахроматопсія Color Burn Затемнення основи Color conversion: Перетворення кольору: Color Dodge Освітлення основи diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index 80cc4951cf..695e003eae 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -621,6 +621,11 @@ font-technology Variable Biến thiên Color blindness – Deuteranopia-type Mù màu – loại Deuteranopia Color blindness – Protanopia-type Mù màu – loại Protanopia Color blindness – Tritanopia-type Mù màu – loại Tritanopia + Show Color Vision Preview Hiện xem trước thị giác màu + Protanopia Mù màu đỏ + Deuteranopia Mù màu lục + Tritanopia Mù màu lam + Achromatopsia Mù màu toàn phần Color Burn Đốt màu Color conversion: Chuyển đổi màu: Color Dodge Tránh màu diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index 9561a51baf..0526f6e6dd 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -482,6 +482,11 @@ antiAlias Sharp 锐利 Color blindness – Deuteranopia-type 色盲 – 绿色盲型 Color blindness – Protanopia-type 色盲 – 红色盲型 Color blindness – Tritanopia-type 色盲 – 蓝色盲型 + Show Color Vision Preview 显示色觉预览 + Protanopia 红色盲 + Deuteranopia 绿色盲 + Tritanopia 蓝色盲 + Achromatopsia 全色盲 Color Burn 颜色加深 Color conversion: 色彩转换: Color Dodge 颜色减淡 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index 7489e3d4d9..77ee5a9c9f 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -499,6 +499,11 @@ font-technology Variable 可變 Color blindness – Deuteranopia-type 色盲 – 綠色盲型 Color blindness – Protanopia-type 色盲 – 紅色盲型 Color blindness – Tritanopia-type 色盲 – 藍色盲型 + Show Color Vision Preview 顯示色覺預覽 + Protanopia 紅色盲 + Deuteranopia 綠色盲 + Tritanopia 藍色盲 + Achromatopsia 全色盲 Color Burn 加深顏色 Color conversion: 色彩轉換: Color Dodge 加亮顏色 diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index d36ecae60f..d13a83c1f3 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1325,7 +1325,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.colorWheel", "Color Wheel Options", "", - "{view?: wheel|box, channel?: hue|saturation|brightness|red|green|blue} 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); keys left out keep their values, params that are not an object, another key or a value off the list are an error and change nothing, both 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}", + "{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}", ), ( "ui.savePdfDialog", diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index d12c89d2af..34a1ad2748 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -698,6 +698,8 @@ mod tests_color_wheel; #[cfg(test)] mod tests_color_wheel_box; #[cfg(test)] +mod tests_color_wheel_vision; +#[cfg(test)] mod tests_constrain; #[cfg(test)] mod tests_css_properties; diff --git a/crates/ui-egui/src/panels/color_wheel.rs b/crates/ui-egui/src/panels/color_wheel.rs index 31522578e5..b66f9c8e38 100644 --- a/crates/ui-egui/src/panels/color_wheel.rs +++ b/crates/ui-egui/src/panels/color_wheel.rs @@ -11,11 +11,16 @@ //! channel strip at its right, for the channel picked under Box Channel (Hue, Saturation, //! Brightness, Red, Green or Blue). The field shows the other two components on the Color //! Picker's axes. The view and the channel are kept with the preferences (`ui.colorWheel`). +//! +//! 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. -use egui::{Ui, UiBuilder, vec2}; +use egui::{Rect, Sense, Stroke, StrokeKind, Ui, UiBuilder, vec2}; use serde::{Deserialize, Serialize}; use serde_json::{Value, json}; -use vectorcraft_color::cms::{self, Cms}; +use vectorcraft_color::cms::{self, Cms, ProofSetup, ProofTarget}; use vectorcraft_color::{Color, Paint, hsb_to_rgb, rgb_to_hsb}; use vectorcraft_doc::{ColorMode, NodeId}; @@ -23,6 +28,7 @@ use super::color::{Target, apply, wheel_target}; use super::{pstate, set_pstate}; use crate::VectorcraftApp; use crate::dialogs::color_picker::Channel; +use crate::theme::Tokens; use crate::widgets::{self, FieldAxis, Live, SliderValue, menu_item}; pub const ID: &str = "colorWheel"; @@ -67,6 +73,13 @@ pub struct Settings { pub view: View, #[serde(serialize_with = "serialize_channel", deserialize_with = "deserialize_channel")] pub channel: Channel, + /// Show Color Vision Preview: the row of simulated colors under the wheel or the box. + #[serde(deserialize_with = "deserialize_flag")] + pub vision: bool, +} + +fn deserialize_flag<'de, D: serde::Deserializer<'de>>(d: D) -> Result { + Ok(::deserialize(d)?.as_bool().unwrap_or_default()) } fn deserialize_view<'de, D: serde::Deserializer<'de>>(d: D) -> Result { @@ -90,11 +103,11 @@ pub fn deserialize_settings<'de, D: serde::Deserializer<'de>>(d: D) -> Result Result { - const KEYS: [&str; 2] = ["view", "channel"]; + const KEYS: [&str; 3] = ["view", "channel", "vision"]; match p { Value::Null => {} Value::Object(o) => { @@ -113,11 +126,15 @@ 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")?, } + if let Some(on) = crate::menus::opt_bool(p, "vision")? { + set.vision = on; + } app.ui.color_wheel = set; Ok(json!(app.ui.color_wheel)) } -/// The panel menu: Wheel View and Box View, and Box Channel while the box shows. +/// The panel menu: Wheel View and Box View, Box Channel while the box shows, and Show Color Vision +/// Preview. pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { let set = app.ui.color_wheel.clone(); for (label, view) in [(tl!("Wheel View"), View::Wheel), (tl!("Box View"), View::Box)] { @@ -134,6 +151,10 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { } }); }); + ui.separator(); + if menu_item(ui, tl!("Show Color Vision Preview"), true, set.vision) { + command(app, &json!({ "vision": !set.vision })).ok(); + } } /// The display values of HSB `hsb` in `ch`'s space, from 0 to 1: hue, saturation and brightness, @@ -207,6 +228,64 @@ fn show_box(ui: &mut Ui, ch: Channel, hsb: [f32; 3], marked: bool, size: f32) -> /// Panel state: the HSB picked last, its [`Owner`] and the display sRGB of the color it stored. const MEMORY: &str = "color-wheel-hsb"; +/// The height of the color vision chips and the space between them. +const VISION_CHIP: f32 = 16.0; +const VISION_GAP: f32 = 3.0; + +/// The display sRGB of `c` as simulated for protanopia, deuteranopia and tritanopia, through +/// `cms`'s Proof Setup simulations, and for achromatopsia: the gray with `c`'s CIE L*, through the +/// same display transform. +pub(crate) fn vision_colors(cms: &Cms, c: &Color) -> [[f32; 3]; 4] { + let srgb = cms.display_rgb(c); + let proof = |target| cms.proof_srgb(srgb, &ProofSetup { target, ..Default::default() }); + let gray = cms.display_rgb(&Color::lab(cms.lab(c).l, 0.0, 0.0)); + [proof(ProofTarget::Protanopia), proof(ProofTarget::Deuteranopia), proof(ProofTarget::Tritanopia), gray] +} + +/// The names of the color vision chips, in the order of [`vision_colors`]. +fn vision_names() -> [String; 4] { + [tl!("Protanopia"), tl!("Deuteranopia"), tl!("Tritanopia"), tl!("Achromatopsia")].map(|s| s.to_string()) +} + +/// The 0 to 255 values of display sRGB `rgb`. +pub(crate) fn bytes(rgb: [f32; 3]) -> [u8; 3] { + rgb.map(|v| (v.clamp(0.0, 1.0) * 255.0).round() as u8) +} + +/// `#rrggbb` of 0 to 255 values. +pub(crate) fn hex([r, g, b]: [u8; 3]) -> String { + format!("#{r:02x}{g:02x}{b:02x}") +} + +/// The Show Color Vision Preview row: four chips across the panel with `color` as each color +/// vision deficiency shows it. Each chip takes the keyboard focus and reports its name and, with a +/// solid color, its hex value as its value to screen readers; its tooltip shows both. A click or a +/// key on a chip does nothing. With no solid color the chips are empty and carry only their names. +fn vision_row(ui: &mut Ui, cms: &Cms, color: Option<&Color>) { + let t = Tokens::get(ui.ctx()); + let colors = color.map(|c| vision_colors(cms, c)); + let width = ui.available_width(); + let (row, _) = ui.allocate_exact_size(vec2(width, VISION_CHIP), Sense::hover()); + let w = ((width - 3.0 * VISION_GAP) / 4.0).max(1.0); + let enabled = ui.is_enabled(); + for (i, name) in vision_names().into_iter().enumerate() { + let cell = Rect::from_min_size(row.min + vec2(i as f32 * (w + VISION_GAP), 0.0), vec2(w, VISION_CHIP)); + let resp = ui.interact(cell, ui.scope_id().with(("color-vision", i)), Sense::focusable_noninteractive()); + let value = colors.map(|cs| { + let [r, g, b] = bytes(cs[i]); + ui.painter().rect_filled(cell, 0.0, egui::Color32::from_rgb(r, g, b)); + hex([r, g, b]) + }); + let stroke = if resp.has_focus() { ui.visuals().selection.stroke } else { Stroke::new(1.0, t.border) }; + ui.painter().rect_stroke(cell, 0.0, stroke, StrokeKind::Inside); + let tip = match &value { + Some(v) => format!("{name}\n{v}"), + None => name.clone(), + }; + resp.widget_info(|| egui::WidgetInfo { current_text_value: value.clone(), ..egui::WidgetInfo::labeled(egui::Role::Image, enabled, &name) }); + resp.on_hover_text(tip); + } +} /// What the HSB picked last belongs to: the document, the selected objects or text characters, /// the appearance item, the proxy, the gradient stop or freeform point, its paint, and the color @@ -344,6 +423,10 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { pick = Some(([hsb[0], x, 1.0 - y], field_phase)); } }); + if app.ui.color_wheel.vision { + ui.add_space(4.0); + vision_row(ui, &cms, color.as_ref()); + } let Some((hsb, phase)) = pick else { return }; let behind = super::alt_held(ui); let cmyk_doc = app.session.active().is_some_and(|d| d.doc.color_mode == ColorMode::Cmyk); 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 d3866fd5d9..4a6144443c 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,16 @@ 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"})); - assert_eq!(app.run("ui.colorWheel", json!({"view": "box"})).unwrap(), json!({"view": "box", "channel": "hue"})); - assert_eq!(app.run("ui.colorWheel", json!({"channel": "green"})).unwrap(), json!({"view": "box", "channel": "green"})); + 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 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 }, "an error changes nothing"); + assert_eq!(app.ui.color_wheel, Settings { view: View::Box, channel: Channel::Green, vision: false }, "an error changes nothing"); let ui = crate::control::inspect(&app, &egui::Context::default()); - assert_eq!(ui["ui"]["color_wheel"], json!({"view": "box", "channel": "green"})); + assert_eq!(ui["ui"]["color_wheel"], json!({"view": "box", "channel": "green", "vision": false})); } /// The command's errors are translated in the catalogs that translate status and error messages, @@ -211,10 +211,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"); + assert_eq!(e, "unknown parameter `veiw`; the command takes: view, channel, 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"); - assert_eq!(app.ui.color_wheel, Settings { view: View::Box, channel: Channel::Red }, "an error changes nothing"); + 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"); } /// With None there is no color to edit: the strip reads 0 to screen readers, as the hue ring does, @@ -249,7 +249,11 @@ fn ui_color_wheel_answers_junk_params_without_a_panic() { /// not know reads as the key's default without losing the other preferences. #[test] fn the_settings_are_kept_and_read_leniently() { - let ui = crate::UiState { color_wheel: Settings { view: View::Box, channel: Channel::Blue }, color_rgb_percent: true, ..Default::default() }; + let ui = crate::UiState { + color_wheel: Settings { view: View::Box, channel: Channel::Blue, vision: true }, + color_rgb_percent: true, + ..Default::default() + }; let saved = serde_json::to_value(&ui).unwrap(); let back: crate::UiState = serde_json::from_value(saved.clone()).unwrap(); assert_eq!(back.color_wheel, ui.color_wheel); @@ -262,11 +266,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() }); + assert_eq!(back.color_wheel, Settings { view: View::Box, channel: Channel::default(), vision: false }); 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 }); + assert_eq!(back.color_wheel, Settings { view: View::Wheel, channel: Channel::Blue, vision: false }); 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_vision.rs b/crates/ui-egui/src/panels/tests_color_wheel_vision.rs new file mode 100644 index 0000000000..818bb49650 --- /dev/null +++ b/crates/ui-egui/src/panels/tests_color_wheel_vision.rs @@ -0,0 +1,258 @@ +//! The Color Wheel panel's Show Color Vision Preview row drawn headless: the simulated colors, their +//! names and values, the painted chips, a gray fill, no solid color, clicks and keys on the chips, +//! the keyboard focus, the panel menu and `ui.colorWheel`. + +use egui::{Color32, Key, Modifiers, Rect, Shape, vec2}; +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; +use serde_json::{Value, json}; +use vectorcraft_color::Color; +use vectorcraft_color::cms::{self, ProofSetup, ProofTarget}; +use vectorcraft_engine::Session; + +use super::color_wheel::{bytes, show, vision_colors}; +use crate::VectorcraftApp; + +/// `#rrggbb` of display sRGB `rgb`, as the chips show it. +fn hex(rgb: [f32; 3]) -> String { + super::color_wheel::hex(bytes(rgb)) +} + +const NAMES: [&str; 4] = ["Protanopia", "Deuteranopia", "Tritanopia", "Achromatopsia"]; + +/// A document with a selected rectangle filled with `fill`, with Show Color Vision Preview on. +fn app(fill: Value) -> 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!({"vision": true})).unwrap(); + app +} + +fn harness(app: VectorcraftApp) -> Harness<'static, VectorcraftApp> { + let mut h = Harness::builder().with_size(vec2(260.0, 360.0)).build_ui_state(|ui, app: &mut VectorcraftApp| show(app, ui), app); + h.run_steps(2); + h +} + +/// The value a chip reports to screen readers. +fn value(h: &Harness<'static, VectorcraftApp>, name: &str) -> Option { + h.get_by_label(name).value() +} + +fn fill(app: &VectorcraftApp) -> Color { + super::current_paints(app).0.color().expect("a solid fill") +} + +fn undo_len(app: &VectorcraftApp) -> usize { + app.session.doc().unwrap().history.undo.len() +} + +/// The fill painted inside `cell`, if a filled rectangle covers it. +fn painted(h: &Harness<'static, VectorcraftApp>, cell: Rect) -> Option { + h.output().shapes.iter().find_map(|c| match &c.shape { + Shape::Rect(r) + if r.fill != Color32::TRANSPARENT && r.rect.expand(0.5).contains_rect(cell.shrink(0.5)) && cell.expand(0.5).contains_rect(r.rect) => + { + Some(r.fill) + } + _ => None, + }) +} + +fn color32(hex: &str) -> Color32 { + Color32::from_hex(hex).expect("a #rrggbb value") +} + +/// The protanopia, deuteranopia and tritanopia chips show the fill as View › Proof Setup's +/// simulations show it: each reports the simulation's hex value and is painted in it. +#[test] +fn the_chips_show_the_proof_setup_simulations_of_the_fill() { + let h = harness(app(json!("#3366cc"))); + let cms = cms::active(); + let srgb = cms.display_rgb(&fill(h.state())); + for (name, target) in + [("Protanopia", ProofTarget::Protanopia), ("Deuteranopia", ProofTarget::Deuteranopia), ("Tritanopia", ProofTarget::Tritanopia)] + { + let want = hex(cms.proof_srgb(srgb, &ProofSetup { target, ..Default::default() })); + assert_eq!(value(&h, name).as_deref(), Some(want.as_str()), "{name}"); + assert_eq!(painted(&h, h.get_by_label(name).rect()), Some(color32(&want)), "{name} is painted {want}"); + } +} + +/// The achromatopsia chip of a red fill is the gray with red's CIE L* (D50, about 54.29: #828282), +/// and the simulations of a pure red differ from it and from each other. +#[test] +fn the_achromatopsia_chip_is_the_gray_of_the_colors_lightness() { + let cms = cms::active(); + let [p, d, t, a] = vision_colors(&cms, &Color::rgb(1.0, 0.0, 0.0)); + assert_eq!(hex(a), "#828282"); + assert_ne!(hex(p), hex(d)); + assert_ne!(hex(t), hex(a)); + let h = harness(app(json!("#ff0000"))); + assert_eq!(value(&h, "Achromatopsia").as_deref(), Some("#828282")); + assert_eq!(painted(&h, h.get_by_label("Achromatopsia").rect()), Some(color32("#828282"))); +} + +/// A gray fill shows as the same gray in every chip. +#[test] +fn a_gray_fill_is_the_same_gray_in_every_chip() { + let h = harness(app(json!("#808080"))); + let gray = hex(cms::active().display_rgb(&fill(h.state()))); + for name in NAMES { + assert_eq!(value(&h, name).as_deref(), Some(gray.as_str()), "{name} shows {gray}"); + } +} + +/// With the box in the wheel's place the row shows under the box, with the same values. +#[test] +fn the_row_shows_under_the_box_too() { + let mut a = app(json!("#3366cc")); + a.run("ui.colorWheel", json!({"view": "box", "channel": "red"})).unwrap(); + let h = harness(a); + let [p, ..] = vision_colors(&cms::active(), &fill(h.state())); + assert_eq!(value(&h, "Protanopia").as_deref(), Some(hex(p).as_str())); + let field = h.get_by_label("Color box").rect(); + for name in NAMES { + assert!(h.get_by_label(name).rect().top() >= field.bottom(), "{name} is under the box"); + } +} + +/// With a None fill the chips carry only their names, with no value and no color. +#[test] +fn with_a_none_fill_the_chips_have_no_color() { + let mut a = app(json!("#ff0000")); + a.run("paint.setFill", json!({"none": true})).unwrap(); + let h = harness(a); + for name in NAMES { + assert_eq!(value(&h, name), None, "{name} has no value"); + assert_eq!(painted(&h, h.get_by_label(name).rect()), None, "{name} is not painted"); + } +} + +/// Screen readers find each chip by its deficiency name, with its hex value as its value, and Tab +/// steps through the four chips in order. +#[test] +fn the_chips_take_the_focus_and_report_their_names_and_values() { + let mut h = harness(app(json!("#3366cc"))); + for name in NAMES { + let node = h.get_by_label(name); + assert_eq!(node.accesskit_node().role(), egui::accesskit::Role::Image, "{name}"); + assert!(node.value().is_some_and(|v| v.starts_with('#') && v.len() == 7), "{name}: {:?}", node.value()); + assert!(!node.accesskit_node().is_disabled(), "{name}"); + } + // Tab stops on the panel's other controls first. + for _ in 0..40 { + if h.get_by_label(NAMES[0]).accesskit_node().is_focused() { + break; + } + h.key_press(Key::Tab); + h.run_steps(1); + } + assert!(h.get_by_label(NAMES[0]).accesskit_node().is_focused(), "Tab reaches {}", NAMES[0]); + for name in &NAMES[1..] { + h.key_press(Key::Tab); + h.run_steps(1); + assert!(h.get_by_label(name).accesskit_node().is_focused(), "the next Tab reaches {name}"); + } +} + +/// A click on a chip, and Enter or Space on a focused chip, leave the fill and the undo history as +/// they were. +#[test] +fn a_click_or_a_key_on_a_chip_applies_nothing() { + let mut h = harness(app(json!("#3366cc"))); + let (before, undo) = (fill(h.state()), undo_len(h.state())); + for name in NAMES { + h.get_by_label(name).click(); + h.run_steps(2); + for key in [Key::Enter, Key::Space] { + h.key_press_modifiers(Modifiers::NONE, key); + h.run_steps(1); + } + assert_eq!(fill(h.state()), before, "{name}"); + assert_eq!(undo_len(h.state()), undo, "{name}: no undo step"); + } +} + +/// Without the setting the row is not drawn, and the panel menu's Show Color Vision Preview turns +/// it on and off. +#[test] +fn the_panel_menu_turns_the_row_on_and_off() { + let mut a = app(json!("#3366cc")); + a.run("ui.colorWheel", json!({"vision": false})).unwrap(); + let h = harness(a); + assert!(h.query_by_label_contains("Protanopia").is_none()); + let mut a = app(json!("#3366cc")); + a.run("ui.colorWheel", json!({"vision": false})).unwrap(); + let mut fonts = false; + let mut menu = Harness::builder().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; + } + super::color_wheel::menu(app, ui); + }, + a, + ); + menu.run_steps(3); + menu.get_by_label_contains("Show Color Vision Preview").click(); + menu.run_steps(2); + assert!(menu.state().ui.color_wheel.vision); + menu.get_by_label_contains("Show Color Vision Preview").click(); + menu.run_steps(2); + assert!(!menu.state().ui.color_wheel.vision); +} + +/// `ui.colorWheel` sets the keys given and reads them with `{}`, and `ui.inspect` reports them as +/// `ui.color_wheel`. A value that is not a bool, params that are not an object and another key +/// are errors that change nothing. +#[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})); + 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!("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" + ); + 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})); +} + +/// `ui.colorWheel` answers every junk parameter, with and without a document, without a panic. +#[test] +fn ui_color_wheel_answers_junk_params_without_a_panic() { + let doc = crate::menus::UI_COMMANDS.iter().find(|c| c.0 == "ui.colorWheel").expect("registered").3; + let mut app = app(json!("#3366cc")); + let mut empty = VectorcraftApp::new(Session::new(), Default::default()); + for p in vectorcraft_testkit::strategies::junk_params(doc, "/nonexistent").into_iter().chain(vectorcraft_testkit::strategies::junk_values()) { + let _ = app.run("ui.colorWheel", p.clone()); + let _ = empty.run("ui.colorWheel", p); + } +} + +/// The saved settings read leniently: a value this build does not know reads as the default and +/// the other preferences are kept. +#[test] +fn saved_settings_read_leniently() { + let read = |v: Value| serde_json::from_value::(v).expect("the preferences read"); + let s = read(json!({"color_wheel": {"vision": true}, "color_rgb_percent": true})); + assert!(s.color_wheel.vision && s.color_rgb_percent); + let s = read(json!({"color_wheel": {"vision": "yes", "later": 3}, "color_rgb_percent": true})); + assert!(!s.color_wheel.vision && s.color_rgb_percent); + let s = read(json!({"color_wheel": "junk", "color_rgb_percent": true})); + assert!(!s.color_wheel.vision && s.color_rgb_percent); +} diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index d1722e8b72..959f20395f 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -734,7 +734,8 @@ pub struct UiState { /// of an RGB field, `ui.colorPanel`, [`crate::panels::color::deserialize_rgb_percent`]). #[serde(default, deserialize_with = "crate::panels::color::deserialize_rgb_percent")] pub color_rgb_percent: bool, - /// Color Wheel panel: the wheel or the box, and the box's channel (`ui.colorWheel`, + /// Color Wheel panel: the wheel or the box, the box's channel, and the color vision row + /// (`ui.colorWheel`, /// [`crate::panels::color_wheel::deserialize_settings`]). #[serde(default, deserialize_with = "crate::panels::color_wheel::deserialize_settings")] pub color_wheel: crate::panels::color_wheel::Settings, diff --git a/docs/control-protocol.md b/docs/control-protocol.md index bb13e0d5f5..6d01fd91e2 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -265,9 +265,9 @@ 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?}` shows the wheel or the box (a -color field with a channel strip at its right) and picks the box's channel; 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?, 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`. 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 12c1f38184..927d37be23 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -625,6 +625,12 @@ strip at its right) in place of the wheel, as the panel menu's Box View and Box 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}`, and both 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 +chip reports its name and hex value to screen readers, and a click on a chip does not apply its color. `false` +hides the row. A value that is not a bool returns an error and changes nothing. The command returns +`{view, channel, vision}`, and the setting is kept with the preferences. In remote desktop mode, `invoke_menu` with `{"command":"ui.sampleScreenColor","params":{}}` shows the system's screen color sampler and returns `null` before a color is picked: the system's sampler on macOS, the XDG desktop diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index e34f814534..e8cfd684ba 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1512,6 +1512,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur A Cmd/Ctrl-click on the Color panel's spectrum applies Complement and a Cmd/Ctrl+Shift-click applies Invert to the active Fill or Stroke (`paint.complement`, `paint.invert`); with Alt also held, the click recolors the inactive one, as the reference app's [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) list them. A double-click right of an RGB field switches the Color panel's R, G and B between percent and 0 to 255 ([Default keyboard shortcuts](https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html), Color panel). In VectorCraft the color does not change, Web Safe RGB and the hex field stay in 0 to 255, and the panel keeps the choice between sessions (`ui.colorPanel {rgbPercent}`); the color mixer of the Fill and Stroke chips and the gradient stop dialog follow the same setting. Toggle RGB Percent (`ui.colorRgbPercent`) in the command palette and Keyboard Shortcuts switches the units from the keyboard. Tests: `rgb_percent_switches_the_rgb_fields_between_percent_and_0_to_255`, `rgb_percent_does_not_switch_while_the_rows_are_disabled`, `rgb_percent_comes_back_after_a_restart` and `toggle_rgb_percent_switches_the_units_from_the_keyboard` in `crates/ui-egui/src/panels/color/tests.rs`. View › Proof Setup › Color blindness – Tritanopia-type turns Proof Colors on and proofs the canvas with the tritanopia simulation of Brettel, Viénot and Mollon (1997). The Separations Preview panel's Proof Setup list offers the same target (`view.proofSetup {target: "tritanopia"}`). Grays keep their value. + In VectorCraft the Color Wheel panel menu's Show Color Vision Preview (`ui.colorWheel {vision: true}`) adds a row of four chips under the wheel or the box: the current color through the protanopia, deuteranopia and tritanopia simulations that View › Proof Setup uses, and an achromatopsia chip, which is VectorCraft's own gray with the color's CIE L*. Each chip takes the keyboard focus and gives its name and hex value in its tooltip and to screen readers, and a click on one does not apply it. The setting is kept with the preferences. Tests: `crates/ui-egui/src/panels/tests_color_wheel_vision.rs`. The Separations Preview panel's Gamut Check button reports one color outside the CMYK gamut in the singular and more in the plural, in English and in each language's plural forms (`gamut_check_status_takes_the_plural_form` in `crates/ui-egui/src/i18n/tests.rs`). - **Document Color Mode outside the layers:** File › Document Color Mode (in one undo step) and `document.open {colorMode}` also convert the colors of graph designs, graphic styles, opacity-mask art, the tile that pattern editing's Cancel puts back and the art of brushes (with a Hue Shift brush's key color); a tint of a global swatch there becomes the converted swatch's color at its tint, as in the art. - **Segments dragged onto the grid (#3835):** with View › Snap to Grid (or Snap to Pixel) on, a straight segment dragged with Direct Selection or Group Selection lands its anchors on the grid, the box round them putting an edge on a gridline on each axis as a moved object's does (Shift keeps the move on its line), instead of the point it was pressed at landing on an intersection and leaving both anchors off the grid; a dragged anchor still lands on an intersection itself, and drawn points and resize handles already snapped (`direct::tests::a_dragged_segment_lands_its_anchors_on_the_grid`). From 4a7acfe0eec6d31aeb09d81c1b4327f4e813f1a8 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 08:25:58 -0800 Subject: [PATCH 2/2] Color Wheel: color vision chips show hex as the Color panel does - The chips report and show their hex value as the Color panel's hex field writes it (828282), not as #828282. - The saved Show Color Vision Preview setting reads through the Color panel's existing reader (`deserialize_rgb_percent`) instead of a copy. - The key test moves the keyboard focus to each chip with Tab before it presses Enter and Space. - A test checks that `{"view": "box", "channel": "red", "vision": 1}` returns an error and leaves the view and the channel unchanged. - docs/mcp.md says the command returns `{view, channel, vision}` in one place, and that `null` keeps the setting. - The module doc says the vision setting is kept with the preferences. --- crates/ui-egui/src/panels/color_wheel.rs | 26 +++++----- .../src/panels/tests_color_wheel_vision.rs | 47 ++++++++++++------- crates/ui-egui/src/state.rs | 3 +- docs/mcp.md | 7 ++- 4 files changed, 48 insertions(+), 35 deletions(-) diff --git a/crates/ui-egui/src/panels/color_wheel.rs b/crates/ui-egui/src/panels/color_wheel.rs index b66f9c8e38..bbc2b588c5 100644 --- a/crates/ui-egui/src/panels/color_wheel.rs +++ b/crates/ui-egui/src/panels/color_wheel.rs @@ -10,12 +10,15 @@ //! The panel menu's Box View puts a box in the wheel's place: a color field with a vertical //! channel strip at its right, for the channel picked under Box Channel (Hue, Saturation, //! Brightness, Red, Green or Blue). The field shows the other two components on the Color -//! Picker's axes. The view and the channel are kept with the preferences (`ui.colorWheel`). +//! Picker's axes. //! //! 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`). use egui::{Rect, Sense, Stroke, StrokeKind, Ui, UiBuilder, vec2}; use serde::{Deserialize, Serialize}; @@ -73,15 +76,12 @@ pub struct Settings { pub view: View, #[serde(serialize_with = "serialize_channel", deserialize_with = "deserialize_channel")] pub channel: Channel, - /// Show Color Vision Preview: the row of simulated colors under the wheel or the box. - #[serde(deserialize_with = "deserialize_flag")] + /// 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, } -fn deserialize_flag<'de, D: serde::Deserializer<'de>>(d: D) -> Result { - Ok(::deserialize(d)?.as_bool().unwrap_or_default()) -} - 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()) @@ -104,8 +104,9 @@ pub fn deserialize_settings<'de, D: serde::Deserializer<'de>>(d: D) -> Result Result { const KEYS: [&str; 3] = ["view", "channel", "vision"]; match p { @@ -252,15 +253,16 @@ pub(crate) fn bytes(rgb: [f32; 3]) -> [u8; 3] { rgb.map(|v| (v.clamp(0.0, 1.0) * 255.0).round() as u8) } -/// `#rrggbb` of 0 to 255 values. +/// The hex text of 0 to 255 values, in the form of the Color panel's hex field (`E67828`). pub(crate) fn hex([r, g, b]: [u8; 3]) -> String { - format!("#{r:02x}{g:02x}{b:02x}") + format!("{r:02X}{g:02X}{b:02X}") } /// The Show Color Vision Preview row: four chips across the panel with `color` as each color /// vision deficiency shows it. Each chip takes the keyboard focus and reports its name and, with a /// solid color, its hex value as its value to screen readers; its tooltip shows both. A click or a -/// key on a chip does nothing. With no solid color the chips are empty and carry only their names. +/// key on a chip does nothing. With no solid color the chips are empty and keep their names in the tooltip and for screen +/// readers. fn vision_row(ui: &mut Ui, cms: &Cms, color: Option<&Color>) { let t = Tokens::get(ui.ctx()); let colors = color.map(|c| vision_colors(cms, c)); 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 818bb49650..5c73496642 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel_vision.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel_vision.rs @@ -62,7 +62,7 @@ fn painted(h: &Harness<'static, VectorcraftApp>, cell: Rect) -> Option } fn color32(hex: &str) -> Color32 { - Color32::from_hex(hex).expect("a #rrggbb value") + Color32::from_hex(&format!("#{hex}")).expect("an RRGGBB value") } /// The protanopia, deuteranopia and tritanopia chips show the fill as View › Proof Setup's @@ -81,18 +81,18 @@ fn the_chips_show_the_proof_setup_simulations_of_the_fill() { } } -/// The achromatopsia chip of a red fill is the gray with red's CIE L* (D50, about 54.29: #828282), +/// The achromatopsia chip of a red fill is the gray with red's CIE L* (D50, about 54.29: 828282), /// and the simulations of a pure red differ from it and from each other. #[test] fn the_achromatopsia_chip_is_the_gray_of_the_colors_lightness() { let cms = cms::active(); let [p, d, t, a] = vision_colors(&cms, &Color::rgb(1.0, 0.0, 0.0)); - assert_eq!(hex(a), "#828282"); + assert_eq!(hex(a), "828282"); assert_ne!(hex(p), hex(d)); assert_ne!(hex(t), hex(a)); let h = harness(app(json!("#ff0000"))); - assert_eq!(value(&h, "Achromatopsia").as_deref(), Some("#828282")); - assert_eq!(painted(&h, h.get_by_label("Achromatopsia").rect()), Some(color32("#828282"))); + assert_eq!(value(&h, "Achromatopsia").as_deref(), Some("828282")); + assert_eq!(painted(&h, h.get_by_label("Achromatopsia").rect()), Some(color32("828282"))); } /// A gray fill shows as the same gray in every chip. @@ -139,18 +139,14 @@ fn the_chips_take_the_focus_and_report_their_names_and_values() { for name in NAMES { let node = h.get_by_label(name); assert_eq!(node.accesskit_node().role(), egui::accesskit::Role::Image, "{name}"); - assert!(node.value().is_some_and(|v| v.starts_with('#') && v.len() == 7), "{name}: {:?}", node.value()); + assert!( + node.value().is_some_and(|v| v.len() == 6 && v.bytes().all(|b| b.is_ascii_digit() || b.is_ascii_uppercase())), + "{name}: {:?}", + node.value() + ); assert!(!node.accesskit_node().is_disabled(), "{name}"); } - // Tab stops on the panel's other controls first. - for _ in 0..40 { - if h.get_by_label(NAMES[0]).accesskit_node().is_focused() { - break; - } - h.key_press(Key::Tab); - h.run_steps(1); - } - assert!(h.get_by_label(NAMES[0]).accesskit_node().is_focused(), "Tab reaches {}", NAMES[0]); + tab_to(&mut h, NAMES[0]); for name in &NAMES[1..] { h.key_press(Key::Tab); h.run_steps(1); @@ -158,6 +154,19 @@ fn the_chips_take_the_focus_and_report_their_names_and_values() { } } +/// Press Tab until the chip `name` has the keyboard focus. Tab stops on the panel's other controls +/// first. +fn tab_to(h: &mut Harness<'static, VectorcraftApp>, name: &str) { + for _ in 0..40 { + if h.get_by_label(name).accesskit_node().is_focused() { + break; + } + h.key_press(Key::Tab); + h.run_steps(1); + } + assert!(h.get_by_label(name).accesskit_node().is_focused(), "Tab reaches {name}"); +} + /// A click on a chip, and Enter or Space on a focused chip, leave the fill and the undo history as /// they were. #[test] @@ -167,6 +176,7 @@ fn a_click_or_a_key_on_a_chip_applies_nothing() { for name in NAMES { h.get_by_label(name).click(); h.run_steps(2); + tab_to(&mut h, name); for key in [Key::Enter, Key::Space] { h.key_press_modifiers(Modifiers::NONE, key); h.run_steps(1); @@ -209,8 +219,9 @@ fn the_panel_menu_turns_the_row_on_and_off() { } /// `ui.colorWheel` sets the keys given and reads them with `{}`, and `ui.inspect` reports them as -/// `ui.color_wheel`. A value that is not a bool, params that are not an object and another key -/// are errors that change nothing. +/// `ui.color_wheel`. A `vision` value other than true, false or null, params that are not an object +/// and another key are errors that change nothing, the view and the channel given with them +/// included. #[test] fn ui_color_wheel_sets_and_reads_the_settings() { let mut app = VectorcraftApp::new(Session::new(), Default::default()); @@ -218,6 +229,8 @@ fn ui_color_wheel_sets_and_reads_the_settings() { assert_eq!(app.run("ui.colorWheel", json!({"vision": true})).unwrap(), json!({"view": "wheel", "channel": "hue", "vision": 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!("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!( diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 959f20395f..4705876ece 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -735,8 +735,7 @@ pub struct UiState { #[serde(default, deserialize_with = "crate::panels::color::deserialize_rgb_percent")] pub color_rgb_percent: bool, /// Color Wheel panel: the wheel or the box, the box's channel, and the color vision row - /// (`ui.colorWheel`, - /// [`crate::panels::color_wheel::deserialize_settings`]). + /// (`ui.colorWheel`, [`crate::panels::color_wheel::deserialize_settings`]). #[serde(default, deserialize_with = "crate::panels::color_wheel::deserialize_settings")] pub color_wheel: crate::panels::color_wheel::Settings, /// Swatches panel: Show Recent Colors in its panel menu, which draws the panel's Recent Colors diff --git a/docs/mcp.md b/docs/mcp.md index 927d37be23..89a10d0a07 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -623,14 +623,13 @@ 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}`, and both settings are kept with -the preferences. +the list return an error and change nothing. The command returns `{view, channel, 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 chip reports its name and hex value to screen readers, and a click on a chip does not apply its color. `false` -hides the row. A value that is not a bool returns an error and changes nothing. The command returns -`{view, channel, vision}`, and the setting is kept with the preferences. +hides the row, and `null` keeps the setting. Any other value returns an error and changes nothing. In remote desktop mode, `invoke_menu` with `{"command":"ui.sampleScreenColor","params":{}}` shows the system's screen color sampler and returns `null` before a color is picked: the system's sampler on macOS, the XDG desktop