Merge feat/color-wheel-opacity into feat/color-wheel-hex-alpha-css

This commit is contained in:
dotCooCoo committed 2026-11-16 02:37:31 -08:00
commit 2bd6094662
3 files changed
+44 -9

No files matched your search

+21
View File
@@ -1443,6 +1443,27 @@ fn paint_targets_leave_a_graph_designs_copy_out() {
assert_eq!(super::paint_targets(d, &[copy, art, mark]), [mark]);
}
/// The fill opacity the proxies show leaves out the art of a column or marker design in a series, which
/// `paint.setFill {opacity}` leaves out too: with only that art selected there is none, also with a row of the art
/// active, and with a mark selected after it the mark's.
#[test]
fn proxy_opacity_leaves_a_graph_designs_art_out() {
let (mut s, _, _, art, mark) = design_art();
let (mut m, _, marker_art) = marker_design_art();
for (s, art) in [(&mut s, art), (&mut m, marker_art)] {
s.execute("select.set", &json!({"ids": [art.0]})).unwrap();
assert_eq!(s.proxy_opacity(false), None);
assert!(s.execute("paint.setFill", &json!({"opacity": 50})).is_err());
let fill = top_row(s, art, true);
s.execute("appearance.setActiveItem", &json!({"index": fill})).unwrap();
assert_eq!(s.proxy_opacity(false), None, "with the art's fill row active");
assert!(s.execute("paint.setFill", &json!({"opacity": 50})).is_err());
}
s.execute("paint.setFill", &json!({"ids": [mark.0], "opacity": 40})).unwrap();
s.execute("select.set", &json!({"ids": [art.0, mark.0]})).unwrap();
assert!((s.proxy_opacity(false).unwrap() - 0.4).abs() < 1e-6, "the mark's fill opacity");
}
/// The art of a marker design in series 1 of a line graph: the design's copy and a path inside it.
fn marker_design_art() -> (Session, NodeId, NodeId) {
let mut s = Session::new();
+14 -9
View File
@@ -217,7 +217,8 @@ impl Session {
/// 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 Type tool has characters selected, and when only
/// type characters or objects without that item are selected.
/// 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()?;
if st.selection.symbol_part.is_some() {
@@ -242,16 +243,22 @@ impl Session {
if stroke { n.appearance.stroke_at(item).map(|s| s.opacity) } else { n.appearance.fill_at(item).map(|f| f.opacity) }
};
let subjects = st.selection.subjects();
// The command leaves out the art of a graph design in a series, which the graph draws again
// from the design, and a series group stands for the paths directly in it
// (graph::paint_targets).
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).
let first = subjects.first().and_then(|id| st.doc.node(*id));
// stacks; else the topmost one of the painted leaves (a group's contents). 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));
if active.is_some() {
return subjects.iter().filter_map(|id| st.doc.node(*id)).find_map(|n| of(n, active));
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()?;
leaves.iter().filter_map(|id| st.doc.node(*id)).find_map(|n| of(n, None))
leaves.iter().filter(editable).filter_map(|id| st.doc.node(*id)).find_map(|n| of(n, None))
}
pub(crate) fn remember_paint_now(&mut self, p: &Paint) {
@@ -553,10 +560,8 @@ pub(crate) fn apply_paint(s: &mut Session, p: &Value, paint: Paint, fill: bool)
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" };
let focus = switch_or(p, "focus", true, cmd)?;
let span = match &paint {
Some(paint) => spans_targets(p, paint).map_err(|e| bad(cmd, e))?,
None => false,
};
// 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()
+9
View File
@@ -156,6 +156,15 @@ fn errors_leave_the_document_and_defaults_alone() {
}
let e = s.execute("paint.setFill", &json!({})).unwrap_err();
assert!(e.to_string().contains("give color, none, swatch, gradient or opacity"), "{e}");
// An opacity alone places no gradient across the selection.
let doc = s.doc().unwrap().doc.clone();
for (span, says) in [(json!("selection"), "give `gradient`"), (json!("all"), "span must be \"object\" or \"selection\"")] {
let e = s.execute("paint.setFill", &json!({"opacity": 40, "span": span})).unwrap_err();
assert!(e.to_string().contains(says), "{span}: {e}");
}
assert_eq!(*s.doc().unwrap().doc, *doc);
s.execute("paint.setFill", &json!({"opacity": 40, "span": "object"})).unwrap();
assert!((fill_opacity(&s, id) - 0.4).abs() < 1e-6);
s.execute("select.none", &json!({})).unwrap();
let doc = s.doc().unwrap().doc.clone();
for p in [json!({"opacity": 40}), json!({"color": "#ff0000", "opacity": 40})] {