From 6ec7d73a5a8e8a92d2c47e830553d2f35a3e66ce Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 06:19:37 -0800 Subject: [PATCH 01/12] Color: the largest OKLCH chroma that fits sRGB is found past a gap Along a hue at a given lightness, sRGB can hold two runs of chroma with chromas outside it between them (near blue, a run of low chroma and one ending at the blue primary). max_chroma bisected as if sRGB held one run, so at blue's lightness and hue it gave about 0.266 instead of the primary's 0.3132, and a request for full chroma came out desaturated. - The search now finds where each linear sRGB component's cubic reaches an edge of the gamut, tests the chromas between those points from the top down, and refines the highest run that fits. - from_oklch lowers a chroma outside sRGB to the largest chroma under it that fits, so a chroma in the gap goes to the top of the run under it instead of being clamped channel by channel. - The C track of OKLCH Sliders dims a gap under the largest chroma and shows there the color a pick stores. - Tests cover the blue primary, a dark blue whose runs are far apart, the C track over that gap, and a grid of lightness and hue where no chroma above the one found fits. --- crates/color/src/oklab.rs | 135 ++++++++++++++++-- crates/ui-egui/src/panels/color_wheel.rs | 10 +- .../ui-egui/src/panels/tests_color_wheel.rs | 15 ++ 3 files changed, 146 insertions(+), 14 deletions(-) diff --git a/crates/color/src/oklab.rs b/crates/color/src/oklab.rs index 90467fc6c3..9084c083a4 100644 --- a/crates/color/src/oklab.rs +++ b/crates/color/src/oklab.rs @@ -36,29 +36,105 @@ pub fn in_srgb(rgb: [f64; 3]) -> bool { rgb.iter().all(|v| (-GAMUT_SLACK..=1.0 + GAMUT_SLACK).contains(v)) } +/// The chroma past which no hue at any lightness is inside sRGB. +const CHROMA_SEARCH: f64 = 0.5; + /// The largest chroma sRGB holds at lightness `l` and hue `h°`: 0 at or outside black and white. pub fn max_chroma(l: f64, h: f64) -> f64 { - if !(l > 0.0 && l < 1.0) || !h.is_finite() { + fitting_chroma(l, h, CHROMA_SEARCH) +} + +/// The largest chroma from 0 to `top` (at most [`CHROMA_SEARCH`]) that sRGB holds at lightness `l` +/// and hue `h°`: 0 at or outside black and white. +/// +/// Along a hue at a given lightness each linear sRGB component is a cubic in the chroma, so sRGB can +/// hold more than one run of chroma: near blue a run of low chroma and one ending at the blue +/// primary. A chroma enters or leaves the gamut only where a component's cubic reaches an edge of +/// [`in_srgb`], so the search tests the chromas between those points from the top down and refines +/// the highest run that fits. +fn fitting_chroma(l: f64, h: f64, top: f64) -> f64 { + if !(l > 0.0 && l < 1.0) || !h.is_finite() || top.is_nan() || top <= 0.0 { return 0.0; } - // sRGB holds every chroma from 0 up to its edge along a hue at a given lightness. - let (mut lo, mut hi) = (0.0, 0.5); - for _ in 0..40 { - let mid = (lo + hi) / 2.0; - if in_srgb(oklch_to_srgb(l, mid, h)) { lo = mid } else { hi = mid } + let top = top.min(CHROMA_SEARCH); + let fits = |c: f64| in_srgb(oklch_to_srgb(l, c, h)); + if fits(top) { + return top; } - lo + let decode = |v: f64| if v <= 0.040_45 { v / 12.92 } else { ((v + 0.055) / 1.055).powf(2.4) }; + let linear = |c: f64| oklch_to_srgb(l, c, h).map(decode); + // The edges of `in_srgb` in linear light. + let edges = [decode(-GAMUT_SLACK), decode(1.0 + GAMUT_SLACK)]; + let samples = [0.0, 1.0, 2.0, 3.0].map(linear); + let mut cuts = vec![0.0, top]; + for i in 0..3 { + // The cubic's coefficients from its values at chroma 0, 1, 2 and 3. + let [p0, p1, p2, p3] = samples.map(|s| s[i]); + let d3 = (p3 - 3.0 * p2 + 3.0 * p1 - p0) / 6.0; + let d2 = (p2 - 2.0 * p1 + p0) / 2.0 - 3.0 * d3; + let d1 = p1 - p0 - d2 - d3; + let cubic = |c: f64| ((d3 * c + d2) * c + d1) * c + p0; + // The cubic is monotonic between its turning points, so it reaches each edge at most once + // between two of them. + let mut ends = vec![0.0, top]; + let (a, b) = (3.0 * d3, 2.0 * d2); + if a != 0.0 { + let disc = b * b - 4.0 * a * d1; + if disc >= 0.0 { + let q = disc.sqrt(); + ends.extend([(-b - q) / (2.0 * a), (-b + q) / (2.0 * a)]); + } + } else if b != 0.0 { + ends.push(-d1 / b); + } + ends.retain(|x| (0.0..=top).contains(x)); + ends.sort_by(f64::total_cmp); + cuts.extend_from_slice(&ends); + for w in ends.windows(2) { + for edge in edges { + let (mut lo, mut hi) = (w[0], w[1]); + let below = cubic(lo) < edge; + if below == (cubic(hi) < edge) { + continue; + } + for _ in 0..60 { + let mid = (lo + hi) / 2.0; + if (cubic(mid) < edge) == below { lo = mid } else { hi = mid } + } + cuts.push((lo + hi) / 2.0); + } + } + } + cuts.sort_by(f64::total_cmp); + cuts.dedup(); + let mut tests = Vec::with_capacity(cuts.len() * 2); + for w in cuts.windows(2) { + tests.extend([w[0], (w[0] + w[1]) / 2.0]); + } + tests.push(top); + // `top` does not fit, so the highest test that fits has a test above it that does not. + for w in tests.windows(2).rev() { + if fits(w[0]) { + let (mut lo, mut hi) = (w[0], w[1]); + for _ in 0..40 { + let mid = (lo + hi) / 2.0; + if fits(mid) { lo = mid } else { hi = mid } + } + return lo; + } + } + 0.0 } /// The sRGB color (gamma encoded, 0..=1) of OKLCH `(l, c, h°)`, and whether its chroma was lowered: -/// a color outside sRGB keeps its lightness and hue and takes the largest chroma that fits. +/// a color outside sRGB keeps its lightness and hue and takes the largest chroma under `c` that fits. /// Lightness is clamped to 0..=1 and chroma to 0 or more. pub fn from_oklch(l: f64, c: f64, h: f64) -> ([f32; 3], bool) { let l = if l.is_nan() { 0.0 } else { l.clamp(0.0, 1.0) }; let c = if c.is_nan() { 0.0 } else { c.max(0.0) }; let h = if h.is_finite() { h } else { 0.0 }; let exact = oklch_to_srgb(l, c, h); - let (rgb, lowered) = if in_srgb(exact) { (exact, false) } else { (oklch_to_srgb(l, max_chroma(l, h).min(c), h), true) }; + let (rgb, lowered) = if in_srgb(exact) { (exact, false) } else { (oklch_to_srgb(l, fitting_chroma(l, h, c), h), true) }; (rgb.map(|v| v.clamp(0.0, 1.0) as f32), lowered) } @@ -126,6 +202,47 @@ mod tests { assert!(!from_oklch(l, max * 0.5, h).1); } + /// At blue's lightness and hue sRGB holds a run of low chroma and a run ending at the blue + /// primary, with chromas outside sRGB between them: the largest chroma is the primary's. + #[test] + fn the_largest_chroma_of_blue_is_the_primarys() { + let [l, c, h] = to_oklch([0.0, 0.0, 1.0]); + assert!(!in_srgb(oklch_to_srgb(l, 0.29, h)), "the runs have a gap"); + let max = max_chroma(l, h); + assert!(max >= 0.3132 && max >= c - 1e-6 && in_srgb(oklch_to_srgb(l, max, h)), "{max} {c}"); + assert_eq!(eight(from_oklch(l, CHROMA_FULL, h).0), [0, 0, 255]); + } + + /// A dark blue whose runs are far apart: the largest chroma is the top of the upper run, and a + /// chroma in the gap is lowered to the top of the run under it, keeping lightness and hue. + #[test] + fn a_chroma_between_two_runs_is_lowered_to_the_run_under_it() { + let (l, h) = (0.14, 264.0); + let max = max_chroma(l, h); + assert!(max > 0.097 && in_srgb(oklch_to_srgb(l, max, h)) && !in_srgb(oklch_to_srgb(l, max + 1e-3, h)), "{max}"); + assert!(!in_srgb(oklch_to_srgb(l, 0.09, h)), "0.09 is in the gap"); + let (rgb, lowered) = from_oklch(l, 0.09, h); + let [ol, oc, oh] = to_oklch(rgb); + assert!(lowered && (ol - l).abs() < 1e-3 && (oh - h).abs() < 0.5 && (oc - 0.0825).abs() < 1e-3, "{ol} {oc} {oh}"); + } + + /// Every lightness and hue on a grid: the chroma found fits, and no chroma above it does. + #[test] + fn no_chroma_above_the_largest_fits() { + for li in 1..50 { + let l = f64::from(li) / 50.0; + for hi in 0..120 { + let h = f64::from(hi) * 3.0; + let max = max_chroma(l, h); + assert!(in_srgb(oklch_to_srgb(l, max, h)), "{l} {h} {max}"); + for step in 1..=200 { + let c = max + f64::from(step) * 0.0005; + assert!(!in_srgb(oklch_to_srgb(l, c, h)), "{l} {h}: {max} but {c} fits"); + } + } + } + } + #[test] fn black_white_and_bad_numbers_hold_no_chroma() { assert_eq!(max_chroma(0.0, 30.0), 0.0); diff --git a/crates/ui-egui/src/panels/color_wheel.rs b/crates/ui-egui/src/panels/color_wheel.rs index 2a88a3f54a..2a2a95d7ad 100644 --- a/crates/ui-egui/src/panels/color_wheel.rs +++ b/crates/ui-egui/src/panels/color_wheel.rs @@ -385,14 +385,14 @@ pub(crate) fn remembered_oklch(cms: &Cms, c: &Color, shown: [f32; 3], lch: [f64; } /// The color a track shows at OKLCH `lch`: the color itself inside sRGB, and outside it dimmed. -/// A color outside sRGB shows at the largest chroma that fits at its L and H, the color a pick -/// there stores. With `max_chroma` (the C track, whose L and H stay fixed) that chroma is given; -/// without it, it is found for each color. +/// A color outside sRGB shows at the largest chroma under its own that fits at its L and H, the +/// color a pick there stores. With `max_chroma` (the C track, whose L and H stay fixed) a chroma +/// past it shows at it; a chroma under it can still be outside sRGB, in a gap between two runs of +/// chroma that fit, and is found as without it. pub(crate) fn oklch_track(lch: [f64; 3], max_chroma: Option) -> Color32 { let (rgb, outside) = match max_chroma { Some(m) if lch[1] > m => (oklab::oklch_to_srgb(lch[0], m, lch[2]), true), - Some(_) => (oklab::oklch_to_srgb(lch[0], lch[1], lch[2]), false), - None => { + _ => { let (rgb, lowered) = oklab::from_oklch(lch[0], lch[1], lch[2]); (rgb.map(f64::from), lowered) } diff --git a/crates/ui-egui/src/panels/tests_color_wheel.rs b/crates/ui-egui/src/panels/tests_color_wheel.rs index 407f6ffabe..821ac678bc 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel.rs @@ -695,6 +695,21 @@ fn the_oklch_tracks_dim_the_colors_outside_srgb_and_the_tick_marks_the_largest_c assert_eq!((chroma_tick(0.0), chroma_tick(0.5)), (0.0, 1.0)); } +/// At a dark blue sRGB holds two runs of chroma with a gap between them: the C track dims the gap +/// and shows there the color a pick stores, the top of the run under it. +#[test] +fn the_c_track_dims_a_gap_under_the_largest_chroma() { + use vectorcraft_color::oklab; + let (l, h) = (0.14, 264.0); + let max = oklab::max_chroma(l, h); + assert!(max > 0.09 && !oklab::in_srgb(oklab::oklch_to_srgb(l, 0.09, h)), "0.09 is in the gap under {max}"); + let (stored, lowered) = oklab::from_oklch(l, 0.09, h); + let [r, g, b] = stored.map(|v| (f64::from(v).clamp(0.0, 1.0) * 255.0).round() as u8); + assert!(lowered); + assert_eq!(oklch_track([l, 0.09, h], Some(max)), egui::Color32::from_rgb(r, g, b).gamma_multiply(0.3)); + assert_eq!(oklch_track([l, max, h], Some(max)).a(), 255, "the top of the upper run is inside sRGB"); +} + /// After Edit › Color Settings picks a working RGB space other than sRGB, Panel menu › OKLCH Sliders /// is gray and `ui.colorWheel {sliders: "oklch"}` answers an error; rows already shown are gray. #[test] From 07be8c649645219616bf9ae4e232c4308d09844b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 22:38:09 -0800 Subject: [PATCH 02/12] Color Wheel: the panel menu's view and channel items run ui.colorWheel Wheel View, Box View and the Box Channel items now run ui.colorWheel through the app's command entry point, as OKLCH Sliders does, and show an error in the status bar. A checked view or channel runs no command. --- crates/ui-egui/src/panels/color_wheel.rs | 21 ++++++++++++------- .../src/panels/tests_color_wheel_box.rs | 9 +++++++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/panels/color_wheel.rs b/crates/ui-egui/src/panels/color_wheel.rs index 2a2a95d7ad..4886a04696 100644 --- a/crates/ui-egui/src/panels/color_wheel.rs +++ b/crates/ui-egui/src/panels/color_wheel.rs @@ -176,18 +176,20 @@ pub(crate) fn set(settings: &mut Settings, p: &Value, cms: &Cms) -> Result<(), S } /// The panel menu: Wheel View and Box View, Box Channel while the box shows, and OKLCH Sliders. +/// Each item runs `ui.colorWheel` through the app's command entry point; a checked view or channel +/// runs nothing. 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)] { - if menu_item(ui, label, true, set.view == view) { - command(app, &json!({ "view": view.id() })).ok(); + if menu_item(ui, label, true, set.view == view) && set.view != view { + run(app, json!({ "view": view.id() })); } } ui.add_enabled_ui(set.view == View::Box, |ui| { ui.menu_button(format!(" {}", tl!("Box Channel")), |ui| { for ch in Channel::ALL { - if menu_item(ui, ch.name(), true, ch == set.channel) { - command(app, &json!({ "channel": ch.id() })).ok(); + if menu_item(ui, ch.name(), true, ch == set.channel) && ch != set.channel { + run(app, json!({ "channel": ch.id() })); } } }); @@ -198,9 +200,14 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { let enabled = on || cms::active().rgb_is_srgb(); if widgets::menu_item_hint(ui, tl!("OKLCH Sliders"), enabled, on, tl!("OKLCH needs sRGB as the working RGB space")) { let sliders = if on { Sliders::None } else { Sliders::Oklch }; - if let Err(e) = app.run("ui.colorWheel", json!({ "sliders": sliders.id() })) { - app.status(e); - } + run(app, json!({ "sliders": sliders.id() })); + } +} + +/// Run `ui.colorWheel` with `p` from the panel menu, and show an error in the status bar. +fn run(app: &mut VectorcraftApp, p: Value) { + if let Err(e) = app.run("ui.colorWheel", p) { + app.status(e); } } 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 2e0e6ae1a5..00eac74e97 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel_box.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel_box.rs @@ -300,7 +300,7 @@ fn the_settings_are_kept_and_read_leniently() { } /// The panel menu lists Wheel View and Box View with the shown one checked, and Box Channel; its -/// items set the view and the channel. +/// items set the view and the channel through the app's command entry point. #[test] fn the_panel_menu_switches_the_view_and_the_channel() { let mut app = app(json!("#ff0000"), "hue"); @@ -320,10 +320,17 @@ fn the_panel_menu_switches_the_view_and_the_channel() { ); h.run_steps(3); assert!(h.query_by_label("✓ Wheel View").is_some()); + let commands = h.state().run_count; h.get_by_label(" Box View").click(); h.run_steps(2); assert_eq!(h.state().ui.color_wheel.view, View::Box); + assert_eq!(h.state().run_count, commands.wrapping_add(1), "Box View runs one ui.colorWheel command"); assert!(h.query_by_label("✓ Box View").is_some()); + // The checked item runs nothing. + h.get_by_label("✓ Box View").click(); + h.run_steps(2); + assert_eq!(h.state().run_count, commands.wrapping_add(1), "the checked Box View runs no command"); + assert_eq!(h.state().ui.color_wheel.view, View::Box); } /// Every channel's box puts each color back where it reads it, and the strip's value is the From f55a779aba78e2781aa77d344f72fbe41cc4d0e8 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 01:08:19 -0800 Subject: [PATCH 03/12] i18n: Gujarati translates the ui.colorWheel sliders errors The `sliders` value error and the OKLCH working-space error get Gujarati @msg rows, as the other catalogs have, with a test that checks every catalog keeps the accepted values. --- crates/ui-egui/src/i18n/gu.tsv | 2 ++ crates/ui-egui/src/panels/tests_color_wheel.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/crates/ui-egui/src/i18n/gu.tsv b/crates/ui-egui/src/i18n/gu.tsv index e0510bceeb..aa999ef649 100644 --- a/crates/ui-egui/src/i18n/gu.tsv +++ b/crates/ui-egui/src/i18n/gu.tsv @@ -1954,6 +1954,8 @@ Chroma ક્રોમા The largest chroma sRGB holds at this lightness and hue આ લાઇટનેસ અને હ્યૂ પર sRGB સમાવી શકે તે સૌથી વધુ ક્રોમા OKLCH needs sRGB as the working RGB space OKLCH માટે કાર્યકારી RGB સ્પેસ તરીકે sRGB જરૂરી છે +@msg `sliders` must be none or oklch `sliders` none અથવા oklch હોવું જોઈએ +@msg OKLCH needs sRGB as the working RGB space OKLCH માટે કાર્યકારી RGB સ્પેસ તરીકે sRGB જરૂરી છે Lightness લાઇટનેસ Lab Spot Colors: Lab સ્પોટ રંગો: Landscape લેન્ડસ્કેપ diff --git a/crates/ui-egui/src/panels/tests_color_wheel.rs b/crates/ui-egui/src/panels/tests_color_wheel.rs index 821ac678bc..48cf4e9e29 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel.rs @@ -861,3 +861,21 @@ fn ui_color_wheel_sets_and_reads_the_sliders() { assert_eq!(e, "`sliders` must be none or oklch"); assert_eq!(app.ui.color_wheel.view, crate::panels::color_wheel::View::Box, "an error changes nothing"); } + +/// The `sliders` errors are translated in every catalog, and each translation keeps the accepted +/// values. +#[test] +fn ui_color_wheel_sliders_errors_are_translated() { + let errors = [("`sliders` must be none or oklch", &["none", "oklch"][..]), ("OKLCH needs sRGB as the working RGB space", &["OKLCH", "sRGB"][..])]; + for code in [ + "bg", "bs", "ca", "cs", "da", "de", "el", "es", "fi", "fr", "gu", "hi", "hu", "id", "it", "ja", "ka", "ko", "nl", "pl", "pt-br", "ru", "sv", "tr", + "uk", "vi", "zh-hans", "zh-hant", + ] { + let lang = crate::i18n::Lang::from_code(code).expect("registered"); + for (error, values) in errors { + let shown = crate::i18n::message(lang, error); + assert_ne!(shown, error, "{code}"); + assert!(values.iter().all(|v| shown.contains(v)), "{code}: {shown}"); + } + } +} From 189720d39798a7eb1f56c02f277e7dc5550bc178 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 01:29:45 -0800 Subject: [PATCH 04/12] Tests: format the Color Wheel sliders translation test --- crates/ui-egui/src/panels/tests_color_wheel.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panels/tests_color_wheel.rs b/crates/ui-egui/src/panels/tests_color_wheel.rs index 48cf4e9e29..b0efcd4b00 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel.rs @@ -868,8 +868,8 @@ fn ui_color_wheel_sets_and_reads_the_sliders() { fn ui_color_wheel_sliders_errors_are_translated() { let errors = [("`sliders` must be none or oklch", &["none", "oklch"][..]), ("OKLCH needs sRGB as the working RGB space", &["OKLCH", "sRGB"][..])]; for code in [ - "bg", "bs", "ca", "cs", "da", "de", "el", "es", "fi", "fr", "gu", "hi", "hu", "id", "it", "ja", "ka", "ko", "nl", "pl", "pt-br", "ru", "sv", "tr", - "uk", "vi", "zh-hans", "zh-hant", + "bg", "bs", "ca", "cs", "da", "de", "el", "es", "fi", "fr", "gu", "hi", "hu", "id", "it", "ja", "ka", "ko", "nl", "pl", "pt-br", "ru", "sv", + "tr", "uk", "vi", "zh-hans", "zh-hant", ] { let lang = crate::i18n::Lang::from_code(code).expect("registered"); for (error, values) in errors { From 00322ad70f343e315ae5d879f1e5b170094bf533 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 11:27:47 -0800 Subject: [PATCH 05/12] Color Wheel: OKLCH lightness endpoints give exact black and white from_oklch returns exactly black at lightness 0 and exactly white at lightness 1, as CSS Color 4 specifies, and reports a positive chroma there as lowered. The gamut tolerance no longer leaves a positive red channel at L=0. The command text and docs say a color outside sRGB takes the largest chroma that fits at or below the one asked for, that color.convert measures the stored color's display sRGB, and that a null key keeps its value. The saved-settings test also checks that an unknown slider value keeps the saved view. --- crates/color/src/oklab.rs | 17 ++++++++++++++++- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/menus/ui_commands.rs | 2 +- crates/ui-egui/src/panels/tests_color_wheel.rs | 14 ++++++++------ docs/mcp.md | 2 +- docs/target-app-parity.md | 2 +- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/crates/color/src/oklab.rs b/crates/color/src/oklab.rs index 31500d1ac5..7deb757f58 100644 --- a/crates/color/src/oklab.rs +++ b/crates/color/src/oklab.rs @@ -113,11 +113,16 @@ fn turning_points(a: f64, b: f64, c: f64) -> Vec { /// The sRGB color (gamma encoded, 0..=1) of OKLCH `(l, c, h°)`, and whether its chroma was lowered: /// a color outside sRGB keeps its lightness and hue and takes the largest chroma below it that -/// fits. Lightness is clamped to 0..=1 and chroma to 0 or more. +/// fits. Lightness is clamped to 0..=1 and chroma to 0 or more. Lightness 0 gives exactly black and +/// lightness 1 exactly white, as CSS Color 4 specifies, and a positive chroma there counts as +/// lowered. pub fn from_oklch(l: f64, c: f64, h: f64) -> ([f32; 3], bool) { let l = if l.is_nan() { 0.0 } else { l.clamp(0.0, 1.0) }; let c = if c.is_nan() { 0.0 } else { c.max(0.0) }; let h = if h.is_finite() { h } else { 0.0 }; + if l == 0.0 || l == 1.0 { + return ([l as f32; 3], c > 0.0); + } let exact = oklch_to_srgb(l, c, h); let (rgb, lowered) = if in_srgb(exact) { (exact, false) } else { (oklch_to_srgb(l, largest_fitting_chroma(l, h, c), h), true) }; (rgb.map(|v| v.clamp(0.0, 1.0) as f32), lowered) @@ -263,4 +268,14 @@ mod tests { assert_eq!(eight(from_oklch(f64::NAN, f64::NAN, f64::NAN).0), [0, 0, 0]); assert_eq!(eight(from_oklch(2.0, -1.0, 0.0).0), [255, 255, 255]); } + + /// The lightness endpoints give exactly black and white at any chroma and hue, and report a + /// positive chroma as lowered. A rounded 8-bit comparison would hide a small leftover channel. + #[test] + fn the_lightness_endpoints_give_exact_black_and_white() { + assert_eq!(from_oklch(0.0, 0.04, 0.0), ([0.0; 3], true)); + assert_eq!(from_oklch(0.0, 0.0, 120.0), ([0.0; 3], false)); + assert_eq!(from_oklch(1.0, 0.1, 250.0), ([1.0; 3], true)); + assert_eq!(from_oklch(1.0, 0.0, 0.0), ([1.0; 3], false)); + } } diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index 290623b48b..6e8e1e3426 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1573,7 +1573,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.colorWheel", "Color Wheel Options", "", - "{view?: wheel|box, channel?: hue|saturation|brightness|red|green|blue, sliders?: none|oklch|hsl, 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, pick the box's channel, as Box Channel does, and show no slider rows under the wheel or the box (none), OKLCH Sliders (oklch) or HSL Sliders (hsl), as the menu items of those names do: 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); OKLCH Sliders edit lightness 0 to 100 %, chroma 0 to 100 % of 0.4 and hue 0 to 360°, CSS Color 4's OKLCH of the display sRGB, and a color outside sRGB keeps L and H and takes the largest chroma that fits; HSL Sliders edit hue 0 to 360°, saturation 0 to 100 % and lightness 0 to 100 %, CSS Color 4's HSL of the display sRGB; 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, oklch is an error while the working RGB space is not sRGB, 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, sliders, harmony, harmonyRule, vision}", + "{view?: wheel|box, channel?: hue|saturation|brightness|red|green|blue, sliders?: none|oklch|hsl, 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, pick the box's channel, as Box Channel does, and show no slider rows under the wheel or the box (none), OKLCH Sliders (oklch) or HSL Sliders (hsl), as the menu items of those names do: 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); OKLCH Sliders edit lightness 0 to 100 %, chroma 0 to 100 % of 0.4 and hue 0 to 360°, CSS Color 4's OKLCH of the display sRGB, and a color outside sRGB keeps L and H and takes the largest chroma that fits at or below the one asked for; HSL Sliders edit hue 0 to 360°, saturation 0 to 100 % and lightness 0 to 100 %, CSS Color 4's HSL of the display sRGB; 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, oklch is an error while the working RGB space is not sRGB, 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, sliders, harmony, harmonyRule, vision}", ), ( "ui.savePdfDialog", diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index ef7975b9a0..7ab1ff88b8 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1574,7 +1574,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.colorWheel", "Color Wheel Options", "", - "{view?: wheel|box, channel?: hue|saturation|brightness|red|green|blue, sliders?: none|oklch|hsl, 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, pick the box's channel, as Box Channel does, and show no slider rows under the wheel or the box (none), OKLCH Sliders (oklch) or HSL Sliders (hsl), as the menu items of those names do: 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); OKLCH Sliders edit lightness 0 to 100 %, chroma 0 to 100 % of 0.4 and hue 0 to 360°, CSS Color 4's OKLCH of the display sRGB, and a color outside sRGB keeps L and H and takes the largest chroma that fits; HSL Sliders edit hue 0 to 360°, saturation 0 to 100 % and lightness 0 to 100 %, CSS Color 4's HSL of the display sRGB; 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, oklch is an error while the working RGB space is not sRGB, 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, sliders, harmony, harmonyRule, vision}", + "{view?: wheel|box, channel?: hue|saturation|brightness|red|green|blue, sliders?: none|oklch|hsl, 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, pick the box's channel, as Box Channel does, and show no slider rows under the wheel or the box (none), OKLCH Sliders (oklch) or HSL Sliders (hsl), as the menu items of those names do: 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); OKLCH Sliders edit lightness 0 to 100 %, chroma 0 to 100 % of 0.4 and hue 0 to 360°, CSS Color 4's OKLCH of the display sRGB, and a color outside sRGB keeps L and H and takes the largest chroma that fits at or below the one asked for; HSL Sliders edit hue 0 to 360°, saturation 0 to 100 % and lightness 0 to 100 %, CSS Color 4's HSL of the display sRGB; 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, oklch is an error while the working RGB space is not sRGB, 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, sliders, harmony, harmonyRule, vision}", ), ( "ui.savePdfDialog", diff --git a/crates/ui-egui/src/panels/tests_color_wheel.rs b/crates/ui-egui/src/panels/tests_color_wheel.rs index 99f7cd97ea..343cd9f8c6 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel.rs @@ -1066,15 +1066,17 @@ fn the_remembered_hsl_follows_a_change_of_working_space() { fn saved_color_wheel_settings_are_read_leniently() { let mut saved = serde_json::to_value(crate::UiState::default()).unwrap(); saved["color_rgb_percent"] = json!(true); - for (value, sliders) in [ - (json!({"sliders": "oklch"}), Sliders::Oklch), - (json!({"sliders": "hsl"}), Sliders::Hsl), - (json!({"sliders": "hwb", "view": "box"}), Sliders::None), - (json!(5), Sliders::None), + let wheel = crate::panels::color_wheel::View::Wheel; + let box_view = crate::panels::color_wheel::View::Box; + for (value, sliders, view) in [ + (json!({"sliders": "oklch"}), Sliders::Oklch, wheel), + (json!({"sliders": "hsl"}), Sliders::Hsl, wheel), + (json!({"sliders": "hwb", "view": "box"}), Sliders::None, box_view), + (json!(5), Sliders::None, wheel), ] { saved["color_wheel"] = value.clone(); let ui: crate::UiState = serde_json::from_value(saved.clone()).unwrap(); - assert_eq!((ui.color_wheel.sliders, ui.color_rgb_percent), (sliders, true), "{value}"); + assert_eq!((ui.color_wheel.sliders, ui.color_wheel.view, ui.color_rgb_percent), (sliders, view, true), "{value}"); } } diff --git a/docs/mcp.md b/docs/mcp.md index 2debb5d7fc..776c1b30f0 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -686,7 +686,7 @@ strip at its right) in place of the wheel, as the panel menu's Box View and Box 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 +`highContrast2`). Keys left out or `null` 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, sliders, harmony, harmonyRule, vision}`, and the settings are kept with the preferences. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 8fd9808c6f..364b1f1e3b 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1947,7 +1947,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. - - **OKLCH Sliders (Color Wheel panel):** as VectorCraft's own addition, the Color Wheel panel's menu item OKLCH Sliders (`ui.colorWheel {sliders: "oklch"}`, kept with the preferences) shows L, C and H rows under the wheel or the box that edit the color by the OKLCH lightness (0 to 100 %), chroma (0 to 100 % of 0.4) and hue (0 to 360°) of its display sRGB, as CSS Color 4 defines them (https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch). Each track dims the colors outside sRGB, and a tick on the C track marks the largest chroma sRGB holds at the row's L and H; a color outside sRGB keeps L and H and takes the largest chroma that fits, and the C row keeps the chroma asked for. The rows take the arrow keys after a click and report their names, values, ranges and adjust actions to screen readers. While the active document's RGB space (its assigned profile, else the working RGB space of Edit › Color Settings) is not sRGB, the unchecked item is gray and `ui.colorWheel {sliders: "oklch"}` answers an error; rows shown before the space changed are gray, and the checked item still hides them. `color.convert {color, to: "oklch"}` answers the same L, C and H for a color inside sRGB. For a color outside sRGB, it clips the display RGB to 0 to 1 first, so its L, C and H can differ from the rows' values. Evidence: `crates/color/src/oklab.rs` tests; `convert_to_oklch_answers_lightness_chroma_and_hue` in `crates/engine/src/tests/colormgmt.rs`; the OKLCH tests in `crates/ui-egui/src/panels/tests_color_wheel.rs`, `the_oklch_tracks_dim_the_colors_outside_srgb_and_the_tick_marks_the_largest_chroma` and `oklch_sliders_are_gray_after_the_working_space_changes` among them. Scores and estimates are unchanged. + - **OKLCH Sliders (Color Wheel panel):** as VectorCraft's own addition, the Color Wheel panel's menu item OKLCH Sliders (`ui.colorWheel {sliders: "oklch"}`, kept with the preferences) shows L, C and H rows under the wheel or the box that edit the color by the OKLCH lightness (0 to 100 %), chroma (0 to 100 % of 0.4) and hue (0 to 360°) of its display sRGB, as CSS Color 4 defines them (https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch). Each track dims the colors outside sRGB, and a tick on the C track marks the largest chroma sRGB holds at the row's L and H; a color outside sRGB keeps L and H and takes the largest chroma that fits at or below the one asked for, and the C row keeps the chroma asked for. At lightness 0 and 100 % the color is exactly black and white. The rows take the arrow keys after a click and report their names, values, ranges and adjust actions to screen readers. While the active document's RGB space (its assigned profile, else the working RGB space of Edit › Color Settings) is not sRGB, the unchecked item is gray and `ui.colorWheel {sliders: "oklch"}` answers an error; rows shown before the space changed are gray, and the checked item still hides them. `color.convert {color, to: "oklch"}` answers the same L, C and H for a color inside sRGB. For a color outside sRGB, it clips the display RGB to 0 to 1 first, so its L, C and H can differ from the rows' values. It always measures the display sRGB of the color stored in the document, so after a pick whose chroma did not fit, its C is the chroma that fit and not the value the C row keeps. Evidence: `crates/color/src/oklab.rs` tests; `convert_to_oklch_answers_lightness_chroma_and_hue` in `crates/engine/src/tests/colormgmt.rs`; the OKLCH tests in `crates/ui-egui/src/panels/tests_color_wheel.rs`, `the_oklch_tracks_dim_the_colors_outside_srgb_and_the_tick_marks_the_largest_chroma` and `oklch_sliders_are_gray_after_the_working_space_changes` among them. Scores and estimates are unchanged. - **HSL Sliders (Color Wheel panel):** as VectorCraft's own addition, the Color Wheel panel's menu item HSL Sliders (`ui.colorWheel {sliders: "hsl"}`, kept with the preferences) shows H, S and L rows in place of OKLCH Sliders that edit the color by the hue (0 to 360°), saturation and lightness (0 to 100 %) of its display sRGB, as CSS Color 4 defines HSL (https://www.w3.org/TR/css-color-4/#the-hsl-notation). A pick goes from display sRGB into the working RGB space as the wheel's picks do, and the rows keep the hue of a gray. The rows take the arrow keys after a click and report their names, values, ranges and adjust actions to screen readers. Evidence: `hsl_follows_css_color_4` and `hsl_roundtrip` in `crates/color/src/lib.rs`; the HSL tests in `crates/ui-egui/src/panels/tests_color_wheel.rs`, `a_gray_keeps_the_hsl_hue_it_was_given` among them. 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}`). From ae34cc3e770ae680860cbe326d03cc91918eeebd Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 17:00:33 -0800 Subject: [PATCH 06/12] Color Wheel: Show Out-of-Gamut Colors runs through the panel menu's command helper The item called the command function directly, so it skipped the app's command entry point and an error went unreported. It now uses the same helper as the other panel menu items. The menu test checks that one command runs. --- crates/ui-egui/src/panels/color_wheel.rs | 2 +- crates/ui-egui/src/panels/tests_color_wheel_gamut.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/panels/color_wheel.rs b/crates/ui-egui/src/panels/color_wheel.rs index 84415d89ca..0e3df51203 100644 --- a/crates/ui-egui/src/panels/color_wheel.rs +++ b/crates/ui-egui/src/panels/color_wheel.rs @@ -318,7 +318,7 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { }); ui.separator(); if menu_item(ui, tl!("Show Out-of-Gamut Colors"), true, set.gamut) { - command(app, &json!({ "gamut": !set.gamut })).ok(); + run(app, json!({ "gamut": !set.gamut })); } let on = set.sliders == Sliders::Hsl; if menu_item(ui, tl!("HSL Sliders"), true, on) { diff --git a/crates/ui-egui/src/panels/tests_color_wheel_gamut.rs b/crates/ui-egui/src/panels/tests_color_wheel_gamut.rs index da47fa684e..450d9b592e 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel_gamut.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel_gamut.rs @@ -214,9 +214,11 @@ fn the_panel_menu_switches_the_shading() { app, ); h.run_steps(3); + let commands = h.state().run_count; h.get_by_label(" Show Out-of-Gamut Colors").click(); h.run_steps(2); assert!(h.state().ui.color_wheel.gamut); + assert_eq!(h.state().run_count, commands.wrapping_add(1), "the item runs one ui.colorWheel command"); assert!(h.query_by_label("✓ Show Out-of-Gamut Colors").is_some()); h.get_by_label("✓ Show Out-of-Gamut Colors").click(); h.run_steps(2); From 83d84dedcac210aed3d0e794b93f315812b2156e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 17:13:57 -0800 Subject: [PATCH 07/12] Color Wheel: the checked Harmony Rule item runs no command Clicking the rule that is already set ran ui.colorWheel and counted as a command. It now does nothing, as the checked view and channel items do. --- crates/ui-egui/src/panels/color_wheel.rs | 2 +- crates/ui-egui/src/panels/tests_color_wheel_harmony.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/panels/color_wheel.rs b/crates/ui-egui/src/panels/color_wheel.rs index 0e3df51203..c34946387c 100644 --- a/crates/ui-egui/src/panels/color_wheel.rs +++ b/crates/ui-egui/src/panels/color_wheel.rs @@ -338,7 +338,7 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { ui.add_enabled_ui(set.view == View::Wheel, |ui| { ui.menu_button(format!(" {}", tl!("Harmony Rule")), |ui| { for rule in harmony_rules() { - if menu_item(ui, rule.label(), true, rule == set.harmony_rule) { + if menu_item(ui, rule.label(), true, rule == set.harmony_rule) && rule != set.harmony_rule { run(app, json!({ "harmonyRule": rule.id() })); } } diff --git a/crates/ui-egui/src/panels/tests_color_wheel_harmony.rs b/crates/ui-egui/src/panels/tests_color_wheel_harmony.rs index 454e43ec49..f7ce477b98 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel_harmony.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel_harmony.rs @@ -344,6 +344,15 @@ fn the_panel_menu_shows_the_harmony_and_picks_the_rule() { h.get_by_label(" Pentagram").click(); h.run_steps(2); assert_eq!(h.state().ui.color_wheel.harmony_rule, Harmony::Pentagram); + // The checked rule runs no command. + if h.query_by_label("✓ Pentagram").is_none() { + h.get_by_label(" Harmony Rule").click(); + h.run_steps(2); + } + let commands = h.state().run_count; + h.get_by_label("✓ Pentagram").click(); + h.run_steps(2); + assert_eq!(h.state().run_count, commands, "the checked rule runs no command"); 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"); From 10373c02a655b0d8738dbcadeeb3b535e29c33ba Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 17:27:17 -0800 Subject: [PATCH 08/12] Color Wheel: the ui.colorWheel description names the document's RGB space for oklch The command rejects sliders: oklch while the active document's RGB space (its assigned profile, else the working RGB space) is not sRGB. Both catalog descriptions now say so. --- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/menus/ui_commands.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index 2d0c977391..1d0a0227cf 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1604,7 +1604,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.colorWheel", "Color Wheel Options", "", - "{view?: wheel|box, channel?: hue|saturation|brightness|red|green|blue, sliders?: none|oklch|hsl, gamut?: bool, harmony?: bool, harmonyRule?: complementary|splitComplementary|leftComplement|rightComplement|analogous|analogous2|triad|tetrad|tetrad2|tetrad3|compound|compound2|highContrast|highContrast3|pentagram, vision?: bool, documentColors?: bool} show the Color Wheel panel's wheel or its box, as the panel menu's Wheel View and Box View do, pick the box's channel, as Box Channel does, and show no slider rows under the wheel or the box (none), OKLCH Sliders (oklch) or HSL Sliders (hsl), as the menu items of those names do: 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); OKLCH Sliders edit lightness 0 to 100 %, chroma 0 to 100 % of 0.4 and hue 0 to 360°, CSS Color 4's OKLCH of the display sRGB, and a color outside sRGB keeps L and H and takes the largest chroma that fits at or below the one asked for; HSL Sliders edit hue 0 to 360°, saturation 0 to 100 % and lightness 0 to 100 %, CSS Color 4's HSL of the display sRGB; gamut true grays out the parts of the wheel's square and the box's field whose colors the CMYK space cannot print (the out-of-gamut warning's test, as color.gamutCheck answers it), as Show Out-of-Gamut Colors does, and false shows them again; the shading is approximate: each cell of a 16 by 16 grid over the square or the field is grayed out or not by the color at its center, so a grayed cell can hold printable colors and a clear cell can hold colors that cannot print; 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; documentColors shows or hides the row the panel menu's Show Document Colors adds under the wheel or the box: the colors color.used {} lists, headed Selection Colors when something is selected and Document Colors otherwise, most used first and as many as fit in one row (a chip's tooltip gives its hex value and how many times the art uses it; a click applies it to the active proxy or to the selected gradient stop, keeping its color model and its link to a global swatch, or to the selected freeform point, which takes the color alone, and Alt+click applies it to the other proxy; the row reads the colors again when the document or the selection changes, not during a drag, and in art with more than 5,000 color uses at most once every half second after an edit); 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, oklch is an error while the working RGB space is not sRGB, 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, sliders, gamut, harmony, harmonyRule, vision, documentColors}", + "{view?: wheel|box, channel?: hue|saturation|brightness|red|green|blue, sliders?: none|oklch|hsl, gamut?: bool, harmony?: bool, harmonyRule?: complementary|splitComplementary|leftComplement|rightComplement|analogous|analogous2|triad|tetrad|tetrad2|tetrad3|compound|compound2|highContrast|highContrast3|pentagram, vision?: bool, documentColors?: bool} show the Color Wheel panel's wheel or its box, as the panel menu's Wheel View and Box View do, pick the box's channel, as Box Channel does, and show no slider rows under the wheel or the box (none), OKLCH Sliders (oklch) or HSL Sliders (hsl), as the menu items of those names do: 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); OKLCH Sliders edit lightness 0 to 100 %, chroma 0 to 100 % of 0.4 and hue 0 to 360°, CSS Color 4's OKLCH of the display sRGB, and a color outside sRGB keeps L and H and takes the largest chroma that fits at or below the one asked for; HSL Sliders edit hue 0 to 360°, saturation 0 to 100 % and lightness 0 to 100 %, CSS Color 4's HSL of the display sRGB; gamut true grays out the parts of the wheel's square and the box's field whose colors the CMYK space cannot print (the out-of-gamut warning's test, as color.gamutCheck answers it), as Show Out-of-Gamut Colors does, and false shows them again; the shading is approximate: each cell of a 16 by 16 grid over the square or the field is grayed out or not by the color at its center, so a grayed cell can hold printable colors and a clear cell can hold colors that cannot print; 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; documentColors shows or hides the row the panel menu's Show Document Colors adds under the wheel or the box: the colors color.used {} lists, headed Selection Colors when something is selected and Document Colors otherwise, most used first and as many as fit in one row (a chip's tooltip gives its hex value and how many times the art uses it; a click applies it to the active proxy or to the selected gradient stop, keeping its color model and its link to a global swatch, or to the selected freeform point, which takes the color alone, and Alt+click applies it to the other proxy; the row reads the colors again when the document or the selection changes, not during a drag, and in art with more than 5,000 color uses at most once every half second after an edit); 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, oklch is an error while the active document's RGB space (its assigned profile, else the working RGB space) is not sRGB, 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, sliders, gamut, harmony, harmonyRule, vision, documentColors}", ), ( "ui.savePdfDialog", diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 86d6aedee0..41b089c9e1 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1605,7 +1605,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.colorWheel", "Color Wheel Options", "", - "{view?: wheel|box, channel?: hue|saturation|brightness|red|green|blue, sliders?: none|oklch|hsl, gamut?: bool, harmony?: bool, harmonyRule?: complementary|splitComplementary|leftComplement|rightComplement|analogous|analogous2|triad|tetrad|tetrad2|tetrad3|compound|compound2|highContrast|highContrast3|pentagram, vision?: bool, documentColors?: bool} show the Color Wheel panel's wheel or its box, as the panel menu's Wheel View and Box View do, pick the box's channel, as Box Channel does, and show no slider rows under the wheel or the box (none), OKLCH Sliders (oklch) or HSL Sliders (hsl), as the menu items of those names do: 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); OKLCH Sliders edit lightness 0 to 100 %, chroma 0 to 100 % of 0.4 and hue 0 to 360°, CSS Color 4's OKLCH of the display sRGB, and a color outside sRGB keeps L and H and takes the largest chroma that fits at or below the one asked for; HSL Sliders edit hue 0 to 360°, saturation 0 to 100 % and lightness 0 to 100 %, CSS Color 4's HSL of the display sRGB; gamut true grays out the parts of the wheel's square and the box's field whose colors the CMYK space cannot print (the out-of-gamut warning's test, as color.gamutCheck answers it), as Show Out-of-Gamut Colors does, and false shows them again; the shading is approximate: each cell of a 16 by 16 grid over the square or the field is grayed out or not by the color at its center, so a grayed cell can hold printable colors and a clear cell can hold colors that cannot print; 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; documentColors shows or hides the row the panel menu's Show Document Colors adds under the wheel or the box: the colors color.used {} lists, headed Selection Colors when something is selected and Document Colors otherwise, most used first and as many as fit in one row (a chip's tooltip gives its hex value and how many times the art uses it; a click applies it to the active proxy or to the selected gradient stop, keeping its color model and its link to a global swatch, or to the selected freeform point, which takes the color alone, and Alt+click applies it to the other proxy; the row reads the colors again when the document or the selection changes, not during a drag, and in art with more than 5,000 color uses at most once every half second after an edit); 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, oklch is an error while the working RGB space is not sRGB, 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, sliders, gamut, harmony, harmonyRule, vision, documentColors}", + "{view?: wheel|box, channel?: hue|saturation|brightness|red|green|blue, sliders?: none|oklch|hsl, gamut?: bool, harmony?: bool, harmonyRule?: complementary|splitComplementary|leftComplement|rightComplement|analogous|analogous2|triad|tetrad|tetrad2|tetrad3|compound|compound2|highContrast|highContrast3|pentagram, vision?: bool, documentColors?: bool} show the Color Wheel panel's wheel or its box, as the panel menu's Wheel View and Box View do, pick the box's channel, as Box Channel does, and show no slider rows under the wheel or the box (none), OKLCH Sliders (oklch) or HSL Sliders (hsl), as the menu items of those names do: 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); OKLCH Sliders edit lightness 0 to 100 %, chroma 0 to 100 % of 0.4 and hue 0 to 360°, CSS Color 4's OKLCH of the display sRGB, and a color outside sRGB keeps L and H and takes the largest chroma that fits at or below the one asked for; HSL Sliders edit hue 0 to 360°, saturation 0 to 100 % and lightness 0 to 100 %, CSS Color 4's HSL of the display sRGB; gamut true grays out the parts of the wheel's square and the box's field whose colors the CMYK space cannot print (the out-of-gamut warning's test, as color.gamutCheck answers it), as Show Out-of-Gamut Colors does, and false shows them again; the shading is approximate: each cell of a 16 by 16 grid over the square or the field is grayed out or not by the color at its center, so a grayed cell can hold printable colors and a clear cell can hold colors that cannot print; 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; documentColors shows or hides the row the panel menu's Show Document Colors adds under the wheel or the box: the colors color.used {} lists, headed Selection Colors when something is selected and Document Colors otherwise, most used first and as many as fit in one row (a chip's tooltip gives its hex value and how many times the art uses it; a click applies it to the active proxy or to the selected gradient stop, keeping its color model and its link to a global swatch, or to the selected freeform point, which takes the color alone, and Alt+click applies it to the other proxy; the row reads the colors again when the document or the selection changes, not during a drag, and in art with more than 5,000 color uses at most once every half second after an edit); 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, oklch is an error while the active document's RGB space (its assigned profile, else the working RGB space) is not sRGB, 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, sliders, gamut, harmony, harmonyRule, vision, documentColors}", ), ( "ui.savePdfDialog", From c46bdce70687f8944f72699f330d29241dc1e39d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 20:35:48 -0800 Subject: [PATCH 09/12] Color Wheel: a remembered pick ends with the document's undo step MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The remembered HSB, OKLCH and HSL now also belong to the document's undo step. Another edit, an Undo or a Redo drops them, also when the slider rows are hidden and the same color comes back before they show again. docs/mcp.md: color.convert to oklch answers an object with model "oklch" and values [L %, C, H°]. --- crates/ui-egui/src/panels/color_wheel.rs | 9 ++++++-- .../ui-egui/src/panels/tests_color_wheel.rs | 22 +++++++++++++++++++ docs/mcp.md | 3 ++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panels/color_wheel.rs b/crates/ui-egui/src/panels/color_wheel.rs index c34946387c..f38c35dfa9 100644 --- a/crates/ui-egui/src/panels/color_wheel.rs +++ b/crates/ui-egui/src/panels/color_wheel.rs @@ -710,11 +710,15 @@ fn vision_row(ui: &mut Ui, cms: &Cms, color: Option<&Color>) { } /// 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 -/// the pick stored. The wheel shows that HSB only while all of them are unchanged. +/// the appearance item, the proxy, the gradient stop or freeform point, its paint, the color the +/// pick stored, and the document's undo step. The wheel shows that HSB only while all of them are +/// unchanged. #[derive(Clone, Debug, PartialEq)] struct Owner { doc: Option, + /// The document's [`History::step`](vectorcraft_engine::History::step): another edit, an Undo + /// or a Redo changes it, also when the same color comes back. + step: Option<(u64, u64)>, selection: Vec, /// The Type tool's selected characters, when it edits the paint. text_selection: Option<(NodeId, usize, usize)>, @@ -738,6 +742,7 @@ impl Owner { }; Self { doc: st.map(|d| d.uid), + step: st.map(|d| d.history.step()), selection: st.map(|d| d.selection.objects.clone()).unwrap_or_default(), text_selection: super::character::text_editing(app), appearance_item: app.session.appearance_item(), diff --git a/crates/ui-egui/src/panels/tests_color_wheel.rs b/crates/ui-egui/src/panels/tests_color_wheel.rs index 2c86f073c5..16538de82f 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel.rs @@ -1169,6 +1169,28 @@ fn a_remembered_hue_is_dropped_after_the_paint_changes() { } } +/// The hue given to a gray is also dropped when the paint changes and comes back while the rows are +/// hidden, so showing the rows again shows the gray's own hue, 0°. +#[test] +fn a_remembered_hue_is_dropped_after_the_paint_changes_while_the_rows_are_hidden() { + for (rows, hue) in [("hsl", "HSL Hue"), ("oklch", "Hue")] { + let mut app = app(json!("#808080")); + app.run("ui.colorWheel", json!({"sliders": rows})).unwrap(); + let mut h = oklch_harness_shown(app); + set_slider_value(&mut h, hue, 240.0); + assert_eq!(oklch_slider(&h, hue).accesskit_node().numeric_value(), Some(240.0), "{rows}"); + h.state_mut().run("ui.colorWheel", json!({"sliders": "none"})).unwrap(); + h.run_steps(2); + h.state_mut().run("paint.setFill", json!({"color": "#ff0000"})).unwrap(); + h.run_steps(2); + h.state_mut().run("paint.setFill", json!({"color": "#808080"})).unwrap(); + h.run_steps(2); + h.state_mut().run("ui.colorWheel", json!({"sliders": rows})).unwrap(); + h.run_steps(2); + assert_eq!(oklch_slider(&h, hue).accesskit_node().numeric_value(), Some(0.0), "{rows}: the gray's own hue"); + } +} + /// Hiding the rows, or showing the other rows, during a drag on a row keeps the color the drag /// previewed as one undo step and leaves no interaction open. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 2a3ad79bdb..b65d1c1ab5 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -702,7 +702,8 @@ the box), and `"none"` hides them in any RGB space. `"oklch"` is an error while not sRGB: the profile assigned to the document when it has one, else the working RGB space of Edit › Color Settings. `ui.colorWheel {"sliders": "hsl"}` shows HSL Sliders in their place: H, S and L rows with the hue (0 to 360°), saturation and lightness (0 to 100 %) of the color's display sRGB, as CSS Color 4's `hsl()` defines them. -`color.convert {"color": "#ff0000", "to": "oklch"}` answers the color's OKLCH as `[L %, C, H°]` of its display sRGB. +`color.convert {"color": "#ff0000", "to": "oklch"}` answers the color's OKLCH of its display sRGB in an object with +`model: "oklch"` and `values: [L %, C, H°]`, next to the `hex`, `lab`, `outOfGamut` and `deltaE` of every conversion. A color outside sRGB (a Lab or CMYK color, an RGB color in a wider RGB space, or RGB numbers past 0 to 1) is clipped to sRGB first. The answer of `ui.colorWheel` and the settings also carry `sliders`. From c29eb5e6e4416053c13ae08b0fc57f92536c5d82 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 13:58:13 -0800 Subject: [PATCH 10/12] Color Wheel: tests for the remembered pick and the document's RGB space The remembered hue of a gray is dropped once the paint changes and the same gray comes back while the slider rows are hidden, and `ui.colorWheel {sliders: "oklch"}` follows the active document's RGB space. Both tests use the panel fixture that replaced the earlier harness. --- .../ui-egui/src/panels/tests_color_wheel.rs | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/panels/tests_color_wheel.rs b/crates/ui-egui/src/panels/tests_color_wheel.rs index 1485986f31..3cd0167b50 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel.rs @@ -7,11 +7,72 @@ use std::rc::Rc; use craft::ui::testing::focus::AccessActionKind; use craft::ui::testing::{Fixture, Target}; use egui::{Key, Modifiers, vec2}; -use serde_json::Value; +use serde_json::{Value, json}; +use vectorcraft_engine::Session; use super::color_wheel::show; use crate::VectorcraftApp; +/// An app with a selected rectangle filled with `fill`. +fn app(fill: &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 +} + +/// A hue given to a gray is remembered only until the document's next undo step: after the paint +/// changes and the same gray comes back while the rows are hidden, the rows show the gray's own hue. +#[test] +fn a_remembered_hue_is_dropped_after_the_paint_changes_while_the_rows_are_hidden() { + for (rows, hue) in [("hsl", "HSL Hue"), ("oklch", "Hue")] { + let mut a = app("#808080"); + a.run("ui.colorWheel", json!({"sliders": rows})).unwrap(); + let mut p = Panel::new(a); + p.set(hue, 240.0); + assert_eq!(p.number(hue), Some(240.0), "{rows}: the gray keeps the hue it was given"); + p.run("ui.colorWheel", json!({"sliders": "none"})); + p.run("paint.setFill", json!({"color": "#ff0000"})); + p.run("paint.setFill", json!({"color": "#808080"})); + p.run("ui.colorWheel", json!({"sliders": rows})); + assert_ne!(p.number(hue), Some(240.0), "{rows}: the remembered hue is dropped"); + } +} + +/// `sliders: "oklch"` follows the active document's RGB space: it is an error in a document assigned +/// Display P3 while the working RGB space is sRGB, and is taken in a document without a profile. +#[test] +fn oklch_sliders_follow_the_active_documents_rgb_space() { + const CHILD: &str = "VECTORCRAFT_TEST_COLOR_WHEEL_DOC_PROFILE"; + if std::env::var_os(CHILD).is_none() { + // Color settings are process-wide: assign the profile in a separate test process. + let output = std::process::Command::new(std::env::current_exe().unwrap()) + .args(["--exact", "panels::tests_color_wheel::oklch_sliders_follow_the_active_documents_rgb_space", "--nocapture"]) + .env(CHILD, "1") + .output() + .unwrap(); + let stdout = String::from_utf8_lossy(&output.stdout); + assert!( + output.status.success() && stdout.contains("test result: ok. 1 passed; 0 failed;"), + "isolated document profile test failed:\n{stdout}\n{}", + String::from_utf8_lossy(&output.stderr), + ); + return; + } + use vectorcraft_color::cms; + let mut a = app("#339966"); + a.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + a.run("edit.assignProfile", json!({"rgb": cms::DISPLAY_P3})).unwrap(); + let mut p = Panel::new(a); + assert!(cms::working_settings().rgb != cms::DISPLAY_P3, "the working RGB space is not Display P3"); + let refused = p.app_mut().run("ui.colorWheel", json!({"sliders": "oklch"})); + assert!(refused.is_err(), "{refused:?}"); + p.run("document.activate", json!({"index": 0})); + p.run("ui.colorWheel", json!({"sliders": "oklch"})); + assert_eq!(p.app().ui.color_wheel.sliders, super::color_wheel::Sliders::Oklch); +} + /// The app shown through the panel's `show`, driven by the parts' names and keys. // PLAN: sh.SH4 `crate::testing::ui_context()` has no entry point on `Fixture` here, so the app's fonts are not installed. pub(super) struct Panel { From 9c93b32c123e269293bff42196d882d222053f57 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 19:41:01 -0800 Subject: [PATCH 11/12] Color Wheel: an opacity edit keeps the HSL and OKLCH picked last The opacity row re-keyed only the remembered HSB after its edit, so a hue given to a gray in the HSL or OKLCH rows jumped back to the gray's own hue when Opacity changed. One helper now moves all three records to the edited paint. --- crates/ui-egui/src/panels/color_wheel.rs | 23 +++++++++++++------ .../src/panels/tests_color_wheel_opacity.rs | 17 ++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/panels/color_wheel.rs b/crates/ui-egui/src/panels/color_wheel.rs index 96354161a1..1fe1cf2d0c 100644 --- a/crates/ui-egui/src/panels/color_wheel.rs +++ b/crates/ui-egui/src/panels/color_wheel.rs @@ -1050,6 +1050,15 @@ fn recall( kept } +/// Move the record in `slot` from owner `was` to owner `now`, when `was` holds it. +fn rekey(slot: &mut Option<(Owner, [f32; 3], T)>, was: &Owner, now: &Owner) { + if let Some((owner, ..)) = slot + && owner == was + { + *owner = now.clone(); + } +} + /// The HSB a color shows on the wheel: that of its display sRGB through `cms`. pub(crate) fn display_hsb(cms: &Cms, c: &Color) -> [f32; 3] { rgb_to_hsb(cms.display_rgb(c)) @@ -1510,13 +1519,13 @@ fn show_rows(app: &mut VectorcraftApp, panel: &mut WheelUi, ui: &mut Ui, cx: &Pi let shown = color.unwrap_or(app.session.last_solid); let owner = color.map(|c| Owner::of(app, tgt, c)); opacity_row(app, panel, ui, tgt, &shown, cx.cms); - // An opacity edit of a gradient stop or point changes the gradient its owner holds, and the - // HSB picked last stays with the new gradient. - if let (Some(c), Some(was)) = (color, owner) - && let Some((remembered, ..)) = &mut panel.hsb - && *remembered == was - { - *remembered = Owner::of(app, tgt, c); + // An opacity edit adds an undo step, and on a gradient stop or point it also changes the + // gradient its owner holds. The HSB, HSL and OKLCH picked last stay with the edited paint. + if let (Some(c), Some(was)) = (color, owner) { + let now = Owner::of(app, tgt, c); + rekey(&mut panel.hsb, &was, &now); + rekey(&mut panel.hsl, &was, &now); + rekey(&mut panel.oklch, &was, &now); } } else { end_opacity_drag(app, panel); diff --git a/crates/ui-egui/src/panels/tests_color_wheel_opacity.rs b/crates/ui-egui/src/panels/tests_color_wheel_opacity.rs index 27def08cd7..ea7aec7096 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel_opacity.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel_opacity.rs @@ -165,6 +165,23 @@ fn screen_readers_read_and_set_the_opacity() { assert!((fill_opacity(&p.app()) - 0.24).abs() < 1e-6); } +/// A hue given to a gray in the HSL or OKLCH rows stays after the row's opacity edit, as the wheel's +/// HSB hue does. +#[test] +fn an_opacity_edit_keeps_the_hue_given_to_a_gray() { + for (rows, hue) in [("hsl", "HSL Hue"), ("oklch", "Hue")] { + let mut a = app(); + a.run("paint.setFill", json!({"color": "#808080"})).unwrap(); + a.run("ui.colorWheel", json!({"sliders": rows})).unwrap(); + let mut p = Panel::new(a); + p.set(hue, 240.0); + assert_eq!(p.number(hue), Some(240.0), "{rows}: the gray takes the hue"); + act(&mut p, AccessActionKind::SetValue(40.0)); + assert!((fill_opacity(&p.app()) - 0.4).abs() < 1e-6, "{rows}: the opacity is set"); + assert_eq!(p.number(hue), Some(240.0), "{rows}: the hue is kept"); + } +} + /// The stroke proxy in front: the row sets the stroke item's opacity and leaves the fill's. #[test] fn with_the_stroke_in_front_the_row_sets_the_stroke() { From d9b119a371d1a756265c084f633d2d909842409a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 00:18:32 -0800 Subject: [PATCH 12/12] Color Wheel: a channel just below sRGB counts as outside it The gamut test allowed 1e-4 beyond 0..1, so OKLCH colors such as L 0.01, C 0.01, H 0 were clipped at their own chroma and not reported as lowered, and the C track marked the wrong maximum. The allowance is now 1e-5, above the 1.7e-6 matrix round-trip error of sRGB boundary colors. --- crates/color/src/oklab.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/color/src/oklab.rs b/crates/color/src/oklab.rs index 7deb757f58..1279de689a 100644 --- a/crates/color/src/oklab.rs +++ b/crates/color/src/oklab.rs @@ -12,7 +12,7 @@ pub const CHROMA_FULL: f64 = 0.4; pub const POWERLESS_CHROMA: f64 = 0.000_004; /// How far outside 0..=1 an sRGB component may be and still count as inside the gamut. -const GAMUT_SLACK: f64 = 1e-4; +const GAMUT_SLACK: f64 = 1e-5; /// OKLCH `[l, c, h°]` of sRGB `rgb` (gamma encoded). Values outside 0..=1 are converted as they /// are. The hue is in 0..360, and 0 while the chroma is powerless. @@ -46,7 +46,7 @@ pub fn max_chroma(l: f64, h: f64) -> f64 { /// /// The chromas sRGB holds along the ray can come in several stretches: at the lightness and hue of /// blue the ray leaves sRGB at a chroma of about 0.266 and comes back at blue itself, about 0.313, -/// and near black the gamut slack opens stretches of its own. Each linear sRGB channel is a cubic +/// and the ray can leave and return near black as well. Each linear sRGB channel is a cubic /// in the chroma, so every stretch ends where a channel's cubic meets a bound of the gamut. The /// search finds each such chroma between the cubic's turning points and takes the largest one that /// fits. @@ -245,12 +245,10 @@ mod tests { } /// The largest chroma fits and is at least the largest one a scan in steps of 0.0005 finds, at - /// every hue and at lightnesses near black too, where the ray can come back into sRGB away from - /// any primary color's hue (L 0.02 and H 242° fit up to about 0.022 after leaving near 0.012). + /// every hue and at lightnesses near black too. #[test] fn the_largest_chroma_is_never_below_a_scan_of_the_ray() { let scan = |l: f64, h: f64| (0..=1000).map(|i| f64::from(i) * 0.0005).filter(|c| in_srgb(oklch_to_srgb(l, *c, h))).fold(0.0, f64::max); - assert!(max_chroma(0.02, 242.0) > 0.02, "{}", max_chroma(0.02, 242.0)); for l in [0.005, 0.02, 0.05, 0.1, 0.3, 0.44, 0.6, 0.8, 0.95, 0.99] { for h in (0..72).map(|i| f64::from(i) * 5.0 + 2.0) { let max = max_chroma(l, h); @@ -278,4 +276,16 @@ mod tests { assert_eq!(from_oklch(1.0, 0.1, 250.0), ([1.0; 3], true)); assert_eq!(from_oklch(1.0, 0.0, 0.0), ([1.0; 3], false)); } + + /// A color whose green is 0.000024 below sRGB is outside it: it is lowered to the chroma that + /// fits, not clipped at its own chroma. + #[test] + fn a_channel_just_below_zero_is_outside_the_gamut() { + assert!(!in_srgb(oklch_to_srgb(0.01, 0.01, 0.0))); + let (rgb, lowered) = from_oklch(0.01, 0.01, 0.0); + assert!(lowered, "{rgb:?}"); + let [_, c, _] = to_oklch(rgb); + assert!(c < 0.01, "{c}"); + assert!(in_srgb(oklch_to_srgb(0.01, max_chroma(0.01, 0.0), 0.0))); + } }