DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
V: scrubby zoom with the Zoom tool
Brandon Thomasfed23aa7ee63
diff --git a/ROADMAP.md b/ROADMAP.mdindex 742af586d..bc702bdbf 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -30,6 +30,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope- Edit › Paste Into (copied objects become a frame's content, clipped by it; rendered, PDF and IDML both ways — verified in InDesign 2026); Polygon Settings (sides, star inset; double-click the Polygon tool).- Color panel (fill/stroke proxy, CMYK/RGB/Lab sliders with channel ramps, tint slider for swatches, spectrum ramp, Add to Swatches) and Color Picker (double-click the proxy); mixed colours are unnamed (not listed in Swatches until added); `object.color`, `swatch.addToSwatches`, `swatch.addUnnamed`.- Place text files: Word (.docx: styles by name with their attributes, bold/italic/underline/size/font, footnotes, tables, tabs, breaks), RTF and plain text, into the insertion point, the selected frame or a new frame; autoflow adds pages and threaded frames until the text fits; Remove Styles option (`designcraft-textimport`).+- Scrubby zoom: drag the Zoom tool left or right to zoom continuously around the press point.- Guides belong to the active layer: hidden with it (or with its Show Guides off) and locked with it.- Pencil tool (N): freehand strokes simplified to smooth paths (Alt closes); Smooth and Erase are still to come.- Edit › Keyboard Shortcuts: every command, click and press the new keys, conflicts shown, per-command and global reset; `window.setShortcut`.diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rsindex 8be96f46c..5d607f142 100644--- a/crates/tools/src/lib.rs+++ b/crates/tools/src/lib.rs@@ -272,7 +272,7 @@ pub fn create(id: &str) -> Box<dyn Tool> {"eyedropper" => Box::new(xform::EyedropperTool),"hand" => Box::new(nav::HandTool::default()),"placeGun" => Box::new(nav::PlaceGun::default()),- "zoom" => Box::new(nav::ZoomTool),+ "zoom" => Box::new(nav::ZoomTool::default()),other => Box::new(NoopTool(tool_info(other).map(|t| t.id).unwrap_or("selection"))),}}diff --git a/crates/tools/src/nav.rs b/crates/tools/src/nav.rsindex 6d84e091d..2b45cc592 100644--- a/crates/tools/src/nav.rs+++ b/crates/tools/src/nav.rs@@ -41,19 +41,51 @@ impl Tool for HandTool {}}+/// Zoom tool: click zooms in (Alt: out); dragging left or right zooms out or in continuously+/// around the press point (scrubby zoom).#[derive(Default)]-pub struct ZoomTool;+pub struct ZoomTool {+ /// Press point (canvas), zoom at the press, whether it has been dragged.+ press: Option<(Point, f64, bool)>,+}++/// Screen pixels of horizontal drag per e-fold of zoom.+const SCRUB_PX: f64 = 150.0;impl Tool for ZoomTool {fn id(&self) -> &'static str {"zoom"}- fn pointer(&mut self, _cx: &ToolContext, ev: &PointerEvent) -> Vec<Action> {- if ev.kind == PointerKind::Up {- let f = if ev.mods.alt { 0.5 } else { 2.0 };- return vec![Action::View(json!({"zoomAt": [ev.pos.x, ev.pos.y], "factor": f}))];+ fn pointer(&mut self, cx: &ToolContext, ev: &PointerEvent) -> Vec<Action> {+ match ev.kind {+ PointerKind::Down => {+ self.press = Some((ev.pos, cx.zoom, false));+ vec![]+ }+ PointerKind::Drag => {+ let Some((start, z0, _)) = self.press else { return vec![] };+ // The press point stays put on screen, so this is the on-screen distance.+ let dx = (ev.pos.x - start.x) * cx.zoom;+ if dx.abs() < 3.0 && self.press.is_some_and(|p| !p.2) {+ return vec![];+ }+ self.press = Some((start, z0, true));+ let want = (z0 * (dx / SCRUB_PX).exp()).clamp(0.05, 40.0);+ vec![Action::View(json!({"zoomAt": [start.x, start.y], "factor": want / cx.zoom.max(1e-9)}))]+ }+ PointerKind::Up => {+ let dragged = self.press.take().is_some_and(|p| p.2);+ if dragged {+ return vec![];+ }+ let f = if ev.mods.alt { 0.5 } else { 2.0 };+ vec![Action::View(json!({"zoomAt": [ev.pos.x, ev.pos.y], "factor": f}))]+ }+ _ => vec![],}- vec![]+ }+ fn busy(&self) -> bool {+ self.press.is_some_and(|p| p.2)}fn cursor(&self, _cx: &ToolContext, _p: Point, m: Mods) -> Cursor {if m.alt { Cursor::ZoomOut } else { Cursor::ZoomIn }diff --git a/crates/tools/src/tests.rs b/crates/tools/src/tests.rsindex ba50a4e3f..1d74dab4b 100644--- a/crates/tools/src/tests.rs+++ b/crates/tools/src/tests.rs@@ -180,3 +180,26 @@ fn pencil_draws_a_smooth_path() {other => panic!("{other:?}"),}}++#[test]+fn zoom_tool_click_and_scrub() {+ let d = Document::new(&NewDocument::default());+ let (s, c, l) = (Selection::default(), Cache::new(), CanvasLayout::new(&d, false));+ let cx = ctx(&d, &s, &c, &l);+ let mut t = create("zoom");+ t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 100.0, 100.0));+ assert_eq!(+ t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 100.0, 100.0)),+ vec![Action::View(serde_json::json!({"zoomAt": [100.0, 100.0], "factor": 2.0}))]+ );+ // Dragging 150 px right zooms in by e, anchored at the press point; no click zoom after.+ t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 100.0, 100.0));+ match &t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, 250.0, 100.0))[..] {+ [Action::View(v)] => {+ assert_eq!(v["zoomAt"], serde_json::json!([100.0, 100.0]));+ assert!((v["factor"].as_f64().unwrap() - std::f64::consts::E).abs() < 1e-9);+ }+ other => panic!("{other:?}"),+ }+ assert!(t.pointer(&cx, &PointerEvent::new(PointerKind::Up, 250.0, 100.0)).is_empty());+}diff --git a/docs/parity.md b/docs/parity.mdindex 78c71cd09..ba2f52660 100644--- a/docs/parity.md+++ b/docs/parity.md@@ -10,7 +10,7 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia| Priority | Features | Done | Partial | Missing | Parity ||---|---|---|---|---|---|| P0 | 102 | 99 | 3 | 0 | 99% |-| P1 | 97 | 53 | 24 | 20 | 67% |+| P1 | 97 | 54 | 24 | 19 | 68% || P2 | 76 | 8 | 7 | 61 | 15% || Area | Parity |@@ -31,7 +31,7 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia| Interactivity & digital | 30% || Output & production | 58% || XML & automation | 39% |-| View & navigation | 68% |+| View & navigation | 75% || Undo, history, saving | 100% || Accessibility | 20% |@@ -298,7 +298,7 @@ Open P0 items: Preferences, Vector/page formats (PDF/AI/SVG/EPS place), Export t| XML & automation | Object Library | P2 | M || View & navigation | Zoom commands | P0 | D || View & navigation | Power Zoom | P2 | M |-| View & navigation | Animated/scrubby zoom | P1 | M |+| View & navigation | Animated/scrubby zoom | P1 | D || View & navigation | Screen modes | P0 | D || View & navigation | Overprint preview | P1 | M || View & navigation | Rulers, guides, grids toggles | P0 | D |