DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Direct Selection: handles around the selected anchors only, and no bounding box
moppeeer3fbaf8dfb972
diff --git a/ROADMAP.md b/ROADMAP.mdindex b4e89178a..a6719bbac 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -348,6 +348,7 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.mNewest first.+- **2026-10-23** · Direct Selection shows a path's direction handles as InDesign: both handles of each selected anchor and, on its neighbours, the handle shaping the segment to it; no handles with no anchor selected, and handles that don't show can't be grabbed. The tool draws the path and its points without the bounding box. Found in the Learn Skills Daily course, chapter 43. No readiness percentage change.- **2026-10-22** · A ruler guide dragged with the Selection tools, out of a ruler, on its own or with other selected guides, snaps along its axis as objects do (#1221): to other ruler guides, margins, columns, bleed, page and object edges and centers (with the smart-guide mark) and the document grid, within the snap zone and following Snap to Guides and Smart Guides. Shift snaps to the ruler's ticks and Cmd suspends snapping. The preview line, the position readout and the drop use the same snapped position. No readiness percentage change.- **2026-10-22** · macOS: the app menu has a Language submenu after Settings… with each interface language in its own name and the current one checked, as in the suite's other apps; Preferences › General › Interface Language stays. No readiness percentage change.- **2026-10-22** · macOS menu bar: the menus keep working after the interface language or Show CJK Features changes (a rebuilt menu bar lost every click, Quit included), and its key equivalents are the shortcuts in effect, so a shortcut moved in the Keyboard Shortcuts editor leaves its old menu item. No readiness percentage change.diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rsindex 634e22cb8..2705500bf 100644--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@ -1652,6 +1652,48 @@ fn a_line_fits_when_its_baseline_does() {assert!(overset(&mut s, 50.0), "a baseline below the frame still oversets the line");}+/// The course's chapter 43: with Direct Selection, a circle's selected anchor shows its handles+/// and they drag, reshaping the curve; the handles of the anchors away from it neither show nor+/// catch a press, as in InDesign.+#[test]+fn direct_selection_drags_only_the_handles_around_the_selected_anchor() {+ use designcraft_tools::{PointerEvent, PointerKind};+ let mut s = session();+ let v = ViewInfo::at_zoom(1.0);+ let id = s.execute("frame.create", &json!({"rect": [100, 300, 300, 500], "shape": "ellipse"})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"ids": [id]})).unwrap();+ s.set_tool("directSelection");+ // Each anchor and its two handles, in the spread.+ let anchors = |s: &Session| {+ let st = s.doc().unwrap();+ let it = st.doc.item(designcraft_doc::ItemId(id)).unwrap();+ it.path.subpaths[0].anchors.iter().map(|a| (it.xf * a.p, it.xf * a.h_in, it.xf * a.h_out)).collect::<Vec<_>>()+ };+ let before = anchors(&s);+ let lowest = |f: &dyn Fn(f64) -> f64| (0..before.len()).min_by(|a, b| f(before[*a].0.y).total_cmp(&f(before[*b].0.y))).unwrap();+ let (bottom, top) = (lowest(&|y| -y), lowest(&|y| y));+ let press = |s: &mut Session, from: designcraft_geom::Point, to: designcraft_geom::Point| {+ s.pointer(&PointerEvent::new(PointerKind::Down, from.x, from.y), v).unwrap();+ s.pointer(&PointerEvent::new(PointerKind::Drag, (from.x + to.x) / 2.0, (from.y + to.y) / 2.0), v).unwrap();+ s.pointer(&PointerEvent::new(PointerKind::Drag, to.x, to.y), v).unwrap();+ s.pointer(&PointerEvent::new(PointerKind::Up, to.x, to.y), v).unwrap();+ };+ // Select the bottom anchor.+ let b = before[bottom].0;+ press(&mut s, b, b);+ assert_eq!(s.doc().unwrap().selection.anchors, [(designcraft_doc::ItemId(id), 0, bottom)]);+ // Its handle drags: the handle moves.+ let h = before[bottom].2;+ press(&mut s, h, h + designcraft_geom::Vec2::new(30.0, 0.0));+ let after = anchors(&s);+ assert!((after[bottom].2 - before[bottom].2).hypot() > 20.0, "the bottom handle moved: {:?} → {:?}", before[bottom], after[bottom]);+ // The top anchor's handle isn't shown, so a press on it doesn't take it.+ let t = before[top].2;+ press(&mut s, t, t + designcraft_geom::Vec2::new(0.0, -30.0));+ let after2 = anchors(&s);+ assert!((after2[top].2 - before[top].2).hypot() < 1e-6, "the top handle stays: {:?} → {:?}", before[top], after2[top]);+}+/// Direct Selection: a marquee over the top edges of two frames selects their top points, and a/// drag on one of them slants both frames in one undo step (InDesign's way to make a row of/// parallelograms).diff --git a/crates/tools/src/select.rs b/crates/tools/src/select.rsindex 5853536aa..4b501fca9 100644--- a/crates/tools/src/select.rs+++ b/crates/tools/src/select.rs@@ -145,21 +145,42 @@ pub fn anchor_at(cx: &ToolContext, p: Point) -> Option<(u64, usize, usize, Optioanchor_at_in(cx, &cx.selection.items, p)}-/// [`anchor_at`] over the given items.+/// Whether the Direct Selection tool shows (and lets you drag) a direction handle of anchor `ai`+/// of a sub-path of `n` anchors, as InDesign: both handles of a selected anchor, and on its+/// neighbours the handle that shapes the segment to it (`out`: the outgoing handle). With no+/// anchor selected no handle shows.+pub fn handle_shown(n: usize, closed: bool, ai: usize, out: bool, chosen: impl Fn(usize) -> bool) -> bool {+ if chosen(ai) {+ return true;+ }+ let neighbour = if out {+ if ai + 1 < n { Some(ai + 1) } else { closed.then_some(0) }+ } else if ai > 0 {+ Some(ai - 1)+ } else {+ closed.then(|| n.saturating_sub(1))+ };+ neighbour.is_some_and(chosen)+}++/// [`anchor_at`] over the given items. Of the direction handles, only those [`handle_shown`]+/// shows are found.pub fn anchor_at_in(cx: &ToolContext, ids: &[designcraft_doc::ItemId], p: Point) -> Option<(u64, usize, usize, Option<&'static str>)> {let tol = cx.tol(5.0);for id in ids {let (Some(it), Some(xf)) = (cx.doc.item(*id), cx.item_canvas_xf(*id)) else { continue };let m = xf * it.xf;for (si, sp) in it.path.subpaths.iter().enumerate() {+ let chosen = |a: usize| cx.selection.anchors.contains(&(*id, si, a));for (ai, a) in sp.anchors.iter().enumerate() {if ((m * a.p) - p).hypot() <= tol {return Some((id.0, si, ai, None));}- if a.has_in() && ((m * a.h_in) - p).hypot() <= tol {+ let shown = |out: bool| handle_shown(sp.anchors.len(), sp.closed, ai, out, chosen);+ if a.has_in() && shown(false) && ((m * a.h_in) - p).hypot() <= tol {return Some((id.0, si, ai, Some("in")));}- if a.has_out() && ((m * a.h_out) - p).hypot() <= tol {+ if a.has_out() && shown(true) && ((m * a.h_out) - p).hypot() <= tol {return Some((id.0, si, ai, Some("out")));}}@@ -1467,3 +1488,26 @@ fn edit_text_at(cx: &ToolContext, p: Point) -> Option<Vec<Action>> {let (_, sp) = cx.layout.spread_at(p).unwrap_or((SpreadRef::Doc(0), p));Some(vec![Action::SwitchTool("type".into()), Action::Exec("text.placeCaret".into(), json!({"frame": id.0, "point": [sp.x, sp.y]}))])}++#[cfg(test)]+mod handle_tests {+ use super::handle_shown;++ /// InDesign's Direct Selection shows a selected anchor's two handles, and on its neighbours+ /// the handle shaping the segment to it; nothing with no anchor selected.+ #[test]+ fn handles_show_around_the_selected_anchors() {+ let shown = |closed: bool, chosen: &[usize]| {+ (0..4)+ .flat_map(|ai| [false, true].map(|out| (ai, out)))+ .filter(|(ai, out)| handle_shown(4, closed, *ai, *out, |a| chosen.contains(&a)))+ .collect::<Vec<_>>()+ };+ assert_eq!(shown(true, &[]), vec![], "no anchor selected");+ assert_eq!(shown(true, &[2]), vec![(1, true), (2, false), (2, true), (3, false)]);+ // Closed, the first anchor's neighbours wrap round.+ assert_eq!(shown(true, &[0]), vec![(0, false), (0, true), (1, false), (3, true)]);+ // Open, the end has no neighbour beyond it.+ assert_eq!(shown(false, &[0]), vec![(0, false), (0, true), (1, false)]);+ }+}diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 6172a5948..099d9e3e2 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -1242,14 +1242,16 @@ fn draw_selection(app: &DesignApp, painter: &egui::Painter, xf: &Xf, doc: &Docum}let mut union: Option<Rect> = None;let mut color = Color32::from_rgb(79, 153, 255);+ let direct = matches!(app.session.tool_id(), "directSelection" | "pen" | "addAnchor" | "deleteAnchor" | "convertDirection");for id in &sel.items {let (Some(it), Some((a, _))) = (doc.item(*id), item_canvas_xf(doc, layout, *id)) else { continue };color = layer_color(doc, it);for poly in path_screen(it, xf, a) {painter.add(egui::Shape::line(poly, Stroke::new(1.0, color)));}- if sel.items.len() == 1 && sel.text.is_none() {- // InDesign draws a 1 pt bounding box around the selection.+ // InDesign draws a 1 pt bounding box around the selection; with the Direct Selection tool,+ // only the path and its points.+ if sel.items.len() == 1 && sel.text.is_none() && !direct {painter.rect_stroke(xf.rect(a.transform_rect_bbox(it.bounds())), 0.0, Stroke::new(1.0, color), StrokeKind::Middle);}let b = xf.rect(a.transform_rect_bbox(it.bounds()));@@ -1277,7 +1279,9 @@ fn draw_selection(app: &DesignApp, painter: &egui::Painter, xf: &Xf, doc: &Docum}}}- let direct = matches!(app.session.tool_id(), "directSelection" | "pen" | "addAnchor" | "deleteAnchor" | "convertDirection");+ // Direct Selection shows only the handles around the selected anchors, as InDesign; the pen+ // and the anchor tools show every handle they work on.+ let some_handles = app.session.tool_id() == "directSelection";if direct {// Looked up once per anchor drawn: a large marquee selection stays linear.let chosen_set: std::collections::HashSet<(designcraft_doc::ItemId, usize, usize)> = sel.anchors.iter().copied().collect();@@ -1290,7 +1294,11 @@ fn draw_selection(app: &DesignApp, painter: &egui::Painter, xf: &Xf, doc: &Documlet p = xf.to_screen(m * an.p);// A selected anchor point is solid, the others hollow (InDesign).let chosen = chosen_set.contains(&(*id, si, ai));- for (h, has) in [(an.h_in, an.has_in()), (an.h_out, an.has_out())] {+ let shown = |out: bool| {+ !some_handles+ || designcraft_tools::select::handle_shown(sp.anchors.len(), sp.closed, ai, out, |a| chosen_set.contains(&(*id, si, a)))+ };+ for (h, has) in [(an.h_in, an.has_in() && shown(false)), (an.h_out, an.has_out() && shown(true))] {if has {let hp = xf.to_screen(m * h);painter.line_segment([p, hp], Stroke::new(1.0, col));