mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 12:16:39 +00:00
Color Wheel: OKLCH Sliders place the chroma tick on the drawn rail
- The C row's tick reads the slider's own rect, so it stays on the bar
when the row is taller than the rail. `color_rail_bar` gives the bar
for both the rail and the tick.
- The L and H tracks show a color outside sRGB at the largest chroma
that fits, the color a pick there stores, instead of clamping each
channel.
- The menu item uses `menu_item_hint`, which translates like
`menu_item`, and `menu_item_name` is unchanged.
- `color.convert {to: "oklch"}` says that any color outside sRGB (Lab,
CMYK, or RGB in a wider working RGB space) is clipped to sRGB first,
with a test for a Lab color.
- docs/mcp.md wraps the new paragraph; gu.tsv puts the new rows where
the other catalogs put them.
This commit is contained in:
@@ -81,7 +81,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Convert Color",
|
||||
[],
|
||||
None,
|
||||
"{color (#rrggbbaa and #rgba are refused), to: \"rgb\"|\"cmyk\"|\"gray\"|\"lab\"|\"oklch\", intent?} → {model, values, hex, lab: [L,a,b], outOfGamut, deltaE}; oklch values are [L (0..100 %), C, H (0..360°)] of the color's display sRGB (CSS Color 4 OKLCH: https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch), with H 0 for a gray; in a working RGB space other than sRGB, a color outside sRGB is clamped to sRGB first",
|
||||
"{color (#rrggbbaa and #rgba are refused), to: \"rgb\"|\"cmyk\"|\"gray\"|\"lab\"|\"oklch\", intent?} → {model, values, hex, lab: [L,a,b], outOfGamut, deltaE}; oklch values are [L (0..100 %), C, H (0..360°)] of the color's display sRGB (CSS Color 4 OKLCH: https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch), with H 0 for a gray; a color outside sRGB (a Lab color, a CMYK color or an RGB color in a wider working RGB space) is clipped to sRGB first",
|
||||
always,
|
||||
convert_color
|
||||
),
|
||||
|
||||
@@ -317,6 +317,12 @@ fn convert_to_oklch_answers_lightness_chroma_and_hue() {
|
||||
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:?}");
|
||||
// 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)));
|
||||
assert!((w[0] / 100.0 - clipped[0]).abs() < 1e-9 && (w[1] - clipped[1]).abs() < 1e-9, "{vivid} {clipped:?}");
|
||||
assert!(vectorcraft_color::oklab::in_srgb(vectorcraft_color::oklab::oklch_to_srgb(w[0] / 100.0, w[1], w[2])), "{vivid}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -640,11 +640,6 @@
|
||||
Color Themes રંગ થીમ
|
||||
Color Type: રંગ પ્રકાર:
|
||||
Color Wheel રંગ વ્હીલ
|
||||
OKLCH Sliders OKLCH સ્લાઇડર્સ
|
||||
Chroma ક્રોમા
|
||||
The largest chroma sRGB holds at this lightness and hue આ લાઇટનેસ અને હ્યૂ પર sRGB સમાવી શકે તે સૌથી વધુ ક્રોમા
|
||||
OKLCH needs sRGB as the working RGB space OKLCH માટે કાર્યકારી RGB સ્પેસ તરીકે sRGB જરૂરી છે
|
||||
Lightness લાઇટનેસ
|
||||
Color blindness – Deuteranopia-type રંગ અંધત્વ – ડ્યુટેરેનોપિયા પ્રકાર
|
||||
Color blindness – Protanopia-type રંગ અંધત્વ – પ્રોટેનોપિયા પ્રકાર
|
||||
Color blindness – Tritanopia-type રંગ અંધત્વ – ટ્રિટેનોપિયા પ્રકાર
|
||||
@@ -1852,6 +1847,11 @@
|
||||
Knife નાઇફ
|
||||
Knockout Group નૉકઆઉટ ગ્રૂપ
|
||||
LZW Compression LZW કમ્પ્રેશન
|
||||
OKLCH Sliders OKLCH સ્લાઇડર્સ
|
||||
Chroma ક્રોમા
|
||||
The largest chroma sRGB holds at this lightness and hue આ લાઇટનેસ અને હ્યૂ પર sRGB સમાવી શકે તે સૌથી વધુ ક્રોમા
|
||||
OKLCH needs sRGB as the working RGB space OKLCH માટે કાર્યકારી RGB સ્પેસ તરીકે sRGB જરૂરી છે
|
||||
Lightness લાઇટનેસ
|
||||
Lab Spot Colors: Lab સ્પોટ રંગો:
|
||||
Landscape લેન્ડસ્કેપ
|
||||
Language ભાષા
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 72 and column 5.
|
@@ -196,7 +196,7 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
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_name_hint(ui, tl!("OKLCH Sliders"), enabled, on, tl!("OKLCH needs sRGB as the working RGB space")) {
|
||||
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);
|
||||
@@ -385,15 +385,16 @@ 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.
|
||||
/// With `max_chroma` (the C track, whose L and H stay fixed) a chroma past it shows the color at
|
||||
/// that chroma; without it, a color outside sRGB shows clamped to it.
|
||||
/// 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.
|
||||
pub(crate) fn oklch_track(lch: [f64; 3], max_chroma: Option<f64>) -> Color32 {
|
||||
let (rgb, outside) = match max_chroma {
|
||||
Some(m) if lch[1] > m => (oklab::oklch_to_srgb(lch[0], m, lch[2]), true),
|
||||
Some(_) => (oklab::oklch_to_srgb(lch[0], lch[1], lch[2]), false),
|
||||
None => {
|
||||
let exact = oklab::oklch_to_srgb(lch[0], lch[1], lch[2]);
|
||||
(exact, !oklab::in_srgb(exact))
|
||||
let (rgb, lowered) = oklab::from_oklch(lch[0], lch[1], lch[2]);
|
||||
(rgb.map(f64::from), lowered)
|
||||
}
|
||||
};
|
||||
let [r, g, b] = rgb.map(|v| (v.clamp(0.0, 1.0) * 255.0).round() as u8);
|
||||
@@ -446,13 +447,13 @@ pub(crate) fn oklch_rows(app: &VectorcraftApp, ui: &mut Ui, tgt: &Target, color:
|
||||
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 rail = Rect::from_min_size(ui.cursor().min, vec2(slider_w, 22.0));
|
||||
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);
|
||||
if i == 1 && enabled {
|
||||
// The bar of `color_slider_stepped`'s rail: 4 points in from its left, top and right.
|
||||
let bar = Rect::from_min_size(rail.min + vec2(4.0, 4.0), vec2(slider_w - 8.0, 7.0));
|
||||
// The tick goes on the bar of the rail as the row laid it out.
|
||||
let rail = (i == 1 && enabled).then(|| ui.ctx().read_response(widgets::id_with(ui.scope_id(), ("color-wheel-oklch", i)))).flatten();
|
||||
if let Some(rail) = rail {
|
||||
let bar = widgets::color_rail_bar(rail.rect);
|
||||
let x = bar.left() + chroma_tick(max_c) * bar.width();
|
||||
ui.painter().line_segment([pos2(x, bar.top() - 3.0), pos2(x, bar.bottom())], Stroke::new(1.5, t.text));
|
||||
let tip = Rect::from_x_y_ranges(x - 3.0..=x + 3.0, bar.top() - 3.0..=bar.bottom());
|
||||
|
||||
@@ -685,6 +685,12 @@ fn the_oklch_tracks_dim_the_colors_outside_srgb_and_the_tick_marks_the_largest_c
|
||||
assert_eq!(oklch_track([l, max * 0.5, h], max_chroma).a(), 255, "{max_chroma:?}: inside sRGB");
|
||||
assert!(oklch_track([l, 0.4, h], max_chroma).a() < 255, "{max_chroma:?}: outside sRGB is dimmed");
|
||||
}
|
||||
// Near white, an L or H track shows the color a pick there stores: the largest chroma that fits,
|
||||
// not each channel clamped on its own.
|
||||
let (stored, lowered) = vectorcraft_color::oklab::from_oklch(0.98, 0.2, h);
|
||||
let [r, g, b] = stored.map(|v| (f64::from(v).clamp(0.0, 1.0) * 255.0).round() as u8);
|
||||
assert!(lowered);
|
||||
assert_eq!(oklch_track([0.98, 0.2, h], None), egui::Color32::from_rgb(r, g, b).gamma_multiply(0.3));
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ pub use blend::{
|
||||
reference_point_named,
|
||||
};
|
||||
pub use buttons::{
|
||||
SPLIT_ARROW, flat_button, flat_button_fit, icon_button, icon_button_enabled, menu_item, menu_item_name, menu_item_name_hint, paint_icon_button,
|
||||
SPLIT_ARROW, flat_button, flat_button_fit, icon_button, icon_button_enabled, menu_item, menu_item_hint, menu_item_name, paint_icon_button,
|
||||
primary_button, primary_button_enabled, secondary_button, split_button, split_button_named, toggle_icon,
|
||||
};
|
||||
pub(crate) use buttons::{button_width, icon_button_info, primary_button_width, secondary_button_width};
|
||||
@@ -39,7 +39,7 @@ pub use color::{
|
||||
color_field, color_mesh, color_slider, color_slider_named, color_slider_stepped, color_slider_valued, harmony_wheel, hex_field, hex_field_named,
|
||||
hsb32, hue_ring, region_texture, ring_square, segment_color, segmented_wheel, stepped_area,
|
||||
};
|
||||
pub(crate) use color::{HEX_FIELD_CHARS, hex_text, pointer_phase};
|
||||
pub(crate) use color::{HEX_FIELD_CHARS, color_rail_bar, hex_text, pointer_phase};
|
||||
pub use drag::{
|
||||
PanelDrag, RowClick, SwatchRows, apply_row_click, art_drop, doc_preview, drag_ghost, drag_source, drop_target_outline, ghost_row, row_click,
|
||||
};
|
||||
|
||||
@@ -204,16 +204,16 @@ pub fn menu_item(ui: &mut Ui, label: &str, enabled: bool, checked: bool) -> bool
|
||||
/// [`menu_item`] for a name that is user or file data (a library, a recent URL), never translated.
|
||||
/// Like the menu bar's items, the row lights up under the pointer.
|
||||
pub fn menu_item_name(ui: &mut Ui, label: &str, enabled: bool, checked: bool) -> bool {
|
||||
menu_row(ui, label, enabled, checked).clicked()
|
||||
let text = if checked { format!("✓ {label}") } else { format!(" {label}") };
|
||||
ui.add_enabled(enabled, egui::Button::new(egui::RichText::new(text).size(12.5)).frame_when_inactive(false)).clicked()
|
||||
}
|
||||
|
||||
/// [`menu_item_name`] that shows `hint` (already translated) under the pointer while the row is
|
||||
/// disabled, to say why it is gray.
|
||||
pub fn menu_item_name_hint(ui: &mut Ui, label: &str, enabled: bool, checked: bool, hint: &str) -> bool {
|
||||
menu_row(ui, label, enabled, checked).on_disabled_hover_text(hint).clicked()
|
||||
}
|
||||
|
||||
fn menu_row(ui: &mut Ui, label: &str, enabled: bool, checked: bool) -> egui::Response {
|
||||
/// [`menu_item`] that shows `hint` under the pointer while the row is disabled, to say why it is
|
||||
/// gray.
|
||||
pub fn menu_item_hint(ui: &mut Ui, label: &str, enabled: bool, checked: bool, hint: &str) -> bool {
|
||||
let label = tl!(label);
|
||||
let text = if checked { format!("✓ {label}") } else { format!(" {label}") };
|
||||
ui.add_enabled(enabled, egui::Button::new(egui::RichText::new(text).size(12.5)).frame_when_inactive(false))
|
||||
.on_disabled_hover_text(tl!(hint))
|
||||
.clicked()
|
||||
}
|
||||
|
||||
@@ -265,6 +265,11 @@ fn rail_step(ui: &Ui, id: egui::Id, focused: bool, s: &SliderValue) -> Option<f6
|
||||
(v != from || (end && v != s.value)).then_some(if exact { v } else { round_to(v, STEP_DECIMALS).clamp(lo, hi) })
|
||||
}
|
||||
|
||||
/// The colored bar inside the rail `rect` of [`color_slider_stepped`] and its siblings.
|
||||
pub(crate) fn color_rail_bar(rect: Rect) -> Rect {
|
||||
Rect::from_min_size(pos2(rect.left() + 4.0, rect.top() + 4.0), vec2(rect.width() - 8.0, 7.0))
|
||||
}
|
||||
|
||||
/// The rail of [`color_slider_valued`] with the id `id`: its response, the new value from 0 to 1
|
||||
/// that a click or drag gives and the phase.
|
||||
fn color_rail(
|
||||
@@ -278,7 +283,7 @@ fn color_rail(
|
||||
) -> (Response, Option<f32>, Live) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(width, 22.0), Sense::hover());
|
||||
let bar = Rect::from_min_size(pos2(rect.left() + 4.0, rect.top() + 4.0), vec2(width - 8.0, 7.0));
|
||||
let bar = color_rail_bar(rect);
|
||||
let resp = ui.interact(rect, id, Sense::click_and_drag());
|
||||
gradient_strip(ui, bar, (bar.width() / 2.0).ceil().max(2.0) as usize, false, track);
|
||||
ui.painter().rect_stroke(bar, 0.0, Stroke::new(1.0, t.border), StrokeKind::Outside);
|
||||
|
||||
+3
-2
@@ -627,8 +627,9 @@ 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. `color.convert {"to": "oklch"}` answers the color's OKLCH as `[L %, C, H°]` of its display sRGB,
|
||||
and headless MCP reaches it too.
|
||||
the box), and `"none"` hides them; `"oklch"` is an error while the working RGB space is not sRGB.
|
||||
`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.
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user