mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 19:51:26 -05:00
Merge main into fix/xwayland-tablet-stylus
This commit is contained in:
@@ -874,6 +874,9 @@ pub(crate) use vectorcraft_doc::range::parse_range;
|
||||
/// What the fill and stroke proxies read from the selected objects, kept with the selection
|
||||
/// ([`crate::doc_state::SelectionRecord`]).
|
||||
pub(crate) use paint::SelectionPaints;
|
||||
/// The faces and edges of Live Paint groups among objects that count with their group
|
||||
/// ([`crate::DocState::live_paint_covered_kept`] keeps an empty answer).
|
||||
pub(crate) use paint::live_paint_covered;
|
||||
#[cfg(test)]
|
||||
pub(crate) use paint::{PAINTS_READ, WEIGHTS_READ};
|
||||
|
||||
|
||||
@@ -967,7 +967,8 @@ pub(crate) fn selection_roots(st: &crate::DocState) -> Vec<NodeId> {
|
||||
}
|
||||
#[cfg(test)]
|
||||
ROOTS_FOUND.set(ROOTS_FOUND.get() + 1);
|
||||
let roots = roots_of(&st.doc, st.selection.in_paint_order(&st.doc));
|
||||
let (ids, paths) = placed_in_paint_order(&st.doc, &st.selection.objects);
|
||||
let roots = roots_placed(&st.doc, ids, &paths, |_, _| false);
|
||||
*kept = Some((Arc::downgrade(&st.doc), st.selection.objects.clone(), roots.clone()));
|
||||
roots
|
||||
})
|
||||
@@ -1015,7 +1016,19 @@ pub(crate) fn no_symbol_part(s: &Session) -> std::result::Result<(), String> {
|
||||
pub(crate) fn selected_roots_to_transform(s: &Session) -> Result<Vec<NodeId>> {
|
||||
refuse_symbol_part(s)?;
|
||||
let st = s.doc()?;
|
||||
Ok(roots_within(&st.doc, st.selection.in_paint_order(&st.doc), |_, _| true))
|
||||
let (ids, paths) = placed_in_paint_order(&st.doc, &st.selection.objects);
|
||||
Ok(roots_placed(&st.doc, ids, &paths, |_, _| true))
|
||||
}
|
||||
|
||||
/// The objects of `objects` that are in `doc`, in paint order as
|
||||
/// [`vectorcraft_doc::Selection::in_paint_order`] gives them, with their places in the tree. One
|
||||
/// walk finds the places for both the order and [`roots_placed`] ([`roots_within`] after
|
||||
/// `in_paint_order` walks the tree twice).
|
||||
fn placed_in_paint_order(doc: &Document, objects: &[NodeId]) -> (Vec<NodeId>, HashMap<NodeId, Vec<usize>>) {
|
||||
let paths = doc.index_paths(objects.iter().copied());
|
||||
let mut ids: Vec<NodeId> = objects.iter().copied().filter(|id| paths.contains_key(id)).collect();
|
||||
ids.sort_by(|a, b| paths.get(a).cmp(&paths.get(b)));
|
||||
(ids, paths)
|
||||
}
|
||||
|
||||
/// [`selected_roots`] for the selected objects inside the isolated object `root`
|
||||
@@ -1027,8 +1040,9 @@ pub(crate) fn selected_roots_to_transform(s: &Session) -> Result<Vec<NodeId>> {
|
||||
pub(crate) fn selected_roots_inside(s: &Session, root: NodeId, members: bool) -> Result<Vec<NodeId>> {
|
||||
refuse_symbol_part(s)?;
|
||||
let st = s.doc()?;
|
||||
let ids = st.selection.in_paint_order(&st.doc).into_iter().filter(|id| super::inside_isolation(&st.doc, root, *id)).collect();
|
||||
Ok(roots_within(&st.doc, ids, |compound, _| members || compound == root))
|
||||
let (ids, paths) = placed_in_paint_order(&st.doc, &st.selection.objects);
|
||||
let ids = ids.into_iter().filter(|id| super::inside_isolation(&st.doc, root, *id)).collect();
|
||||
Ok(roots_placed(&st.doc, ids, &paths, |compound, _| members || compound == root))
|
||||
}
|
||||
|
||||
/// The top-level objects among `ids` (in paint order): compound-path members stand for their
|
||||
@@ -1042,6 +1056,11 @@ pub(crate) fn roots_of(doc: &Document, ids: Vec<NodeId>) -> Vec<NodeId> {
|
||||
fn roots_within(doc: &Document, ids: Vec<NodeId>, keep_member: impl Fn(NodeId, NodeId) -> bool) -> Vec<NodeId> {
|
||||
// Every id's place in the tree, found in one walk (a lookup per id is a walk per id).
|
||||
let paths = doc.index_paths(ids.iter().copied());
|
||||
roots_placed(doc, ids, &paths, keep_member)
|
||||
}
|
||||
|
||||
/// [`roots_within`] with `paths`, the places of `ids` in `doc`'s tree, found already.
|
||||
fn roots_placed(doc: &Document, ids: Vec<NodeId>, paths: &HashMap<NodeId, Vec<usize>>, keep_member: impl Fn(NodeId, NodeId) -> bool) -> Vec<NodeId> {
|
||||
// A compound-path member acts as its compound (compounds are one object).
|
||||
let mut sel: Vec<(NodeId, Option<Vec<usize>>)> = ids
|
||||
.into_iter()
|
||||
@@ -1105,7 +1124,8 @@ fn copy_cut_targets(s: &Session) -> Result<(bool, Vec<NodeId>)> {
|
||||
st.doc.node(compound).and_then(|n| n.children()).is_some_and(|members| !members.is_empty() && members.iter().all(|m| whole(m)))
|
||||
})
|
||||
};
|
||||
let roots = roots_within(&st.doc, st.selection.in_paint_order(&st.doc), |compound, _member| in_isolated_compound || !all_members_whole(compound));
|
||||
let (ids, paths) = placed_in_paint_order(&st.doc, &st.selection.objects);
|
||||
let roots = roots_placed(&st.doc, ids, &paths, |compound, _member| in_isolated_compound || !all_members_whole(compound));
|
||||
Ok((direct, roots))
|
||||
}
|
||||
|
||||
|
||||
@@ -348,6 +348,36 @@ fn direct_selection_cut_timing() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Finding the selected roots (for the menus, for Move and its siblings, for Copy and Cut, and
|
||||
/// inside an isolated group) walks the tree once for the paint order and the roots together, in
|
||||
/// paint order whatever order the objects were selected in.
|
||||
#[test]
|
||||
fn finding_the_selected_roots_walks_the_tree_once() {
|
||||
let mut s = session(2_000, square);
|
||||
let all = crate::tests_large_edits::layer(&s, 0);
|
||||
let reversed: Vec<u64> = all.iter().rev().map(|id| id.0).collect();
|
||||
s.execute("select.set", &json!({"ids": reversed})).unwrap();
|
||||
type Find = fn(&Session) -> Vec<NodeId>;
|
||||
let finds: [(&str, Find); 3] = [
|
||||
("the selected roots", |s| selected_roots(s).unwrap()),
|
||||
("the roots to transform", |s| selected_roots_to_transform(s).unwrap()),
|
||||
("Copy's targets", |s| copy_cut_targets(s).unwrap().1),
|
||||
];
|
||||
for (what, find) in finds {
|
||||
let walks = tree_walks();
|
||||
assert!(find(&s) == all, "{what} in paint order");
|
||||
assert_eq!(tree_walks() - walks, 1, "finding {what} walked the tree {} times", tree_walks() - walks);
|
||||
}
|
||||
s.execute("object.group", &json!({})).unwrap();
|
||||
let group = s.doc().unwrap().doc.layers[0].children().unwrap()[0].id;
|
||||
s.execute("select.set", &json!({"ids": reversed})).unwrap();
|
||||
// The first call also builds the lookup cache that the isolation check reads.
|
||||
assert!(selected_roots_inside(&s, group, false).unwrap() == all, "the roots inside the group in paint order");
|
||||
let walks = tree_walks();
|
||||
assert!(selected_roots_inside(&s, group, false).unwrap() == all);
|
||||
assert_eq!(tree_walks() - walks, 1, "finding the roots inside the group walked the tree {} times", tree_walks() - walks);
|
||||
}
|
||||
|
||||
/// The selected roots are found once for a document version and its selected objects, however many enabled checks
|
||||
/// read them, and found again after the selection changes, after an edit, and for another selection.
|
||||
#[test]
|
||||
|
||||
@@ -142,6 +142,18 @@ pub(crate) fn keep_compound_aligned(d: &mut Document, id: NodeId, sc: Scaling) {
|
||||
}
|
||||
}
|
||||
|
||||
/// [`keep_compound_aligned`] for the object at `path` in `d`'s tree, found already: the compound
|
||||
/// path is read at the parent's place, without looking either object up by id.
|
||||
pub(crate) fn keep_compound_aligned_at(d: &mut Document, path: &[usize], sc: Scaling) {
|
||||
let Some((_, up)) = path.split_last() else { return };
|
||||
if up.is_empty() || !d.node_at(up).is_some_and(|n| matches!(n.kind, NodeKind::Compound { .. }) && n.extras().pixel_aligned) {
|
||||
return;
|
||||
}
|
||||
if let Some(n) = d.node_mut_at(up) {
|
||||
snap_object(n, sc);
|
||||
}
|
||||
}
|
||||
|
||||
/// After any edit ([`Session::edit`]): snap each pixel-aligned object that the edit changed or added
|
||||
/// (its node in `doc` is not the one in `before`), with the pixel-aligned art of its linked opacity
|
||||
/// mask, to the pixel grid. Objects the edit did not touch are not visited.
|
||||
|
||||
@@ -66,10 +66,15 @@ pub(super) fn scaling_options(s: &Session, p: &Value) -> Scaling {
|
||||
/// param, else General › Transform Pattern Tiles)? Noted in the journal when they or the art of
|
||||
/// their linked opacity masks use a pattern, so a replay moves their tiles alike whatever the preference is then.
|
||||
pub(crate) fn transform_patterns(s: &mut Session, p: &Value, ids: &[NodeId]) -> Result<bool> {
|
||||
let paths = s.doc()?.doc.index_paths(ids.iter().copied());
|
||||
transform_patterns_at(s, p, ids, &paths)
|
||||
}
|
||||
|
||||
/// [`transform_patterns`] with `paths`, the places of `ids` in the document's tree, found already.
|
||||
fn transform_patterns_at(s: &mut Session, p: &Value, ids: &[NodeId], paths: &std::collections::HashMap<NodeId, Vec<usize>>) -> Result<bool> {
|
||||
let on = bool_or(p, "patterns", s.prefs.transform_pattern_tiles);
|
||||
let d = &s.doc()?.doc;
|
||||
let mut uses = false;
|
||||
let paths = d.index_paths(ids.iter().copied());
|
||||
for n in ids.iter().filter_map(|id| paths.get(id)).filter_map(|p| d.node_at(p)) {
|
||||
uses |= uses_pattern_with_masks(n);
|
||||
}
|
||||
@@ -152,7 +157,9 @@ fn apply_transform_moving_guides(
|
||||
let areas = bool_or(p, "typeAreas", false);
|
||||
let objects = transforms_objects(p);
|
||||
let mut sc = if Scaling::factor(xf).is_some() { scaling(s, p) } else { Scaling::default() };
|
||||
sc.patterns = transform_patterns(s, p, &ids)?;
|
||||
// The places of `ids`, found in one walk for Transform Patterns and for the edit below.
|
||||
let paths = s.doc()?.doc.index_paths(ids.iter().copied());
|
||||
sc.patterns = transform_patterns_at(s, p, &ids, &paths)?;
|
||||
let c = xf.as_coeffs();
|
||||
let is_translation = (c[0] - 1.0).abs() < 1e-9 && c[1].abs() < 1e-9 && c[2].abs() < 1e-9 && (c[3] - 1.0).abs() < 1e-9;
|
||||
let delta = guides.unwrap_or(Vec2::new(c[4], c[5]));
|
||||
@@ -174,8 +181,6 @@ fn apply_transform_moving_guides(
|
||||
// An edit normally preserves the tree positions already found here. Settling an active
|
||||
// typing session can change the document before the edit closure runs, so look up again then.
|
||||
let reindex = copy || (!s.previewing && crate::cmd::typing_in_progress(s));
|
||||
let d = &s.doc()?.doc;
|
||||
let paths = d.index_paths(ids.iter().copied());
|
||||
let none = paths.is_empty() && !has_guides;
|
||||
// A move of direct-selected anchors may re-map the handles beside them (`interpolate`).
|
||||
let mut interpolate = None;
|
||||
@@ -195,7 +200,7 @@ fn apply_transform_moving_guides(
|
||||
// A move of whole objects, not of copies (which `reindex` covers): the document before it,
|
||||
// and the moved objects as the transform left them, for [`moved_by`] to check after the edit.
|
||||
let from = (objects && !areas && !reindex && c[..4] == [1.0, 0.0, 0.0, 1.0]).then(|| s.doc().map(|st| st.doc.clone())).transpose()?;
|
||||
let mut held: Vec<(NodeId, Arc<Node>)> = vec![];
|
||||
let mut held: Vec<(Vec<usize>, Arc<Node>)> = vec![];
|
||||
let targets = s.edit(label, |d, sel| {
|
||||
let mut targets = match &kept {
|
||||
// The document becomes the snapshot with the kept copies, untransformed, and the
|
||||
@@ -235,11 +240,12 @@ fn apply_transform_moving_guides(
|
||||
}
|
||||
// Holding them makes any later change to them copy them first, which `moved_by` sees.
|
||||
if from.is_some() {
|
||||
held = targets.iter().filter_map(|id| Some((*id, node_arc(d, paths.get(id)?)?))).collect();
|
||||
held = targets.iter().filter_map(|id| paths.get(id)).filter_map(|p| Some((p.clone(), node_arc(d, p)?))).collect();
|
||||
}
|
||||
if objects {
|
||||
for id in &targets {
|
||||
super::pixelgrid::keep_compound_aligned(d, *id, sc);
|
||||
// The transforms above leave every object at its place, so `paths` still holds them.
|
||||
for p in targets.iter().filter_map(|id| paths.get(id)) {
|
||||
super::pixelgrid::keep_compound_aligned_at(d, p, sc);
|
||||
}
|
||||
// Moving all of the tile art moves the tile as far.
|
||||
if let Some(before) = tile_art {
|
||||
@@ -288,20 +294,22 @@ fn node_arc(d: &Document, path: &[usize]) -> Option<Arc<Node>> {
|
||||
}
|
||||
|
||||
/// The [`crate::Moved`] of a move by `by` that took `from` to the document of `st`, given the moved
|
||||
/// objects as the transform left them (`held`). `None` unless every moved object is still that
|
||||
/// node, none is a member of a blend (whose spine follows its members), and every object the
|
||||
/// selection shows, the key object and the key anchor's object included, is a moved object or
|
||||
/// inside one. A pass after the transform that changes a moved object, such as the one that snaps
|
||||
/// moved pixel-aligned objects to the pixel grid again ([`super::pixelgrid::refresh`]), copies it
|
||||
/// first, so it is no longer that node.
|
||||
fn moved_by(from: &Arc<Document>, st: &crate::DocState, held: &[(NodeId, Arc<Node>)], by: Vec2) -> Option<crate::Moved> {
|
||||
/// objects as the transform left them (`held`, each with its index path). `None` unless every moved
|
||||
/// object is still that node at its path, none is a member of a blend (whose spine follows its
|
||||
/// members), and every object the selection shows, the key object and the key anchor's object
|
||||
/// included, is a moved object or inside one. A pass after the transform that changes a moved
|
||||
/// object, such as the one that snaps moved pixel-aligned objects to the pixel grid again
|
||||
/// ([`super::pixelgrid::refresh`]), copies it first, so it is no longer that node. The checks read
|
||||
/// the nodes at their paths and look nothing up by id.
|
||||
fn moved_by(from: &Arc<Document>, st: &crate::DocState, held: &[(Vec<usize>, Arc<Node>)], by: Vec2) -> Option<crate::Moved> {
|
||||
let d = &st.doc;
|
||||
let unchanged = |(id, n): &(NodeId, Arc<Node>)| d.node(*id).is_some_and(|now| std::ptr::eq(now, Arc::as_ptr(n)));
|
||||
let unchanged = |(p, n): &(Vec<usize>, Arc<Node>)| d.node_at(p).is_some_and(|now| std::ptr::eq(now, Arc::as_ptr(n)));
|
||||
if held.is_empty() || !held.iter().all(unchanged) {
|
||||
return None;
|
||||
}
|
||||
let in_blend = |id: NodeId| d.parent_of(id).and_then(|p| d.node(p)).is_some_and(|p| matches!(p.kind, NodeKind::Blend { .. }));
|
||||
if held.iter().any(|(id, _)| in_blend(*id)) {
|
||||
// The node at each path is the moved object, so its parent is the node one level up.
|
||||
let in_blend = |p: &[usize]| p.split_last().and_then(|(_, up)| d.node_at(up)).is_some_and(|parent| matches!(parent.kind, NodeKind::Blend { .. }));
|
||||
if held.iter().any(|(p, _)| in_blend(p)) {
|
||||
return None;
|
||||
}
|
||||
let mut moved = std::collections::HashSet::new();
|
||||
|
||||
@@ -1470,12 +1470,13 @@ fn in_live_paint(d: &Document, id: NodeId) -> bool {
|
||||
|
||||
impl DocState {
|
||||
/// [`live_paint_covered`] for `ids`, the selected objects or the selection's subjects: none
|
||||
/// when the [`SelectionPaints`] of the selection say no selected object is in a Live Paint group.
|
||||
/// when the [`SelectionPaints`] of the selection say no selected object is in a Live Paint group,
|
||||
/// else as [`DocState::live_paint_covered_kept`] keeps it for this version of the document.
|
||||
pub(crate) fn selection_live_paint_covered(&self, ids: &[NodeId]) -> std::collections::HashSet<NodeId> {
|
||||
if self.selection_paints().is_some_and(|p| !p.in_live_paint()) {
|
||||
return std::collections::HashSet::new();
|
||||
}
|
||||
live_paint_covered(&self.doc, ids)
|
||||
self.live_paint_covered_kept(ids)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -242,6 +242,58 @@ fn the_question_marks_read_only_the_selected_objects() {
|
||||
assert!(vectorcraft_doc::tree_walks() - walks <= 1, "one walk for a large selection");
|
||||
}
|
||||
|
||||
/// How many times this thread read the groups around selected objects for their Live Paint faces
|
||||
/// and edges ([`DocState::live_paint_covered_kept`]).
|
||||
fn cover_reads() -> usize {
|
||||
crate::doc_state::LIVE_PAINT_COVER_READS.with(Cell::get)
|
||||
}
|
||||
|
||||
/// After an edit the selection keeps no record of what it holds, and the proxies, the Stroke panel
|
||||
/// and the "?" ask on every frame whether its objects lie in a Live Paint group. They read the
|
||||
/// objects' groups once for each version of the document and selection, not once for each question.
|
||||
/// A Live Paint group selected with one of its faces still counts the face with its group.
|
||||
#[test]
|
||||
fn live_paint_faces_are_looked_for_once_per_document_version() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 800, "height": 600})).unwrap();
|
||||
let ids: Vec<NodeId> = (0..20).map(|i| rect(&mut s, 10.0 + 30.0 * f64::from(i), "#ff0000", "#000000")).collect();
|
||||
s.execute("select.all", &json!({})).unwrap();
|
||||
s.execute("object.move", &json!({"dx": 5, "dy": 0})).unwrap();
|
||||
assert!(s.active().unwrap().selection_paints().is_none(), "the edit leaves the selection without a record");
|
||||
let ask = |s: &Session| {
|
||||
for _ in 0..3 {
|
||||
s.proxy_paints();
|
||||
s.shown_stroke();
|
||||
s.proxy_mixed();
|
||||
s.active().unwrap().stroke_mixed();
|
||||
}
|
||||
};
|
||||
let before = cover_reads();
|
||||
ask(&s);
|
||||
assert_eq!(cover_reads() - before, 1, "one read for this version of the document");
|
||||
s.execute("object.move", &json!({"dx": 5, "dy": 0})).unwrap();
|
||||
let before = cover_reads();
|
||||
ask(&s);
|
||||
assert_eq!(cover_reads() - before, 1, "an edit reads them again, once");
|
||||
s.execute("select.set", &json!({"ids": [ids[0].0, ids[1].0]})).unwrap();
|
||||
s.execute("object.move", &json!({"dx": 5, "dy": 0})).unwrap();
|
||||
let before = cover_reads();
|
||||
ask(&s);
|
||||
assert_eq!(cover_reads() - before, 1, "another selection reads them again, once");
|
||||
|
||||
// A Live Paint group with one of its edges selected too: the edge counts with its group on every ask.
|
||||
s.execute("livePaint.make", &json!({"ids": [ids[2].0, ids[3].0]})).unwrap();
|
||||
let group = s.active().unwrap().selection.objects[0];
|
||||
let edge = vectorcraft_tools::builder::edges(s.active().unwrap().doc.node(group).unwrap())[0].id;
|
||||
s.execute("select.set", &json!({"ids": [group.0, edge.0]})).unwrap();
|
||||
let st = s.active().unwrap();
|
||||
let covered = live_paint_covered(&st.doc, &st.selection.objects);
|
||||
assert!(covered.contains(&edge));
|
||||
for _ in 0..2 {
|
||||
assert_eq!(st.selection_live_paint_covered(&st.selection.objects), covered);
|
||||
}
|
||||
}
|
||||
|
||||
/// Random selections of a document with nested groups answer as a walk does.
|
||||
#[test]
|
||||
fn random_selections_match_a_walk_of_the_document() {
|
||||
|
||||
@@ -725,6 +725,8 @@ impl Session {
|
||||
for e in self.prefs.keep_folders(&mut p) {
|
||||
log::warn!("{e}");
|
||||
}
|
||||
// Tool settings saved by an earlier version are updated once.
|
||||
p.migrate_tool_settings();
|
||||
// Saved gradient presets get names no built-in preset or other saved one has.
|
||||
for (old, new) in super::gradpresets::rename_clashing_presets(&mut p.gradient_presets) {
|
||||
log::warn!("saved gradient preset {old} is listed as {new}: another preset has its name");
|
||||
|
||||
@@ -1027,6 +1027,84 @@ fn used_colors(d: &Document, ids: &[NodeId], only: Option<&BTreeSet<NodeId>>) ->
|
||||
used.into_iter().map(|(_, u)| u).collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
thread_local! {
|
||||
/// Tests: how many objects [`several_colors`] read on this thread.
|
||||
static SEVERAL_COLORS_READS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
|
||||
/// Whether [`used_colors`] lists more than one color for the objects `ids`. The objects are read
|
||||
/// until a second color turns up.
|
||||
fn several_colors(d: &Document, ids: &[NodeId], only: Option<&BTreeSet<NodeId>>) -> bool {
|
||||
struct Seen<'a> {
|
||||
first: Option<ColorKey>,
|
||||
several: bool,
|
||||
patterns: Vec<&'a str>,
|
||||
}
|
||||
impl<'a> Seen<'a> {
|
||||
fn read(&mut self, m: &'a Node) {
|
||||
#[cfg(test)]
|
||||
SEVERAL_COLORS_READS.with(|c| c.set(c.get() + 1));
|
||||
let (first, several) = (&mut self.first, &mut self.several);
|
||||
paints(
|
||||
m,
|
||||
&mut |c, _, _, _| {
|
||||
let k = ColorKey::of(c);
|
||||
match first {
|
||||
None => *first = Some(k),
|
||||
Some(f) => *several |= *f != k,
|
||||
}
|
||||
},
|
||||
&mut self.patterns,
|
||||
);
|
||||
}
|
||||
fn read_tree(&mut self, n: &'a Node, only: Option<&BTreeSet<NodeId>>) {
|
||||
if self.several || only.is_some_and(|o| !o.contains(&n.id)) {
|
||||
return;
|
||||
}
|
||||
self.read(n);
|
||||
for c in n.children().into_iter().flatten() {
|
||||
self.read_tree(c, only);
|
||||
if self.several {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut seen = Seen { first: None, several: false, patterns: vec![] };
|
||||
for n in ids.iter().filter_map(|id| d.node(*id)) {
|
||||
seen.read_tree(n, only);
|
||||
if seen.several {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
let mut next = 0;
|
||||
while !seen.several
|
||||
&& let Some(&name) = seen.patterns.get(next)
|
||||
{
|
||||
next += 1;
|
||||
for a in d.pattern(name).map(|def| def.art.as_slice()).unwrap_or_default() {
|
||||
let _ = a.try_walk(&mut |m| {
|
||||
seen.read(m);
|
||||
if seen.several { std::ops::ControlFlow::Break(()) } else { std::ops::ControlFlow::Continue(()) }
|
||||
});
|
||||
if seen.several {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
seen.several
|
||||
}
|
||||
|
||||
impl Session {
|
||||
/// Whether the objects `recolor.colors` reads without `ids` use more than one color: the
|
||||
/// selection, or with nothing selected the objects Select All takes. False without a document.
|
||||
pub fn several_colors_used(&self) -> bool {
|
||||
let Ok((ids, only)) = scope_ids(self, &Value::Null, "recolor.colors") else { return false };
|
||||
self.doc().is_ok_and(|st| several_colors(&st.doc, &ids, only.as_ref()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Count the colors `m` holds itself with `count` (the color, its swatch, the tint the paint
|
||||
/// stores, and whether it is a gradient stop that mixes the swatch's ink with process inks), and
|
||||
/// add the patterns it is painted with to `patterns`.
|
||||
@@ -2050,6 +2128,69 @@ mod tests {
|
||||
assert!(has(&t, RED), "P100 read again at the top");
|
||||
}
|
||||
|
||||
/// How many objects [`several_colors`] read on this thread.
|
||||
fn several_reads() -> usize {
|
||||
SEVERAL_COLORS_READS.with(std::cell::Cell::get)
|
||||
}
|
||||
|
||||
/// Whether more than one color is used ([`Session::several_colors_used`]), checked against the
|
||||
/// length of `recolor.colors`'s list, with how many objects the answer read.
|
||||
fn several(s: &mut Session, what: &str) -> (bool, usize) {
|
||||
let before = several_reads();
|
||||
let several = s.several_colors_used();
|
||||
let reads = several_reads() - before;
|
||||
let listed = s.execute("recolor.colors", &json!({})).unwrap()["colors"].as_array().map_or(0, Vec::len);
|
||||
assert_eq!(several, listed > 1, "{what}: {listed} colors listed");
|
||||
(several, reads)
|
||||
}
|
||||
|
||||
/// The Recolor quick action asks on every change whether the selection uses more than one
|
||||
/// color. The answer matches `recolor.colors`, pattern tiles and Select All's objects included,
|
||||
/// and the objects are read only until a second color turns up.
|
||||
#[test]
|
||||
fn several_colors_stop_at_the_second_color() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 800, "height": 600})).unwrap();
|
||||
let ids: Vec<u64> = (0..30)
|
||||
.map(|i| {
|
||||
let id =
|
||||
s.execute("shape.rectangle", &json!({"x": 10 + 20 * i, "y": 10, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap();
|
||||
s.execute("paint.setFill", &json!({"ids": [id], "color": "#ff0000"})).unwrap();
|
||||
s.execute("paint.setStroke", &json!({"ids": [id], "none": true})).unwrap();
|
||||
id
|
||||
})
|
||||
.collect();
|
||||
s.execute("select.all", &json!({})).unwrap();
|
||||
assert_eq!(several(&mut s, "one red"), (false, 30), "one color: every object is read");
|
||||
// A blue object in the middle: the objects are read up to it, from either end.
|
||||
s.execute("paint.setFill", &json!({"ids": [ids[15]], "color": "#0000ff"})).unwrap();
|
||||
let (found, reads) = several(&mut s, "a blue in the middle");
|
||||
assert!(found && matches!(reads, 15 | 16), "{reads} objects read");
|
||||
s.execute("paint.setFill", &json!({"ids": [ids[0], ids[29]], "color": "#00ff00"})).unwrap();
|
||||
assert_eq!(several(&mut s, "green at both ends"), (true, 2), "the second object holds the second color");
|
||||
s.execute("select.set", &json!({"ids": &ids[1..15]})).unwrap();
|
||||
assert!(!several(&mut s, "the red ones").0);
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
assert!(several(&mut s, "Select All's objects").0);
|
||||
|
||||
// A red object filled with a pattern too: its tile's color counts.
|
||||
for (tile, expect) in [(BLUE, true), (RED, false)] {
|
||||
let filled = NodeId(ids[1]);
|
||||
s.edit("t", |d, _| {
|
||||
let art = square(d, 0.0, Paint::solid(tile));
|
||||
d.patterns.retain(|p| p.name != "Tile");
|
||||
d.patterns.push(PatternDef::new("Tile", vec![art]));
|
||||
if let Some(n) = d.node_mut(filled) {
|
||||
n.appearance.set_fill(Paint::Pattern { pattern: "Tile".into(), xf: Affine::IDENTITY });
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
s.execute("select.set", &json!({"ids": [ids[1], ids[2]]})).unwrap();
|
||||
assert_eq!(several(&mut s, "a pattern tile").0, expect, "a tile of {tile:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A pattern tile's symbol instances charge the same limit as the art around it.
|
||||
#[test]
|
||||
fn pattern_tiles_charge_the_symbol_limit() {
|
||||
|
||||
@@ -203,11 +203,23 @@ pub struct DocState {
|
||||
/// The selected objects as [`crate::Session::select`] last checked them or the proxies last
|
||||
/// read them, with the document they were checked in ([`SelectionRecord`]). Not saved.
|
||||
pub(crate) selection_record: Option<SelectionRecord>,
|
||||
/// The objects that [`DocState::live_paint_covered_kept`] last found no face or edge of a Live
|
||||
/// Paint group among, with the document it read. Not saved.
|
||||
outside_live_paint: std::cell::RefCell<Option<OutsideLivePaint>>,
|
||||
/// The last move of the selected objects that changed nothing else they show ([`Moved`]).
|
||||
/// Not saved.
|
||||
pub moved: Option<Moved>,
|
||||
}
|
||||
|
||||
/// Objects that hold no face or edge of a Live Paint group that counts with its group
|
||||
/// ([`cmd::live_paint_covered`] is empty for them), with the document they were read in, held as
|
||||
/// [`EmptyArtboards::doc`] holds it.
|
||||
#[derive(Clone, Debug)]
|
||||
struct OutsideLivePaint {
|
||||
doc: std::sync::Weak<Document>,
|
||||
ids: Vec<NodeId>,
|
||||
}
|
||||
|
||||
/// A move of whole objects that took document `from` to document `to`: each object the selection
|
||||
/// shows, the key object and the key anchor included, is the one in `from` moved by `by`, and
|
||||
/// nothing else they are drawn from changed (no member snapped to the pixel grid, no blend spine
|
||||
@@ -320,6 +332,8 @@ thread_local! {
|
||||
pub(crate) static EMPTY_ARTBOARD_MEASURES: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
/// Tests: how many times [`DocState::any_art_to_fit`] measured a document on this thread.
|
||||
pub(crate) static ART_TO_FIT_MEASURES: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
/// Tests: how many times [`DocState::live_paint_covered_kept`] read the objects' groups on this thread.
|
||||
pub(crate) static LIVE_PAINT_COVER_READS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
|
||||
static NEXT_DOC_UID: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
|
||||
@@ -540,6 +554,7 @@ impl DocState {
|
||||
measured_in_own: None,
|
||||
inline_resolved: None,
|
||||
selection_record: None,
|
||||
outside_live_paint: Default::default(),
|
||||
moved: None,
|
||||
}
|
||||
}
|
||||
@@ -558,6 +573,25 @@ impl DocState {
|
||||
pub(crate) fn selection_paints(&self) -> Option<&cmd::SelectionPaints> {
|
||||
self.selection_record().and_then(|r| r.paints.as_ref())
|
||||
}
|
||||
/// The faces and edges of Live Paint groups among `ids` that count with their group
|
||||
/// ([`cmd::live_paint_covered`]). An empty answer is kept for this version of the document and
|
||||
/// these objects, so the proxies and the Stroke panel, which ask on every frame, read the
|
||||
/// objects' groups once after an edit.
|
||||
pub(crate) fn live_paint_covered_kept(&self, ids: &[NodeId]) -> std::collections::HashSet<NodeId> {
|
||||
let kept = |k: &OutsideLivePaint| std::ptr::eq(k.doc.as_ptr(), Arc::as_ptr(&self.doc)) && k.ids == ids;
|
||||
if self.outside_live_paint.try_borrow().is_ok_and(|k| k.as_ref().is_some_and(kept)) {
|
||||
return std::collections::HashSet::new();
|
||||
}
|
||||
#[cfg(test)]
|
||||
LIVE_PAINT_COVER_READS.with(|c| c.set(c.get() + 1));
|
||||
let covered = cmd::live_paint_covered(&self.doc, ids);
|
||||
if covered.is_empty()
|
||||
&& let Ok(mut k) = self.outside_live_paint.try_borrow_mut()
|
||||
{
|
||||
*k = Some(OutsideLivePaint { doc: Arc::downgrade(&self.doc), ids: ids.to_vec() });
|
||||
}
|
||||
covered
|
||||
}
|
||||
/// Keep the [`SelectionRecord`] of the selection that [`crate::Session::select`] left, with
|
||||
/// Lock Guides `guides_locked`. `record` is the record of the selection before, in the same
|
||||
/// document: the objects that leave the selection are taken out of its paints and the objects
|
||||
|
||||
@@ -438,6 +438,12 @@ pub struct Prefs {
|
||||
/// resetting the preferences keeps them; `tool.setOption` edits them.
|
||||
#[serde(skip_serializing_if = "std::collections::BTreeMap::is_empty")]
|
||||
pub tool_settings: std::collections::BTreeMap<String, serde_json::Map<String, Value>>,
|
||||
/// The version of [`Self::tool_settings`]: [`TOOL_SETTINGS_VERSION`] once this version stores
|
||||
/// or updates a tool setting, 0 while none is stored and in preferences saved without one.
|
||||
/// [`Prefs::migrate_tool_settings`] updates older tool settings once. Not a Preferences dialog
|
||||
/// field: resetting the preferences keeps it.
|
||||
#[serde(default, skip_serializing_if = "is_zero")]
|
||||
pub tool_settings_version: u32,
|
||||
/// View → Perspective Grid presets: the user's (the built-in ones aren't stored). A local
|
||||
/// library, not a Preferences dialog field: resetting the preferences keeps it;
|
||||
/// `perspective.presets.*` edit it.
|
||||
@@ -464,7 +470,36 @@ pub const KEY_HOLD_DELAY: f64 = 0.35;
|
||||
/// The range of the Hold Shortcut Delay, in seconds.
|
||||
pub const KEY_HOLD_DELAY_RANGE: (f64, f64) = (0.2, 1.0);
|
||||
|
||||
/// The version of the tool settings these preferences write ([`Prefs::tool_settings_version`]).
|
||||
/// Version 1 makes Color Swatches the Shape Builder's Pick Color From.
|
||||
pub const TOOL_SETTINGS_VERSION: u32 = 1;
|
||||
|
||||
fn is_zero(v: &u32) -> bool {
|
||||
*v == 0
|
||||
}
|
||||
|
||||
impl Prefs {
|
||||
/// Update tool settings saved by an earlier version to [`TOOL_SETTINGS_VERSION`], once. Before
|
||||
/// version 1, leaving the Shape Builder saved its `pickColorFrom` whether or not it was
|
||||
/// changed, so a saved `artwork` becomes `swatches`. Without tool settings, nothing changes; a
|
||||
/// version newer than this one is kept.
|
||||
pub fn migrate_tool_settings(&mut self) {
|
||||
if self.tool_settings_version < 1
|
||||
&& let Some(saved) = self.tool_settings.get_mut("shapeBuilder")
|
||||
&& saved.get("pickColorFrom").and_then(Value::as_str) == Some("artwork")
|
||||
{
|
||||
saved.insert("pickColorFrom".into(), Value::from("swatches"));
|
||||
}
|
||||
self.mark_tool_settings_current();
|
||||
}
|
||||
|
||||
/// Record that [`Self::tool_settings`], when any is stored, is in this version's form.
|
||||
pub(crate) fn mark_tool_settings_current(&mut self) {
|
||||
if !self.tool_settings.is_empty() {
|
||||
self.tool_settings_version = self.tool_settings_version.max(TOOL_SETTINGS_VERSION);
|
||||
}
|
||||
}
|
||||
|
||||
/// The `document.open` / place params `p` with `embeddedFonts: false` added when Preferences
|
||||
/// › File Handling › Use fonts embedded in imported PDFs is off and `p` gives no choice of its own.
|
||||
pub fn with_pdf_font_choice(&self, p: &serde_json::Value) -> serde_json::Value {
|
||||
@@ -672,6 +707,7 @@ impl Default for Prefs {
|
||||
use_registration_point_for_symbol: false,
|
||||
show_on_shape_creation: false,
|
||||
tool_settings: Default::default(),
|
||||
tool_settings_version: 0,
|
||||
perspective_presets: vec![],
|
||||
blend_options: None,
|
||||
perspective_widget: Default::default(),
|
||||
|
||||
@@ -1753,7 +1753,8 @@ fn shape_builder_swatches_keep_the_current_fill_and_the_first_covered_objects_lo
|
||||
}
|
||||
|
||||
/// The Shape Builder tool sends the point where the drag started first and the point where it
|
||||
/// ended last, so a drag from the hole into the square takes the square's look.
|
||||
/// ended last, so with Pick Color From Artwork a drag from the hole into the square takes the
|
||||
/// square's look.
|
||||
#[test]
|
||||
fn shape_builder_tool_drag_from_the_hole_takes_the_look_where_it_ends() {
|
||||
let mut s = session();
|
||||
@@ -1762,6 +1763,7 @@ fn shape_builder_tool_drag_from_the_hole_takes_the_look_where_it_ends() {
|
||||
select_ids(&mut s, &bars.iter().copied().chain([red]).collect::<Vec<_>>());
|
||||
let v = ViewInfo::default();
|
||||
s.select_tool("shapeBuilder", v).unwrap();
|
||||
s.set_tool_option_cmd(&json!({"tool": "shapeBuilder", "values": {"pickColorFrom": "artwork"}})).unwrap();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Down, 50.0, 50.0), v).unwrap();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Drag, 85.0, 50.0), v).unwrap();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Drag, 120.0, 50.0), v).unwrap();
|
||||
@@ -1853,6 +1855,7 @@ fn shape_builder_arrow_keys_step_the_current_fill_through_the_swatches() {
|
||||
let v = ViewInfo::default();
|
||||
s.select_tool("shapeBuilder", v).unwrap();
|
||||
let chips = |s: &mut Session| s.overlays(v).iter().filter(|o| matches!(o, vectorcraft_tools::Overlay::Swatch { .. })).count();
|
||||
s.set_tool_option_cmd(&json!({"tool": "shapeBuilder", "values": {"pickColorFrom": "artwork"}})).unwrap();
|
||||
assert!(!s.tool_claims_key(ToolKey::Right, v), "Artwork leaves the arrows to nudging");
|
||||
let values = json!({"pickColorFrom": "swatches", "cursorSwatchPreview": true});
|
||||
s.set_tool_option_cmd(&json!({"tool": "shapeBuilder", "values": values})).unwrap();
|
||||
@@ -2071,6 +2074,31 @@ fn shape_builder_fill_preview_is_put_back_by_a_cancel() {
|
||||
assert_eq!(s.paint.fill, before, "the cancel puts the fill back");
|
||||
}
|
||||
|
||||
/// With the Shape Builder's default options, a fill picked while it is active (a swatch or a
|
||||
/// color) fills the next merge: the tool sends `pickColorFrom: "swatches"`, and the merged shape
|
||||
/// is not the red or blue of the art.
|
||||
#[test]
|
||||
fn shape_builder_default_merge_fills_with_the_picked_fill() {
|
||||
let v = ViewInfo::default();
|
||||
for pick in [json!({"swatch": "Leaf"}), json!({"color": "#ff8800"})] {
|
||||
let mut s = session();
|
||||
two(&mut s);
|
||||
s.execute("swatch.new", &json!({"name": "Leaf", "color": "#00ff00"})).unwrap();
|
||||
s.select_tool("shapeBuilder", v).unwrap();
|
||||
s.execute("paint.setFill", &pick).unwrap();
|
||||
let picked = s.paint.fill.clone();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Down, 25.0, 50.0), v).unwrap();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Drag, 75.0, 50.0), v).unwrap();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Drag, 125.0, 50.0), v).unwrap();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Up, 125.0, 50.0), v).unwrap();
|
||||
let (cmd, params) = s.journal.last().unwrap().clone();
|
||||
assert_eq!((cmd.as_str(), ¶ms["pickColorFrom"]), ("shapeBuilder.merge", &json!("swatches")), "{pick}");
|
||||
let d = &s.doc().unwrap().doc;
|
||||
let fills: Vec<Paint> = d.children(d.default_layer()).into_iter().flatten().map(|n| n.appearance.fill_paint()).collect();
|
||||
assert_eq!(fills, vec![picked], "{pick}: the two squares merged into one shape with the picked fill");
|
||||
}
|
||||
}
|
||||
|
||||
/// With Pick Color From Color Swatches, a merge fills with the fill chosen while the Shape Builder
|
||||
/// is active, and the Gradient panel's eyedropper samples into a stop of that fill's gradient.
|
||||
#[test]
|
||||
|
||||
@@ -253,6 +253,24 @@ fn transform_each_with_copy_of_50000_objects_takes_few_tree_walks() {
|
||||
undo_gives_back(&mut s, &before);
|
||||
}
|
||||
|
||||
/// A move of 10,000 selected objects walks the tree once for the paint order and the top-level
|
||||
/// objects, once for Transform Patterns and the edit, and once for the selection's check after the
|
||||
/// edit. It reads each object's compound path at the object's place, so the only lookups by id are
|
||||
/// the range check's, one per object.
|
||||
#[test]
|
||||
fn moving_10000_selected_objects_walks_the_tree_three_times() {
|
||||
let n = 10_000;
|
||||
let mut s = session(n, square);
|
||||
let ids = layer(&s, 0);
|
||||
let (walks, lookups) = (vectorcraft_doc::tree_walks(), vectorcraft_doc::path_lookups());
|
||||
s.execute("object.move", &json!({"dx": 3, "dy": 0})).unwrap();
|
||||
let (walks, lookups) = (vectorcraft_doc::tree_walks() - walks, vectorcraft_doc::path_lookups() - lookups);
|
||||
assert_eq!(walks, 3, "walked the tree {walks} times");
|
||||
assert!(lookups <= n as u64, "{lookups} lookups by id for {n} objects");
|
||||
assert_eq!(bounds(&s, ids[n - 1]), square_at(n - 1) + vectorcraft_geom::Vec2::new(3.0, 0.0));
|
||||
assert!(selected(&s, &ids));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offset_path_of_50000_objects_takes_few_tree_walks() {
|
||||
let s = session(50_000, square);
|
||||
|
||||
@@ -698,3 +698,55 @@ fn a_parametric_shape_kind_and_its_values_set_together() {
|
||||
assert_eq!(s.tool_options_of("parametricShape")["kind"], json!("star"), "a refused call sets nothing");
|
||||
}
|
||||
}
|
||||
|
||||
/// The Shape Builder picks colors from the color swatches by default: a fresh session, and saved
|
||||
/// preferences that hold other Shape Builder options but no `pickColorFrom`, give `swatches`.
|
||||
/// Preferences saved without `toolSettingsVersion` read a saved `artwork` as `swatches` once and
|
||||
/// are then written with the version, so a later `artwork` is kept. A saved `swatches` is kept.
|
||||
#[test]
|
||||
fn shape_builder_pick_color_from_defaults_to_swatches_and_migrates_a_saved_artwork_once() {
|
||||
let mut s = session();
|
||||
select(&mut s, "shapeBuilder");
|
||||
assert_eq!(s.tool_options()["pickColorFrom"], json!("swatches"), "a fresh session");
|
||||
select(&mut s, "selection");
|
||||
assert_eq!(s.prefs.to_json()["toolSettingsVersion"], json!(1), "stored settings are written with the version");
|
||||
let load = |version: Option<u32>, saved: &Value| {
|
||||
let mut prefs = Prefs::default().to_json();
|
||||
prefs["toolSettings"] = json!({ "shapeBuilder": saved });
|
||||
let fields = prefs.as_object_mut().unwrap();
|
||||
match version {
|
||||
Some(v) => fields.insert("toolSettingsVersion".into(), json!(v)),
|
||||
None => fields.remove("toolSettingsVersion"),
|
||||
};
|
||||
let mut next = session();
|
||||
next.apply_prefs(serde_json::from_str(&prefs.to_string()).unwrap());
|
||||
next
|
||||
};
|
||||
for (version, saved, want) in [
|
||||
(None, json!({"highlightFill": false}), "swatches"),
|
||||
(None, json!({"pickColorFrom": "artwork"}), "swatches"),
|
||||
(None, json!({"pickColorFrom": "swatches"}), "swatches"),
|
||||
(Some(1), json!({"pickColorFrom": "artwork"}), "artwork"),
|
||||
(Some(1), json!({"pickColorFrom": "swatches"}), "swatches"),
|
||||
(Some(1), json!({"highlightFill": false}), "swatches"),
|
||||
] {
|
||||
let mut next = load(version, &saved);
|
||||
assert_eq!(next.prefs.tool_settings_version, 1, "the version is written: {version:?} {saved}");
|
||||
select(&mut next, "shapeBuilder");
|
||||
assert_eq!(next.tool_options()["pickColorFrom"], json!(want), "saved {version:?} {saved}");
|
||||
select(&mut next, "selection");
|
||||
assert_eq!(next.prefs.tool_settings["shapeBuilder"]["pickColorFrom"], json!(want), "stored again: {version:?} {saved}");
|
||||
}
|
||||
// Artwork picked after the update, or in a session that started without saved settings, is
|
||||
// kept at the next launch.
|
||||
for mut next in [load(None, &json!({"pickColorFrom": "artwork"})), session()] {
|
||||
select(&mut next, "shapeBuilder");
|
||||
next.set_tool_option("pickColorFrom", &json!("artwork"));
|
||||
select(&mut next, "selection");
|
||||
let saved_text = serde_json::to_string(&next.prefs).unwrap();
|
||||
let mut later = session();
|
||||
later.apply_prefs(serde_json::from_str(&saved_text).unwrap());
|
||||
select(&mut later, "shapeBuilder");
|
||||
assert_eq!(later.tool_options()["pickColorFrom"], json!("artwork"), "picked after the update: {saved_text}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,6 +581,7 @@ impl Session {
|
||||
}
|
||||
}
|
||||
}
|
||||
prefs.mark_tool_settings_current();
|
||||
}
|
||||
|
||||
/// Keep the active tool's persistent options for the next time it, or a tool sharing them, is
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -66,11 +66,12 @@ pub struct ShapeBuilderOptions {
|
||||
/// region as if an invisible edge closed it. When it is off, the path cuts the regions it crosses
|
||||
/// as a line does.
|
||||
pub open_filled_as_closed: bool,
|
||||
/// Pick Color From Color Swatches (`pickColorFrom: "swatches"`; off: `"artwork"`): a merge
|
||||
/// Pick Color From Color Swatches (`pickColorFrom: "swatches"`, on; off: `"artwork"`): a merge
|
||||
/// fills the new shape with the current fill, and the Left and Right arrow keys step the current
|
||||
/// fill through the document's color swatches. With Artwork, the shape takes the look of the
|
||||
/// object where the drag starts, else of the one where it ends, else of the front-most selected
|
||||
/// object.
|
||||
/// object. A saved `pickColorFrom` is kept, except that preferences saved by an earlier version
|
||||
/// read a saved Artwork as Color Swatches once; preferences without one take Color Swatches.
|
||||
pub swatches: bool,
|
||||
/// Cursor Swatch Preview (`cursorSwatchPreview`, off): with Color Swatches, the current fill
|
||||
/// and the swatches before and after it show as chips above the pointer while no drag is on.
|
||||
@@ -105,7 +106,7 @@ impl Default for ShapeBuilderOptions {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
open_filled_as_closed: true,
|
||||
swatches: false,
|
||||
swatches: true,
|
||||
cursor_swatch_preview: false,
|
||||
straight_line: false,
|
||||
highlight_fill: true,
|
||||
|
||||
@@ -631,7 +631,7 @@ pub(super) mod tests {
|
||||
tool: "shapeBuilder",
|
||||
opens_on: vec![
|
||||
("openFilledAsClosed", json!(true)),
|
||||
("pickColorFrom", json!("artwork")),
|
||||
("pickColorFrom", json!("swatches")),
|
||||
("cursorSwatchPreview", json!(false)),
|
||||
("selection", json!("freeform")),
|
||||
("highlightFill", json!(true)),
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -88,7 +88,7 @@ impl Outcome for CellOutput {
|
||||
}
|
||||
}
|
||||
|
||||
/// A row's target circle: a ring, doubled while the row is targeted, with a dot when it has an
|
||||
/// A row's target circle: a ring, doubled while the row is targeted, with a diamond when it has an
|
||||
/// appearance or transparency of its own ([`target_marks`]).
|
||||
#[derive(Component, Props)]
|
||||
#[component(sample = TargetCircle::sample)]
|
||||
@@ -107,7 +107,13 @@ pub(super) struct TargetCircle {
|
||||
|
||||
impl TargetCircle {
|
||||
fn new(document: (u64, u64), id: NodeId, targeted: bool, styled: bool) -> Self {
|
||||
Self { common: Common::new(), document, id, targeted, styled, held: false, pick: None }
|
||||
let state = match (targeted, styled) {
|
||||
(true, true) => tl!("Target appearance: targeted, additional appearance or transparency"),
|
||||
(true, false) => tl!("Target appearance: targeted, basic appearance"),
|
||||
(false, true) => tl!("Target appearance: not targeted, additional appearance or transparency"),
|
||||
(false, false) => tl!("Target appearance: not targeted, basic appearance"),
|
||||
};
|
||||
Self { common: Common::new(), document, id, targeted, styled, held: false, pick: None }.tooltip(state).description(state).selected(targeted)
|
||||
}
|
||||
|
||||
/// A targeted circle with an appearance, for the suite.
|
||||
@@ -186,12 +192,13 @@ impl Component for TargetCircle {
|
||||
let draw = ui.draw();
|
||||
let (ring, width) = if self.held { (cx.style.accent, StrokeWidth::Medium) } else { (cx.style.ink, StrokeWidth::Thin) };
|
||||
draw.stroke(&PaintShape::Circle(center, TARGET_RADIUS), width, ring);
|
||||
let (inner, dot) = target_marks(self.targeted, self.styled);
|
||||
let (inner, mark) = target_marks(self.targeted, self.styled);
|
||||
if let Some(radius) = inner {
|
||||
draw.stroke(&PaintShape::Circle(center, radius), StrokeWidth::Thin, cx.style.ink);
|
||||
}
|
||||
if let Some(radius) = dot {
|
||||
draw.fill(&PaintShape::Circle(center, radius), cx.style.ink);
|
||||
if let Some(radius) = mark {
|
||||
let points = vec![center - vec2(0.0, radius), center + vec2(radius, 0.0), center + vec2(0.0, radius), center - vec2(radius, 0.0)];
|
||||
draw.stroke(&PaintShape::Polygon(points), StrokeWidth::Thin, cx.style.ink);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -246,23 +246,20 @@ fn listed_nodes(tree: &DocLayers<'_>, filter: &LayerFilter) -> Vec<NodeId> {
|
||||
pub(super) const TARGET_RADIUS: f32 = 5.0;
|
||||
/// The radius of the inner ring of a targeted item's target circle (the double ring).
|
||||
pub(super) const TARGET_RING: f32 = 2.8;
|
||||
// PLAN: the sheet keeps `TARGET_STROKE`; the circle's rings take the theme's thin stroke (`StrokeWidth::Thin`), so it is gone.
|
||||
/// The radius of the dot filling the circle of an item that has an appearance of its own and is
|
||||
/// not targeted.
|
||||
pub(super) const TARGET_DOT: f32 = 3.2;
|
||||
/// The radius of that dot inside a targeted item's inner ring: clear of the ring, so a targeted
|
||||
/// item with an appearance of its own shows both (#8711).
|
||||
pub(super) const TARGET_DOT_IN_RING: f32 = 1.5;
|
||||
/// The radius of the outlined diamond marking an item's own appearance or transparency.
|
||||
pub(super) const APPEARANCE_MARK: f32 = 2.5;
|
||||
/// A mitered thin stroke extends a diamond's corner by width / sqrt(2). Radius 1 keeps
|
||||
/// the diamond clear of the targeted ring's inner edge (#8711).
|
||||
pub(super) const APPEARANCE_MARK_IN_RING: f32 = 1.0;
|
||||
|
||||
/// The marks inside a target circle's outer ring: the inner ring's radius when the item is
|
||||
/// `targeted`, and the appearance dot's radius when it is `styled` (has an appearance of its own).
|
||||
/// Each of the four combinations looks different, as the Layers panel's target icons do.
|
||||
/// The inner target ring's radius and the own-appearance diamond's radius. Each of the four
|
||||
/// combinations differs, and the diamond inside a targeted ring leaves that ring visible.
|
||||
pub(super) fn target_marks(targeted: bool, styled: bool) -> (Option<f32>, Option<f32>) {
|
||||
let dot = if targeted { TARGET_DOT_IN_RING } else { TARGET_DOT };
|
||||
(targeted.then_some(TARGET_RING), styled.then_some(dot))
|
||||
let mark = if targeted { APPEARANCE_MARK_IN_RING } else { APPEARANCE_MARK };
|
||||
(targeted.then_some(TARGET_RING), styled.then_some(mark))
|
||||
}
|
||||
|
||||
/// Whether an object's target circle is filled: its appearance is not basic (a group or layer:
|
||||
/// Whether an object's target circle shows its appearance mark: its appearance is not basic (a group or layer:
|
||||
/// it has fills, strokes or effects of its own) or its transparency (opacity, blend mode,
|
||||
/// isolation, knockout or an opacity mask) is not the default.
|
||||
pub(super) fn has_styled_target(n: &Node) -> bool {
|
||||
|
||||
@@ -74,21 +74,15 @@ fn answer(app: &mut VectorcraftApp, ctx: &egui::Context, ok: bool) {
|
||||
crate::dialogs::host::pump(app, ctx);
|
||||
}
|
||||
|
||||
/// The target-mark rule: each of the four looks (neither, targeted, an appearance, both) differs,
|
||||
/// and the dot sits clear of the inner ring, drawn in the theme's thin stroke, when both show.
|
||||
/// The four target/appearance combinations remain distinct, with the appearance diamond clear of
|
||||
/// the inner target ring in the theme's thin stroke.
|
||||
#[test]
|
||||
fn target_circle_marks_follow_targeted_and_styled() {
|
||||
use rows::{TARGET_DOT, TARGET_DOT_IN_RING, TARGET_RING, target_marks};
|
||||
use rows::{APPEARANCE_MARK, APPEARANCE_MARK_IN_RING, TARGET_RING, target_marks};
|
||||
assert_eq!(target_marks(false, false), (None, None));
|
||||
assert_eq!(target_marks(true, false), (Some(TARGET_RING), None));
|
||||
assert_eq!(target_marks(false, true), (None, Some(TARGET_DOT)));
|
||||
let (ring, dot) = target_marks(true, true);
|
||||
assert_eq!((ring, dot), (Some(TARGET_RING), Some(TARGET_DOT_IN_RING)));
|
||||
let thin = std::rc::Rc::new(std::cell::Cell::new(f32::INFINITY));
|
||||
let seen = std::rc::Rc::clone(&thin);
|
||||
let mut fixture = craft::ui::testing::Fixture::new(move |ui| seen.set(craft::ui::runtime::env::Env::of(ui).tokens.stroke.thin));
|
||||
fixture.root(crate::app::root_env(&vectorcraft_engine::Prefs::default(), 1.0, None)).frame(vec![]);
|
||||
assert!(TARGET_DOT_IN_RING + 0.5 < TARGET_RING - thin.get() / 2.0, "the dot covers the ring");
|
||||
assert_eq!(target_marks(false, true), (None, Some(APPEARANCE_MARK)));
|
||||
assert_eq!(target_marks(true, true), (Some(TARGET_RING), Some(APPEARANCE_MARK_IN_RING)));
|
||||
}
|
||||
|
||||
/// A document with two rectangles on one layer → (app, layer, [bottom, top]).
|
||||
@@ -1329,6 +1323,156 @@ fn a_target_circle_drop_after_file_revert_leaves_the_restored_appearance_in_plac
|
||||
assert_eq!(fill(&panel.app(), b), red, "a target circle drag started after the revert still moves the appearance");
|
||||
}
|
||||
|
||||
/// The cardinal four-point outline actually painted by the native cell, independently of its constants.
|
||||
fn appearance_diamond(shape: &egui::Shape) -> Option<(egui::Pos2, f32, f32)> {
|
||||
let egui::Shape::Path(path) = shape else { return None };
|
||||
if !path.closed || path.fill != egui::Color32::TRANSPARENT || path.points.len() != 4 {
|
||||
return None;
|
||||
}
|
||||
let c = egui::pos2((path.points[0].x + path.points[2].x) / 2.0, (path.points[0].y + path.points[2].y) / 2.0);
|
||||
let r = path.points[0].distance(c);
|
||||
if ![2.5, 1.0].iter().any(|expected| (r - expected).abs() < 1e-4) {
|
||||
return None;
|
||||
}
|
||||
let expected = [c - egui::vec2(0.0, r), c + egui::vec2(r, 0.0), c + egui::vec2(0.0, r), c - egui::vec2(r, 0.0)];
|
||||
path.points.iter().zip(expected).all(|(a, b)| a.distance(b) < 1e-4).then_some((c, r, path.stroke.width))
|
||||
}
|
||||
|
||||
/// The actual native cell's marks at `name`, read from the fixture's paint output: radius, diamond, width.
|
||||
fn target_marks_painted(panel: &mut crate::tests::panel_harness::Panel, name: &str) -> Vec<(f32, bool, f32)> {
|
||||
let center = panel.rect(name).center();
|
||||
let (shapes, _) = panel.paint_at(1.0);
|
||||
let ink = shapes
|
||||
.iter()
|
||||
.find_map(|shape| match shape {
|
||||
egui::Shape::Circle(circle) if circle.center.distance(center) < 0.01 && (circle.radius - 5.0).abs() < 1e-4 => Some(circle.stroke.color),
|
||||
_ => None,
|
||||
})
|
||||
.expect("the cell's outer target ring");
|
||||
for shape in &shapes {
|
||||
if appearance_diamond(shape).is_some_and(|(at, _, _)| at.distance(center) < 0.01)
|
||||
&& let egui::Shape::Path(path) = shape
|
||||
{
|
||||
assert_eq!(path.stroke.color, egui::epaint::ColorMode::Solid(ink), "the native marker keeps the target ring's themed ink");
|
||||
assert_eq!(path.stroke.kind, egui::StrokeKind::Middle, "the diamond's stroke is centered on its outline");
|
||||
}
|
||||
}
|
||||
let mut marks: Vec<_> = shapes
|
||||
.iter()
|
||||
.filter_map(|shape| match shape {
|
||||
egui::Shape::Circle(circle)
|
||||
if circle.center.distance(center) < 0.01 && circle.radius < 5.0 && circle.fill == egui::Color32::TRANSPARENT =>
|
||||
{
|
||||
Some((circle.radius, false, circle.stroke.width))
|
||||
}
|
||||
shape => appearance_diamond(shape).filter(|(at, _, _)| at.distance(center) < 0.01).map(|(_, r, width)| (r, true, width)),
|
||||
})
|
||||
.collect();
|
||||
marks.sort_by(|a, b| a.0.total_cmp(&b.0));
|
||||
marks
|
||||
}
|
||||
|
||||
/// Retain #8757's historical regression name: the own-appearance diamond leaves the actual inner
|
||||
/// ring visible, and neither, targeted, styled and both paint four different looks.
|
||||
#[test]
|
||||
fn a_targeted_circle_with_an_appearance_shows_both_ring_and_dot() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
let (mut app, _, [a, _]) = two_rects();
|
||||
name_row(&mut app, a, "A");
|
||||
let mut panel = Panel::new(app, show);
|
||||
let neither = target_marks_painted(&mut panel, "Target A");
|
||||
panel.click("Target A");
|
||||
let targeted = target_marks_painted(&mut panel, "Target A");
|
||||
panel.app().session.execute("transparency.set", &json!({"ids": [a.0], "opacity": 30})).unwrap();
|
||||
panel.frame();
|
||||
let both = target_marks_painted(&mut panel, "Target A");
|
||||
panel.app().session.execute("select.none", &json!({})).unwrap();
|
||||
panel.frame();
|
||||
let styled = target_marks_painted(&mut panel, "Target A");
|
||||
let ring = both.iter().find(|m| (m.0 - 2.8).abs() < 1e-4 && !m.1).expect("the actual inner ring");
|
||||
let mark = both.iter().find(|m| m.1).expect("the actual hollow diamond");
|
||||
let outer_extent = mark.0 + mark.2 * std::f32::consts::FRAC_1_SQRT_2;
|
||||
assert!(outer_extent < ring.0 - ring.2 / 2.0 - 0.5, "the diamond {mark:?} covers the ring {ring:?}");
|
||||
assert!((mark.0 - 1.0).abs() < 1e-4);
|
||||
assert_eq!(mark.2, ring.2, "the marker retains the theme's thin stroke");
|
||||
let alone = styled.iter().find(|m| m.1).expect("the standalone diamond");
|
||||
assert!((alone.0 - 2.5).abs() < 1e-4);
|
||||
let looks = [&neither, &targeted, &styled, &both];
|
||||
for (i, x) in looks.iter().enumerate() {
|
||||
for y in &looks[i + 1..] {
|
||||
assert_ne!(x, y, "all four actual cell looks differ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Hover and accessibility explain the mark without replacing the contextual row name; the same
|
||||
/// native cell still targets its art, while selecting other art leaves its own appearance intact.
|
||||
#[test]
|
||||
fn appearance_marker_names_its_state_and_keeps_targeting_actions() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
struct RestoreLanguage(crate::i18n::Lang);
|
||||
impl Drop for RestoreLanguage {
|
||||
fn drop(&mut self) {
|
||||
crate::i18n::set_current(self.0);
|
||||
}
|
||||
}
|
||||
let _language = RestoreLanguage(crate::i18n::current());
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
let (mut app, _, [a, b]) = two_rects();
|
||||
name_row(&mut app, a, "A");
|
||||
name_row(&mut app, b, "B");
|
||||
app.session.execute("transparency.set", &json!({"ids": [a.0], "opacity": 30})).unwrap();
|
||||
let mut panel = Panel::new(app, show);
|
||||
let idle = "Target appearance: not targeted, additional appearance or transparency";
|
||||
let active = "Target appearance: targeted, additional appearance or transparency";
|
||||
assert_eq!(panel.description("Target A").as_deref(), Some(idle));
|
||||
assert_eq!(panel.description("Target B").as_deref(), Some("Target appearance: not targeted, basic appearance"));
|
||||
assert_eq!(panel.toggled("Target A"), Some(craft::behavior::Mixed::Same(false)));
|
||||
let before = {
|
||||
let app = panel.app();
|
||||
(app.session.active().unwrap().selection.clone(), undo_len(&app))
|
||||
};
|
||||
panel.hover("Target A");
|
||||
panel.advance(2.0);
|
||||
panel.frame();
|
||||
let (shapes, _) = panel.paint_at(1.0);
|
||||
assert!(shapes.iter().any(|s| matches!(s, egui::Shape::Text(t) if t.galley.text() == idle)), "the native tooltip explains the mark");
|
||||
{
|
||||
let app = panel.app();
|
||||
assert_eq!((app.session.active().unwrap().selection.clone(), undo_len(&app)), before, "hover changes no selection or history");
|
||||
}
|
||||
panel.click("Target A");
|
||||
assert_eq!(targeted(&panel.app()), (Some(a), vec![a]));
|
||||
assert_eq!(panel.description("Target A").as_deref(), Some(active));
|
||||
assert_eq!(panel.toggled("Target A"), Some(craft::behavior::Mixed::Same(true)));
|
||||
panel.click("Target B");
|
||||
assert_eq!(panel.description("Target A").as_deref(), Some(idle));
|
||||
assert_eq!(panel.description("Target B").as_deref(), Some("Target appearance: targeted, basic appearance"));
|
||||
assert_eq!(panel.toggled("Target B"), Some(craft::behavior::Mixed::Same(true)));
|
||||
assert!(target_marks_painted(&mut panel, "Target A").iter().any(|m| m.1), "the appearance stays after targeting other art");
|
||||
}
|
||||
|
||||
/// The marker's native cell retains appearance move and Alt-copy admission and payloads.
|
||||
#[test]
|
||||
fn dragging_a_target_circle_moves_or_copies_the_appearance() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
let (mut app, layer, [a, b]) = two_rects();
|
||||
name_row(&mut app, layer, "Layer");
|
||||
name_row(&mut app, a, "A");
|
||||
name_row(&mut app, b, "B");
|
||||
app.session.execute("transparency.set", &json!({"ids": [a.0], "opacity": 30})).unwrap();
|
||||
let mut panel = Panel::new(app, show);
|
||||
let opacity = |app: &VectorcraftApp, id: NodeId| app.session.active().unwrap().doc.node(id).unwrap().opacity;
|
||||
panel.drag("Target A", "Target B", egui::Modifiers::ALT);
|
||||
{
|
||||
let app = panel.app();
|
||||
assert!((opacity(&app, a) - 0.3).abs() < 1e-6 && (opacity(&app, b) - 0.3).abs() < 1e-6);
|
||||
}
|
||||
panel.drag("Target B", "Target Layer", egui::Modifiers::NONE);
|
||||
let app = panel.app();
|
||||
assert!((opacity(&app, layer) - 0.3).abs() < 1e-6 && opacity(&app, b) == 1.0);
|
||||
}
|
||||
|
||||
/// The rows find which nodes hold selected art once per revision: frames that change nothing walk no node for the
|
||||
/// selection squares, and a new selection walks the tree once.
|
||||
#[test]
|
||||
|
||||
@@ -291,8 +291,9 @@ fn can_merge_live_paint(app: &VectorcraftApp) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether the selection uses more than one colour (`recolor.colors`), which offers the Recolor
|
||||
/// quick action; memoised per document revision.
|
||||
/// Whether the selection uses more than one colour (`recolor.colors` lists more than one,
|
||||
/// [`vectorcraft_engine::Session::several_colors_used`]), which offers the Recolor quick action;
|
||||
/// memoised per document revision.
|
||||
pub(crate) fn multi_color(app: &mut VectorcraftApp) -> bool {
|
||||
let Some(st) = app.session.active() else { return false };
|
||||
let key = (st.uid, st.revision);
|
||||
@@ -301,8 +302,7 @@ pub(crate) fn multi_color(app: &mut VectorcraftApp) -> bool {
|
||||
{
|
||||
return multi;
|
||||
}
|
||||
let r = app.session.execute("recolor.colors", &json!({})).unwrap_or_default();
|
||||
let multi = r["colors"].as_array().is_some_and(|c| c.len() > 1);
|
||||
let multi = app.session.several_colors_used();
|
||||
app.canvas.multi_color = Some((key, multi));
|
||||
multi
|
||||
}
|
||||
|
||||
@@ -421,6 +421,9 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let lit: Vec<String> = highlighted(&st.doc, &base).into_iter().map(str::to_string).collect();
|
||||
let doc = Arc::clone(&st.doc);
|
||||
let start = dnd::DragStart::of(st);
|
||||
// The row menu, the drop rules and the drag payload read the document, its reverts and the drag start alone, so
|
||||
// the browser's rows replay while this version holds.
|
||||
let host = start.version(st.revision);
|
||||
let document = st.uid;
|
||||
let reverts = st.reverts;
|
||||
let foot = Footer::of(app, &model, held);
|
||||
@@ -448,6 +451,7 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
.row_items(|key| row_items(shown_app, key))
|
||||
.takes_drop::<PanelDrag>(DropPlace::Between, |drag, _| dnd::accepts(drag, document, reverts))
|
||||
.takes_drop::<PanelDrag>(DropPlace::Onto, |drag, _| dnd::accepts(drag, document, reverts))
|
||||
.host_version(host)
|
||||
.select(SelectMode::Multi)
|
||||
.search(search)
|
||||
.reveal(focus.clone().map(SwatchKey::Swatch))
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
use std::sync::{Arc, Weak};
|
||||
|
||||
use super::{Document, Paint, PanelDrag, REGISTRATION, Swatch, Value, VectorcraftApp, json, name_of, swatch_params};
|
||||
@@ -126,6 +127,15 @@ impl DragStart {
|
||||
DragStart { uid: st.uid, reverts: st.reverts, doc: Arc::clone(&st.doc), steps: steps(st), back }
|
||||
}
|
||||
|
||||
/// A version of this start in the document's `revision` ([`DocState::revision`]): it changes with
|
||||
/// the document, its count of File › Revert and its newest undo and redo steps, which are what the
|
||||
/// panel's row menu, drop rules and drag payload read.
|
||||
pub(super) fn version(&self, revision: u64) -> u64 {
|
||||
let mut h = DefaultHasher::new();
|
||||
(self.uid, self.reverts, revision, self.steps).hash(&mut h);
|
||||
h.finish()
|
||||
}
|
||||
|
||||
/// Rows `names` as this document holds them.
|
||||
fn rows(&self, names: &[String]) -> HeldRows {
|
||||
let rows: Vec<_> = names.iter().map(|n| (n.clone(), HeldRow::of(&self.doc, n))).collect();
|
||||
|
||||
@@ -1623,3 +1623,35 @@ fn the_swatch_libraries_menu_fits_its_rows_like_a_library_panels_menu() {
|
||||
let panel_menu = panel.rect_role("Swatch Libraries Menu", Role::MENU);
|
||||
assert_eq!(footer_menu.width(), panel_menu.width(), "footer menu {footer_menu:?}, library panel menu {panel_menu:?}");
|
||||
}
|
||||
|
||||
/// Frames that change nothing replay the swatch rows instead of running them again; deleting a swatch and undoing it
|
||||
/// each run them, the rows show the change, and the frames after replay them again.
|
||||
#[test]
|
||||
fn idle_frames_replay_the_swatch_rows() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
use craft::ui::testing::{MemoRun, last_frame_memo_runs};
|
||||
let runs =
|
||||
|panel: &Panel| last_frame_memo_runs(panel.ctx()).iter().filter(|(name, _, run)| name.contains("ListProps") && *run == MemoRun::Ran).count();
|
||||
let idle = |panel: &mut Panel, after: &str| {
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
for _ in 0..5 {
|
||||
panel.frame();
|
||||
assert_eq!(runs(panel), 0, "an idle frame {after} replays the swatch rows");
|
||||
}
|
||||
};
|
||||
let red = "Red, #ed1c24";
|
||||
let mut panel = Panel::new(app(), show);
|
||||
idle(&mut panel, "of a new document");
|
||||
assert!(panel.shows(red), "the rows show Red");
|
||||
panel.app().run("swatch.delete", json!({"names": ["Red"]})).unwrap();
|
||||
panel.frame();
|
||||
assert!(runs(&panel) > 0, "deleting a swatch runs the rows");
|
||||
assert!(!panel.shows(red), "and they no longer show it");
|
||||
idle(&mut panel, "after a delete");
|
||||
panel.app().run("edit.undo", json!({})).unwrap();
|
||||
panel.frame();
|
||||
assert!(runs(&panel) > 0, "an undo runs the rows");
|
||||
assert!(panel.shows(red), "and they show the swatch again");
|
||||
idle(&mut panel, "after an undo");
|
||||
}
|
||||
|
||||
@@ -126,6 +126,12 @@ impl Panel {
|
||||
self.aim(name, target)
|
||||
}
|
||||
|
||||
/// Moves the pointer over `name` without pressing a button.
|
||||
pub(crate) fn hover(&mut self, name: &str) {
|
||||
let at = self.find_aimed(name).center();
|
||||
self.frame_with(vec![Event::PointerMoved(at)]);
|
||||
}
|
||||
|
||||
/// Clicks the control named `name`.
|
||||
pub(crate) fn click(&mut self, name: &str) {
|
||||
let target = self.find_aimed(name);
|
||||
|
||||
+4
-1
File diff suppressed because one or more lines are too long
+6
-4
@@ -15727,10 +15727,12 @@ a flare into a plain group of its parts. The document saves a flare's settings.
|
||||
The Shape Builder tool's options are its Shape Builder Tool Options (dialog `shapeBuilderOptions`):
|
||||
`openFilledAsClosed` (on: a filled open path bounds a region as if an invisible edge closed it; a path counts as
|
||||
filled when any of its fill rows is shown, painted and above 0% opacity, whichever row is on top; off: it cuts regions
|
||||
as an unfilled path does), `pickColorFrom` (`artwork`, the default: a merged shape takes the appearance, opacity and
|
||||
blending mode of the front-most selected object under the drag's first point, else of the one under its last point,
|
||||
else of the front-most selected object; `swatches`: the current fill, and the Left and Right arrow keys without
|
||||
Shift, Alt or Cmd/Ctrl step the current fill through the document's color swatches), `cursorSwatchPreview` (off; with `swatches`, chips above the
|
||||
as an unfilled path does), `pickColorFrom` (`swatches`, the default: a merged shape fills with the current fill, and
|
||||
the Left and Right arrow keys without Shift, Alt or Cmd/Ctrl step the current fill through the document's color
|
||||
swatches; `artwork`: a merged shape takes the appearance, opacity and blending mode of the front-most selected object
|
||||
under the drag's first point, else of the one under its last point, else of the front-most selected object; a
|
||||
`pickColorFrom` saved with the preferences is kept, except that preferences saved by an earlier version, without
|
||||
`toolSettingsVersion`, read a saved `artwork` as `swatches` once; preferences saved without one take `swatches`), `cursorSwatchPreview` (off; with `swatches`, chips above the
|
||||
pointer show the current fill and the swatches before and after it), `selection` (`freeform`, the default, or
|
||||
`straightLine`: a drag touches what the line from its first point to the pointer crosses), `highlightFill` (on by
|
||||
default; when it is off, merge mode shades no regions), `gapDetection` (off) with `gapLength` (pt, 0 to 72; 3), `clickStrokeSplitsPath` (In Merge Mode,
|
||||
|
||||
+5
-2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+5
-1
File diff suppressed because one or more lines are too long
+36
-9
@@ -267,12 +267,14 @@ fn cmd_test() -> Result<(), String> {
|
||||
test_packages(&["--workspace".to_owned()], "--workspace", None)
|
||||
}
|
||||
|
||||
/// The test targets that [`test_packages`] runs and `ci warm` builds.
|
||||
const TARGETS: [&str; 3] = ["--lib", "--bins", "--tests"];
|
||||
|
||||
/// [`cmd_test`] for the packages `select` picks (`--workspace` or `-p` ids), shown as `shown`;
|
||||
/// with `part`, only that part's share of their tests (xtask/src/shards.rs), which needs nextest.
|
||||
/// A part runs its counted share, then its pinned tests, each with nextest's default thread count.
|
||||
/// Every run finishes before the first error is returned.
|
||||
fn test_packages(select: &[String], shown: &str, part: Option<shards::Part>) -> Result<(), String> {
|
||||
const TARGETS: [&str; 3] = ["--lib", "--bins", "--tests"];
|
||||
if let Some(part) = part {
|
||||
if !has_nextest() {
|
||||
return Err(format!("cargo nextest run {shown}: a shard that runs part of a crate's tests needs cargo-nextest"));
|
||||
@@ -393,11 +395,13 @@ fn cmd_ci_shard() -> Result<(), String> {
|
||||
run_steps(&steps)
|
||||
}
|
||||
|
||||
/// `cargo xtask ci warm`: for each test shard, builds its crates' library and binary tests without
|
||||
/// running them, then builds what the checks shard builds, so one dependency-cache entry holds the
|
||||
/// dependencies of every shard with the features that shard builds them with (cargo resolves
|
||||
/// features over the packages each command selects). The integration tests are left out: they
|
||||
/// build no dependency that the library tests do not, since both take the crate's dev-dependencies.
|
||||
/// `cargo xtask ci warm`: for each test shard, builds its crates' library, binary and integration
|
||||
/// tests without running them, then builds what the checks shard builds, so one dependency-cache
|
||||
/// entry holds the dependencies of every shard with the features that shard builds them with (cargo
|
||||
/// resolves features over the packages each command selects). The test builds select the same
|
||||
/// targets as the test shards ([`TARGETS`]), so the cache also holds the test executables the
|
||||
/// shards run, and cargo does not warn (`cargo::unused_dependencies`) about a dev-dependency that
|
||||
/// only an integration test uses.
|
||||
///
|
||||
/// In a leg that saves the cache, every build records its units in `CRAFT_CACHE_UNITS`
|
||||
/// (xtask/src/cache_units.rs), xtask's own build included.
|
||||
@@ -414,9 +418,8 @@ fn cmd_ci_warm() -> Result<(), String> {
|
||||
steps.push((
|
||||
"build tests",
|
||||
Box::new(move || {
|
||||
let mut c = cargo();
|
||||
c.arg("test").args(shards::select(&crates)).args(["--lib", "--bins", "--no-run"]);
|
||||
cache_units::run(c, &format!("cargo test --lib --bins --no-run ({})", shards::names(&crates)))
|
||||
let (c, what) = warm_tests(&crates);
|
||||
cache_units::run(c, &what)
|
||||
}),
|
||||
));
|
||||
}
|
||||
@@ -447,6 +450,13 @@ fn cmd_ci_warm() -> Result<(), String> {
|
||||
run_steps(&steps)
|
||||
}
|
||||
|
||||
/// The command `ci warm` builds one test shard's tests with, and its description.
|
||||
fn warm_tests(crates: &[shards::Member]) -> (Command, String) {
|
||||
let mut c = cargo();
|
||||
c.arg("test").args(shards::select(crates)).args(TARGETS).arg("--no-run");
|
||||
(c, format!("cargo test {} --no-run ({})", TARGETS.join(" "), shards::names(crates)))
|
||||
}
|
||||
|
||||
/// Runs `steps` in turn, stopping at the first that fails; the summary names the steps that passed
|
||||
/// and, after a failure, the one that failed and those skipped.
|
||||
fn run_steps(steps: &[Step]) -> Result<(), String> {
|
||||
@@ -588,3 +598,20 @@ fn i18n_report_packages(select: &[String], shown: &str) -> Result<(), String> {
|
||||
c.arg("test").args(select).args(["--lib", "--bins", "--tests", "--", "i18n::tests::untranslated_report", "--exact", "--nocapture"]);
|
||||
run(c, &format!("cargo test {shown} --lib --bins --tests -- i18n::tests::untranslated_report --exact --nocapture"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn warm_builds_the_test_targets_the_shards_run() {
|
||||
let crates = [shards::Member { name: "a".into(), id: "path+file:///w/a#0.1.0".into(), version: "0.1.0".into(), doctests: true }];
|
||||
let (c, what) = warm_tests(&crates);
|
||||
let args: Vec<String> = c.get_args().map(|a| a.to_string_lossy().into_owned()).collect();
|
||||
assert_eq!(args, ["test", "-p", "path+file:///w/a#0.1.0", "--lib", "--bins", "--tests", "--no-run"]);
|
||||
for target in TARGETS {
|
||||
assert!(args.iter().any(|a| a == target), "ci warm does not build {target}");
|
||||
}
|
||||
assert_eq!(what, "cargo test --lib --bins --tests --no-run (a)");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user