DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Place cursor: a thumbnail of the loaded graphic; a drag draws a proportional frame with its scale
moppeeere1812231a902
diff --git a/ROADMAP.md b/ROADMAP.mdindex 0128924c0..e8a0494ac 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-20** · The loaded place cursor shows a thumbnail of the graphic, as InDesign's does; dragging with it draws the frame at the graphic's proportions from where the drag started, with its scale beside the pointer, and places exactly that frame. No readiness percentage change.- **2026-10-16** · Type › Reload Fonts (`font.reload`): fonts installed, edited or removed while DesignCraft runs are read again without a restart, and the open documents recompose with them (#328, #547). An edited font file is noticed by its length and modification time; bundled, added and document fonts stay as they are. InDesign does this by itself, so noticing changes automatically is still open (gap 6). No readiness percentage change.- **2026-10-16** · Parents can be deleted from their Pages-panel context menu or `layout.parents.delete {id}`. Applied-page and based-on references are cleared, local override copies survive, and Undo restores the parent. Addresses the deletion portion of #956; no readiness percentage change.- **2026-10-17** · File › Package writes the document's and the IDML's links relative to the package (`Links/logo.png`, `file:Links/logo.png`), so a package holds no path from the machine that made it; opening a document resolves them to the files beside it. Links › Copy Link(s) To still links by full path. (#340). No readiness percentage change.diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rsindex 9aacf469d..ad8c5b107 100644--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@ -476,6 +476,33 @@ fn place_gun_click_drag_and_into_frame() {assert_eq!(graphic_xf(&s), placed);}+/// A place-cursor drag draws the frame at the graphic's proportions from where it started, as+/// InDesign does, shows its scale, and places exactly that frame, in any direction.+#[test]+fn place_gun_drag_previews_and_places_a_proportional_frame() {+ use designcraft_tools::{Cursor, Mods, Overlay, PointerEvent, PointerKind};+ let mut s = session();+ let png = designcraft_render::Rendered { width: 40, height: 20, pixels: vec![200; 40 * 20 * 4] }.to_png();+ s.execute("place.load", &json!({"base64": cmd::base64_encode(&png), "name": "a.png"})).unwrap();+ let v = ViewInfo::at_zoom(1.0);+ let p = designcraft_geom::Point::new;+ assert_eq!(s.cursor(p(300.0, 300.0), Mods::default(), v), Cursor::LoadedGraphic);+ // Up and to the left: 80 × 200 holds the 40 × 20 graphic at 200 %, 80 × 40, hanging from the press.+ s.pointer(&PointerEvent::new(PointerKind::Down, 300.0, 300.0), v).unwrap();+ s.pointer(&PointerEvent::new(PointerKind::Drag, 220.0, 100.0), v).unwrap();+ assert_eq!(s.cursor(p(220.0, 100.0), Mods::default(), v), Cursor::Crosshair, "the crosshair while drawing");+ let o = s.overlays(v);+ assert!(o.iter().any(|o| matches!(o, Overlay::Marquee(r) if *r == designcraft_geom::Rect::new(220.0, 260.0, 300.0, 300.0))), "{o:?}");+ assert!(+ o.iter().any(|o| matches!(o, Overlay::Measure { text, .. } if text == "X: 200.00%+Y: 200.00%")),+ "{o:?}"+ );+ s.pointer(&PointerEvent::new(PointerKind::Up, 220.0, 100.0), v).unwrap();+ let it = s.doc().unwrap().doc.spreads[0].items.last().unwrap().clone();+ assert_eq!(it.bounds(), designcraft_geom::Rect::new(220.0, 260.0, 300.0, 300.0), "the frame previewed");+}+#[test]fn preflight_reports_overset_and_missing_fonts() {let mut s = session();diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rsindex c58236090..e388aa869 100644--- a/crates/engine/src/tooling.rs+++ b/crates/engine/src/tooling.rs@@ -108,6 +108,7 @@ impl Session {snap: view.snap,unit: view.unit,stroke_in_front: view.stroke_in_front,+ loaded: self.loaded.map(|l| l.size),};Some(f(self, &cx))}diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rsindex a92f1c132..3491401b1 100644--- a/crates/tools/src/lib.rs+++ b/crates/tools/src/lib.rs@@ -220,6 +220,8 @@ pub struct ToolContext<'a> {pub unit: Unit,/// The toolbox's Stroke box is in front: sampled colours go to strokes (the Eyedropper).pub stroke_in_front: bool,+ /// Natural size, in points, of the graphic loaded in the place cursor.+ pub loaded: Option<(f64, f64)>,}impl ToolContext<'_> {diff --git a/crates/tools/src/nav.rs b/crates/tools/src/nav.rsindex f77c5d0bb..db15effad 100644--- a/crates/tools/src/nav.rs+++ b/crates/tools/src/nav.rs@@ -142,7 +142,8 @@ impl Tool for PlaceGun {{return vec![Action::Exec("place.drop".into(), json!({"frame": id.0}))];}- let r = designcraft_geom::Rect::from_points(sa, b);+ // The frame the drag drew: at the graphic's proportions from where it started.+ let r = cx.loaded.map_or_else(|| designcraft_geom::Rect::from_points(sa, b), |size| proportional(sa, b, size).0);vec![Action::Exec("place.drop".into(),json!({"spread": crate::spread_json(sr), "x": sa.x, "y": sa.y, "rect": [r.x0, r.y0, r.x1, r.y1]}),@@ -151,11 +152,24 @@ impl Tool for PlaceGun {_ => vec![],}}- fn overlays(&self, _cx: &ToolContext) -> Vec<crate::Overlay> {- match self.start {- Some(a) => vec![crate::Overlay::Marquee(designcraft_geom::Rect::from_points(a, self.cur))],- None => vec![],- }+ fn overlays(&self, cx: &ToolContext) -> Vec<crate::Overlay> {+ let Some(a) = self.start else { return vec![] };+ let (Some(size), true) = (cx.loaded, (self.cur - a).hypot() >= cx.tol(3.0)) else {+ return vec![crate::Overlay::Marquee(designcraft_geom::Rect::from_points(a, self.cur))];+ };+ // As InDesign: the frame the graphic will fill, and its scale beside the pointer.+ let (r, k) = proportional(a, self.cur, size);+ let pct = format!("{:.2}%", k * 100.0);+ vec![+ crate::Overlay::Marquee(r),+ crate::Overlay::Measure {+ p: self.cur,+ text: format!(+ "X: {pct}+Y: {pct}"+ ),+ },+ ]}fn key(&mut self, _cx: &ToolContext, key: crate::ToolKey, _mods: Mods) -> Vec<Action> {match key {@@ -165,10 +179,22 @@ impl Tool for PlaceGun {}}fn cursor(&self, _cx: &ToolContext, _p: Point, _m: Mods) -> Cursor {- Cursor::LoadedGraphic+ // Drawing the frame: the crosshair (the loaded graphic's thumbnail would hide the frame).+ if self.start.is_some() { Cursor::Crosshair } else { Cursor::LoadedGraphic }}}+/// The frame a place-cursor drag from `a` to `b` draws for a graphic of natural `size`: the+/// graphic's proportions, from `a` towards `b`, as large as fits the drag. With its scale.+fn proportional(a: Point, b: Point, size: (f64, f64)) -> (designcraft_geom::Rect, f64) {+ let (w, h) = (size.0.max(1e-6), size.1.max(1e-6));+ let (dx, dy) = (b.x - a.x, b.y - a.y);+ let k = (dx.abs() / w).min(dy.abs() / h);+ let k = if k.is_finite() { k } else { 0.0 };+ let c = Point::new(a.x + (w * k).copysign(dx), a.y + (h * k).copysign(dy));+ (designcraft_geom::Rect::from_points(a, c), k)+}+/// Page tool (Shift+P): click a page to select it; drag one of its handles to preview its liquid/// page rule (the page springs back on release), Alt-drag to resize it, Shift to keep its/// proportions; double-click a page for exact sizes.diff --git a/crates/tools/src/snap.rs b/crates/tools/src/snap.rsindex 0cbc9aadd..2bbb20a24 100644--- a/crates/tools/src/snap.rs+++ b/crates/tools/src/snap.rs@@ -1416,6 +1416,7 @@ mod tests {snap: SnapView::FACTORY,unit: Unit::Points,stroke_in_front: false,+ loaded: None,}}diff --git a/crates/tools/src/tests.rs b/crates/tools/src/tests.rsindex ee3b362f1..86054431e 100644--- a/crates/tools/src/tests.rs+++ b/crates/tools/src/tests.rs@@ -19,6 +19,7 @@ fn ctx<'a>(d: &'a Document, s: &'a Selection, c: &'a Cache, l: &'a CanvasLayout)snap: SnapView::OFF,unit: Unit::Points,stroke_in_front: false,+ loaded: None,}}diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 8d94f099f..66963c528 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -606,7 +606,61 @@ pub fn show(app: &mut DesignApp, ui: &mut egui::Ui) {let icon = crate::cursors::show(ui.ctx(), &mut app.cursors, c, p);ui.ctx().set_cursor_icon(icon);draw_cursor_badge(&painter, p, c, &t);+ if c == Cursor::LoadedGraphic {+ draw_loaded_thumbnail(app, &painter, p, &t);+ }+ }+}++/// Longest side of the loaded place cursor's thumbnail, in points.+const LOADED_THUMB: f32 = 128.0;++/// The loaded place cursor's thumbnail, as InDesign shows it: the graphic, at most 128 pt on its+/// longer side, hanging from the pointer, with an image badge in its corner.+fn draw_loaded_thumbnail(app: &DesignApp, painter: &egui::Painter, p: Pos2, t: &Tokens) {+ let (Some(l), Ok(st)) = (app.session.loaded.as_ref(), app.session.doc()) else { return };+ let (w, h) = (l.size.0 as f32, l.size.1 as f32);+ if !(w.is_finite() && h.is_finite() && w > 0.0 && h > 0.0) {+ return;}+ let k = LOADED_THUMB / w.max(h);+ let r = Rect::from_min_size(p + vec2(2.0, 2.0), vec2(w * k, h * k));+ if let Some(tex) = loaded_thumb_texture(painter.ctx(), &st.doc, l.asset, l.size) {+ painter.image(tex.id(), r, Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::from_white_alpha(225));+ } else {+ // Not drawable here (an unreadable file): its frame only.+ painter.rect_stroke(r, 0.0, Stroke::new(1.0, t.measure_text), StrokeKind::Inside);+ }+ let badge = Rect::from_min_size(r.min + vec2(6.0, 6.0), vec2(16.0, 12.0));+ painter.rect_filled(badge, 2.0, t.measure_bg);+ let ink = Stroke::new(1.2, t.measure_text);+ let inner = badge.shrink2(vec2(3.0, 2.5));+ painter.rect_stroke(inner, 0.5, ink, StrokeKind::Middle);+ painter.add(egui::Shape::line(+ vec![pos2(inner.min.x, inner.max.y), pos2(inner.min.x + 3.5, inner.min.y + 2.5), pos2(inner.max.x, inner.max.y)],+ ink,+ ));+}++/// The loaded graphic's thumbnail texture, cached per image data.+fn loaded_thumb_texture(ctx: &egui::Context, doc: &Document, asset: designcraft_doc::AssetId, size: (f64, f64)) -> Option<egui::TextureHandle> {+ let a = doc.assets.get(&asset)?;+ let key = egui::Id::new(("loaded_thumb", std::sync::Arc::as_ptr(&a.data) as usize, a.data.len(), a.page));+ if let Some(t) = ctx.data(|d| d.get_temp::<egui::TextureHandle>(key)) {+ return Some(t);+ }+ // Twice the thumbnail's size in pixels, for high-density screens.+ let scale = (2.0 * f64::from(LOADED_THUMB) / size.0.max(size.1)).min(1.0);+ let pm = designcraft_render::images::mip(&a.data, a.page, size.0, scale)?;+ let (pw, ph) = (pm.width() as usize, pm.height() as usize);+ if pw == 0 || ph == 0 {+ return None;+ }+ let ci = egui::ColorImage::from_rgba_premultiplied([pw, ph], pm.data_as_u8_slice());+ let max = ctx.input(|i| i.max_texture_side).min(1024);+ let t = ctx.load_texture("loaded_thumb", crate::widgets::fit_texture(ci, max), egui::TextureOptions::LINEAR);+ ctx.data_mut(|d| d.insert_temp(key, t.clone()));+ Some(t)}/// The loaded text cursor's badge beside the system cursor: lines of text, a closed chain@@ -4481,6 +4535,7 @@ mod tests {snap: SnapView { snap_to_document_grid: true, zone_px: 20.0, ..SnapView::OFF },unit: Unit::Points,stroke_in_front: false,+ loaded: None,};let (snapped, _) = designcraft_tools::snap::snap_point(&cx, sr, Point::new(page.x0 + 31.3, page.y0 + 47.9));assert_eq!((snapped.x - page.x0, snapped.y - page.y0), (27.0, 45.0));