Color Wheel: Show Opacity edge cases in the opacity commands and the row

- paint.setFill and paint.setStroke give a graph's series marks and axis lines the opacity they write even when the object already shows it, so another mark's kept opacity no longer comes back after the graph is drawn again.
- The proxies answer no opacity whenever the Live Paint Bucket paints, which includes a Cmd+click and an Eyedropper pick armed for it.
- A swatch that is not a name is an error with an opacity instead of an opacity alone.
- Hiding the Show Opacity row, or the row turning gray, during a drag keeps the previewed opacity as one undo step and ends the interaction.
- The help text and docs/mcp.md name the picked mesh points case, the grayscale image colorize exception and the New Art Has Basic Appearance off case.
This commit is contained in:
dotCooCoo committed 2026-11-19 16:31:57 -08:00
1 parent c55515ed41
commit ff5071c93d
7 files changed
+193 -14

No files matched your search

+18
View File
@@ -1184,6 +1184,24 @@ pub(crate) fn capture_series_paint_writes(
super::graph::capture_series_top_paints(d, &rows)
}
/// Store on the graph the opacity and blend mode of each row an edit wrote (`written`: an object with the index of the
/// row) on the series marks among them, when that row is the topmost visible one of its kind, also when the mark
/// already showed that opacity: it replaces the opacity another mark of the series left on the graph. When the edit
/// reaches several marks of one series, the frontmost one sets what the graph stores. Returns whether the stored
/// opacity or blend mode changed.
pub(crate) fn capture_series_opacity_writes(d: &mut vectorcraft_doc::Document, written: &[(NodeId, usize)]) -> bool {
let ids: Vec<NodeId> = written.iter().map(|(id, _)| *id).collect();
// A later mark's capture replaces an earlier one's: take them in paint order.
let rows: Vec<(NodeId, bool)> = series_children_in_paint_order(d, &ids)
.into_iter()
.flat_map(|id| {
let shown = written.iter().filter(move |(w, _)| *w == id).filter_map(|(_, at)| Some((id, top_row_kind(&d.node(id)?.appearance, *at)?)));
shown.collect::<Vec<_>>()
})
.collect();
super::graph::capture_series_opacity(d, &rows)
}
/// The kind of the row at `at` (fill `true`, stroke `false`) when it is the topmost visible row of that kind in `ap`.
fn top_row_kind(ap: &Appearance, at: usize) -> Option<bool> {
let fill = ap.items.get(at)?.is_fill();
+41
View File
@@ -352,6 +352,47 @@ fn a_paint_opacity_on_a_series_mark_survives_regeneration() {
assert!(opacities.iter().all(|o| *o == (0.4, 0.6)), "{opacities:?}");
}
/// `paint.setFill {opacity}` and `paint.setStroke {opacity}` with the opacity a mark already shows replace the opacity
/// another mark of the series left on the graph, as an explicit 100% does.
#[test]
fn a_paint_opacity_a_series_mark_already_shows_replaces_the_kept_opacity() {
let (mut s, id, _, marks) = column_marks();
s.execute("paint.setFill", &json!({"ids": [marks[0].0], "opacity": 40})).unwrap();
s.execute("paint.setStroke", &json!({"ids": [marks[0].0], "opacity": 60})).unwrap();
let kept = spec(&s, id).series_paints[0].clone();
assert_eq!((kept.fill_opacity, kept.stroke_opacity), (Some(0.4), Some(0.6)));
// The second mark is opaque already: its row comes out as it was.
s.execute("paint.setFill", &json!({"ids": [marks[1].0], "color": "#ff0000", "opacity": 100})).unwrap();
let kept = spec(&s, id).series_paints[0].clone();
assert_eq!((kept.fill_opacity, kept.stroke_opacity), (None, Some(0.6)));
s.execute("paint.setStroke", &json!({"ids": [marks[1].0], "opacity": 100})).unwrap();
let kept = spec(&s, id).series_paints[0].clone();
assert_eq!((kept.fill_opacity, kept.stroke_opacity), (None, None));
s.execute("graph.setData", &json!({"rows": [[1, 2], [3, 4]]})).unwrap();
let n = s.doc().unwrap().doc.node(id).unwrap().clone();
let opacities: Vec<(f32, f32)> =
series(&n, 0).children().unwrap().iter().map(|m| (m.appearance.fill().unwrap().opacity, m.appearance.stroke().unwrap().opacity)).collect();
assert!(opacities.iter().all(|o| *o == (1.0, 1.0)), "{opacities:?}");
}
/// The same for a graph's axis lines: a stroke opacity set on an opaque line replaces the one its kind keeps from another
/// line.
#[test]
fn a_stroke_opacity_an_axis_line_already_shows_replaces_the_kept_opacity() {
let mut s = Session::new();
s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap();
let id = graph(&mut s, "column");
let lines = line_nodes(&s, id);
s.execute("paint.setStroke", &json!({"ids": [lines[0].id.0], "opacity": 40})).unwrap();
let kept = |s: &Session| spec(s, id).label_styles.axis_rows.and_then(|r| r.paint.stroke_opacity);
assert_eq!(kept(&s), Some(0.4));
s.execute("paint.setStroke", &json!({"ids": [lines[1].id.0], "opacity": 100})).unwrap();
assert_eq!(kept(&s), None);
s.execute("graph.setData", &json!({"id": id.0, "csv": ",2024,2025\nQ1,3,2\nQ2,5,4\nQ3,-1,6"})).unwrap();
let opacities: Vec<f32> = line_nodes(&s, id).iter().map(|n| n.appearance.stroke().map_or(1.0, |st| st.opacity)).collect();
assert!(opacities.iter().all(|o| *o == 1.0), "{opacities:?}");
}
/// Clear Appearance and Reduce to Basic Appearance on a series mark take its fill and stroke opacity away, and the
/// graph keeps none, so the series stays opaque when it is drawn again.
#[test]
+25 -8
View File
@@ -27,7 +27,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 Live Paint group among the targets (or inside one) takes the fill on its faces 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 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 (with New Art Has Basic Appearance off, the next shape copies the first selected object's appearance after any command, its opacity included); with no paint or a solid color, the gradient mesh points picked with the Mesh tool, Direct Selection or the Lasso take it themselves, and with another paint the fill item takes it; 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, except for the color a grayscale or 1-bit image is drawn in, which creates none), 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 Live Paint group among the targets (or inside one) takes the fill on its faces 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 Line truncated
has_doc,
|s, p| set_paint(s, p, true)
),
@@ -243,14 +243,15 @@ impl Session {
/// first picked point's. The rows the command would edit are read in order (a group without an
/// active Appearance row stands for its contents), and the first that exists answers. `None`
/// with nothing selected, for an object selected in a symbol instance, while the Live Paint
/// Bucket is the active tool, while the Type tool has characters selected, and when only type
/// Bucket is the active tool (or another tool works for it, [`Session::bucket_paints`]), while
/// the Type tool has characters selected, and when only type
/// characters, objects without that item or the art of graph designs in a graph series are
/// selected.
pub fn proxy_opacity(&self, stroke: bool) -> Option<f32> {
let st = self.active()?;
// The Live Paint Bucket takes a fill or stroke chosen as the color it paints with, and the
// selection keeps its own (for_bucket).
if st.selection.symbol_part.is_some() || self.tool_id() == LIVE_PAINT_BUCKET {
if st.selection.symbol_part.is_some() || self.bucket_paints() {
return None;
}
// The command would give the opacity to the characters, which have none of their own.
@@ -604,7 +605,9 @@ fn set_paint(s: &mut Session, p: &Value, fill: bool) -> Result<Value> {
check_keep_model(p, cmd)?;
let opacity = opacity_param(p, cmd)?;
let paint = paint_from(s, p)?;
if paint.is_none() && opacity.is_none() {
// A `swatch` that is no name gives no paint, and does not turn the request into an opacity alone.
let swatch_not_a_name = p.get("swatch").is_some_and(|v| !v.is_null() && !v.is_string());
if paint.is_none() && (opacity.is_none() || swatch_not_a_name) {
return Err(bad(cmd, "give color, none, swatch, gradient or opacity"));
}
// As `paint.editGradient`: a `dither` given applies to gradient fills only. A gradient swatch
@@ -647,8 +650,10 @@ pub(crate) fn apply_paint(s: &mut Session, p: &Value, paint: Paint, fill: bool)
/// [`apply_paint`] with `paint` optional, which also sets the `opacity` (0..1) of the fill (or
/// stroke) item each target takes it on, in the same undo step: the picked gradient mesh points'
/// own opacity for a fill, nothing on a target without that item. The opacity alone changes neither
/// the defaults for new art nor the remembered colors. An opacity that would go only to type
/// own opacity for a fill (with no paint or a solid color), nothing on a target without that item.
/// The opacity alone changes neither the defaults for new art nor the remembered colors; with New
/// Art Has Basic Appearance off, new art copies the first selected object's appearance after any
/// command, its opacity included. An opacity that would go only to type
/// characters, to an object selected in a symbol instance, or to no target at all is an error.
fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity: Option<f32>, fill: bool) -> Result<Value> {
let cmd = if fill { "paint.setFill" } else { "paint.setStroke" };
@@ -781,6 +786,8 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
let characters = std::cell::RefCell::new(Vec::new());
// 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));
// The row each target took the opacity on, for what a graph keeps.
let opacity_written = std::cell::RefCell::new(Vec::new());
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);
@@ -866,6 +873,8 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
if let Some(item) = item {
*item = o;
took_opacity.borrow_mut().insert(n.id);
let at = index.or_else(|| n.appearance.items.iter().rposition(|it| it.is_fill() == fill));
opacity_written.borrow_mut().extend(at.map(|at| (n.id, at)));
}
};
// The objects counted: with a design's art, those with a row equal to the art's.
@@ -894,8 +903,16 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
}
return Err(bad(cmd, "no target has that fill or stroke to take the opacity"));
}
// A graph keeps the opacity of a series mark's topmost visible fill and stroke for the whole series.
let kept = opacity.is_some() && super::appearance::capture_series_changes(before, d, changed);
// A graph keeps the opacity of a series mark's topmost visible fill and stroke for the whole series, and of a
// graph line's, also when the object already showed it.
let kept = opacity.is_some() && {
let rows = opacity_written.borrow();
let on = super::graph::RowWrites { opacity: true, ..super::graph::RowWrites::NONE };
let (on_fill, on_stroke) = if fill { (on, super::graph::RowWrites::NONE) } else { (super::graph::RowWrites::NONE, on) };
let marks = super::appearance::capture_series_changes(before, d, changed);
let written = super::appearance::capture_series_opacity_writes(d, &rows);
marks | written | super::graph::capture_line_row_writes(d, &rows, on_fill, on_stroke)
};
let Some(paint) = &paint else { return Ok(kept) };
let series = super::appearance::capture_series_paint_writes(before, d, changed, &written.borrow());
// A graph line keeps the paint written to it, also when it already showed it.
+34
View File
@@ -449,3 +449,37 @@ fn the_live_paint_bucket_answers_no_opacity() {
assert!(s.execute("paint.setFill", &json!({"opacity": 40})).is_err());
assert_eq!(*s.doc().unwrap().doc, *doc);
}
/// The Eyedropper armed to sample into the Live Paint Bucket's gradient works for the bucket, so
/// the proxies answer no opacity for the selection then too, as they show no paint of its own.
#[test]
fn the_eyedropper_armed_for_the_bucket_answers_no_opacity() {
let mut s = session();
let id = rect(&mut s, 10.0);
select(&mut s, &[id]);
s.select_tool("eyedropper", ViewInfo::default()).unwrap();
assert_eq!(proxies(&mut s)["fillOpacity"], 100.0, "the Eyedropper alone shows the selection's");
s.set_tool_option("stop", &json!("livePaintBucket"));
assert!(s.bucket_paints());
assert_eq!(proxies(&mut s)["fillOpacity"], Value::Null);
assert_eq!(proxies(&mut s)["strokeOpacity"], Value::Null);
}
/// A `swatch` that is no name does not turn a request into an opacity alone: it is an error and
/// leaves the document as it was.
#[test]
fn a_swatch_that_is_no_name_is_refused_with_an_opacity() {
let mut s = session();
let id = rect(&mut s, 10.0);
select(&mut s, &[id]);
let doc = s.doc().unwrap().doc.clone();
for cmd in ["paint.setFill", "paint.setStroke"] {
for swatch in [json!(5), json!(true), json!(["a"]), json!({})] {
assert!(s.execute(cmd, &json!({"swatch": swatch, "opacity": 40})).is_err(), "{cmd} {swatch}");
}
// A null swatch names none, so the opacity goes alone.
s.execute(cmd, &json!({"swatch": null, "opacity": 40})).unwrap();
s.execute("edit.undo", &json!({})).unwrap();
}
assert_eq!(*s.doc().unwrap().doc, *doc);
}
+31 -3
View File
@@ -658,11 +658,13 @@ fn show_box(ui: &mut Ui, ch: Channel, hsb: [f32; 3], marked: bool, size: f32, ga
/// picks it), else that of the fill or stroke item
/// ([`vectorcraft_engine::Session::proxy_opacity`]), which nothing selected and type characters
/// do not have. A stop or point of a gradient on type characters belongs to the gradient, so the
/// row sets it. With nothing selected the stop or point belongs to the defaults for new art, which
/// the row leaves alone, and an object selected in a symbol instance has no opacity the row can set.
/// row sets it. With nothing selected, or while the Live Paint Bucket paints
/// ([`vectorcraft_engine::Session::bucket_paints`]), the stop or point belongs to the defaults for
/// new art, which the row leaves alone, and an object selected in a symbol instance has no opacity
/// the row can set.
fn shown_opacity(app: &VectorcraftApp, tgt: &Target) -> (f32, bool) {
let stroke = !app.session.fill_active;
let selected = app.session.active().is_some_and(|d| !d.selection.is_empty() && d.selection.symbol_part.is_none());
let selected = !app.session.bucket_paints() && app.session.active().is_some_and(|d| !d.selection.is_empty() && d.selection.symbol_part.is_none());
let point = |index: usize| match super::active_paint(app) {
Paint::Gradient(g) => super::gradient::shown_points(&g).points.get(index).map(|p| p.opacity),
_ => None,
@@ -700,6 +702,25 @@ fn apply_opacity(app: &mut VectorcraftApp, tgt: &Target, o: f32, phase: Live) {
}
}
/// Panel state: whether a drag of the Show Opacity row has previewed on an open interaction and not
/// been released.
const OPACITY_LIVE: &str = "color-wheel-opacity-live";
/// End the drag of the Show Opacity row when its row is hidden (`ui.colorWheel {opacity: false}`) or
/// turned gray before the release: the preview is kept as one undo step and the interaction ends.
fn end_opacity_drag(app: &mut VectorcraftApp, ui: &Ui) {
if !pstate::<bool>(ui.ctx(), OPACITY_LIVE) {
return;
}
if app.session.in_interaction()
&& let Err(e) = app.session.commit_interaction()
{
app.status(e.to_string());
}
app.sync_views();
set_pstate(ui.ctx(), OPACITY_LIVE, false);
}
/// The Show Opacity row: the Transparency panel's icon, a slider whose track shows `color` from
/// clear to solid, and a percent field. Gray when [`shown_opacity`] finds nothing to set.
fn opacity_row(app: &mut VectorcraftApp, ui: &mut Ui, tgt: &Target, color: &Color) {
@@ -724,6 +745,11 @@ fn opacity_row(app: &mut VectorcraftApp, ui: &mut Ui, tgt: &Target, color: &Colo
});
if let Some((v, phase)) = edit.filter(|_| live) {
apply_opacity(app, tgt, v, phase);
set_pstate(ui.ctx(), OPACITY_LIVE, phase == Live::Dragging);
}
// A drag whose row turned gray reports no release.
if !live {
end_opacity_drag(app, ui);
}
}
@@ -1200,6 +1226,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
set_pstate(ui.ctx(), MEMORY, Some((now, rgb, hsb)));
}
}
} else {
end_opacity_drag(app, ui);
}
let (mut picked_lch, mut picked_hsl) = (None, None);
match app.ui.color_wheel.sliders {
@@ -137,6 +137,34 @@ fn the_slider_sets_the_fill_opacity_and_takes_the_arrow_keys() {
assert_eq!((fill_opacity(h.state()) * 100.0).round(), before + 1.0);
}
/// Hiding the row during a drag on its slider keeps the opacity the drag previewed as one undo step
/// and leaves no interaction open.
#[test]
fn hiding_the_row_during_a_drag_keeps_its_opacity_as_one_undo_step() {
let mut h = harness(app());
let undo = undo_labels(h.state()).len();
let r = slider_rect(&h);
let at = |f: f32| Pos2::new(r.left() + 4.0 + f * (r.width() - 8.0), r.top() + 7.0);
let press = |h: &mut Harness<'static, VectorcraftApp>, pos: Pos2, pressed: bool| {
h.event(Event::PointerMoved(pos));
h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
h.run_steps(1);
};
press(&mut h, at(0.5), true);
for _ in 0..2 {
h.event(Event::PointerMoved(at(0.25)));
h.run_steps(1);
}
assert!(h.state().session.in_interaction(), "the drag previews");
let previewed = fill_opacity(h.state());
assert!((previewed - 0.25).abs() < 0.05, "{previewed}");
h.state_mut().run("ui.colorWheel", json!({"opacity": false})).unwrap();
h.run_steps(2);
assert!(!h.state().session.in_interaction(), "the interaction ended");
assert!((fill_opacity(h.state()) - previewed).abs() < 1e-6);
assert_eq!(undo_labels(h.state()).len(), undo + 1);
}
/// Screen readers get a slider named Opacity with its percentage and its range, and can step it and
/// set it.
#[test]
@@ -322,6 +350,16 @@ fn the_row_is_gray_with_nothing_selected_and_on_type() {
action(&mut h, Action::SetValue, Some(ActionData::NumericValue(25.0)));
assert_eq!(h.state().session.paint.fill, defaults);
// The Live Paint Bucket painting a gradient with an object selected: the stop is the bucket's.
let mut app = self::app();
app.session.select_tool("livePaintBucket", Default::default()).unwrap();
app.run("paint.setFill", json!({"gradient": {}})).unwrap();
let mut h = harness(app);
assert!(h.get_by_role_and_label(Role::Slider, "Opacity").accesskit_node().is_disabled());
let defaults = h.state().session.paint.fill.clone();
action(&mut h, Action::SetValue, Some(ActionData::NumericValue(25.0)));
assert_eq!(h.state().session.paint.fill, defaults);
// An object with a gradient fill selected in a dynamic symbol instance.
let mut app = self::app();
app.run("paint.setFill", json!({"gradient": {}})).unwrap();
+6 -3
View File
@@ -912,10 +912,13 @@ 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. Without a new paint, `objects` counts only the targets that took the opacity. `paint.proxies` answers it as `fillOpacity` and `strokeOpacity`, from the first selected object that has
undone. A `swatch` that is not a name does not make the request an opacity alone: it is an error without a paint of
its own. A color for a grayscale or 1-bit image's drawing color creates no fill row, so an opacity given with it goes
to a fill row the image has. With New Art Has Basic Appearance off, the next shape copies the first selected object's
appearance after any command, its opacity included. Without a new paint, `objects` counts only the targets that took the opacity. `paint.proxies` answers it as `fillOpacity` and `strokeOpacity`, from the first selected object that has
that row (a selected path of a compound path answers with its compound path's row, which the commands edit, and a
selected Live Paint group answers with its faces' fills and its edges' strokes). It answers null with nothing selected, for an object selected in a symbol instance, while the Live Paint Bucket is the
active tool, while the Type tool has characters selected, and when only type characters (which have no opacity of their own) or objects without that
selected Live Paint group answers with its faces' fills and its edges' strokes). It answers null with nothing selected, for an object selected in a symbol instance, while the Live Paint Bucket paints (it is the active tool, or a Cmd+click or an Eyedropper pick works for it),
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
`effect.remove`, `effect.setParams` (`visible` toggles one) and `effect.duplicate` address that item's effects;