Color Wheel: opacity edits target and count what the command changes

- A null `id` or `ids` names no object, so while the Type tool has
  characters selected the paint still goes to those characters.
- An opacity for selected characters is refused before the typing
  session ends, so the session and its undo step stay as they are.
- With an opacity alone, `objects` counts only the objects that took it.
- `paint.proxies` reads a targeted layer's visible, unlocked art, as the
  commands do, so a locked object's fill no longer enables the control.
- A field commit on one OKLCH row keeps a value clicked or dragged on
  another row in the same frame, and a drag in progress stays in
  progress.
This commit is contained in:
dotCooCoo committed 2026-11-19 05:46:34 -08:00
1 parent 29a379ad5e
commit 7533a81e22
5 files changed
+179 -25

No files matched your search

+27 -13
View File
@@ -21,7 +21,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Fill",
[],
None,
"{color?: \"#rrggbb\"|[r,g,b]|{c,m,y,k}|{gray}|{l,a,b} (CIE Lab; #rrggbbaa and #rgba are refused), none?: true, swatch?: name (a global or spot colour stays linked, so swatch edits recolour it; a tint swatch links to its base at its tint; a gradient swatch is recorded as the gradient's swatch and fits each object, keeping its aspect; the built-in \"[Registration]\" prints on every plate), tint?: 0..100 (% of a global or spot `swatch`; default 100, or a tint swatch's own), gradient?: {kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical: the stops sweep once around the center `start`, clockwise from the vector; diamond: the stops run from the center `start` out to a square with a corner at `end`), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (as paint.editGradient; default classic), spread?: pad|repeat|reflect (as paint.editGradient; default pad), repeats?: 1..100 (as paint.editGradient; default 1), stops?: [{offset 0..1, color, opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: global or spot colour (or tint) swatch the stop links to (its colour comes from the swatch), tint?: 0..100}] (at least 2; default white→black), angle?: deg counter-clockwise (0: the gradient runs left to right), start?: [x,y], end?: [x,y] (the vector in document coordinates, both or neither; type objects keep it in text space), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep, counterclockwise, and is an error for the other kinds; without start/end the gradient is placed on each object's bounds), focal?: [x,y] (radial, with start/end: the focal point, where the first stop sits; an error with a conic or diamond), dither?: bool (linear, radial, conic and diamond fills: drawn with fine noise that hides banding, and as pixels in SVG and PDF exports; strokes ignore it), swatch?: linked gradient swatch name}, item?: appearance item index|null (omitted: the Appearance panel's active item if it is a fill, else the top fill), aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md), opacity?: 0..100 (a percentage, as transparency.set's; the opacity of that fill item on each target, in the undo step of the paint, or alone without color, none, swatch or gradient, when it changes neither the defaults nor the recent colors; the gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso take it themselves; with no paint, a target without that fill item is left as it is (a paint given with the opacity creates the item, which then takes it), and an opacity that no target takes is an error that also leaves the paint undone; type characters have no opacity of their own, so an opacity that only characters would take is an error, and so are one with nothing selected and no ids and one for an object selected in a symbol instance), ids?|id?, focus?: true (false keeps the active proxy), keepModel?: false (in a CMYK document, RGB colours and gradient stops are stored as CMYK unless true; Gray stays Gray), target?: \"object\"|\"contents\", span?: \"object\" (default: each target fits a gradient to its own bounds)|\"selection\" (a linear, radial, conic or diamond `gradient` without start/end is placed once on the union of the targets' bounds, so it runs across them)} sets the selection's fill and the default (new art fits a gradient to itself); a solid color recolors only the gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso (unless an `item` index is given or the Appearance panel's active item is a fill); while the Type tool has characters selected (and no ids, id or item are given), the paint goes to those characters only; without `item`, a grayscale or 1-bit image takes a solid color as the color it is drawn in (white pixels transparent; `none` takes it off; an image with an alpha channel takes only a spot color, black or white; a colorized image whose link is missing takes a solid color as its new colorize color, and refuses a process color while its color is a spot color, black or white); with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's fill changes for this instance only (solid, none, gradient or pattern). On a path directly in a graph series, the graph also stores the paint of the topmost visible fill when the command wrote that row or changed it, and its opacity when `opacity` changed it (exceptions: docs/mcp.md); on a graph label, the graph stores the paint for every label of its kind, as a character fill when the characters took it and with the label's rows when a row did; on a graph's axis line, tick mark or radar ring, its rows for every line of its kind → {objects: how many objects took the paint (the objects inside a group, unless an appearanc Line truncated
"{color?: \"#rrggbb\"|[r,g,b]|{c,m,y,k}|{gray}|{l,a,b} (CIE Lab; #rrggbbaa and #rgba are refused), none?: true, swatch?: name (a global or spot colour stays linked, so swatch edits recolour it; a tint swatch links to its base at its tint; a gradient swatch is recorded as the gradient's swatch and fits each object, keeping its aspect; the built-in \"[Registration]\" prints on every plate), tint?: 0..100 (% of a global or spot `swatch`; default 100, or a tint swatch's own), gradient?: {kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical: the stops sweep once around the center `start`, clockwise from the vector; diamond: the stops run from the center `start` out to a square with a corner at `end`), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (as paint.editGradient; default classic), spread?: pad|repeat|reflect (as paint.editGradient; default pad), repeats?: 1..100 (as paint.editGradient; default 1), stops?: [{offset 0..1, color, opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: global or spot colour (or tint) swatch the stop links to (its colour comes from the swatch), tint?: 0..100}] (at least 2; default white→black), angle?: deg counter-clockwise (0: the gradient runs left to right), start?: [x,y], end?: [x,y] (the vector in document coordinates, both or neither; type objects keep it in text space), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep, counterclockwise, and is an error for the other kinds; without start/end the gradient is placed on each object's bounds), focal?: [x,y] (radial, with start/end: the focal point, where the first stop sits; an error with a conic or diamond), dither?: bool (linear, radial, conic and diamond fills: drawn with fine noise that hides banding, and as pixels in SVG and PDF exports; strokes ignore it), swatch?: linked gradient swatch name}, item?: appearance item index|null (omitted: the Appearance panel's active item if it is a fill, else the top fill), aligned?: bool (index and item are rows of the first target's stack: each other target edits its equal one, as the Appearance panel does for a mixed selection; with the art of a graph design in a series given first, rows of the art's stack: docs/mcp.md), opacity?: 0..100 (a percentage, as transparency.set's; the opacity of that fill item on each target, in the undo step of the paint, or alone without color, none, swatch or gradient, when it changes neither the defaults nor the recent colors; the gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso take it themselves; with no paint, a target without that fill item is left as it is (a paint given with the opacity creates the item, which then takes it), and an opacity that no target takes is an error that also leaves the paint undone; type characters have no opacity of their own, so an opacity that only characters would take is an error, and so are one with nothing selected and no ids and one for an object selected in a symbol instance), ids?|id?, focus?: true (false keeps the active proxy), keepModel?: false (in a CMYK document, RGB colours and gradient stops are stored as CMYK unless true; Gray stays Gray), target?: \"object\"|\"contents\", span?: \"object\" (default: each target fits a gradient to its own bounds)|\"selection\" (a linear, radial, conic or diamond `gradient` without start/end is placed once on the union of the targets' bounds, so it runs across them)} sets the selection's fill and the default (new art fits a gradient to itself); a solid color recolors only the gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso (unless an `item` index is given or the Appearance panel's active item is a fill); while the Type tool has characters selected (and no item, and no ids or id other than null, are given), the paint goes to those characters only; without `item`, a grayscale or 1-bit image takes a solid color as the color it is drawn in (white pixels transparent; `none` takes it off; an image with an alpha channel takes only a spot color, black or white; a colorized image whose link is missing takes a solid color as its new colorize color, and refuses a process color while its color is a spot color, black or white); with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's fill changes for this instance only (solid, none, gradient or pattern). On a path directly in a graph series, the graph also stores the paint of the topmost visible fill when the command wrote that row or changed it, and its opacity when `opacity` changed it (exceptions: docs/mcp.md); on a graph label, the graph stores the paint for every label of its kind, as a character fill when the characters took it and with the label's rows when a row did; on a graph's axis line, tick mark or radar ring, its rows for every line of its kind → {objects: how many objects took the paint (the objects inside a gr Line truncated
has_doc,
|s, p| set_paint(s, p, true)
),
@@ -257,7 +257,8 @@ impl Session {
let targets = super::graph::series_group_marks_where(&st.doc, subjects, |n| n.extras().series_index.is_some());
return targets.iter().filter(editable).filter_map(|id| st.doc.node(*id)).find_map(|n| of(n, active));
}
let leaves = super::leaf_targets(self, subjects).ok()?;
// The command's targets: a targeted layer stands for its visible, unlocked art.
let leaves = super::paint_targets(self, &Value::Null).ok()?;
leaves.iter().filter(editable).filter_map(|id| st.doc.node(*id)).find_map(|n| of(n, None))
}
@@ -537,6 +538,11 @@ fn opacity_param(p: &Value, cmd: &str) -> Result<Option<f32>> {
}
}
/// Whether `p` gives `key` a value other than null.
fn names(p: &Value, key: &str) -> bool {
p.get(key).is_some_and(|v| !v.is_null())
}
/// The error for an `opacity` that would go to type characters, which have no opacity of their own.
fn characters_have_no_opacity(cmd: &str) -> EngineError {
bad(cmd, "type characters have no opacity of their own: add a fill or stroke with the Appearance panel's Add New Fill or Add New Stroke")
@@ -565,10 +571,15 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
let focus = switch_or(p, "focus", true, cmd)?;
// An opacity alone places no gradient, so `span` may only be "object" with it.
let span = spans_targets(p, paint.as_ref().unwrap_or(&Paint::None)).map_err(|e| bad(cmd, e))?;
// Characters selected with the Type tool take the paint, not the whole type object (#1063).
if p.get("ids").is_none()
&& p.get("id").is_none()
&& p.get("item").is_none()
// Characters selected with the Type tool take the paint, not the whole type object (#1063). A
// null `ids` or `id` names no object, as the targets read it.
let on_characters = !names(p, "ids") && !names(p, "id") && p.get("item").is_none();
// An opacity for the characters is refused before their typing session ends, so the session
// and its undo step stay as they are.
if on_characters && opacity.is_some() && super::textedit::selected_range(s).is_some_and(|(_, a, b)| a != b) {
return Err(characters_have_no_opacity(cmd));
}
if on_characters
&& let Some((id, a, b)) = super::textedit::editing_range(s)?
&& a != b
{
@@ -687,8 +698,8 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
// The type objects whose characters took the paint (no row targeted): only those change what a graph's labels keep
// for their characters; a row edit is kept with the label's rows.
let characters = std::cell::RefCell::new(Vec::new());
// Whether a target took the opacity, and whether one would have given it to its characters.
let (took_opacity, characters_skipped) = (std::cell::Cell::new(false), std::cell::Cell::new(false));
// The targets that took the opacity, and whether one would have given it to its characters.
let (took_opacity, characters_skipped) = (std::cell::RefCell::new(std::collections::BTreeSet::new()), std::cell::Cell::new(false));
let paint_one = |n: &mut Node, index: Option<usize>, paint: &Paint| -> Result<()> {
if index.is_none() && matches!(n.kind, NodeKind::Text(_)) {
characters.borrow_mut().push(n.id);
@@ -764,7 +775,7 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
for i in points {
if let Some(q) = m.points.get_mut(*i) {
q.opacity = o;
took_opacity.set(true);
took_opacity.borrow_mut().insert(n.id);
}
}
return;
@@ -773,7 +784,7 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
if fill { n.appearance.fill_at_mut(index).map(|f| &mut f.opacity) } else { n.appearance.stroke_at_mut(index).map(|s| &mut s.opacity) };
if let Some(item) = item {
*item = o;
took_opacity.set(true);
took_opacity.borrow_mut().insert(n.id);
}
};
// The objects counted: with a design's art, those with a row equal to the art's.
@@ -796,7 +807,7 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
},
|before, d, changed| {
// An opacity that no target took is an error, which also takes back the paint given with it.
if opacity.is_some() && !took_opacity.get() {
if opacity.is_some() && took_opacity.borrow().is_empty() {
if characters_skipped.get() {
return Err(characters_have_no_opacity(cmd));
}
@@ -829,14 +840,17 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
paint_new_art(s, paint, fill);
s.remember_paint(paint);
}
Ok(json!({"objects": ids.iter().collect::<std::collections::BTreeSet<_>>().len()}))
// An opacity alone counts only the objects that took it.
let took = took_opacity.into_inner();
let counted: std::collections::BTreeSet<_> = ids.iter().filter(|id| paint.is_some() || took.contains(*id)).collect();
Ok(json!({"objects": counted.len()}))
}
/// The instance whose object is selected with Direct Selection, and that object's path
/// ([`super::brushsym::selected_part`]), when `p` names no `ids`, `id` or `item`: the paint commands
/// then change that object. A bad `target` or `aligned` is refused as it is for any other selection.
fn selected_part_target(s: &Session, p: &Value, cmd: &str) -> Result<Option<(NodeId, Vec<u32>)>> {
if p.get("ids").is_some() || p.get("id").is_some() || p.get("item").is_some() {
if names(p, "ids") || names(p, "id") || p.get("item").is_some() {
return Ok(None);
}
let part = super::brushsym::selected_part(s)?;
+83
View File
@@ -234,6 +234,89 @@ fn with_characters_selected_an_id_takes_the_opacity() {
assert_eq!(node(&s, t), before, "the characters keep their paint");
}
/// While the Type tool has characters selected, a null `id` or `ids` names no object: the paint goes
/// to the selected characters only, as without the key.
#[test]
fn with_characters_selected_a_null_id_paints_the_characters() {
let runs = |key: Option<&str>| {
let mut s = session();
let r = s.execute("text.create", &json!({"x": 10, "y": 150, "text": "Hello"})).unwrap();
let t = NodeId(r["id"].as_u64().unwrap());
select(&mut s, &[t]);
select_characters(&mut s, t);
let mut p = json!({"color": "#ff0000"});
if let Some(key) = key {
p[key] = Value::Null;
}
s.execute("paint.setFill", &p).unwrap();
match &node(&s, t).kind {
NodeKind::Text(t) => t.runs.clone(),
_ => panic!("not type"),
}
};
let characters = runs(None);
assert!(characters.len() > 1, "only the selected characters take the paint");
for key in ["id", "ids"] {
assert_eq!(runs(Some(key)), characters, "{key}: null");
}
}
/// An opacity for characters selected while the Type tool is typing is refused before the typing
/// session ends: the session goes on, and no undo step is recorded.
#[test]
fn an_opacity_for_characters_leaves_the_typing_session_running() {
let mut s = session();
let v = ViewInfo::default();
s.select_tool("type", v).unwrap();
for kind in [PointerKind::Down, PointerKind::Up] {
s.pointer(&PointerEvent::new(kind, 50.0, 250.0), v).unwrap();
}
s.tool_text("Hello", v).unwrap();
s.set_tool_option("select", &json!({"start": 0, "end": 2}));
assert!(crate::cmd::typing_in_progress(&s));
let undo = undo_labels(&s).len();
let e = s.execute("paint.setFill", &json!({"opacity": 40})).unwrap_err();
assert!(e.to_string().contains("type characters have no opacity of their own"), "{e}");
assert!(crate::cmd::typing_in_progress(&s), "the typing session goes on");
assert_eq!(undo_labels(&s).len(), undo, "no undo step");
}
/// With an opacity alone, the reply counts only the objects that took it: a selected object without
/// that fill item is left out, and one already at that opacity still counts. With a paint, every
/// target counts.
#[test]
fn an_opacity_alone_counts_the_objects_that_took_it() {
let mut s = session();
let (a, b) = (rect(&mut s, 10.0), rect(&mut s, 200.0));
select(&mut s, &[a]);
s.execute("appearance.removeItem", &json!({"index": 0})).unwrap();
assert!(node(&s, a).appearance.fill().is_none());
select(&mut s, &[a, b]);
assert_eq!(s.execute("paint.setFill", &json!({"opacity": 40})).unwrap()["objects"], 1);
assert_eq!(s.execute("paint.setFill", &json!({"opacity": 40})).unwrap()["objects"], 1, "already at 40%");
assert_eq!(s.execute("paint.setFill", &json!({"color": "#ff0000", "opacity": 40})).unwrap()["objects"], 2);
}
/// With a layer targeted, `paint.proxies` reads the art the command edits: a locked object's fill
/// row does not count, so the proxy answers null when the edit finds no fill to take the opacity.
#[test]
fn a_targeted_layers_proxy_leaves_out_locked_art() {
let mut s = session();
let (a, b) = (rect(&mut s, 10.0), rect(&mut s, 200.0));
select(&mut s, &[b]);
s.execute("appearance.removeItem", &json!({"index": 0})).unwrap();
select(&mut s, &[a]);
s.execute("object.lock", &json!({})).unwrap();
let layer = s.doc().unwrap().doc.layers[0].id;
s.execute("layer.target", &json!({"id": layer.0})).unwrap();
assert_eq!(proxies(&mut s)["fillOpacity"], Value::Null);
let e = s.execute("paint.setFill", &json!({"opacity": 40})).unwrap_err();
assert!(e.to_string().contains("no target has that fill or stroke to take the opacity"), "{e}");
s.execute("object.unlockAll", &json!({})).unwrap();
s.execute("layer.target", &json!({"id": layer.0})).unwrap();
assert_eq!(proxies(&mut s)["fillOpacity"], 100.0, "the unlocked fill counts");
}
/// A type object whose characters take the paint is left alone beside a rectangle that takes the
/// opacity, with no error; alone, it answers the characters error.
#[test]
+30 -9
View File
@@ -729,14 +729,32 @@ pub(crate) fn chroma_tick(max_chroma: f64) -> f32 {
(max_chroma / CHROMA_FULL).clamp(0.0, 1.0) as f32
}
/// The OKLCH rows' edits of one frame with row `i`'s edit added: row `i` takes its value from
/// `asked`, on top of `out` (the other rows' edits so far, or none on top of `lch`). A drag on one
/// row stays in progress when another row's field commits in the same frame.
pub(crate) fn oklch_row_edit(
out: Option<([f64; 3], [bool; 3], Live)>,
lch: [f64; 3],
asked: [f64; 3],
i: usize,
phase: Live,
) -> ([f64; 3], [bool; 3], Live) {
let (mut base, mut rows, was) = out.unwrap_or((lch, [false; 3], phase));
base[i] = asked[i];
rows[i] = true;
let phase = if matches!(was, Live::Dragging) { Live::Dragging } else { phase };
(base, rows, phase)
}
/// The L, C and H rows of OKLCH Sliders for the target's `color` through `cms`: lightness from 0 to
/// 100 %, chroma from 0 to 100 % of 0.4 (as CSS reads a chroma percentage) and hue from 0 to 360°.
/// Each track shows the colors its slider reaches and dims the part outside sRGB, and a tick on the
/// C track marks the largest chroma sRGB holds at the row's L and H. The rows are gray with no
/// color to edit and while the working RGB space is not sRGB. Returns the OKLCH a drag, an arrow
/// key, a screen reader or a field asks for, the index of the row that set it (0 for L, 1 for C, 2
/// for H) and its phase.
pub(crate) fn oklch_rows(app: &VectorcraftApp, ui: &mut Ui, tgt: &Target, color: Option<Color>, cms: &Cms) -> Option<([f64; 3], usize, Live)> {
/// key, a screen reader or a field asks for, which rows set it (L, C and H in that order) and the
/// phase of the last edit. A field that commits when a click on another row takes its focus keeps
/// its value along with the click's.
pub(crate) fn oklch_rows(app: &VectorcraftApp, ui: &mut Ui, tgt: &Target, color: Option<Color>, cms: &Cms) -> Option<([f64; 3], [bool; 3], Live)> {
let t = Tokens::get(ui.ctx());
let enabled = color.is_some() && cms.rgb_is_srgb();
let lch = match (color, pstate::<Option<(Owner, [f32; 3], [f64; 3])>>(ui.ctx(), OKLCH_MEMORY)) {
@@ -757,7 +775,8 @@ pub(crate) fn oklch_rows(app: &VectorcraftApp, ui: &mut Ui, tgt: &Target, color:
}
out
};
let mut out = None;
let mut out: Option<([f64; 3], [bool; 3], Live)> = None;
let mut set = |asked: [f64; 3], i: usize, phase: Live| out = Some(oklch_row_edit(out, lch, asked, i, phase));
ui.add_enabled_ui(enabled, |ui| {
let field_w = 48.0;
let slider_w = (ui.available_width() - field_w - 12.0 - 3.0 * ui.spacing().item_spacing.x).max(60.0);
@@ -783,13 +802,13 @@ pub(crate) fn oklch_rows(app: &VectorcraftApp, ui: &mut Ui, tgt: &Target, color:
.on_hover_text(tl!("The largest chroma sRGB holds at this lightness and hue"));
}
if let Some(x) = dragged {
out = Some((at(x), i, phase));
set(at(x), i, phase);
}
if let Some(k) = keyed {
out = Some((with(i, k), i, Live::Released));
set(with(i, k), i, Live::Released);
}
if let Some(f) = widgets::plain_field_named(ui, ("color-wheel-oklch-field", i), Some(name), v, suffix, 0, field_w) {
out = Some((with(i, f), i, Live::Released));
set(with(i, f), i, Live::Released);
}
});
}
@@ -890,11 +909,13 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let now = tgt.color().filter(|c| committed && Some(*c) != color);
let behind = super::alt_held(ui);
let cmyk_doc = app.session.active().is_some_and(|d| d.doc.color_mode == ColorMode::Cmyk);
if let Some((asked, row, phase)) = picked_lch {
if let Some((asked, rows, phase)) = picked_lch {
let lch = match now {
Some(c) => {
let mut lch = oklab::to_oklch(cms.display_rgb(&c));
lch[row] = asked[row];
for row in (0..3).filter(|r| rows[*r]) {
lch[row] = asked[row];
}
lch
}
None => asked,
+36 -1
View File
@@ -12,9 +12,10 @@ use vectorcraft_color::{Color, Paint};
use vectorcraft_engine::Session;
use super::color_wheel::{
ID, Settings, Sliders, chroma_tick, display_hsb, oklch_rows, oklch_track, remembered_hsb, remembered_oklch, set, show, stored,
ID, Settings, Sliders, chroma_tick, display_hsb, oklch_row_edit, oklch_rows, oklch_track, remembered_hsb, remembered_oklch, set, show, stored,
};
use crate::VectorcraftApp;
use crate::widgets::Live;
/// An app with a selected rectangle filled with `fill`.
fn app(fill: serde_json::Value) -> VectorcraftApp {
@@ -646,6 +647,40 @@ fn a_drag_on_lightness_keeps_the_chroma_asked_for() {
assert!((l2 - l0).abs() < 0.01 && (c2 - c0).abs() < 0.01, "{:?} → {:?}", [l0, c0], [l2, c2]);
}
/// A lightness typed in the L field and committed by a click on the C rail in one frame keeps both
/// edits: the color takes the typed L and the clicked C.
#[test]
fn a_typed_lightness_committed_by_a_click_on_chroma_keeps_both() {
let mut h = oklch_harness(app(json!("#ff0000")));
let h0 = fill_oklch(h.state())[2];
h.get_by_role_and_label(egui::accesskit::Role::TextInput, "Lightness").click();
h.run_steps(1);
h.key_press_modifiers(Modifiers::COMMAND, egui::Key::A);
h.run_steps(1);
h.get_by_role_and_label(egui::accesskit::Role::TextInput, "Lightness").type_text("50");
h.run_steps(1);
let rail = oklch_slider(&h, "Chroma").rect();
quick_click(&mut h, on_rail(rail, 0.2));
let [l, c, hue] = fill_oklch(h.state());
assert!((l - 0.5).abs() < 0.01, "the typed lightness stays: {l}");
assert!((c - 0.08).abs() < 0.01, "the click sets the chroma: {c}");
assert!((hue - h0).abs() < 1.0, "the hue stays: {h0} → {hue}");
}
/// When a drag on one OKLCH row and a field commit on another come in one frame, the frame's edit
/// keeps both values and the drag stays in progress, in either order.
#[test]
fn a_field_commit_beside_a_drag_keeps_the_drag_going() {
let lch = [0.6, 0.2, 30.0];
let drag = |out| oklch_row_edit(out, lch, [0.8, 0.0, 0.0], 0, Live::Dragging);
let field = |out| oklch_row_edit(out, lch, [0.0, 0.0, 200.0], 2, Live::Released);
for (out, order) in [(field(Some(drag(None))), "drag first"), (drag(Some(field(None))), "field first")] {
assert_eq!(out.0, [0.8, 0.2, 200.0], "{order}");
assert_eq!(out.1, [true, false, true], "{order}");
assert!(matches!(out.2, Live::Dragging), "{order}");
}
}
/// A press on a row gives it the keyboard focus, and → raises it by one unit as one undo step.
/// Each row reports its range and the adjust actions to screen readers.
#[test]
+3 -2
View File
@@ -888,8 +888,9 @@ its kind (`paint.proxies`) and the Gradient tool's annotator then show that row.
`inspect_document` reports it as `paint.appearanceItem`. `paint.setFill` and `paint.setStroke` also take `opacity`
(0 to 100, a percentage as in `transparency.set`), which sets the opacity of the fill or stroke row they paint, with
or without a new paint, as one undo step. An opacity that no target takes is an error and also leaves the paint
undone. `paint.proxies` answers it as `fillOpacity` and `strokeOpacity`, from the first selected object that has
that row. It answers null with nothing selected, for an object selected in a symbol instance, while the Type tool
undone. With an opacity alone, the reply's `objects` counts only the objects that took it. `paint.proxies` answers
it as `fillOpacity` and `strokeOpacity`, from the first selected object that has that row. With a layer targeted,
it reads the layer's visible, unlocked art, as the commands do. It answers null with nothing selected, for an object selected in a symbol instance, while the Type tool
has characters selected, and when only type characters (which have no opacity of their own) or objects without that
row are selected. Live effects take the same `item` to apply to one fill or
stroke instead of the whole object: `run_command effect.apply {"effect": "path.offsetPath", "item": 0}`, and