mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 10:30:03 +00:00
Color: a targeted layer shows the opacity of its editable art
With a layer targeted and no Appearance row active, the Opacity
readback walked the layer itself and could answer for a locked or
hidden object, while paint.setFill and paint.setStroke {opacity} edit
the layer's selected editable art. The readback now reads the painted
leaves of the selected objects, as the command does.
This commit is contained in:
@@ -249,7 +249,8 @@ impl Session {
|
||||
let editable = |id: &&NodeId| !super::graph::is_design_art(&st.doc, **id);
|
||||
// As the command picks its rows (ItemTarget::of_kind): the active item when it is a row of
|
||||
// this kind in the first selected object's stack, read in the selected objects' own
|
||||
// stacks; else the topmost one of the painted leaves (a group's contents). A row of a
|
||||
// stacks; else the topmost one of the painted leaves of the selected objects (a group's
|
||||
// contents; for a targeted layer, its editable art, ItemTarget::targets). A row of a
|
||||
// graph design's art selected first stands for nothing (item_target_at).
|
||||
let first = subjects.first().filter(editable).and_then(|id| st.doc.node(*id));
|
||||
let active = item.filter(|i| first.and_then(|n| n.appearance.items.get(*i)).is_some_and(|it| it.is_fill() == !stroke));
|
||||
@@ -257,7 +258,7 @@ 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()?;
|
||||
let leaves = super::leaf_targets(self, &st.selection.objects).ok()?;
|
||||
leaves.iter().filter(editable).filter_map(|id| st.doc.node(*id)).find_map(|n| of(n, None))
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,24 @@ fn a_group_with_its_own_fill_answers_for_its_contents() {
|
||||
assert!((node(&s, g).appearance.items[own].opacity() - 0.3).abs() < 1e-6, "the group's own fill keeps its opacity");
|
||||
}
|
||||
|
||||
/// A targeted layer without an active Appearance row: `paint.proxies` answers the opacity of the
|
||||
/// layer's editable art, which `paint.setFill {opacity}` sets, not that of a locked object before it.
|
||||
#[test]
|
||||
fn a_targeted_layer_answers_for_its_editable_art() {
|
||||
let mut s = session();
|
||||
let (locked, open) = (rect(&mut s, 10.0), rect(&mut s, 200.0));
|
||||
s.execute("paint.setFill", &json!({"ids": [locked.0], "opacity": 20})).unwrap();
|
||||
s.execute("paint.setFill", &json!({"ids": [open.0], "opacity": 80})).unwrap();
|
||||
s.execute("object.lock", &json!({"ids": [locked.0]})).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"], 80.0);
|
||||
s.execute("paint.setFill", &json!({"opacity": 40})).unwrap();
|
||||
assert!((fill_opacity(&s, open) - 0.4).abs() < 1e-6);
|
||||
assert!((fill_opacity(&s, locked) - 0.2).abs() < 1e-6, "the locked object keeps its opacity");
|
||||
assert_eq!(proxies(&mut s)["fillOpacity"], 40.0);
|
||||
}
|
||||
|
||||
/// With the Appearance panel's lower fill row active, that row takes the opacity and the top fill
|
||||
/// keeps its own.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user