mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Merge pull request #7632 from dotCooCoo/feat/color-wheel-oklch-sliders-v2
Color Wheel: OKLCH Sliders give exact black and white, describe the document's RGB space and drop a remembered pick after an undo step
This commit is contained in:
7 files changed
+136
-19
No files matched your search
@@ -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.
|
||||
@@ -112,11 +112,16 @@ fn turning_points(a: f64, b: f64, c: f64) -> Vec<f64> {
|
||||
|
||||
/// 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)
|
||||
@@ -239,12 +244,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);
|
||||
@@ -262,4 +265,26 @@ 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));
|
||||
}
|
||||
|
||||
/// 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)));
|
||||
}
|
||||
}
|
||||
@@ -1597,7 +1597,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, opacity?: bool, contrast?: bool, contrastFor?: normalText|largeText|graphics, contrastBackground?: a color, or null, 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, and set Show Contrast, Contrast For, Contrast Background, Show Color Vision Preview and Show Document Colors: 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; 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; opacity checks (true) or unchecks (false) Show Opacity, as the panel menu does: a row under the wheel or the box with a slider and a percent field that set the opacity of what the panel edits (the fill item, as paint.setFill {opacity} sets it, the stroke item, as paint.setStroke {opacity} sets it, the selected gradient stop, or the selected freeform point, the first stop or point when none is selected; gray with nothing selected, for an object selected in a symbol instance, and when the fill or stroke item it would set is on type characters or missing); contrast shows a row under the wheel or the box with the background's chip, the WCAG 2 contrast ratio cut off at two decimals and the AA and AAA results for contrastFor (AA only for graphics), as color.contrast answers them, and contrastBackground pins the background the row measures against (Contrast Background › Current Color; null: the color drawn behind the selection, Behind Selection); 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, opacity, contrast, contrastFor, contrastBackground, 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, opacity?: bool, contrast?: bool, contrastFor?: normalText|largeText|graphics, contrastBackground?: a color, or null, 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, and set Show Contrast, Contrast For, Contrast Background, Show Color Vision Preview and Show Document Colors: 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; opacity checks (true) or unchecks (false) Show Opacity, as the panel menu does: a row under the wheel or the box with a slider and a percent field that set the opacity of what the panel edits (the fill item, as paint.setFill {opacity} sets it, the stroke item, as paint.setStroke {opacity} sets it, the selected gradient stop, or the selected freeform point, the first stop or point when none is selected; gray with nothing selected, for an object selected in a symbol instance, and when the fill or stroke item it would set is on type characters or missing); contrast shows a row under the wheel or the box with the background's chip, the WCAG 2 contrast ratio cut off at two decimals and the AA and AAA results for contrastFor (AA only for graphics), as color.contrast answers them, and contrastBackground pins the background the row measures against (Contrast Background › Current Color; null: the color drawn behind the selection, Behind Selection); 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, opacity, contrast, contrastFor, contrastBackground, vision, documentColors
Line truncated
|
||||
),
|
||||
(
|
||||
"ui.savePdfDialog",
|
||||
|
||||
@@ -1598,7 +1598,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, opacity?: bool, contrast?: bool, contrastFor?: normalText|largeText|graphics, contrastBackground?: a color, or null, 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, and set Show Contrast, Contrast For, Contrast Background, Show Color Vision Preview and Show Document Colors: 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; 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; opacity checks (true) or unchecks (false) Show Opacity, as the panel menu does: a row under the wheel or the box with a slider and a percent field that set the opacity of what the panel edits (the fill item, as paint.setFill {opacity} sets it, the stroke item, as paint.setStroke {opacity} sets it, the selected gradient stop, or the selected freeform point, the first stop or point when none is selected; gray with nothing selected, for an object selected in a symbol instance, and when the fill or stroke item it would set is on type characters or missing); contrast shows a row under the wheel or the box with the background's chip, the WCAG 2 contrast ratio cut off at two decimals and the AA and AAA results for contrastFor (AA only for graphics), as color.contrast answers them, and contrastBackground pins the background the row measures against (Contrast Background › Current Color; null: the color drawn behind the selection, Behind Selection); 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, opacity, contrast, contrastFor, contrastBackground, 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, opacity?: bool, contrast?: bool, contrastFor?: normalText|largeText|graphics, contrastBackground?: a color, or null, 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, and set Show Contrast, Contrast For, Contrast Background, Show Color Vision Preview and Show Document Colors: 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; opacity checks (true) or unchecks (false) Show Opacity, as the panel menu does: a row under the wheel or the box with a slider and a percent field that set the opacity of what the panel edits (the fill item, as paint.setFill {opacity} sets it, the stroke item, as paint.setStroke {opacity} sets it, the selected gradient stop, or the selected freeform point, the first stop or point when none is selected; gray with nothing selected, for an object selected in a symbol instance, and when the fill or stroke item it would set is on type characters or missing); contrast shows a row under the wheel or the box with the background's chip, the WCAG 2 contrast ratio cut off at two decimals and the AA and AAA results for contrastFor (AA only for graphics), as color.contrast answers them, and contrastBackground pins the background the row measures against (Contrast Background › Current Color; null: the color drawn behind the selection, Behind Selection); 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, opacity, contrast, contrastFor, contrastBackground, vision, documentColors
Line truncated
|
||||
),
|
||||
(
|
||||
"ui.savePdfDialog",
|
||||
|
||||
@@ -985,11 +985,15 @@ fn contrast_row(app: &mut VectorcraftApp, panel: &mut WheelUi, ui: &mut Ui, cms:
|
||||
}
|
||||
|
||||
/// 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<u64>,
|
||||
/// 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<NodeId>,
|
||||
/// The Type tool's selected characters, when it edits the paint.
|
||||
text_selection: Option<(NodeId, usize, usize)>,
|
||||
@@ -1013,6 +1017,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(),
|
||||
@@ -1045,6 +1050,15 @@ fn recall<T: Clone>(
|
||||
kept
|
||||
}
|
||||
|
||||
/// Move the record in `slot` from owner `was` to owner `now`, when `was` holds it.
|
||||
fn rekey<T>(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))
|
||||
@@ -1505,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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -2074,7 +2074,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **Colorized images overprint:** Overprint Fill (`object.setOverprint {fill: true}`) on a colorized grayscale or 1-bit image makes its color print over the inks below instead of knocking them out. Raster art has an overprint setting in the [scripting reference](https://ai-scripting.docsforadobe.dev/jsobjref/RasterItem/). `attributes.info` reports it, native files keep it, and Overprint Preview, Separations Preview and printed separations show it; they show an image knocking out when it has a visible effect of its own other than a warp or a geometry effect (a drop shadow, a glow, a raster effect or a color adjustment), or a fill or stroke with an opacity above 0 that draws a shape with Convert to Shape or Outline Object and does not overprint. Printed separations also show an image knocking out when its pixels do not take its color (a preview of its file), and separate those pixels as they are. PDF and EPS export leave raster effects out and still overprint such an image. PDF export draws the image with an overprinting graphics state and writes a gray or process color as an image of only the process inks it puts down (ISO 32000-1 §8.6.7). EPS export turns overprinting on for it and writes a gray or process color in only the process inks it puts down (one DeviceN image at Level 3, one Separation image per ink at Level 2). A legacy `.ai` file writes it with the image mask's fill overprint, and reading one takes the fill overprint in force at the image mask. White follows the rule for white fills: with Discard White Overprint on, PDF export, EPS export, the previews and printed separations show a white color knocking out, but a tint above 0% of a spot swatch whose color is white keeps overprinting, as it does for fills and strokes in PDF export, the previews and printed separations ([White overprint](https://helpx.adobe.com/illustrator/desktop/manage-colors/apply-transparency-and-blending/white-overprint.html)). Taking the color off with a fill of None also turns its overprint off. Edit › Edit Colors › Overprint Black and Print Ink Fixes' Remove White Overprint reach a colorized image's color as its fill. Evidence: engine `tests::colorize::overprint_fill_makes_a_colorized_images_color_overprint`, `tests::colorize::overprint_black_and_print_fixes_reach_a_colorized_images_color`, `tests::colorize::flattening_without_preserve_overprints_drops_a_colorized_images_overprint`, `tests::colorize::flattening_without_preserve_overprints_clears_an_uncolored_images_overprint`, doc `overprint::tests::a_white_colorized_image_knocks_out_under_discard_white`, `overprint::tests::a_white_spot_ink_keeps_overprinting_under_discard_white`, `overprint::tests::a_colorized_image_darkens_unless_its_rows_draw_an_effect`, `overprint::tests::a_colorized_image_darkens_past_a_row_with_no_opacity`, `overprint::tests::a_colorized_image_with_a_node_effect_keeps_knocking_out`, `overprint::tests::overprint_black_takes_a_black_colorized_image`, `overprint::tests::clearing_overprints_clears_the_flag_of_an_image_without_a_color`, render `tests::colorize::an_overprinting_colorized_image_keeps_the_ink_below_in_the_previews`, pdf `tests::colorize::an_overprinting_colorized_image_sets_overprint`, `tests::colorize::separations_hide_an_overprinting_image_on_plates_without_its_ink`, `tests::colorize::separations_show_an_overprinting_image_whose_pixels_refuse_its_color`, `tests::colorize::a_white_spot_ink_image_overprints_with_discard_white_overprint`, eps `tests::an_overprinting_colorized_image_writes_only_its_process_inks`, `tests::a_white_spot_ink_colorized_image_overprints_with_discard_white_overprint`, `tests::a_plate_leaves_out_an_overprinting_image_without_its_ink`, `tests::an_overprinting_colorized_image_at_the_page_limit_keeps_all_its_inks_or_none`, `legacy_ai::tests::a_colorized_image_mask_takes_the_fill_overprint_in_force`, doc `live::tests::mesh_warp_image_pieces_keep_an_overprinting_color`, effects `tests::an_image_under_a_geometry_effect_keeps_its_color_and_smoothing`.
|
||||
- **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. 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 document colors (part of #978):** the Color Wheel panel menu's Show Document Colors adds a row under the wheel or the box with the colors of the selection, headed Selection Colors, or with nothing selected of the art Select All takes, headed Document Colors, most used first and as many as fit in one row (`color.used`, `ui.colorWheel {documentColors}`). A color's tooltip gives its hex value and how many times the art uses it, and a click applies it as a pick does, keeping its color model; the active proxy and a selected gradient stop also keep its link to a global swatch. Tests: `crates/engine/src/tests/recolor.rs`, `crates/ui-egui/src/panels/tests_color_wheel_document_colors.rs`.
|
||||
- **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. Show Out-of-Gamut Colors grays out the parts of the square and the box's field whose colors the CMYK space cannot print, by the out-of-gamut warning's test on a 16 by 16 grid (`ui.colorWheel {gamut}`). 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.
|
||||
|
||||
Reference in new issue
Block a user