mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-21 09:54:09 +01:00
Color Wheel: fix OKLCH and HSL slider review findings
- The largest chroma at a hue near a primary color finds the stretch past
the first gamut edge, so pure blue at chroma 0.4 stays blue. The C track
dims the gap between the two stretches.
- Oklab conversions use the signed sRGB transfer curve for channels below 0.
- HSL hues wrap before the channel offsets; Color::to_hsl and from_hsl are
removed, so callers pass the color settings themselves.
- color.convert {to: "oklch"} clips RGB numbers past 0 to 1, as hex does.
- A hue on a gray, or a saturation on black or white, leaves a Gray paint
unchanged and records no undo step.
- Remembered row and wheel components are dropped once the panel shows
another color or target.
- Hiding or switching the rows during a row drag keeps the preview as one
undo step and ends the interaction.
- The L and H tracks keep their colors until the other two components
change, so a frame does not search the gamut for every track color.
- Docs name the document's assigned profile as the RGB space OKLCH Sliders
need, and give color.convert's example its color.
This commit is contained in:
1 parent
9e902a313c
commit
1d7f3f6f22
10 files changed
+319
-62
No files matched your search
+10
-14
@@ -151,15 +151,6 @@ impl Color {
|
||||
let [r, g, b] = hsb_to_rgb([h, s, v]);
|
||||
Color::Rgb { r, g, b }
|
||||
}
|
||||
/// HSL with hue in degrees 0..360, saturation and lightness 0..1 ([`rgb_to_hsl`] of the
|
||||
/// display color).
|
||||
pub fn to_hsl(&self) -> [f32; 3] {
|
||||
rgb_to_hsl(self.to_rgb())
|
||||
}
|
||||
pub fn from_hsl(h: f32, s: f32, l: f32) -> Self {
|
||||
let [r, g, b] = hsl_to_rgb([h, s, l]);
|
||||
Color::Rgb { r, g, b }
|
||||
}
|
||||
/// `#rrggbb` (display RGB).
|
||||
pub fn to_hex(&self) -> String {
|
||||
let [r, g, b, _] = self.to_rgba8(1.0);
|
||||
@@ -380,10 +371,11 @@ pub fn rgb_to_hsl([r, g, b]: [f32; 3]) -> [f32; 3] {
|
||||
|
||||
/// RGB numbers 0..1 of HSL `[h, s, l]` (hue in degrees, saturation and lightness 0..1), as CSS
|
||||
/// Color 4 converts HSL to sRGB (<https://www.w3.org/TR/css-color-4/#hsl-to-rgb>): the inverse of
|
||||
/// [`rgb_to_hsl`]. A hue outside 0..360 wraps into that range, so -120° gives the color of 240°.
|
||||
/// The specification's sample code uses JavaScript's remainder operator and gives a different
|
||||
/// color for a negative hue.
|
||||
/// [`rgb_to_hsl`]. A hue outside 0..360 wraps into that range before the conversion, so -120°
|
||||
/// gives the color of 240° and a hue of 10,000,000,000° the color of 280°. The specification's
|
||||
/// sample code uses JavaScript's remainder operator and gives a different color for a negative hue.
|
||||
pub fn hsl_to_rgb([h, s, l]: [f32; 3]) -> [f32; 3] {
|
||||
let h = h.rem_euclid(360.0);
|
||||
let a = s * l.min(1.0 - l);
|
||||
let f = |n: f32| {
|
||||
let k = (n + h / 30.0).rem_euclid(12.0);
|
||||
@@ -565,11 +557,12 @@ mod tests {
|
||||
([360.0, 1.0, 0.5], "#ff0000"),
|
||||
([-120.0, 1.0, 0.5], "#0000ff"),
|
||||
] {
|
||||
assert_eq!(Color::from_hsl(hsl[0], hsl[1], hsl[2]).to_hex(), hex, "{hsl:?}");
|
||||
let [r, g, b] = hsl_to_rgb(hsl);
|
||||
assert_eq!(Color::rgb(r, g, b).to_hex(), hex, "{hsl:?}");
|
||||
}
|
||||
let [h, s, l] = rgb_to_hsl([1.0, 0.5, 0.0]);
|
||||
assert!((h - 30.0).abs() < 1e-4 && (s - 1.0).abs() < 1e-6 && (l - 0.5).abs() < 1e-6, "{h} {s} {l}");
|
||||
let [h, s, l] = Color::rgb8(255, 128, 0).to_hsl();
|
||||
let [h, s, l] = rgb_to_hsl(Color::rgb8(255, 128, 0).to_rgb_uncalibrated());
|
||||
assert!((h - 30.0).abs() < 0.2 && (s - 1.0).abs() < 1e-6 && (l - 0.5).abs() < 1e-3, "{h} {s} {l}");
|
||||
// A gray has no hue: the hue is 0 and the saturation 0, at any lightness.
|
||||
for v in [0.0, 0.25, 0.5, 1.0] {
|
||||
@@ -581,6 +574,9 @@ mod tests {
|
||||
// A color past the gamut that gives a negative saturation turns its hue by 180°.
|
||||
let [h, s, _] = rgb_to_hsl([1.2, 1.5, 1.4]);
|
||||
assert!(s > 0.0 && (h - (160.0 + 180.0)).abs() < 1e-3, "{h} {s}");
|
||||
// A huge hue wraps before the channels are worked out: 10,000,000,000° is 280°.
|
||||
let (huge, wrapped) = (hsl_to_rgb([10_000_000_000.0, 1.0, 0.5]), hsl_to_rgb([280.0, 1.0, 0.5]));
|
||||
assert!((0..3).all(|i| (huge[i] - wrapped[i]).abs() < 1e-6), "{huge:?} {wrapped:?}");
|
||||
}
|
||||
|
||||
/// The 216 web colors go to HSL and back to the same 8-bit color.
|
||||
|
||||
@@ -99,7 +99,9 @@ pub fn builtin_library(id: &str) -> Option<Arc<SwatchLibrary>> {
|
||||
|
||||
// ---------- colour construction ----------
|
||||
|
||||
/// sRGB (0..=1, gamma encoded) of OKLab `(l, a, b)`, unclamped.
|
||||
/// sRGB (0..=1, gamma encoded) of OKLab `(l, a, b)`, unclamped. A linear channel below
|
||||
/// −0.0031308 is encoded with the curve's sign turned, as CSS Color 4's extended sRGB does
|
||||
/// (<https://www.w3.org/TR/css-color-4/#color-conversion-code>).
|
||||
pub(crate) fn oklab_to_srgb(l: f64, a: f64, b: f64) -> [f64; 3] {
|
||||
let l_ = l + 0.396_337_777_4 * a + 0.215_803_757_3 * b;
|
||||
let m_ = l - 0.105_561_345_8 * a - 0.063_854_172_8 * b;
|
||||
@@ -110,7 +112,7 @@ pub(crate) fn oklab_to_srgb(l: f64, a: f64, b: f64) -> [f64; 3] {
|
||||
-1.268_438_004_6 * l3 + 2.609_757_401_1 * m3 - 0.341_319_396_5 * s3,
|
||||
-0.004_196_086_3 * l3 - 0.703_418_614_7 * m3 + 1.707_614_701_0 * s3,
|
||||
];
|
||||
lin.map(|v| if v <= 0.003_130_8 { 12.92 * v } else { 1.055 * v.powf(1.0 / 2.4) - 0.055 })
|
||||
lin.map(|v| if v.abs() <= 0.003_130_8 { 12.92 * v } else { v.signum() * (1.055 * v.abs().powf(1.0 / 2.4) - 0.055) })
|
||||
}
|
||||
|
||||
/// OKLab `[l, a, b]` of a colour's display RGB.
|
||||
@@ -118,11 +120,13 @@ pub fn to_oklab(c: &Color) -> [f64; 3] {
|
||||
srgb_to_oklab(c.to_rgb_uncalibrated())
|
||||
}
|
||||
|
||||
/// OKLab `[l, a, b]` of sRGB `rgb` (0..=1, gamma encoded).
|
||||
/// OKLab `[l, a, b]` of sRGB `rgb` (0..=1, gamma encoded). A channel below −0.04045 is decoded
|
||||
/// with the curve's sign turned, as CSS Color 4's extended sRGB does
|
||||
/// (<https://www.w3.org/TR/css-color-4/#color-conversion-code>).
|
||||
pub(crate) fn srgb_to_oklab(rgb: [f32; 3]) -> [f64; 3] {
|
||||
let [r, g, b] = rgb.map(|v| {
|
||||
let v = f64::from(v);
|
||||
if v <= 0.040_45 { v / 12.92 } else { ((v + 0.055) / 1.055).powf(2.4) }
|
||||
if v.abs() <= 0.040_45 { v / 12.92 } else { v.signum() * ((v.abs() + 0.055) / 1.055).powf(2.4) }
|
||||
});
|
||||
let l = (0.412_221_470_8 * r + 0.536_332_536_3 * g + 0.051_445_992_9 * b).cbrt();
|
||||
let m = (0.211_903_498_2 * r + 0.680_699_545_1 * g + 0.107_396_956_6 * b).cbrt();
|
||||
|
||||
@@ -38,27 +38,78 @@ pub fn in_srgb(rgb: [f64; 3]) -> bool {
|
||||
|
||||
/// 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 {
|
||||
largest_fitting_chroma(l, h, f64::INFINITY)
|
||||
}
|
||||
|
||||
/// The primary and secondary colors of sRGB: the corners of its cube next to black.
|
||||
const PRIMARIES: [[f32; 3]; 6] = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], [0.0, 1.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 0.0]];
|
||||
|
||||
/// The largest chroma no more than `limit` that sRGB holds at lightness `l` and hue `h°`: 0 at or
|
||||
/// outside black and white.
|
||||
fn largest_fitting_chroma(l: f64, h: f64, limit: f64) -> f64 {
|
||||
if !(l > 0.0 && l < 1.0) || !h.is_finite() {
|
||||
return 0.0;
|
||||
}
|
||||
// sRGB holds every chroma from 0 up to its edge along a hue at a given lightness.
|
||||
let fits = |c: f64| in_srgb(oklch_to_srgb(l, c, h));
|
||||
// The edge of the chromas from 0 that sRGB holds without a break.
|
||||
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 }
|
||||
if fits(mid) { lo = mid } else { hi = mid }
|
||||
}
|
||||
lo
|
||||
// Past that edge the ray can come back into sRGB near a line from black to a primary or
|
||||
// secondary color. Such a line is straight in Oklab, so it keeps that color's hue and its
|
||||
// chroma grows with its lightness. At the lightness and hue of blue, for example, the ray leaves
|
||||
// sRGB at a chroma of about 0.266 and meets blue itself at about 0.313; at L 0.44 and a hue
|
||||
// 0.01° past blue's, a second stretch runs from about 0.3042 to 0.3048. Each such stretch ends
|
||||
// at or just below the line's chroma, so the search walks down from there in small steps to the
|
||||
// first chroma that fits and then finds the stretch's end between it and the step above.
|
||||
let past = PRIMARIES.iter().filter_map(|rgb| {
|
||||
let [pl, a, b] = srgb_to_oklab(*rgb);
|
||||
let edge = l / pl * a.hypot(b);
|
||||
let off = (h - b.atan2(a).to_degrees()).rem_euclid(360.0);
|
||||
if l > pl || edge <= lo || off.min(360.0 - off) > NEAR_PRIMARY_HUE {
|
||||
return None;
|
||||
}
|
||||
let start = edge.min(limit);
|
||||
let mut c = start;
|
||||
while c > lo && start - c <= PAST_WALK {
|
||||
if fits(c) {
|
||||
let (mut inside, mut outside) = (c, (c + PAST_STEP).min(start));
|
||||
if outside > inside && !fits(outside) {
|
||||
for _ in 0..20 {
|
||||
let mid = (inside + outside) / 2.0;
|
||||
if fits(mid) { inside = mid } else { outside = mid }
|
||||
}
|
||||
} else {
|
||||
inside = outside;
|
||||
}
|
||||
return Some(inside);
|
||||
}
|
||||
c -= PAST_STEP;
|
||||
}
|
||||
None
|
||||
});
|
||||
past.fold(lo.min(limit), f64::max)
|
||||
}
|
||||
|
||||
/// How near a primary or secondary color's hue, in degrees, the ray must pass for
|
||||
/// [`largest_fitting_chroma`] to look past the first edge.
|
||||
const NEAR_PRIMARY_HUE: f64 = 2.0;
|
||||
/// The step of that walk.
|
||||
const PAST_STEP: f64 = 2e-4;
|
||||
/// How far below the line's chroma that walk goes.
|
||||
const PAST_WALK: f64 = 0.06;
|
||||
|
||||
/// 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.
|
||||
/// Lightness is clamped to 0..=1 and chroma to 0 or more.
|
||||
/// 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.
|
||||
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, largest_fitting_chroma(l, h, c), h), true) };
|
||||
(rgb.map(|v| v.clamp(0.0, 1.0) as f32), lowered)
|
||||
}
|
||||
|
||||
@@ -126,6 +177,45 @@ mod tests {
|
||||
assert!(!from_oklch(l, max * 0.5, h).1);
|
||||
}
|
||||
|
||||
/// At the lightness and hue of blue the ray leaves sRGB and comes back at blue itself, so the
|
||||
/// largest chroma is blue's, and a chroma past it gives blue.
|
||||
#[test]
|
||||
fn the_largest_chroma_at_blues_hue_is_blues() {
|
||||
let [l, c, h] = to_oklch([0.0, 0.0, 1.0]);
|
||||
let max = max_chroma(l, h);
|
||||
assert!((max - c).abs() < 1e-4 && in_srgb(oklch_to_srgb(l, max, h)), "{max} {c}");
|
||||
let (rgb, lowered) = from_oklch(l, CHROMA_FULL, h);
|
||||
assert_eq!((eight(rgb), lowered), ([0, 0, 255], true));
|
||||
// A chroma between the two stretches takes the end of the first one, inside sRGB.
|
||||
let (rgb, lowered) = from_oklch(l, 0.29, h);
|
||||
let [_, gc, _] = to_oklch(rgb);
|
||||
assert!(lowered && gc < 0.27 && in_srgb(oklch_to_srgb(l, gc, h)), "{gc}");
|
||||
// A hue just past blue's: a narrow second stretch ends just below the line from black to blue.
|
||||
let (l, h) = (0.44, 264.06);
|
||||
let max = max_chroma(l, h);
|
||||
assert!(max > 0.304 && max < 0.305 && in_srgb(oklch_to_srgb(l, max, h)), "{max}");
|
||||
let [_, got, _] = to_oklch(from_oklch(l, 0.35, h).0);
|
||||
assert!(got > 0.303, "{got}");
|
||||
// A darker blue on the line from black to blue.
|
||||
let [l, c, h] = to_oklch([0.0, 0.0, 0.25]);
|
||||
assert!((max_chroma(l, h) - c).abs() < 1e-4, "{} {c}", max_chroma(l, h));
|
||||
}
|
||||
|
||||
/// sRGB channels below 0 go through the transfer curve with its sign turned, as CSS Color 4's
|
||||
/// extended sRGB does, in both directions.
|
||||
#[test]
|
||||
fn negative_channels_use_the_signed_transfer_curve() {
|
||||
let linear = -((0.5_f64 + 0.055) / 1.055).powf(2.4);
|
||||
let [l, c, _] = to_oklch([-0.5; 3]);
|
||||
assert!((l - linear.cbrt()).abs() < 1e-4 && c <= POWERLESS_CHROMA, "{l} {c}");
|
||||
for v in oklch_to_srgb(linear.cbrt(), 0.0, 0.0) {
|
||||
assert!((v + 0.5).abs() < 1e-4, "{v}");
|
||||
}
|
||||
// Small values near 0 keep the straight part of the curve.
|
||||
let [l, _, _] = to_oklch([-0.01; 3]);
|
||||
assert!((l - (-0.01_f64 / 12.92).cbrt()).abs() < 1e-4, "{l}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn black_white_and_bad_numbers_hold_no_chroma() {
|
||||
assert_eq!(max_chroma(0.0, 30.0), 0.0);
|
||||
|
||||
@@ -891,7 +891,8 @@ fn convert_color(_: &mut Session, p: &Value) -> Result<Value> {
|
||||
"gray" | "grayscale" => ("gray", json!(values(&c.convert(&col, Model::Gray, intent)))),
|
||||
"lab" => ("lab", json!([lab.l, lab.a, lab.b])),
|
||||
"oklch" => {
|
||||
let [l, ch, h] = vectorcraft_color::oklab::to_oklch(c.display_rgb(&col));
|
||||
// RGB numbers past 0..1 ([2, 2, 2]) display clipped, as `hex` reports them.
|
||||
let [l, ch, h] = vectorcraft_color::oklab::to_oklch(c.display_rgb(&col).map(|v| v.clamp(0.0, 1.0)));
|
||||
("oklch", json!([l * 100.0, ch, h]))
|
||||
}
|
||||
other => return Err(bad(C, format!("unknown model `{other}`"))),
|
||||
|
||||
@@ -338,14 +338,23 @@ fn convert_to_oklch_answers_lightness_chroma_and_hue() {
|
||||
let cyan = s.execute("color.convert", &json!({"color": ink, "to": "oklch"})).unwrap();
|
||||
let shown = vectorcraft_color::oklab::to_oklch(cms::active().display_rgb(&Color::cmyk(1.0, 0.0, 0.0, 0.0)));
|
||||
let naive = vectorcraft_color::oklab::to_oklch([0.0, 1.0, 1.0]);
|
||||
let l = cyan["values"][0].as_f64().unwrap() / 100.0;
|
||||
assert!((l - shown[0]).abs() < 1e-9 && (l - naive[0]).abs() > 0.02, "{cyan} {shown:?} {naive:?}");
|
||||
let c: Vec<f64> = cyan["values"].as_array().unwrap().iter().map(|v| v.as_f64().unwrap()).collect();
|
||||
let got = [c[0] / 100.0, c[1], c[2]];
|
||||
assert!((0..3).all(|i| (got[i] - shown[i]).abs() < 1e-9) && shown[1] > 0.05, "{cyan} {shown:?}");
|
||||
assert!((got[0] - naive[0]).abs() > 0.02, "{cyan} {naive:?}");
|
||||
// A Lab color outside sRGB answers the OKLCH of its color clipped to sRGB.
|
||||
let vivid = s.execute("color.convert", &json!({"color": {"l": 50.0, "a": 100.0, "b": 0.0}, "to": "oklch"})).unwrap();
|
||||
let w: Vec<f64> = vivid["values"].as_array().unwrap().iter().map(|v| v.as_f64().unwrap()).collect();
|
||||
let clipped = vectorcraft_color::oklab::to_oklch(cms::active().display_rgb(&Color::lab(50.0, 100.0, 0.0)));
|
||||
let shown = cms::active().display_rgb(&Color::lab(50.0, 100.0, 0.0)).map(|v| v.clamp(0.0, 1.0));
|
||||
let clipped = vectorcraft_color::oklab::to_oklch(shown);
|
||||
assert!((w[0] / 100.0 - clipped[0]).abs() < 1e-9 && (w[1] - clipped[1]).abs() < 1e-9, "{vivid} {clipped:?}");
|
||||
assert!((w[2] - clipped[2]).abs() < 1e-9 && (0.0..360.0).contains(&w[2]), "{vivid} {clipped:?}");
|
||||
assert!(vectorcraft_color::oklab::in_srgb(vectorcraft_color::oklab::oklch_to_srgb(w[0] / 100.0, w[1], w[2])), "{vivid}");
|
||||
// RGB numbers past 0..1 answer the OKLCH of the clipped color `hex` reports: white.
|
||||
let past = s.execute("color.convert", &json!({"color": [2.0, 2.0, 2.0], "to": "oklch"})).unwrap();
|
||||
assert_eq!(past["hex"], "#ffffff");
|
||||
let l = past["values"][0].as_f64().unwrap();
|
||||
assert!((l - 100.0).abs() < 0.01 && past["values"][1].as_f64().unwrap() < 1e-3, "{past}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -14,8 +14,9 @@
|
||||
//!
|
||||
//! Panel menu › OKLCH Sliders shows L, C and H rows under the wheel or the box that edit the color
|
||||
//! by OKLCH lightness, chroma and hue (CSS Color 4:
|
||||
//! <https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch>), while the working RGB space is
|
||||
//! sRGB. Panel menu › HSL Sliders shows H, S and L rows in their place that edit the color by the
|
||||
//! <https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch>), while the active document's RGB
|
||||
//! space ([`cms::active`]: the profile assigned to the document, else the working RGB space of the
|
||||
//! color settings) is sRGB. Panel menu › HSL Sliders shows H, S and L rows in their place that edit the color by the
|
||||
//! hue, saturation and lightness of CSS Color 4's HSL
|
||||
//! (<https://www.w3.org/TR/css-color-4/#the-hsl-notation>). The choice is kept with the
|
||||
//! preferences too.
|
||||
@@ -139,7 +140,8 @@ pub fn deserialize_settings<'de, D: serde::Deserializer<'de>>(d: D) -> Result<Se
|
||||
/// `ui.colorWheel {view?, channel?, sliders?}`: show the wheel or the box, pick the box's channel,
|
||||
/// and show OKLCH Sliders, HSL Sliders or neither. 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.
|
||||
/// `sliders: "oklch"` is an error while the working RGB space is not sRGB. → the settings.
|
||||
/// `sliders: "oklch"` is an error while the active document's RGB space (its assigned profile,
|
||||
/// else the working RGB space) is not sRGB. → the settings.
|
||||
pub(crate) fn command(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
|
||||
set(&mut app.ui.color_wheel, p, &cms::active())?;
|
||||
Ok(json!(app.ui.color_wheel))
|
||||
@@ -292,7 +294,9 @@ const MEMORY: &str = "color-wheel-hsb";
|
||||
/// Panel state: the OKLCH the slider rows asked for last, the [`Owner`] of the color they stored
|
||||
/// and its display sRGB.
|
||||
const OKLCH_MEMORY: &str = "color-wheel-oklch";
|
||||
/// The message for OKLCH Sliders while the working RGB space is not sRGB.
|
||||
/// Panel state: the slider rows whose drag previews on an open interaction, until it is released.
|
||||
const ROWS_LIVE: &str = "color-wheel-rows-live";
|
||||
/// The message for OKLCH Sliders while the active document's RGB space is not sRGB.
|
||||
const OKLCH_NEEDS_SRGB: &str = "OKLCH needs sRGB as the working RGB space";
|
||||
/// Panel state: the HSL the slider rows asked for last, the [`Owner`] of the color they stored and
|
||||
/// its display sRGB.
|
||||
@@ -338,6 +342,28 @@ impl Owner {
|
||||
}
|
||||
}
|
||||
|
||||
/// The components remembered under `key` for the target's `color`: the display sRGB the color had
|
||||
/// when they were stored, and the components. A record whose owner or display color differs from
|
||||
/// what the panel shows now is dropped, so that it does not come back when the same color returns
|
||||
/// later.
|
||||
fn recall<T: Clone + Send + Sync + 'static>(
|
||||
app: &VectorcraftApp,
|
||||
ui: &Ui,
|
||||
key: &str,
|
||||
tgt: &Target,
|
||||
color: Option<Color>,
|
||||
cms: &Cms,
|
||||
) -> Option<([f32; 3], T)> {
|
||||
let (owner, shown, v) = pstate::<Option<(Owner, [f32; 3], T)>>(ui.ctx(), key)?;
|
||||
match color {
|
||||
Some(c) if owner == Owner::of(app, tgt, c) && cms.display_rgb(&c) == shown => Some((shown, v)),
|
||||
_ => {
|
||||
set_pstate(ui.ctx(), key, None::<(Owner, [f32; 3], T)>);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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))
|
||||
@@ -403,13 +429,15 @@ 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.
|
||||
/// there stores. With `max_chroma` (the C track, whose L and H stay fixed) that chroma is given
|
||||
/// for the colors past it; without it, or in a gap below it where the ray leaves sRGB and comes
|
||||
/// back, it is found for each color.
|
||||
pub(crate) fn oklch_track(lch: [f64; 3], max_chroma: Option<f64>) -> Color32 {
|
||||
let exact = oklab::oklch_to_srgb(lch[0], lch[1], lch[2]);
|
||||
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 => {
|
||||
Some(_) if oklab::in_srgb(exact) => (exact, false),
|
||||
_ => {
|
||||
let (rgb, lowered) = oklab::from_oklch(lch[0], lch[1], lch[2]);
|
||||
(rgb.map(f64::from), lowered)
|
||||
}
|
||||
@@ -434,8 +462,8 @@ pub(crate) fn chroma_tick(max_chroma: f64) -> f32 {
|
||||
pub(crate) fn oklch_rows(app: &VectorcraftApp, ui: &mut Ui, tgt: &Target, color: Option<Color>, cms: &Cms) -> Option<([f64; 3], Live)> {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let enabled = color.is_some() && cms.rgb_is_srgb();
|
||||
let lch = match (color, pstate::<Option<(Owner, [f32; 3], [f64; 3])>>(ui.ctx(), OKLCH_MEMORY)) {
|
||||
(Some(c), Some((owner, shown, lch))) if owner == Owner::of(app, tgt, c) => remembered_oklch(cms, &c, shown, lch),
|
||||
let lch = match (color, recall::<[f64; 3]>(app, ui, OKLCH_MEMORY, tgt, color, cms)) {
|
||||
(Some(c), Some((shown, lch))) => remembered_oklch(cms, &c, shown, lch),
|
||||
(Some(c), _) => oklab::to_oklch(cms.display_rgb(&c)),
|
||||
(None, _) => [0.0; 3],
|
||||
};
|
||||
@@ -453,6 +481,9 @@ pub(crate) fn oklch_rows(app: &VectorcraftApp, ui: &mut Ui, tgt: &Target, color:
|
||||
out
|
||||
};
|
||||
let mut out = None;
|
||||
// The L and H tracks search the gamut for each color outside sRGB, so their colors are kept
|
||||
// until the other two components change.
|
||||
let mut tracks = pstate::<[Option<([u64; 3], Vec<Color32>)>; 3]>(ui.ctx(), OKLCH_TRACKS);
|
||||
ui.add_enabled_ui(enabled, |ui| {
|
||||
let field_w = 48.0;
|
||||
let slider_w = (ui.available_width() - field_w - 12.0 - 3.0 * ui.spacing().item_spacing.x).max(60.0);
|
||||
@@ -463,7 +494,23 @@ pub(crate) fn oklch_rows(app: &VectorcraftApp, ui: &mut Ui, tgt: &Target, color:
|
||||
ui.add_sized(vec2(12.0, 22.0), egui::Label::new(egui::RichText::new(letter).size(12.5).color(t.text)));
|
||||
let v = shown[i].clamp(0.0, max);
|
||||
let at = |x: f32| with(i, f64::from(x) * max);
|
||||
let track = |x: f32| if enabled { oklch_track(at(x), (i == 1).then_some(max_c)) } else { t.input };
|
||||
let mut key = lch.map(f64::to_bits);
|
||||
key[i] = 0;
|
||||
let colors = match &tracks[i] {
|
||||
Some((k, colors)) if i != 1 && enabled && *k == key => colors.clone(),
|
||||
_ if i != 1 && enabled => {
|
||||
let last = (TRACK_SAMPLES - 1) as f32;
|
||||
let colors: Vec<Color32> = (0..TRACK_SAMPLES).map(|s| oklch_track(at(s as f32 / last), None)).collect();
|
||||
tracks[i] = Some((key, colors.clone()));
|
||||
colors
|
||||
}
|
||||
_ => Vec::new(),
|
||||
};
|
||||
let track = |x: f32| match colors.get((x.clamp(0.0, 1.0) * (TRACK_SAMPLES - 1) as f32).round() as usize) {
|
||||
Some(c) => *c,
|
||||
None if enabled => oklch_track(at(x), (i == 1).then_some(max_c)),
|
||||
None => t.input,
|
||||
};
|
||||
let value = SliderValue::field(v, 0.0..=max, suffix, 0);
|
||||
let (dragged, phase, keyed) =
|
||||
widgets::color_slider_stepped(ui, ("color-wheel-oklch", i), name, Some(value), (v / max) as f32, slider_w, &track);
|
||||
@@ -489,9 +536,16 @@ pub(crate) fn oklch_rows(app: &VectorcraftApp, ui: &mut Ui, tgt: &Target, color:
|
||||
});
|
||||
}
|
||||
});
|
||||
set_pstate(ui.ctx(), OKLCH_TRACKS, tracks);
|
||||
out.filter(|_| enabled)
|
||||
}
|
||||
|
||||
/// Panel state: the colors of the L and H tracks of OKLCH Sliders, each with the OKLCH (its own
|
||||
/// component left out) they were drawn for.
|
||||
const OKLCH_TRACKS: &str = "color-wheel-oklch-tracks";
|
||||
/// How many colors along a cached track.
|
||||
const TRACK_SAMPLES: usize = 128;
|
||||
|
||||
/// The HSL `[h°, s, l]` the rows show for `c` through `cms` when `hsl` was asked for last and `c`
|
||||
/// then displayed as the sRGB `shown`: `hsl` while `c` still displays as `shown` (the hue of a gray
|
||||
/// and the saturation of black and white stay), else `c`'s own.
|
||||
@@ -512,8 +566,8 @@ fn hsl32(hsl: [f32; 3]) -> Color32 {
|
||||
pub(crate) fn hsl_rows(app: &VectorcraftApp, ui: &mut Ui, tgt: &Target, color: Option<Color>, cms: &Cms) -> Option<([f32; 3], Live)> {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let enabled = color.is_some();
|
||||
let hsl = match (color, pstate::<Option<(Owner, [f32; 3], [f32; 3])>>(ui.ctx(), HSL_MEMORY)) {
|
||||
(Some(c), Some((owner, shown, hsl))) if owner == Owner::of(app, tgt, c) => remembered_hsl(cms, &c, shown, hsl),
|
||||
let hsl = match (color, recall::<[f32; 3]>(app, ui, HSL_MEMORY, tgt, color, cms)) {
|
||||
(Some(c), Some((shown, hsl))) => remembered_hsl(cms, &c, shown, hsl),
|
||||
(Some(c), _) => rgb_to_hsl(cms.display_rgb(&c)),
|
||||
(None, _) => [0.0; 3],
|
||||
};
|
||||
@@ -567,8 +621,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let cms = cms::active();
|
||||
// With None, a pattern or a "?" proxy the wheel shows the last solid color without markers,
|
||||
// and a click, an arrow key or a screen reader's action applies the picked color.
|
||||
let hsb = match (color, pstate::<Option<(Owner, [f32; 3], [f32; 3])>>(ui.ctx(), MEMORY)) {
|
||||
(Some(c), Some((owner, shown, hsb))) if owner == Owner::of(app, &tgt, c) => remembered_hsb(&cms, &c, shown, hsb),
|
||||
let hsb = match (color, recall::<[f32; 3]>(app, ui, MEMORY, &tgt, color, &cms)) {
|
||||
(Some(c), Some((shown, hsb))) => remembered_hsb(&cms, &c, shown, hsb),
|
||||
(c, _) => display_hsb(&cms, &c.unwrap_or(app.session.last_solid)),
|
||||
};
|
||||
let marked = color.is_some();
|
||||
@@ -618,22 +672,41 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
picked_hsl = hsl_rows(app, ui, &tgt, color, &cms);
|
||||
}
|
||||
}
|
||||
// A row drag whose rows were hidden or replaced (`ui.colorWheel {sliders}`) reports no release:
|
||||
// its preview is kept as one undo step and the interaction ends.
|
||||
let live = pstate::<Option<Sliders>>(ui.ctx(), ROWS_LIVE);
|
||||
if live.is_some_and(|rows| rows != app.ui.color_wheel.sliders) {
|
||||
if app.session.in_interaction()
|
||||
&& let Err(e) = app.session.commit_interaction()
|
||||
{
|
||||
app.status(e.to_string());
|
||||
}
|
||||
app.sync_views();
|
||||
set_pstate(ui.ctx(), ROWS_LIVE, None::<Sliders>);
|
||||
}
|
||||
let behind = super::alt_held(ui);
|
||||
let cmyk_doc = app.session.active().is_some_and(|d| d.doc.color_mode == ColorMode::Cmyk);
|
||||
if let Some((hsl, phase)) = picked_hsl {
|
||||
let c = stored_srgb(&cms, hsl_to_rgb(hsl), replaced(app, &tgt, behind).as_ref(), cmyk_doc);
|
||||
apply(app, &tgt, c, phase, behind);
|
||||
if !behind {
|
||||
set_pstate(ui.ctx(), HSL_MEMORY, Some((Owner::of(app, &tgt, c), cms.display_rgb(&c), hsl)));
|
||||
let rows = match (picked_hsl, picked_lch) {
|
||||
(Some((hsl, phase)), _) => Some((hsl_to_rgb(hsl), phase, HSL_MEMORY, Remembered::Hsl(hsl))),
|
||||
(_, Some((lch, phase))) => Some((oklab::from_oklch(lch[0], lch[1], lch[2]).0, phase, OKLCH_MEMORY, Remembered::Oklch(lch))),
|
||||
_ => None,
|
||||
};
|
||||
if let Some((srgb, phase, key, asked)) = rows {
|
||||
// A hue on a gray, or a saturation on black or white, leaves the displayed color as it is:
|
||||
// the rows keep what they were given, and the paint (a Gray color too) stays unchanged.
|
||||
let current = color.filter(|c| {
|
||||
let d = cms.display_rgb(c);
|
||||
!behind && live.is_none() && (0..3).all(|i| (d[i] - srgb[i]).abs() <= 1e-5)
|
||||
});
|
||||
if let Some(c) = current {
|
||||
asked.remember(ui, key, Owner::of(app, &tgt, c), cms.display_rgb(&c));
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let Some((lch, phase)) = picked_lch {
|
||||
let (srgb, _) = oklab::from_oklch(lch[0], lch[1], lch[2]);
|
||||
let c = stored_srgb(&cms, srgb, replaced(app, &tgt, behind).as_ref(), cmyk_doc);
|
||||
apply(app, &tgt, c, phase, behind);
|
||||
set_pstate(ui.ctx(), ROWS_LIVE, (phase == Live::Dragging).then_some(app.ui.color_wheel.sliders));
|
||||
if !behind {
|
||||
set_pstate(ui.ctx(), OKLCH_MEMORY, Some((Owner::of(app, &tgt, c), cms.display_rgb(&c), lch)));
|
||||
asked.remember(ui, key, Owner::of(app, &tgt, c), cms.display_rgb(&c));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -644,3 +717,18 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
set_pstate(ui.ctx(), MEMORY, Some((Owner::of(app, &tgt, c), cms.display_rgb(&c), hsb)));
|
||||
}
|
||||
}
|
||||
|
||||
/// What a slider row asked for, kept under its memory key.
|
||||
enum Remembered {
|
||||
Hsl([f32; 3]),
|
||||
Oklch([f64; 3]),
|
||||
}
|
||||
|
||||
impl Remembered {
|
||||
fn remember(self, ui: &Ui, key: &str, owner: Owner, shown: [f32; 3]) {
|
||||
match self {
|
||||
Remembered::Hsl(v) => set_pstate(ui.ctx(), key, Some((owner, shown, v))),
|
||||
Remembered::Oklch(v) => set_pstate(ui.ctx(), key, Some((owner, shown, v))),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -691,6 +691,15 @@ fn the_oklch_tracks_dim_the_colors_outside_srgb_and_the_tick_marks_the_largest_c
|
||||
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([0.98, 0.2, h], None), egui::Color32::from_rgb(r, g, b).gamma_multiply(0.3));
|
||||
// At blue's L and H the ray leaves sRGB below the largest chroma and comes back at blue: the C
|
||||
// track dims that gap and shows the color a pick there stores.
|
||||
let [bl, _, bh] = vectorcraft_color::oklab::to_oklch([0.0, 0.0, 1.0]);
|
||||
let blue_max = vectorcraft_color::oklab::max_chroma(bl, bh);
|
||||
let (stored, lowered) = vectorcraft_color::oklab::from_oklch(bl, 0.29, bh);
|
||||
let [r, g, b] = stored.map(|v| (f64::from(v).clamp(0.0, 1.0) * 255.0).round() as u8);
|
||||
assert!(lowered && blue_max > 0.3);
|
||||
assert_eq!(oklch_track([bl, 0.29, bh], Some(blue_max)), egui::Color32::from_rgb(r, g, b).gamma_multiply(0.3));
|
||||
assert_eq!(oklch_track([bl, blue_max, bh], Some(blue_max)).a(), 255, "blue itself is inside sRGB");
|
||||
assert!((chroma_tick(max) - (max / 0.4) as f32).abs() < 1e-6 && chroma_tick(max) > 0.1 && chroma_tick(max) < 1.0);
|
||||
assert_eq!((chroma_tick(0.0), chroma_tick(0.5)), (0.0, 1.0));
|
||||
}
|
||||
@@ -792,16 +801,17 @@ fn oklch_sliders_need_srgb_as_the_working_space() {
|
||||
move |ui, app: &mut VectorcraftApp| {
|
||||
let tgt = super::color::wheel_target(app, ui);
|
||||
let color = tgt.color();
|
||||
let _ = oklch_rows(app, ui, &tgt, color, &p3);
|
||||
let picked = oklch_rows(app, ui, &tgt, color, &p3);
|
||||
assert!(picked.is_none(), "a gray row picks nothing: {picked:?}");
|
||||
},
|
||||
app(json!("#ff0000")),
|
||||
);
|
||||
h.run_steps(2);
|
||||
assert!(oklch_slider(&h, "Lightness").accesskit_node().is_disabled());
|
||||
let undo = undo_len(h.state());
|
||||
let rail = oklch_slider(&h, "Lightness").rect();
|
||||
click(&mut h, on_rail(rail, 0.2), Modifiers::NONE);
|
||||
assert_eq!(undo_len(h.state()), undo, "a gray row picks nothing");
|
||||
key(&mut h, egui::Key::ArrowRight, Modifiers::NONE);
|
||||
set_slider_value(&mut h, "Lightness", 20.0);
|
||||
}
|
||||
|
||||
/// The rows show what they asked for while the color displays as it did, and the color's own
|
||||
@@ -1024,3 +1034,60 @@ fn ui_color_wheel_sets_and_reads_the_sliders() {
|
||||
assert_eq!(e, "`sliders` must be none, oklch or hsl");
|
||||
assert_eq!(app.ui.color_wheel.view, crate::panels::color_wheel::View::Box, "an error changes nothing");
|
||||
}
|
||||
|
||||
/// A hue given to a Gray color does not change how it displays, so its paint stays a Gray color
|
||||
/// and no undo step is recorded; the hue row keeps the hue.
|
||||
#[test]
|
||||
fn a_hue_on_a_gray_color_leaves_its_paint_gray() {
|
||||
for (rows, hue) in [("hsl", "HSL Hue"), ("oklch", "Hue")] {
|
||||
let mut app = app(json!({"gray": 0.5}));
|
||||
app.run("ui.colorWheel", json!({"sliders": rows})).unwrap();
|
||||
let mut h = oklch_harness_shown(app);
|
||||
let (gray, undo) = (fill(h.state()), undo_len(h.state()));
|
||||
assert!(matches!(gray, Color::Gray { .. }), "{gray:?}");
|
||||
set_slider_value(&mut h, hue, 200.0);
|
||||
assert_eq!(oklch_slider(&h, hue).accesskit_node().numeric_value(), Some(200.0), "{rows}");
|
||||
assert_eq!((fill(h.state()), undo_len(h.state())), (gray, undo), "{rows}: the Gray fill stays as it was");
|
||||
}
|
||||
}
|
||||
|
||||
/// The hue given to a gray is dropped once the panel shows another color, so the same gray applied
|
||||
/// again later shows its own hue, 0°.
|
||||
#[test]
|
||||
fn a_remembered_hue_is_dropped_after_the_paint_changes() {
|
||||
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("paint.setFill", json!({"color": "#ff0000"})).unwrap();
|
||||
h.run_steps(2);
|
||||
h.state_mut().run("paint.setFill", json!({"color": "#808080"})).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]
|
||||
fn hiding_the_rows_during_a_drag_keeps_its_color_as_one_undo_step() {
|
||||
for rows in ["none", "oklch"] {
|
||||
let mut h = hsl_harness(app(json!("#ff8000")));
|
||||
let rail = oklch_slider(&h, "HSL Lightness").rect();
|
||||
let undo = undo_len(h.state());
|
||||
press(&mut h, on_rail(rail, 0.5), true, Modifiers::NONE);
|
||||
for _ in 0..2 {
|
||||
h.event(Event::PointerMoved(on_rail(rail, 0.25)));
|
||||
h.run_steps(1);
|
||||
}
|
||||
assert!(h.state().session.in_interaction(), "{rows}: the drag previews");
|
||||
let previewed = fill(h.state());
|
||||
h.state_mut().run("ui.colorWheel", json!({"sliders": rows})).unwrap();
|
||||
h.run_steps(2);
|
||||
press(&mut h, on_rail(rail, 0.25), false, Modifiers::NONE);
|
||||
assert!(!h.state().session.in_interaction(), "{rows}: the interaction ended");
|
||||
assert_eq!((fill(h.state()), undo_len(h.state())), (previewed, undo + 1), "{rows}");
|
||||
}
|
||||
}
|
||||
@@ -270,8 +270,8 @@ pick runs the commands the Color panel's sliders run: `paint.setFill` or `paint.
|
||||
`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?, sliders?}` shows the wheel or
|
||||
the box (a color field with a channel strip at its right), picks the box's channel, and shows OKLCH Sliders, HSL
|
||||
Sliders or neither (`sliders: "oklch"`, `"hsl"` or `"none"`; `"oklch"` is an error while the working RGB space is not
|
||||
sRGB); it returns the settings, and `ui.inspect` reports them as `ui.color_wheel`.
|
||||
Sliders or neither (`sliders: "oklch"`, `"hsl"` or `"none"`; `"oklch"` is an error while the active document's RGB
|
||||
space, its assigned profile or else the working RGB space, is not sRGB); 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`,
|
||||
|
||||
+5
-3
@@ -677,11 +677,13 @@ the list return an error and change nothing. The command returns `{view, channel
|
||||
kept with the preferences.
|
||||
|
||||
`ui.colorWheel {"sliders": "oklch"}` shows the Color Wheel panel's OKLCH Sliders (L, C and H rows under the wheel or
|
||||
the box), and `"none"` hides them; `"oklch"` is an error while the working RGB space is not sRGB.
|
||||
the box), and `"none"` hides them in any RGB space. `"oklch"` is an error while the active document's RGB space is
|
||||
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 {"to": "oklch"}` answers the color's OKLCH as `[L %, C, H°]` of its display sRGB. A color outside sRGB
|
||||
(a Lab or CMYK color, or an RGB color in a wider working RGB space) is clipped to sRGB first.
|
||||
`color.convert {"color": "#ff0000", "to": "oklch"}` answers the color's OKLCH as `[L %, C, H°]` of its display sRGB.
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
@@ -1819,7 +1819,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **Missing library files:** a persistent swatch or graphic style library panel whose file is gone at startup reopens and stays in the preferences, showing the file's path with Locate Library… (`ui.libraryPanel.locate`), which reads the file from where it is now into the same panel.
|
||||
- **Swatch library and Recolor Artwork parameters:** the `swatch.library.*` commands, `swatch.resetDefaults`, the graphic style library save, load and add, the `recolor.*` commands and `color.harmony`'s `limitTo` refuse parameters of the wrong form, such as `names: "Grays"`, `limitTo: 5` or `includeImages: "false"`. Errors name the parameter, except that a `limitTo` that is not a string, such as `5`, gets an unknown-library error. A `null` counts as left out except for `recolor.apply`'s `model`, which must be a string when given.
|
||||
- **Color Wheel panel (part of #978):** Window › Color Wheel shows the Fill and Stroke proxy beside a hue ring around a square with saturation across and brightness up. It edits what the Color panel's sliders edit (the active proxy's color, the selected gradient stop or freeform point) through the same paint commands, and a drag is one undo step. Alt paints the other proxy, and Shift steps the ring by 45°. A pick goes from display sRGB into the working RGB space; an RGB, CMYK or Lab color keeps its model, and a Gray color or a tint of a global swatch becomes a process color in the document's color mode. A click gives the ring or the square the keyboard focus, and the arrow keys then step the color; both report their names and values to screen readers, and the Color Picker's color field takes the same keys. The panel menu's Box View puts a box in the wheel's place: a color field with a channel strip at its right for Hue, Saturation, Brightness, Red, Green or Blue (Box Channel), on the Color Picker's axes, kept with the preferences (`ui.colorWheel`); the strip and the Color Picker's channel slider take the arrow keys after a click. Scores and estimates are unchanged.
|
||||
- **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. The item is gray, and `ui.colorWheel` answers an error, while the working RGB space is not sRGB. `color.convert {to: "oklch"}` answers the same L, C and H. 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, 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. 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.
|
||||
- **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}`).
|
||||
Plain Comma and Period, and also Shift+Comma and Shift+Period, apply the last solid color and the last gradient to the active Fill or Stroke proxy in VectorCraft ([Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html), "Select color fill mode" and "Select gradient fill mode").
|
||||
|
||||
Reference in new issue
Block a user