Skip to content

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

O: Live Distribute while resizing a selection

Brandon Thomas036144d327b0
diff --git a/ROADMAP.md b/ROADMAP.md
index 2ced3603c..83070361a 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -88,6 +88,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope
- Buttons (`button.set/clear/list`, Buttons and Forms panel): go to page / next / previous / first / last / URL as PDF link annotations. Form fields need AcroForm support the PDF writer lacks.
- Power Zoom (Hand tool, Alt-press): zoom out to the spread, aim the red view rectangle, release to zoom back in there. InDesign triggers it by press-and-hold instead.
- Graphic cells (`table.placeGraphic`, `table.textCell`, Table › Convert Cell Type, Table panel): images in table cells, fitted or filled, clipped to the cell on screen and in PDF.
+- Live Distribute (Space while dragging a selection handle; `transform.resize {distribute}`): objects keep their size and spread with the bounds.
- Drag and drop text editing: drag selected text to move it (Alt copies) with its formatting (`text.release`).
- Image Import Options: place any page of a multi-page PDF (`file.place {pdfPage}`; the app asks which page), shown on screen and embedded as that page in PDF export.
- Define Lists: named numbered lists that continue across stories in page order (`list.define`, paragraph `listName` / `startAt`), round-tripped through IDML; `null` in `type.para` / `type.char` now removes an override.
diff --git a/crates/engine/src/cmd/object.rs b/crates/engine/src/cmd/object.rs
index 177bd1bf8..6d5942deb 100644
--- a/crates/engine/src/cmd/object.rs
+++ b/crates/engine/src/cmd/object.rs
@@ -26,7 +26,15 @@ pub fn specs() -> Vec<CommandSpec> {
),
cmd!("line.create", "Create Line", [], None, "{spread?, a: [x,y], b: [x,y]}", has_doc, line_create),
cmd!("transform.move", "Move", ["Object", "Transform"], None, "{dx, dy, copy?: bool, ids?, toSpread?}", has_selection, transform_move),
- cmd!("transform.resize", "Resize", [], None, "{from: rect, to: rect, content?: bool (scale content), ids?}", has_selection, transform_resize),
+ cmd!(
+ "transform.resize",
+ "Resize",
+ [],
+ None,
+ "{from: rect, to: rect, content?: bool (scale content), distribute?: bool (Live Distribute: objects keep their size, their centres spread with the bounds), ids?}",
+ has_selection,
+ transform_resize
+ ),
cmd!("transform.rotate", "Rotate", ["Object", "Transform"], None, "{angle (degrees, CCW), ids?}", has_selection, transform_rotate),
cmd!("transform.scale", "Scale", ["Object", "Transform"], None, "{sx, sy, ids?} (about the selection centre)", has_selection, |s, p| {
let sx = f64_or(p, "sx", 1.0);
@@ -807,6 +815,7 @@ fn transform_resize(s: &mut Session, p: &Value) -> Result<Value> {
let from = rect_param(p, "from").ok_or_else(|| bad("transform.resize", "missing from"))?;
let to = rect_param(p, "to").ok_or_else(|| bad("transform.resize", "missing to"))?;
let scale_content = bool_or(p, "content", false);
+ let distribute = bool_or(p, "distribute", false);
if from.width().abs() < 1e-9 || from.height().abs() < 1e-9 {
return Err(bad("transform.resize", "degenerate source rect"));
}
@@ -822,7 +831,10 @@ fn transform_resize(s: &mut Session, p: &Value) -> Result<Value> {
if it.locked {
continue;
}
- if scale_content {
+ if distribute {
+ let c = it.bounds().center();
+ it.xf = Affine::translate(m * c - c) * it.xf;
+ } else if scale_content {
scale_item(it, m, (sx * sy).abs().sqrt(), strokes);
} else if matches!(it.content, Content::Group { .. }) {
it.xf = m * it.xf;
@@ -2011,6 +2023,20 @@ mod attributes_tests {
mod fitting_tests {
use super::*;
+ #[test]
+ fn live_distribute_spreads_objects_without_resizing() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let a = s.execute("frame.create", &json!({"rect": [100, 100, 120, 120]})).unwrap()["id"].as_u64().unwrap();
+ let b = s.execute("frame.create", &json!({"rect": [180, 100, 200, 120]})).unwrap()["id"].as_u64().unwrap();
+ s.execute("transform.resize", &json!({"ids": [a, b], "from": [100, 100, 200, 120], "to": [100, 100, 300, 120], "distribute": true})).unwrap();
+ let d = &s.doc().unwrap().doc;
+ let (ra, rb) = (d.item(ItemId(a)).unwrap().bounds(), d.item(ItemId(b)).unwrap().bounds());
+ assert!((ra.width() - 20.0).abs() < 1e-9 && (rb.width() - 20.0).abs() < 1e-9, "sizes kept");
+ assert!((ra.center().x - 120.0).abs() < 1e-9, "{ra:?}");
+ assert!((rb.center().x - 280.0).abs() < 1e-9, "{rb:?}");
+ }
+
#[test]
fn frame_fitting_options_align_crop_and_auto_fit() {
let mut s = Session::new();
diff --git a/crates/tools/src/select.rs b/crates/tools/src/select.rs
index f877c1510..8a630276e 100644
--- a/crates/tools/src/select.rs
+++ b/crates/tools/src/select.rs
@@ -280,7 +280,12 @@ impl Tool for SelectionTool {
let off = cx.layout.offset(spread);
let to = resize_rect(from, handle, p - off, ev.mods);
let _ = start;
- vec![Action::Preview("transform.resize".into(), json!({"from": rect_json(from), "to": rect_json(to), "content": ev.mods.cmd}))]
+ // Space while dragging: Live Distribute (several objects keep their size).
+ let distribute = ev.mods.space && cx.selection.items.len() > 1;
+ vec![Action::Preview(
+ "transform.resize".into(),
+ json!({"from": rect_json(from), "to": rect_json(to), "content": ev.mods.cmd, "distribute": distribute}),
+ )]
}
Drag::Marquee { start, .. } => {
self.drag = Drag::Marquee { start, cur: p };
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index d30056a52..63587c9f4 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -1254,8 +1254,10 @@ fn handle_input(app: &mut DesignApp, ui: &mut egui::Ui, resp: &egui::Response, r
}
}
}
- // Space-drag = hand.
- if space && resp.dragged() {
+ // Space-drag = hand (unless a tool drag is under way: then Space is a modifier, e.g. Live
+ // Distribute while resizing).
+ let tool_drag: bool = ui.data(|d| d.get_temp(egui::Id::new("canvas_pointer_down"))).unwrap_or(false);
+ if space && !tool_drag && resp.dragged() {
let d = resp.drag_delta();
if let Some(v) = app.view_mut() {
v.origin = Point::new(v.origin.x - d.x as f64 / v.zoom, v.origin.y - d.y as f64 / v.zoom);
diff --git a/docs/parity.md b/docs/parity.md
index f93e4c3b5..0a34c0ae9 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -11,14 +11,14 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia
|---|---|---|---|---|---|
| P0 | 102 | 99 | 3 | 0 | 99% |
| P1 | 97 | 92 | 4 | 1 | 97% |
-| P2 | 76 | 36 | 24 | 16 | 63% |
+| P2 | 76 | 37 | 24 | 15 | 64% |
| Area | Parity |
|---|---|
| Application shell & workspace | 88% |
| Documents, pages, spreads | 90% |
| Layers | 95% |
-| Frames, shapes & paths | 99% |
+| Frames, shapes & paths | 100% |
| Transform | 100% |
| Fill, stroke, colour | 96% |
| Effects & transparency | 71% |
@@ -115,7 +115,7 @@ Open P0 items: Preferences, Vector/page formats (PDF/AI/SVG/EPS place), Export t
| Frames, shapes & paths | Step and Repeat | P1 | D |
| Frames, shapes & paths | Gridify while drawing | P2 | D |
| Frames, shapes & paths | Gap tool | P2 | D |
-| Frames, shapes & paths | Live Distribute | P2 | M |
+| Frames, shapes & paths | Live Distribute | P2 | D |
| Frames, shapes & paths | Generate QR Code | P2 | D |
| Frames, shapes & paths | Placeholder text | P1 | D |
| Frames, shapes & paths | Arrange | P0 | D |