Merge pull request #9329 from dotCooCoo/feat/rotate-ruler-guides

Guides: selected ruler guides rotate with the Rotate tool and Object › Transform › Rotate
This commit is contained in:
BFlat
2026-11-26 08:48:18 +07:00
committed by GitHub
10 changed files with 309 additions and 22 deletions
+65
View File
@@ -5,6 +5,15 @@ use super::node::{held_guides, map_held, strip_held};
use super::{Affine, Arc, Document, Node, NodeId, NodeKind, PatternDef, Point, Rect, Selection, SymbolBoxes, Vec2, artboard_holds};
use std::collections::{BTreeMap, HashSet};
/// What a transform makes of a ruler guide ([`Document::transformed_guide`]).
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum GuideTransform {
/// It stays a ruler guide: vertical at x `pos`, or horizontal at y `pos`.
Ruler { vertical: bool, pos: f64 },
/// It becomes a guide path along the line between the two points.
Path(Point, Point),
}
impl Document {
/// Union of the geometric bounds of `ids` (their visual bounds when `visual`), with symbol
/// instances measured by their art ([`Node::geometric_bounds_with`]).
@@ -369,6 +378,62 @@ impl Document {
Some(if g.vertical { (r.y0, r.y1) } else { (r.x0, r.x1) })
}
/// The line ruler guide `g` stands for as a path: across its artboard for an artboard guide,
/// and across the bounds of all the artboards for a canvas guide. None when there is no
/// artboard to measure a canvas guide by.
pub fn guide_line(&self, g: &Guide) -> Option<(Point, Point)> {
let artboards = || self.artboards.iter().map(|a| a.rect).reduce(|a, b| a.union(b));
let (a, b) = self.guide_span(g).or_else(|| artboards().map(|r| if g.vertical { (r.y0, r.y1) } else { (r.x0, r.x1) }))?;
Some(if g.vertical { (Point::new(g.pos, a), Point::new(g.pos, b)) } else { (Point::new(a, g.pos), Point::new(b, g.pos)) })
}
/// What `xf` makes of ruler guide `g` ([`Self::transform_ruler_guides`]), or None when the
/// document has no line for it ([`Self::guide_line`]).
pub fn transformed_guide(&self, g: &Guide, xf: Affine) -> Option<GuideTransform> {
let (a, b) = self.guide_line(g)?;
let (a, b) = (xf * a, xf * b);
let tol = 1e-9 * a.distance(b).max(1.0);
Some(if (a.x - b.x).abs() <= tol {
GuideTransform::Ruler { vertical: true, pos: (a.x + b.x) / 2.0 }
} else if (a.y - b.y).abs() <= tol {
GuideTransform::Ruler { vertical: false, pos: (a.y + b.y) / 2.0 }
} else {
GuideTransform::Path(a, b)
})
}
/// Apply `xf` to the ruler guides selected in `sel`, each as the line [`Self::guide_line`]
/// gives it. A line that stays vertical or horizontal stays a ruler guide, at its new place. A
/// line at any other angle becomes a guide path with that line, on the guide's layer, named
/// as the guide was; `sel` then holds the path as a selected object instead of the guide.
/// Guides that cannot be edited ([`Self::guide_editable`]) stay as they are.
pub fn transform_ruler_guides(&mut self, sel: &mut Selection, xf: Affine) {
for id in sel.guides.clone() {
let Some(g) = self.ruler_guide(id).filter(|g| self.guide_editable(g)) else { continue };
let (a, b) = match self.transformed_guide(&g, xf) {
Some(GuideTransform::Ruler { vertical, pos }) => {
self.edit_ruler_guide(id, |g| (g.vertical, g.pos) = (vertical, pos));
continue;
}
Some(GuideTransform::Path(a, b)) => (a, b),
None => continue,
};
let Some(layer) = self.parent_of(id) else { continue };
let path = self.alloc_id();
let look = crate::Appearance::basic(vectorcraft_color::Paint::None, vectorcraft_color::Paint::None, 0.0);
let mut n = Node::path(path, vectorcraft_geom::shapes::line(a, b), look);
if let NodeKind::Path { guide, .. } = &mut n.kind {
*guide = true;
}
n.name = g.name.clone();
if self.insert(Some(layer), usize::MAX, n).is_err() {
continue;
}
self.retain_guides(sel, |g| g.id != Some(id));
sel.objects.push(path);
}
}
/// The ruler guide node `g` names, if this document has it.
fn guide_node(&self, g: &Guide) -> Option<NodeId> {
g.id.filter(|id| self.node(*id).is_some_and(Node::is_ruler_guide))
+1
View File
@@ -168,6 +168,7 @@ pub use artboard::{ARTBOARD_GAP, Artboard, ArtboardSide, LockedArtboards, Retire
pub use canvas_range::BeyondCanvas;
#[cfg(test)]
use document_ext::free_id;
pub use document_guides::GuideTransform;
pub use graphic_style::{DEFAULT_GRAPHIC_STYLE, GraphicStyle};
pub use guides::{GridPrefs, Guide, RulerMode};
#[cfg(test)]
+3 -6
View File
@@ -14,8 +14,8 @@ use super::panelcmds::artboard_at;
use super::pathops::Beside;
use super::select::{first_selectable, is_selectable, selectable_ids, walk_selectable};
use super::{
CommandSpec, EngineError, Point, Result, Session, bad, checked_ids_param, cmd, f64_req, has_doc, has_selection, id_param, number_or, ok,
str_param, switch_or, text_param,
CommandSpec, EngineError, Result, Session, bad, checked_ids_param, cmd, f64_req, has_doc, has_selection, id_param, number_or, ok, str_param,
switch_or, text_param,
};
pub fn specs() -> Vec<CommandSpec> {
@@ -730,13 +730,10 @@ fn release_guides(s: &mut Session, p: &Value) -> Result<Value> {
};
// Find each ruler guide's line and its parent: the guide's layer, else where new art goes.
let st = s.doc()?;
let artboards = st.doc.artboards.iter().map(|a| a.rect).reduce(|a, b| a.union(b));
let mut lines = Vec::with_capacity(rulers.len());
for &i in &rulers {
let Some(g) = st.doc.ruler_guide(i) else { continue };
let span = st.doc.guide_span(&g).or_else(|| artboards.map(|r| if g.vertical { (r.y0, r.y1) } else { (r.x0, r.x1) }));
let Some((a, b)) = span else { continue };
let (a, b) = if g.vertical { (Point::new(g.pos, a), Point::new(g.pos, b)) } else { (Point::new(a, g.pos), Point::new(b, g.pos)) };
let Some((a, b)) = st.doc.guide_line(&g) else { continue };
let parent = match g.layer.filter(|l| st.doc.node(*l).is_some_and(Node::is_layer)) {
Some(l) => Some(l),
None => st.target_parent()?,
+3 -3
View File
@@ -34,8 +34,8 @@ pub fn specs() -> Vec<CommandSpec> {
"Rotate…",
["Object", "Transform"],
None,
"{ids?: [id…] (selected first; default: the selection), angle: deg (counter-clockwise), absolute?: bool (angle is the bounding box's new angle, not an amount), origin?: [x,y] (default: the bounding box centre), copy?, objects?: bool (Transform Objects, default true; false: the art stays and, with patterns, only its pattern tiles transform), patterns?: bool (Transform Patterns: pattern fills and strokes transform with the art; default: prefs transformPatternTiles), typeAreas?: bool (area type: the frame is reshaped and the text reflows at its size)} → {ids}. With anchors selected with Direct Selection (and no copy), only those anchors and their handles transform, about the centre of their own box.",
has_selection,
"{ids?: [id…] (selected first; default: the selection), angle: deg (counter-clockwise), absolute?: bool (angle is the bounding box's new angle, not an amount), origin?: [x,y] (default: the bounding box centre), copy?, objects?: bool (Transform Objects, default true; false: the art stays and, with patterns, only its pattern tiles transform), patterns?: bool (Transform Patterns: pattern fills and strokes transform with the art; default: prefs transformPatternTiles), typeAreas?: bool (area type: the frame is reshaped and the text reflows at its size)} → {ids}. With anchors selected with Direct Selection (and no copy), only those anchors and their handles transform, about the centre of their own box. Selected ruler guides that can be edited rotate too (without ids), each as the line view.guides.release makes of it, and the default origin is the center of the objects' box and those lines together: a guide that ends up vertical or horizontal stays a ruler guide, and one at any other angle becomes a selected guide path along its line. absolute with only ruler guides selected is an error.",
has_selection_or_guides,
rotate
),
cmd!(
@@ -71,7 +71,7 @@ pub fn specs() -> Vec<CommandSpec> {
["Object", "Transform"],
Some("Cmd+D"),
"{copy?, strokes?, corners?, patterns?, typeAreas?, interpolate?: bool (as object.transform's; default: the value the transform it repeats used, else object.transform's default)} the last transform's matrix on the selection (after a perspective move or scale: that plane-space transform, without these params)",
has_selection,
has_selection_or_guides,
transform_again
),
cmd!(
+40 -4
View File
@@ -16,7 +16,27 @@ fn origin_of(s: &Session, p: &Value, ids: &[NodeId]) -> Result<Point> {
{
return Ok(b.center());
}
s.transform_box(ids).map(|b| b.center()).ok_or_else(|| EngineError::Other("selection has no bounds".into()))
// Selected ruler guides transform with the selection (not with objects named by `ids`, nor
// with Transform Objects off), so the center is that of the objects' box and the guides'
// lines together.
let guides = if p.get("ids").is_none_or(Value::is_null) && transforms_objects(p) { editable_guides(s)? } else { vec![] };
let boxed = s.transform_box(ids);
if guides.is_empty() {
return boxed.map(|b| b.center()).ok_or_else(|| EngineError::Other("selection has no bounds".into()));
}
let objects = boxed.map(|b| {
let c = b.corners();
c.iter().fold(Rect::from_points(c[0], c[0]), |r, p| r.union_pt(*p))
});
let lines = guides.into_iter().filter_map(|g| st.doc.guide_line(&g)).map(|(a, b)| Rect::from_points(a, b));
let b = lines.fold(objects, |acc, r| Some(acc.map_or(r, |acc| acc.union(r))));
b.map(|b| b.center()).ok_or_else(|| EngineError::Other("selection has no bounds".into()))
}
/// The selected ruler guides that a transform changes: those that can be edited.
fn editable_guides(s: &Session) -> Result<Vec<vectorcraft_doc::Guide>> {
let st = s.doc()?;
Ok(st.selection.guides.iter().filter_map(|id| st.doc.ruler_guide(*id)).filter(|g| st.doc.guide_editable(g)).collect())
}
/// What a transform command scales besides geometry: Scale Strokes & Effects and Scale Corners from
@@ -125,8 +145,18 @@ fn apply_transform_moving_guides(
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]));
let with_guides = objects && p.get("ids").is_none_or(Value::is_null) && is_translation;
let has_guides = with_guides && !s.doc()?.selection.guides.is_empty();
// The selected ruler guides transform with the selection: a move moves them, and any other
// transform maps the line each one stands for ([`Document::transform_ruler_guides`]).
let with_guides = objects && p.get("ids").is_none_or(Value::is_null);
// A transform that leaves every guide where it is (a scale of a guide along its own line)
// changes no guide; with a copy, the guides are copied all the same.
let has_guides = with_guides && {
let d = &s.doc()?.doc;
let same = |g: &vectorcraft_doc::Guide| {
d.transformed_guide(g, xf) == Some(vectorcraft_doc::GuideTransform::Ruler { vertical: g.vertical, pos: g.pos })
};
editable_guides(s)?.iter().any(|g| is_translation || copy || !same(g))
};
// A transform of ids that name no object, or an identity transform without a copy, moves
// nothing: the document and its undo history stay as they are, and Transform Again repeats it.
// With a copy, the reply lists the copies, and there are none.
@@ -196,10 +226,12 @@ fn apply_transform_moving_guides(
crate::cmd::patterncmds::move_tile_with_art(d, &targets, before);
}
}
if with_guides && (delta.x != 0.0 || delta.y != 0.0) {
if with_guides && is_translation && (delta.x != 0.0 || delta.y != 0.0) {
for i in sel.guides.clone() {
d.edit_ruler_guide(i, |g| *g = g.moved(delta));
}
} else if with_guides && !is_translation {
d.transform_ruler_guides(sel, xf);
}
Ok(targets)
})?
@@ -388,6 +420,10 @@ pub(super) fn rotate(s: &mut Session, p: &Value) -> Result<Value> {
check_switches(p, &TRANSFORM_SWITCHES, "object.rotate")?;
check_switches(p, &["absolute"], "object.rotate")?;
let ids = selected_roots_to_transform(s)?;
// A bounding box angle is that of objects; ruler guides selected alone have none.
if bool_or(p, "absolute", false) && ids.is_empty() {
return Err(bad("object.rotate", "absolute needs objects selected: ruler guides have no bounding box angle"));
}
let o = origin_of(s, p, &ids)?;
let mut angle = f64_or(p, "angle", 0.0);
if bool_or(p, "absolute", false) {
+13 -2
View File
@@ -328,10 +328,21 @@ pub(crate) fn interpolates_handles(s: &mut Session, p: &Value, cmd: &str) -> Res
Ok(on)
}
/// [`transform_selected`] on the active document's selection, as one undo step `label`.
/// [`transform_selected`] on the active document's selection, as one undo step `label`. A
/// transform other than a move also transforms the selected ruler guides
/// ([`Document::transform_ruler_guides`]).
pub(crate) fn transform_anchors(s: &mut Session, label: &str, xf: vectorcraft_geom::Affine, sc: Scaling, interpolate: bool) -> Result<()> {
let sel = s.doc()?.selection.clone();
s.edit(label, |doc, _| transform_selected(doc, &sel, xf, sc, interpolate))
// As [`transform_selected`] tells a move apart, which moves the guides itself.
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;
s.edit(label, |doc, live| {
transform_selected(doc, &sel, xf, sc, interpolate)?;
if !is_translation {
doc.transform_ruler_guides(live, xf);
}
Ok(())
})
}
/// Apply `xf` to the direct-selected anchors, their handles with them, and (with `sc`) to the
+109
View File
@@ -4535,6 +4535,115 @@ fn release_guides_turns_ruler_guides_into_paths() {
assert_eq!(guides(&s).len(), 1);
}
/// The direction of a two-anchor line, in degrees from the page's x axis (y down), from 0 to 180.
fn line_angle(ends: &[(f64, f64)]) -> f64 {
let [(x0, y0), (x1, y1)] = ends[..] else { panic!("not a line of two anchors") };
(y1 - y0).atan2(x1 - x0).to_degrees().rem_euclid(180.0)
}
/// A selected ruler guide rotates with `object.rotate` on its own, in one undo step, about the
/// middle of the line Release Guides makes of it. At 30° it becomes a selected guide path along
/// the turned line; Transform Again turns that path on, and undo gives the ruler guide back.
#[test]
fn rotating_a_ruler_guide_makes_an_angled_guide() {
let mut s = session();
s.execute("guide.add", &json!({"vertical": true, "pos": 100})).unwrap();
let line = s.doc().unwrap().doc.guide_line(&s.doc().unwrap().doc.ruler_guides()[0]).unwrap();
s.execute("guide.select", &json!({"indexes": [0]})).unwrap();
let n = undo_len(&s);
s.execute("object.rotate", &json!({"angle": 30})).unwrap();
assert_eq!(undo_len(&s), n + 1);
assert!(guides(&s).is_empty(), "the ruler guide is replaced");
let [path] = selected(&s)[..] else { panic!("one guide path selected") };
assert!(selected_guides(&s).is_empty());
let (ends, guide) = line_ends(&s, path);
assert!(guide, "the path is a guide");
let (mid, len) = (line.0.midpoint(line.1), line.0.distance(line.1));
let (a, b) = (vectorcraft_geom::Point::new(ends[0].0, ends[0].1), vectorcraft_geom::Point::new(ends[1].0, ends[1].1));
assert!(a.midpoint(b).distance(mid) < 1e-6 && close(a.distance(b), len), "it turns about its middle");
// Counter-clockwise on the page: the downward vertical line now points 30° toward the right.
assert!(close(line_angle(&ends), 60.0), "{ends:?}");
s.execute("object.transformAgain", &json!({})).unwrap();
assert!(close(line_angle(&line_ends(&s, path).0), 30.0));
s.execute("edit.undo", &json!({})).unwrap();
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(guides(&s), vec![(true, 100.0)]);
assert!(s.doc().unwrap().doc.node(path).is_none());
}
/// A ruler guide turned by a quarter turn stays a ruler guide, horizontal now, through the same
/// middle; a turn of 0 changes nothing and records no undo step; a copy leaves the guide where it
/// was; and locked guides cannot be rotated.
#[test]
fn ruler_guides_turned_square_stay_ruler_guides() {
let mut s = session();
s.execute("guide.add", &json!({"vertical": true, "pos": 100})).unwrap();
let mid = {
let d = &s.doc().unwrap().doc;
let (a, b) = d.guide_line(&d.ruler_guides()[0]).unwrap();
a.midpoint(b)
};
s.execute("guide.select", &json!({"indexes": [0]})).unwrap();
let n = undo_len(&s);
s.execute("object.rotate", &json!({"angle": 0})).unwrap();
assert_eq!((guides(&s), undo_len(&s)), (vec![(true, 100.0)], n));
// Guides alone have no bounding box angle for `absolute` to set.
assert!(s.execute("object.rotate", &json!({"angle": 90, "absolute": true})).is_err());
assert_eq!((guides(&s), undo_len(&s)), (vec![(true, 100.0)], n));
s.execute("object.rotate", &json!({"angle": 90})).unwrap();
let [(vertical, pos)] = guides(&s)[..] else { panic!("one ruler guide") };
assert!(!vertical && close(pos, mid.y), "{pos}");
assert_eq!((selected_guides(&s), undo_len(&s)), (vec![0], n + 1));
// A copy at 45° adds a guide path and keeps the ruler guide.
s.execute("object.rotate", &json!({"angle": 45, "copy": true})).unwrap();
assert_eq!(guides(&s).len(), 1);
let [path] = selected(&s)[..] else { panic!("the copy is selected") };
assert!(line_ends(&s, path).1);
// Locked guides are deselected, and nothing is left to rotate.
s.execute("guide.select", &json!({"indexes": [0]})).unwrap();
s.execute("view.guides.lock", &json!({"locked": true})).unwrap();
assert!(s.execute("object.rotate", &json!({"angle": 30})).is_err());
assert_eq!(guides(&s).len(), 1);
}
/// Art and a ruler guide selected together rotate about the center of the art's box and the
/// guide's line together, and the angled guide survives a save and reopen as a guide path.
#[test]
fn a_ruler_guide_rotates_with_the_selected_art() {
let mut s = session();
let a = rect(&mut s, 300.0, 100.0, 100.0, 100.0);
s.execute("guide.add", &json!({"vertical": false, "pos": 50})).unwrap();
sel(&mut s, &[a]);
s.execute("guide.select", &json!({"indexes": [0], "toggle": true})).unwrap();
assert_eq!((selected(&s), selected_guides(&s)), (vec![a], vec![0]));
let center = {
let d = &s.doc().unwrap().doc;
let (p, q) = d.guide_line(&d.ruler_guides()[0]).unwrap();
Rect::from_points(p, q).union(bounds(&s, a)).center()
};
s.execute("object.rotate", &json!({"angle": 90})).unwrap();
let [(vertical, pos)] = guides(&s)[..] else { panic!("one ruler guide") };
assert!(vertical && close(pos, center.x + (50.0 - center.y)), "{pos}");
let turned = bounds(&s, a);
assert!(close(turned.center().x, center.x + (150.0 - center.y)), "{turned:?}");
s.execute("object.rotate", &json!({"angle": 20})).unwrap();
let paths: Vec<NodeId> = selected(&s).into_iter().filter(|id| *id != a).collect();
let [path] = paths[..] else { panic!("the guide path is selected with the art") };
let back = vectorcraft_format::load(&vectorcraft_format::save(&s.doc().unwrap().doc, false)).unwrap();
let saved = back.node(path).unwrap();
assert!(matches!(&saved.kind, NodeKind::Path { guide: true, path: p, .. } if *p == match &node(&s, path).kind {
NodeKind::Path { path, .. } => path.clone(),
_ => panic!("not a path"),
}));
// With anchors selected with Direct Selection, the selected guide turns with them.
s.execute("guide.add", &json!({"vertical": true, "pos": 600})).unwrap();
s.execute("select.anchors", &json!({"id": a.0, "anchors": [[0, 1]], "mode": "set"})).unwrap();
s.execute("guide.select", &json!({"indexes": [0], "toggle": true})).unwrap();
assert!(!s.doc().unwrap().selection.anchors.is_empty());
s.execute("object.rotate", &json!({"angle": 90})).unwrap();
assert!(!guides(&s)[0].0, "the vertical guide is horizontal now: {:?}", guides(&s));
}
#[test]
fn ruler_guides_and_lock() {
let mut s = session();
+64 -7
View File
@@ -128,6 +128,11 @@ pub struct TransformTool {
snap: Option<PointSnap>,
}
/// The selected objects and ruler guides, which a reference point set by a click belongs to.
fn selected_ids(cx: &ToolContext) -> Vec<NodeId> {
cx.selection.objects.iter().chain(&cx.selection.guides).copied().collect()
}
fn about(o: Point, a: Affine) -> Affine {
Affine::translate(o.to_vec2()) * a * Affine::translate(-o.to_vec2())
}
@@ -170,10 +175,11 @@ impl TransformTool {
}
/// The effective reference point: the custom one if it belongs to the current selection,
/// otherwise the centre of its bounding box (rotated with rotated objects).
/// otherwise the centre of its bounding box (rotated with rotated objects). With ruler guides
/// selected, it is the center of the objects' box and the guides' lines together.
pub fn reference_point(&self, cx: &ToolContext) -> Option<Point> {
if let Some((p, ids)) = &self.origin
&& *ids == cx.selection.objects
&& *ids == selected_ids(cx)
&& !ids.is_empty()
{
return Some(*p);
@@ -181,7 +187,29 @@ impl TransformTool {
// Anchors selected with Direct Selection transform alone, about their own centre.
vectorcraft_effects::preview::anchor_bounds_with(cx.selection, cx.doc, cx.bounds_measure())
.map(|b| b.center())
.or_else(|| selection_box(cx).map(|b| b.center()))
.or_else(|| if self.guide_lines(cx).is_empty() { selection_box(cx).map(|b| b.center()) } else { self.bounds(cx).map(|b| b.center()) })
}
/// The selected ruler guides the tool transforms, as the boxes of the lines they stand for
/// ([`vectorcraft_doc::Document::guide_line`]): those that can be edited, with objects
/// selected, and with the Rotate tool also without.
fn guide_lines(&self, cx: &ToolContext) -> Vec<Rect> {
if cx.selection.is_empty() && self.kind != TransformKind::Rotate {
return vec![];
}
let d = cx.doc;
let guides = cx.selection.guides.iter().filter_map(|id| d.ruler_guide(*id)).filter(|g| d.guide_editable(g));
guides.filter_map(|g| d.guide_line(&g)).map(|(a, b)| Rect::from_points(a, b)).collect()
}
/// The bounding box of the selected objects and the lines of the guides the tool transforms.
fn bounds(&self, cx: &ToolContext) -> Option<Rect> {
self.guide_lines(cx).into_iter().fold(selection_bounds(cx), |acc, r| Some(acc.map_or(r, |acc| acc.union(r))))
}
/// Is there anything selected for the tool to transform?
fn has_target(&self, cx: &ToolContext) -> bool {
!cx.selection.is_empty() || !self.guide_lines(cx).is_empty()
}
/// Transform for dragging from `start` to `p` about `o`; returns the matrix and a readout.
@@ -331,7 +359,7 @@ impl Tool for TransformTool {
let p = ev.pos;
match ev.kind {
PointerKind::Down => {
let Some(bounds) = selection_bounds(cx) else { return vec![] };
let Some(bounds) = self.bounds(cx) else { return vec![] };
self.hover.clear();
let (pick, _) = snap_pick(cx, p);
// Alt: decided on release. A click sets the point and opens the dialog; a drag
@@ -422,7 +450,7 @@ impl Tool for TransformTool {
} else {
// A click sets the reference point; with Alt, it opens the dialog too. With the
// Reflect tool, a plain click also sets the first point of an axis.
self.origin = Some((d.pick, cx.selection.objects.clone()));
self.origin = Some((d.pick, selected_ids(cx)));
self.drop_axis();
if d.alt {
vec![self.dialog(d.pick)]
@@ -450,7 +478,7 @@ impl Tool for TransformTool {
PointerKind::TripleClick => vec![],
PointerKind::Move => {
if self.drag.is_none() {
let (pick, hover) = if cx.selection.is_empty() { (p, vec![]) } else { snap_pick(cx, p) };
let (pick, hover) = if self.has_target(cx) { snap_pick(cx, p) } else { (p, vec![]) };
self.hover = hover;
self.axis_to = self.axis_first(cx).map(|_| pick);
}
@@ -525,7 +553,7 @@ impl Tool for TransformTool {
}
fn cursor(&self, cx: &ToolContext, _p: Point, _m: Mods) -> Cursor {
if cx.selection.is_empty() {
if !self.has_target(cx) {
return Cursor::NotAllowed;
}
match self.kind {
@@ -657,6 +685,35 @@ mod tests {
assert_eq!(up.last(), Some(&Action::Commit));
}
/// With only a ruler guide selected, the Rotate tool drags about the middle of the guide's
/// line, and Alt-click opens its dialog; the Scale tool still needs objects.
#[test]
fn the_rotate_tool_turns_a_selected_ruler_guide_alone() {
let mut d = vectorcraft_doc::Document::new(500.0, 500.0);
let g = d.add_ruler_guide(&vectorcraft_doc::Guide::new(true, 100.0));
let mut s = Selection::default();
s.guides.push(g);
let p = paint();
let cx = cx(&d, &s, &p);
let mut t = TransformTool::new(TransformKind::Rotate);
assert_eq!(t.reference_point(&cx), Some(Point::new(100.0, 250.0)));
assert_ne!(t.cursor(&cx, Point::ZERO, Mods::default()), Cursor::NotAllowed);
assert!(t.pointer(&cx, &ev(PointerKind::Down, 200.0, 250.0)).is_empty());
let a = t.pointer(&cx, &ev(PointerKind::Drag, 100.0, 350.0));
assert_eq!(a[0], Action::Begin("Rotate".into()));
let m = matrix(&a[1]);
assert!((m * Point::new(100.0, 250.0)).distance(Point::new(100.0, 250.0)) < 1e-9);
assert!((m * Point::new(200.0, 250.0)).distance(Point::new(100.0, 350.0)) < 1e-9);
assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, 100.0, 350.0)).last(), Some(&Action::Commit));
t.pointer(&cx, &ev(PointerKind::Down, 50.0, 60.0).with_mods(alt()));
let up = t.pointer(&cx, &ev(PointerKind::Up, 50.0, 60.0).with_mods(alt()));
assert!(matches!(up.as_slice(), [Action::Dialog(id, _)] if id == "rotate"), "{up:?}");
let mut scale = TransformTool::new(TransformKind::Scale);
assert_eq!(scale.reference_point(&cx), None);
assert!(scale.pointer(&cx, &ev(PointerKind::Down, 200.0, 250.0)).is_empty());
assert!(scale.pointer(&cx, &ev(PointerKind::Drag, 100.0, 350.0)).is_empty());
}
#[test]
fn click_sets_reference_point_then_drag_uses_it() {
let (d, id) = doc_with_rect();
+10
View File
@@ -3972,6 +3972,16 @@ Selection tool, a double-click with Cmd/Ctrl and Shift held releases the ruler g
(`pointer_gesture` with a `doubleclick` event and `mods: {cmd: true, shift: true}`), unless guides are hidden or
locked.
Selected ruler guides rotate with the Rotate tool, `object.rotate` (Object › Transform › Rotate…, with `copy` for
Copy) and `object.transformAgain`, also when no object is selected, in one undo step. `object.transform`,
`object.scale`, `object.reflect` and `object.shear` transform them too when objects are selected with them. Each
guide transforms as the line `view.guides.release` makes of it, and the default origin is the center of the selected
objects' box and those lines together. A guide that ends up vertical or horizontal stays a ruler guide at its new
place: a turn of 180° keeps it, and a turn of 90° makes a horizontal guide vertical. A guide at any other angle
becomes a guide path along its line, on the guide's layer, and is selected as one. Locked or hidden guides do not
transform, nor do guides when `ids` is given or `objects` is false. `object.rotate` with `absolute` and only ruler
guides selected is an error, as guides have no bounding box angle.
The Selection, Direct Selection and Group Selection tools pick a guide within the selection tolerance, over the art
(an anchor on it comes first with Direct Selection), and drag the selected guides: `mods.alt` copies them,
`mods.shift` snaps the dragged guide to the ruler's ticks, and otherwise it snaps to whole pixels, the grid or, with
+1
View File
@@ -642,6 +642,7 @@ since 2026-10-01.
- **Guide row highlight (#7344):** `guide_row_highlight_stays_selected_without_hover` in `crates/ui-egui/src/panels/layers/tests.rs` checks selected guide background after the pointer leaves, with unselected guide and ordinary row controls. Guide selection, dragging and deletion are unchanged. Scores and estimates unchanged.
- **Trim View hides guides and the grid (#8363):** while View › Trim View is on, the canvas and tiled panes draw no ruler guides, no guide paths and no grid, the guides are neither snapped to nor picked, and Show/Hide Guides and Show/Hide Grid are greyed out (menu bar, canvas context menu, Properties) and refuse to run; the stored choices come back when it is turned off, and the rulers stay ([trim view hides guides](https://community.adobe.com/t5/illustrator-discussions/trim-view-hides-guides/td-p/14066140), [guides greyed out](https://community.adobe.com/t5/illustrator-discussions/guides-greyed-out/m-p/11132728)). A drag or double-click on a ruler makes no guide while it is on (no preview, no undo step, a status message). `trim_view_hides_the_guides_and_the_grid`, `trim_view_deselects_selected_guide_paths`, `trim_view_makes_no_guide_from_the_rulers` in `crates/ui-egui/src/canvas/tests.rs`; `trim_view_greys_out_show_guides_and_show_grid` in `crates/ui-egui/src/menus/tests.rs`.
- **Rotating ruler guides (part of #2418):** unlocked guides can be moved, modified and deleted ([user guide, Use guides](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=90)). A selected ruler guide rotates with the Rotate tool, Object › Transform › Rotate… (Copy included) and Transform Again, also with no object selected, in one undo step, and transforms with the selected objects under Scale, Reflect and Shear. Each guide transforms as the line Release Guides makes of it, about the center of that line and the objects' box together. By VectorCraft's own rule, a guide that ends up vertical or horizontal stays a ruler guide, and one at any other angle becomes a guide path along its line, which saves and opens as other guide paths do. `rotating_a_ruler_guide_makes_an_angled_guide`, `ruler_guides_turned_square_stay_ruler_guides`, `a_ruler_guide_rotates_with_the_selected_art` in `crates/engine/src/tests/menucmds.rs`; `the_rotate_tool_turns_a_selected_ruler_guide_alone` in `crates/tools/src/xform/transform.rs`.
- **Recolor picker follow-up (#8031/#4028):** native Lab numeric entry, document/loaded-library swatches in the Color Picker, and Assign-row Pick from Swatches / Limit to Library menus. #4090 provided the double-click picker and #5113 the Assign sliders. Regression tests `native_lab_entry_in_color_picker` and `row_context_menu_pick_from_swatches_and_limit_to_library` exercise the fields and menu callbacks rather than writing their result state. Area score and hours unchanged.
- **Recolor with Preset asks for a library first:** Edit › Edit Colors › Recolor with Preset (1, 2 and 3 Color Job, Color Library) opens a Recolor with Preset dialog whose Limit to Library menu (None, Document Swatches or a library) is applied when Recolor Artwork opens (<https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=251>, "Quickly reduce colors using a preset"). A 1 Color Job limited to the document's swatches with a spot or global ink picked turns gray art into tints of that ink linked to its swatch, so editing the swatch recolors the art. Tests `recolor_with_preset_asks_for_a_library_first` and `a_one_color_job_limited_to_document_swatches_links_gray_art_to_the_ink`. Area score and hours unchanged.