Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge branch 'codex/page-tool' into codex/page-tool-control-panel

moppeeer3f1eb00bb30a
diff --cc ROADMAP.md
index d9957d5d1,a97355ddd..573b0a37b
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -129,8 -128,14 +128,15 @@@ list) · [roadmap.md](docs/roadmap.md)
Newest first.
+- **2026-10-14** · With the Page tool, the Control panel shows the page as InDesign's does: W/H from a reference point, page-size preset (US Business Card added), orientation, Liquid Page Rule (now with Controlled by Parent) and Show Parent Page Overlay, which draws the parent page's size over a resized page. No readiness percentage change.
- **2026-10-14** · The Page tool works as InDesign's: a click selects a page and shows its handles and liquid page rule; dragging a handle previews the rule and springs back, Alt-drag resizes the page from the opposite edge, Shift keeps proportions, with a W/H readout. No readiness percentage change.
+ - **2026-10-12** · Text threads by hand: click a selected text frame's in or out port to load
+ the text cursor, then click a frame to thread it, click empty space for a column-wide frame or
+ drag one (it snaps like frame drawing); Shift-click autoflows, Alt-click stays loaded on the
+ frame just added; click the linked frame or double-click a port to break the thread.
+ `text.thread`, `text.unthread`, `text.removeFromThread` with undo; locked frames and layers
+ refuse threads. The alpha gate now waits only on the Primary Text Frame page fixes (#165). No
+ readiness percentage change.
- **2026-10-12** · macOS Dock Quit uses the same unsaved-document prompts as window and menu Quit. Repeated requests keep the current answers; Cancel retains every tab and unsaved recovery checkpoint, and completed Save/Don't Save answers exit through the ordinary event loop. No readiness percentage change.
- **2026-10-12** · Orderly native exit writes the latest recovery state after finalizing current quit approvals; incomplete or stale plans keep their documents, and Undo to the saved state clears stale recovery. Unavailable or failed recovery is reported. Cancelable macOS Dock Quit remains open (#544). No readiness percentage change.
- **2026-10-12** · Recovered documents keep a checkpoint until saved, closed or reverted, including a second crash before autosave. Restarted document IDs and explicit recovery folders preserve other snapshots; failed republishing retains the original. No readiness percentage change.
diff --cc crates/engine/src/tests.rs
index 9557e03cf,22da23590..a89c579e1
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@@ -643,27 -643,102 +643,127 @@@ fn page_size_keeps_objects_by_its_ancho
assert_eq!(s.execute("layout.selectPage", &json!({"page": 1})).unwrap()["page"], 1);
}
+#[test]
+fn controlled_by_parent_takes_the_parent_pages_rule() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"width": 400, "height": 400, "facingPages": false})).unwrap();
+ let id = s.execute("frame.create", &json!({"rect": [100, 100, 200, 200]})).unwrap()["id"].as_u64().unwrap();
+ let frame = |s: &Session| s.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().bounds();
+ // The page follows its parent; the parent page re-centres.
+ s.execute("liquid.pageRule", &json!({"rule": "controlledByParent", "pages": [1]})).unwrap();
+ s.edit(|d, _| {
+ std::sync::Arc::make_mut(&mut d.parents[0]).pages[0].liquid = designcraft_doc::LiquidRule::ReCenter;
+ Ok(())
+ })
+ .unwrap();
+ s.execute("layout.pageSize", &json!({"pages": [1], "width": 600})).unwrap();
+ assert_eq!(frame(&s).x0, 200.0, "re-centred: {:?}", frame(&s));
+ // Without a parent (or a parent that's also controlled by its parent) nothing moves.
+ s.execute("layout.pages.applyParent", &json!({"pages": [0], "parent": null})).unwrap();
+ s.execute("layout.pageSize", &json!({"pages": [1], "width": 800})).unwrap();
+ assert_eq!(frame(&s).x0, 200.0);
+ // Show Parent Page Overlay is a page option.
+ s.execute("layout.pageOptions", &json!({"pages": [1], "showParentOverlay": true})).unwrap();
+ assert!(s.doc().unwrap().doc.spreads[0].pages[0].show_parent_overlay);
+ assert!(s.execute("layout.pageOptions", &json!({"pages": [2], "showParentOverlay": true})).is_err());
+}
++
+ /// Load the text from a frame's out port with the Selection tool and click on the pasteboard:
+ /// a new frame is threaded there and the overset text flows into it.
+ #[test]
+ fn threading_with_the_loaded_text_cursor_on_the_sample() {
+ use designcraft_tools::{PointerEvent, PointerKind};
+ let mut s = Session::new();
+ s.execute("file.newSample", &json!({})).unwrap();
+ let d = s.doc().unwrap().doc.clone();
+ let (sid, first) = d.stories.values().find(|st| st.frames.len() >= 2).map(|st| (st.id, st.frames[0])).expect("a threaded story");
+ // Break the thread so the first frame is overset, and select it.
+ s.execute("text.unthread", &json!({"frame": first.0})).unwrap();
+ assert!(s.cache.get(&s.doc().unwrap().doc, sid, None).is_overset());
+ s.execute("selection.set", &json!({"ids": [first.0]})).unwrap();
+ s.set_tool("selection");
+ let v = ViewInfo::at_zoom(1.0);
+ let layout = s.layout();
+ let port = designcraft_tools::thread::port_center(&s.doc().unwrap().doc, &layout, first, true, v.zoom).unwrap();
+ let ev = |k, p: designcraft_geom::Point| PointerEvent::new(k, p.x, p.y);
+ s.pointer(&ev(PointerKind::Down, port), v).unwrap();
+ s.pointer(&ev(PointerKind::Up, port), v).unwrap();
+ assert_eq!(s.cursor(port + designcraft_geom::Vec2::new(-2000.0, 0.0), Default::default(), v), designcraft_tools::Cursor::LoadedText);
+ // On the pasteboard left of the first spread.
+ let b = layout.slots[0].bounds;
+ let at = designcraft_geom::Point::new(b.x0 - 300.0, b.y0 + 100.0);
+ let undo = s.doc().unwrap().history.undo.len();
+ s.pointer(&ev(PointerKind::Down, at), v).unwrap();
+ s.pointer(&ev(PointerKind::Up, at), v).unwrap();
+ let st = s.doc().unwrap();
+ assert_eq!(st.history.undo.len(), undo + 1, "one undo step");
+ let frames = st.doc.story(sid).unwrap().frames.clone();
+ assert_eq!(frames.len(), 2);
+ let new = frames[1];
+ assert_eq!(st.selection.items, [new]);
+ let cs = s.cache.get(&s.doc().unwrap().doc, sid, None);
+ assert!(cs.frames.iter().any(|f| f.frame == new && !f.range.is_empty()), "the text flows into the new frame");
+ let nb = s.doc().unwrap().doc.item(new).unwrap().bounds();
+ assert!((nb.y0 - layout.to_spread(designcraft_doc::SpreadRef::Doc(0), at).y).abs() < 1e-6, "{nb:?}");
+ }
+
+ /// Drag a selection handle of item 0 on spread 0 from the edge point `at` by `by` (canvas units).
+ fn drag_handle(s: &mut Session, at: designcraft_geom::Point, by: designcraft_geom::Vec2, v: ViewInfo) {
+ use designcraft_tools::{PointerEvent, PointerKind};
+ let p = s.layout().to_canvas(designcraft_doc::SpreadRef::Doc(0), at);
+ s.pointer(&PointerEvent::new(PointerKind::Down, p.x, p.y), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Drag, p.x + by.x / 2.0, p.y + by.y / 2.0), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Drag, p.x + by.x, p.y + by.y), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Up, p.x + by.x, p.y + by.y), v).unwrap();
+ }
+
+ #[test]
+ fn text_frame_resize_snaps_to_the_margins() {
+ use designcraft_geom::{Point, Vec2};
+ for zoom in [1.0, 0.5] {
+ let mut s = Session::new();
+ s.execute("file.newSample", &json!({})).unwrap();
+ let margin = s.doc().unwrap().doc.spreads[0].pages[0].margin_rect();
+ let (x0, y0) = (margin.x0 + 40.0, margin.y0 + 40.0);
+ s.execute("frame.create", &json!({"rect": [x0, y0, x0 + 200.0, y0 + 200.0], "content": "text"})).unwrap();
+ s.set_tool("selection");
+ let v = ViewInfo::at_zoom(zoom);
+ let b0 = s.doc().unwrap().doc.spreads[0].items.last().unwrap().bounds();
+ // Right handle to 1.5 pt short of the right margin.
+ drag_handle(&mut s, Point::new(b0.x1, b0.center().y), Vec2::new(margin.x1 - 1.5 - b0.x1, 0.0), v);
+ let b = s.doc().unwrap().doc.spreads[0].items.last().unwrap().bounds();
+ assert!((b.x1 - margin.x1).abs() < 1e-6, "zoom {zoom}: right edge {} not on the margin {}", b.x1, margin.x1);
+ // Bottom handle to 1.5 pt past the bottom margin.
+ drag_handle(&mut s, Point::new(b.center().x, b.y1), Vec2::new(0.0, margin.y1 + 1.5 - b.y1), v);
+ let b = s.doc().unwrap().doc.spreads[0].items.last().unwrap().bounds();
+ assert!((b.y1 - margin.y1).abs() < 1e-6, "zoom {zoom}: bottom edge {} not on the margin {}", b.y1, margin.y1);
+ // Top-left corner handle onto the top and left margins.
+ drag_handle(&mut s, Point::new(b.x0, b.y0), Vec2::new(margin.x0 + 1.0 - b.x0, margin.y0 - 1.0 - b.y0), v);
+ let b = s.doc().unwrap().doc.spreads[0].items.last().unwrap().bounds();
+ assert!((b.x0 - margin.x0).abs() < 1e-6 && (b.y0 - margin.y0).abs() < 1e-6, "zoom {zoom}: corner {b:?} not on the margins {margin:?}");
+ }
+ }
+
+ #[test]
+ fn type_tool_frames_snap_to_the_margins() {
+ use designcraft_geom::Point;
+ use designcraft_tools::{PointerEvent, PointerKind};
+ let mut s = session();
+ let margin = s.doc().unwrap().doc.spreads[0].pages[0].margin_rect();
+ s.set_tool("type");
+ let v = ViewInfo::at_zoom(1.0);
+ let c = |s: &Session, x: f64, y: f64| s.layout().to_canvas(designcraft_doc::SpreadRef::Doc(0), Point::new(x, y));
+ // From 1.5 pt off the top-left margin corner to 1.5 pt off the right margin.
+ let a = c(&s, margin.x0 + 1.5, margin.y0 + 1.5);
+ let b = c(&s, margin.x1 - 1.5, margin.y0 + 101.5);
+ let before = s.doc().unwrap().doc.spreads[0].items.len();
+ s.pointer(&PointerEvent::new(PointerKind::Down, a.x, a.y), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Drag, (a.x + b.x) / 2.0, b.y), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Drag, b.x, b.y), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Up, b.x, b.y), v).unwrap();
+ let items = &s.doc().unwrap().doc.spreads[0].items;
+ assert_eq!(items.len(), before + 1, "a frame was drawn");
+ let r = items.last().unwrap().bounds();
+ assert!((r.x0 - margin.x0).abs() < 1e-6 && (r.y0 - margin.y0).abs() < 1e-6, "press point {r:?} vs {margin:?}");
+ assert!((r.x1 - margin.x1).abs() < 1e-6, "right edge {} vs {}", r.x1, margin.x1);
+ }