Merge feat/color-wheel-oklch-sliders-v2 into feat/color-wheel-copy-color-as

Brings in #7632's exact black and white at the OKLCH lightness endpoints, the color.convert docs on the chroma that fit, and the panel menu items that run ui.colorWheel. Show Opacity and Show Hex Field run ui.colorWheel the same way.
This commit is contained in:
dotCooCoo committed 2026-11-20 15:50:59 -08:00
commit b3bcdcbb07
11 files changed
+125 -34

No files matched your search

+16 -1
View File
@@ -113,11 +113,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)
@@ -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));
}
}
+1 -1
View File
@@ -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, opacity?: bool, hexField?: 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; 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); 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); hexField checks (true) or unchecks (false) Show Hex Field, as the panel menu does: a field under the wheel or the box that shows the color's hex digits (two more when the opacity rounds to less than ff) and takes a hex color of 3, 4, 6 or 8 digits or a CSS rgb(), hsl() or oklch() color, read as color.parse reads it, whose alpha sets the opacity Show Opacity edits when there is one to set; keys left out or null keep their values ({} reads them), params that are not an object, another key or a value off the list (opacity, hexField, harmony, vision, documentColors: not true or false) 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, opacity, hexField, 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, opacity?: bool, hexField?: 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); 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); hexField checks (true) or unchecks (false) Show Hex Field, as the panel menu does: a field under the wheel or the box that shows the color's hex digits (two more when the opacity rounds to less than ff) and takes a hex color of 3, 4, 6 or 8 digits or a CSS rgb(), hsl() or oklch() color, read as color.parse reads it, whose alpha sets the opacity Show Opacity edits when there is one to set; keys left out or null keep their values ({} reads them), params that are not an object, another key or a value off the list (opacity, hexField, harmony, vision, documentColors: not true or false) 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, opacity, hexField, documentColors}",
),
(
"ui.savePdfDialog",
+2
View File
@@ -2050,6 +2050,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, oklch or hsl `sliders` none, oklch અથવા hsl હોવું જોઈએ
@msg OKLCH needs sRGB as the working RGB space OKLCH માટે કાર્યકારી RGB સ્પેસ તરીકે sRGB જરૂરી છે
Lightness લાઇટનેસ
Lab Spot Colors: Lab સ્પોટ રંગો:
Landscape લેન્ડસ્કેપ
Can't render this file because it contains an unexpected character in line 72 and column 5.
+1 -1
View File
@@ -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, opacity?: bool, hexField?: 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; 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); 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); hexField checks (true) or unchecks (false) Show Hex Field, as the panel menu does: a field under the wheel or the box that shows the color's hex digits (two more when the opacity rounds to less than ff) and takes a hex color of 3, 4, 6 or 8 digits or a CSS rgb(), hsl() or oklch() color, read as color.parse reads it, whose alpha sets the opacity Show Opacity edits when there is one to set; keys left out or null keep their values ({} reads them), params that are not an object, another key or a value off the list (opacity, hexField, harmony, vision, documentColors: not true or false) 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, opacity, hexField, 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, opacity?: bool, hexField?: 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); 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); hexField checks (true) or unchecks (false) Show Hex Field, as the panel menu does: a field under the wheel or the box that shows the color's hex digits (two more when the opacity rounds to less than ff) and takes a hex color of 3, 4, 6 or 8 digits or a CSS rgb(), hsl() or oklch() color, read as color.parse reads it, whose alpha sets the opacity Show Opacity edits when there is one to set; keys left out or null keep their values ({} reads them), params that are not an object, another key or a value off the list (opacity, hexField, harmony, vision, documentColors: not true or false) 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, opacity, hexField, documentColors}",
),
(
"ui.savePdfDialog",
+31 -21
View File
@@ -336,67 +336,65 @@ pub(crate) fn set(settings: &mut Settings, p: &Value, cms: &Cms) -> Result<(), S
/// The panel menu: Wheel View and Box View, and Box Channel while the box shows; Show Out-of-Gamut
/// Colors; HSL Sliders and OKLCH Sliders; Show Harmony and Harmony Rule while the wheel shows; Show
/// Color Vision Preview; Show Document Colors; Show Opacity, Show Hex Field and Copy Color As.
/// Color Vision Preview; Show Document Colors; Show Opacity, Show Hex Field and Copy Color As. Each
/// item but Copy Color As 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() }));
}
}
});
});
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) {
let sliders = if on { Sliders::None } else { Sliders::Hsl };
if let Err(e) = app.run("ui.colorWheel", json!({ "sliders": sliders.id() })) {
app.status(e);
}
run(app, json!({ "sliders": sliders.id() }));
}
let on = set.sliders == Sliders::Oklch;
// While the rows show, the item stays enabled so that they can be hidden.
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() }));
}
if menu_item(ui, tl!("Show Harmony"), set.view == View::Wheel, set.harmony) {
command(app, &json!({ "harmony": !set.harmony })).ok();
run(app, json!({ "harmony": !set.harmony }));
}
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) {
command(app, &json!({ "harmonyRule": rule.id() })).ok();
if menu_item(ui, rule.label(), true, rule == set.harmony_rule) && rule != set.harmony_rule {
run(app, json!({ "harmonyRule": rule.id() }));
}
}
});
});
if menu_item(ui, tl!("Show Color Vision Preview"), true, set.vision) {
command(app, &json!({ "vision": !set.vision })).ok();
run(app, json!({ "vision": !set.vision }));
}
if menu_item(ui, tl!("Show Document Colors"), true, set.document_colors) {
command(app, &json!({ "documentColors": !set.document_colors })).ok();
run(app, json!({ "documentColors": !set.document_colors }));
}
ui.separator();
if menu_item(ui, tl!("Show Opacity"), true, set.opacity) {
command(app, &json!({ "opacity": !set.opacity })).ok();
run(app, json!({ "opacity": !set.opacity }));
}
if menu_item(ui, tl!("Show Hex Field"), true, set.hex_field) {
command(app, &json!({ "hexField": !set.hex_field })).ok();
run(app, json!({ "hexField": !set.hex_field }));
}
ui.separator();
let has_color = wheel_target(app, ui).color().is_some();
@@ -405,6 +403,13 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) {
});
}
/// 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);
}
}
/// The items of Copy Color As.
pub(crate) fn copy_menu(app: &mut VectorcraftApp, ui: &mut Ui) {
let notations = [
@@ -1029,11 +1034,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<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)>,
@@ -1057,6 +1066,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(),
+51 -6
View File
@@ -1102,15 +1102,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}");
}
}
@@ -1157,6 +1159,27 @@ fn ui_color_wheel_keeps_a_key_given_as_null() {
);
}
/// 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, oklch or hsl", &["none", "oklch", "hsl"][..]),
("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}");
}
}
}
/// 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]
@@ -1209,6 +1232,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]
@@ -315,7 +315,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");
@@ -335,10 +335,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
@@ -217,9 +217,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);
@@ -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");
+3 -2
View File
@@ -698,7 +698,7 @@ box with a slider and a percent field sets the opacity of the fill row (`paint.s
when none is selected), and `false` hides the row. The row is gray with nothing selected, for an object selected in
a symbol instance, and when the fill or stroke row it would set is on type characters or missing.
`{"documentColors": true}` shows the row the panel
menu's Show Document Colors adds under the wheel or the box. Keys left out or null keep their values.
menu's Show Document Colors adds under the wheel or the box. 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, gamut, harmony, harmonyRule, vision, opacity, hexField, documentColors}`, and the
settings are kept with the preferences.
@@ -708,7 +708,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.
+1 -1
View File
@@ -1972,7 +1972,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 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.