Skip to content

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

Merge parent-pages-panel: Pages panel: double-clicking a parent shows that parent; parent thumbnails (#624)

aionggdfd98fca138a
diff --cc ROADMAP.md
index dcf012b24,8b6ea2d7d..73ec8d43f
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -1,8 -1,8 +1,8 @@@
# DesignCraft roadmap
-**Stage: pre-alpha** · next: alpha, ~0% and ~15–25 h away; beta ~28 points and ~420–750 h beyond that (the core-workflow gate, not the percentage: ready for real work is already ~47%)
+**Stage: pre-alpha** · next: alpha, ~5–7 h away; beta ~28 points and ~420–750 h beyond that (the core-workflow gate, not the percentage: ready for real work is already ~47%)
- > **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-12 · **Change:** minor (text threads by hand; the alpha gate waits on Primary Text Frame page fixes; Japanese print, import and table controls localized; Live corners (#186); Optical kerning from outlines (#181); window and menu quit confirmation; failed writes preserve live save and collection state; spring-loaded Zoom navigation; orderly native exit recovery) · **Target:** Adobe InDesign 2026
-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-12 · **Change:** minor (Pages panel parents) · **Target:** Adobe InDesign 2026
++> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-12 · **Change:** minor (text threads by hand; the alpha gate waits on Primary Text Frame page fixes; Japanese print, import and table controls localized; Live corners (#186); Optical kerning from outlines (#181); window and menu quit confirmation; failed writes preserve live save and collection state; spring-loaded Zoom navigation; orderly native exit recovery; Pages panel parents) · **Target:** Adobe InDesign 2026
DesignCraft aims at full Adobe InDesign parity, and to be better: faster, open (documented JSON
format + IDML), scriptable by agents (MCP), and available on the web.
@@@ -128,34 -129,8 +128,35 @@@ list) · [roadmap.md](docs/roadmap.md)
Newest first.
+ - **2026-10-12** · Pages panel: double-clicking a parent shows that parent and selects only its row; parent rows show rendered thumbnails. Commands name parents by id, full name, or a prefix only one parent has; an unknown or ambiguous name is an error instead of clearing the page's parent (#624). No readiness percentage change.
+- **2026-10-12** · With the Type tool, dragging a table's column or row border resizes it (the double-arrow cursor shows over a border): later columns and rows move along, Shift keeps the table size, and Shift on the right or bottom edge scales every column or row. A dragged row becomes At Least; one undo step per drag, Esc cancels; works in rotated frames and turned spreads. Scripts use `table.resizeBorder`. No readiness percentage change.
+- **2026-10-12** · The Tools panel's Fill/Stroke keys work: D (default fill and stroke), X (fill or stroke in front), Shift+X (swap per object, tints included) and / (Apply None), as `color.*` commands; swap and default are one undo step (`object.swapFillStroke`, `object.defaultFillStroke`); the Color panel follows the proxy's fill/stroke choice. No readiness percentage change.
+- **2026-10-12** · With a placed graphic selected (Direct Selection), the Transform values act on the graphic inside its frame, as in InDesign: a tilted frame's image can be straightened to 0°. No readiness percentage change.
+- **2026-10-11** · Font menu laid out like InDesign's: filters (classification, favourites,
+ recently added), families opening to their styles, the selected text as the sample in three
+ sizes, Recently Used fonts, Show Similar Fonts and each font's format.
+- **2026-10-12** · The Effects panel shows the level its settings apply to ("Group: Color Dodge 100%") and, as in InDesign, Isolate Blending and Knockout Group for a selected group. No readiness percentage change.
+- **2026-10-12** · Edit › Step and Repeat has its InDesign dialog: Repeat (Count, or Rows and Columns with Create as a grid), Offset (Vertical, Horizontal, in ruler units) and Preview, which shows the copies while the dialog is open; Cancel takes them away and OK makes them as one undo step. No readiness percentage change.
+- **2026-10-12** · Load Styles: the Paragraph Styles and Character Styles panels load styles from another DesignCraft document or an IDML file, with the styles, swatches and lists they name; a dialog picks the styles and what happens to one the document defines differently (`style.load`). No readiness percentage change.
+- **2026-10-12** · On screen, blend modes blend with the objects below and not with the paper, as in InDesign and in PDF export: a Color Dodge or Screen object over blank paper shows as it is. 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** · Properties › Transform shows rotation, shear and X/Y scale, and Rotate 90° and Flip Horizontal/Vertical buttons, as InDesign's does. No readiness percentage change.
+- **2026-10-12** · Underlines and strikethroughs are drawn as one bar per stretch of text on screen, as in PDF export: a bar per letter left faint seams between the letters. No readiness percentage change.
+- **2026-10-12** · The section marker character shows its section's marker text on document pages (nothing when the section has none) instead of the word "Section", which stays on parent pages; editing the marker recomposes (#556). No readiness percentage change.
+- **2026-10-12** · IDML import keeps a font family name exactly as written, trailing spaces included, and font lookup falls back to the name without surrounding spaces; `FontStyle="Nothing"` leaves the style to the paragraph (#558). No readiness percentage change.
+- **2026-10-12** · Clipping paths saved with images in IDML (Detect Edges, Alpha Channel, Photoshop Path, User-Modified Path, inverted or not) clip the image on screen and in PDF and survive IDML export; `object.clippingPathOptions` reports, inverts or removes one (#450). No readiness percentage change.
+- **2026-10-12** · Anchored objects with text wrap push text aside: other stories' text under them and the lines of their own story after the anchor's line (#557). No readiness percentage change.
+- **2026-10-12** · Hyphenation Zone applies to the Single-line Composer only, as in InDesign. With the default Paragraph Composer, ragged text hyphenates where InDesign does (aper-natem), giving the same line breaks. No readiness percentage change.
+- **2026-10-12** · Text frame auto-size: Height Only, Width Only, Height and Width (also keeping proportions) frames grow and shrink to fit their text after edits and IDML import, around their reference point, with minimum sizes and No Line Breaks, in the same undo step (#180). No readiness percentage change.
+- **2026-10-12** · Text Frame Options › Balance Columns (`object.textFrameOptions {balanceColumns}`, IDML `VerticalBalanceColumns`) evens out the columns of the frame a story ends in, from its last column break on; frames the text runs on from fill normally (#609). 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** · Windows: dragging the window across monitors with different display scales keeps its size instead of growing until it crashes (winit pinned to its 0.30.x backport of the fix). The GPU surface may be as large as the adapter's largest texture (16384 px on DirectX 12, Vulkan and Metal hardware) instead of 8192, and a wgpu error is logged instead of closing the app. 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.
- **2026-10-12** · Book numbering and style updates prepare every chapter before saving. Only closed native chapters are changed; imported IDML remains a read-only style/PDF source. If a later disk write fails, the error names the completed chapters; the batch is not a whole-book transaction. No readiness percentage change.
- **2026-10-12** · Desktop write callbacks and CLI raster exports use the atomic writer too; open readers retain the original bytes, while private Unix modes and symlink targets survive replacement. Permanent tests cover both actual callers. No readiness percentage change.
diff --cc crates/engine/src/cmd/layout.rs
index 10933b024,aa08dd65d..b0fa92b23
--- a/crates/engine/src/cmd/layout.rs
+++ b/crates/engine/src/cmd/layout.rs
@@@ -196,13 -179,42 +196,42 @@@ pub fn specs() -> Vec<CommandSpec>
Ok(json!({"id": id.0, "prefix": prefix}))
})
}),
- cmd!(noundo "layout.parents.edit", "Edit Parents", [], None, "{on: bool} — show parent spreads on the canvas", has_doc, |s, p| {
- let st = s.doc_mut()?;
- st.editing_parents = p.get("on").and_then(Value::as_bool).unwrap_or(!st.editing_parents);
- st.selection = Default::default();
- st.bump_revision();
- ok()
- }),
+ cmd!(
+ noundo "layout.parents.edit",
+ "Edit Parents",
+ [],
+ None,
+ "{on?: bool, parent?: id|\"A-Parent\"|\"A\"} — show parent spreads on the canvas; `parent` shows that parent (and implies on). Turning on without `parent` shows the first parent",
+ has_doc,
+ |s, p| {
+ const ID: &str = "layout.parents.edit";
+ let doc = s.doc()?.doc.clone();
+ let parent = match p.get("parent") {
+ None | Some(Value::Null) => None,
+ v => match parent_ref(ID, &doc, v)? {
+ Some(Some(id)) => Some(id),
+ _ => return Err(bad(ID, "`parent` names a parent to show")),
+ },
+ };
+ let st = s.doc_mut()?;
+ let was = st.editing_parents;
+ let on = p.get("on").and_then(Value::as_bool).unwrap_or(parent.is_some() || !was);
+ st.editing_parents = on;
+ st.selection = Default::default();
- st.revision += 1;
++ st.bump_revision();
+ // The parent to show: the one asked for, or the first when editing starts.
+ let index = match parent {
+ Some(id) => doc.parent_index(id),
+ None if !was && !doc.parents.is_empty() => Some(0),
+ None => None,
+ };
+ let shown = index.filter(|_| on);
+ if let Some(i) = shown {
+ s.ui_requests.push(crate::UiRequest::View { params: json!({"showSpread": designcraft_doc::SpreadRef::Parent(i)}) });
+ }
+ Ok(json!({"on": on, "parent": shown.and_then(|i| doc.parents.get(i)).map(|x| x.id.0)}))
+ }
+ ),
cmd!(
"layout.marginsAndColumns",
"Margins and Columns…",
@@@ -650,41 -638,34 +679,62 @@@
]
}
- /// `"A"` → that parent's id; `null` → Some(None) (= [None]); missing → None (use default).
+/// Apply the `margins`, `columns` and `gutter` params of `layout.marginsAndColumns` to a page.
+fn set_margins_columns(pg: &mut designcraft_doc::Page, p: &Value) {
+ match p.get("margins") {
+ Some(Value::Number(n)) => pg.margins = Margins::uniform(n.as_f64().unwrap_or(36.0)),
+ Some(v @ Value::Object(_)) => {
+ if let Ok(m) = serde_json::from_value(v.clone()) {
+ pg.margins = m;
+ }
+ }
+ _ => {}
+ }
+ if let Some(c) = p.get("columns").and_then(Value::as_u64) {
+ pg.columns.count = (c as u32).clamp(1, 216);
+ }
+ if let Some(g) = p.get("gutter").and_then(Value::as_f64) {
+ pg.columns.gutter = g.max(0.0);
+ }
+}
+
+/// A parent spread named by prefix, label (`A-Parent`) or index.
+fn parent_spread_index(d: &designcraft_doc::Document, v: &Value) -> Option<usize> {
+ match v {
+ Value::Number(n) => n.as_u64().and_then(|i| usize::try_from(i).ok()).filter(|i| *i < d.parents.len()),
+ Value::String(s) => d.parents.iter().position(|p| p.parent.as_ref().is_some_and(|i| i.prefix == *s || i.label() == *s)),
+ _ => None,
+ }
+}
+
- fn parent_ref(d: &designcraft_doc::Document, v: Option<&Value>) -> Option<Option<SpreadId>> {
- match v? {
- Value::Null => Some(None),
- Value::String(s) if s == "[None]" => Some(None),
- Value::String(s) => Some(d.parents.iter().find(|p| p.parent.as_ref().is_some_and(|i| i.prefix == *s || i.label() == *s)).map(|p| p.id)),
- _ => None,
+ /// A parent named by a command parameter: its id (a number), its full label (`"A-Parent"`), or
+ /// its prefix (`"A"`) when only one parent has it. `null` or `"[None]"` → `Some(None)` (no parent);
+ /// missing → `None` (the command's default). Unknown or ambiguous names are errors, so a typo never
+ /// clears a page's parent.
+ fn parent_ref(cmd: &str, d: &designcraft_doc::Document, v: Option<&Value>) -> Result<Option<Option<SpreadId>>> {
+ let Some(v) = v else { return Ok(None) };
+ match v {
+ Value::Null => Ok(Some(None)),
+ Value::String(s) if s == "[None]" => Ok(Some(None)),
+ Value::Number(n) => {
+ let id = n.as_u64().ok_or_else(|| bad(cmd, format!("no parent with id {n}")))?;
+ d.parents.iter().find(|p| p.id.0 == id).map(|p| Some(Some(p.id))).ok_or_else(|| bad(cmd, format!("no parent with id {id}")))
+ }
+ Value::String(s) => {
+ let by = |f: &dyn Fn(&designcraft_doc::ParentInfo) -> bool| -> Vec<SpreadId> {
+ d.parents.iter().filter(|p| p.parent.as_ref().is_some_and(f)).map(|p| p.id).collect()
+ };
+ let mut hits = by(&|i| i.label() == *s);
+ if hits.is_empty() {
+ hits = by(&|i| i.prefix == *s);
+ }
+ match hits.as_slice() {
+ [id] => Ok(Some(Some(*id))),
+ [] => Err(bad(cmd, format!("no parent named `{s}`"))),
+ _ => Err(bad(cmd, format!("more than one parent is named `{s}`: give its id"))),
+ }
+ }
+ _ => Err(bad(cmd, "`parent` is a parent id, a parent name or null")),
}
}
@@@ -1360,134 -972,60 +1410,192 @@@ mod adjust_tests
}
}
+#[cfg(test)]
+mod spread_rotation_input_tests {
+ use serde_json::json;
+
+ #[test]
+ fn quarter_turns_work_and_other_angles_are_rejected_without_mutation() {
+ let mut s = crate::Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let rotation = |s: &crate::Session| s.doc().unwrap().doc.spreads[0].pages[0].view_rotation;
+ for bad in [json!(45), json!(-45), json!(91), json!("90"), json!(0.5)] {
+ assert!(s.execute("layout.rotateSpreadView", &json!({"angle": bad})).is_err(), "{bad}");
+ assert_eq!(rotation(&s), 0, "invalid input must not change the view");
+ }
+ s.execute("layout.rotateSpreadView", &json!({"angle": 90})).unwrap();
+ assert_eq!(rotation(&s), 1);
+ s.execute("layout.rotateSpreadView", &json!({"angle": -90})).unwrap();
+ assert_eq!(rotation(&s), 0);
+ s.execute("layout.rotateSpreadView", &json!({"angle": 180})).unwrap();
+ assert_eq!(rotation(&s), 2);
+ s.execute("layout.rotateSpreadView", &json!({"angle": 0})).unwrap();
+ assert_eq!(rotation(&s), 0, "zero resets the spread view");
+ }
+}
+
+#[cfg(test)]
+mod layer_options_tests {
+ use serde_json::json;
+
+ #[test]
+ fn layer_set_sets_every_field_and_rejects_bad_names() {
+ let mut s = crate::Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let first = s.doc().unwrap().doc.layers[0].id.0;
+ let id = s.execute("layer.new", &json!({"name": "Art"})).unwrap()["id"].as_u64().unwrap();
+ let all = json!({"id": id, "name": " Artwork ", "color": "Gold", "visible": false, "locked": true, "printable": false,
+ "showGuides": false, "suppressWrapWhenHidden": true});
+ s.execute("layer.set", &all).unwrap();
+ let l = s.doc().unwrap().doc.layer(designcraft_doc::LayerId(id)).cloned().unwrap();
+ assert_eq!(l.name, "Artwork");
+ assert_eq!(l.color, [255, 153, 0]);
+ assert!(!l.visible && l.locked && !l.printable && !l.show_guides && l.suppress_wrap_when_hidden);
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert_eq!(s.doc().unwrap().doc.layer(designcraft_doc::LayerId(id)).unwrap().name, "Art", "one undo step");
+ let first_name = s.doc().unwrap().doc.layers.iter().find(|l| l.id.0 == first).unwrap().name.clone();
+ let before = s.doc().unwrap().doc.layers.clone();
+ for p in [
+ json!({"id": id, "name": ""}),
+ json!({"id": id, "name": " "}),
+ json!({"id": id, "name": first_name}),
+ json!({"id": id, "name": "Fine", "color": "Plaid"}),
+ json!({"id": id, "color": [300, 0, 0]}),
+ json!({"id": id, "visible": "yes"}),
+ json!({"id": 999_999, "name": "Ghost"}),
+ ] {
+ assert!(s.execute("layer.set", &p).is_err(), "{p}");
+ }
+ assert_eq!(s.doc().unwrap().doc.layers, before);
+ // Keeping its own name is fine.
+ s.execute("layer.set", &json!({"id": id, "name": "Art", "color": [1, 2, 3]})).unwrap();
+ }
+}
+
+#[cfg(test)]
+mod parent_margin_tests {
+ use designcraft_doc::{Document, Margins};
+ use serde_json::json;
+
+ use crate::Session;
+
+ fn margins(d: &Document) -> Vec<(Margins, u32, bool)> {
+ (0..d.page_count()).filter_map(|i| d.page(i)).map(|p| (p.margins, p.columns.count, p.local_margins)).collect()
+ }
+
+ #[test]
+ fn document_setup_margins_let_pages_follow_their_parent_page_again() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"pages": 3})).unwrap();
+ s.execute("layout.marginsAndColumns", &json!({"pages": [1], "margins": 100})).unwrap();
+ s.execute("layout.marginsAndColumns", &json!({"pages": [2], "margins": 100, "columns": 3})).unwrap();
+ s.execute("layout.documentSetup", &json!({"margins": 20})).unwrap();
+ let m = margins(&s.doc().unwrap().doc);
+ let twenty = Margins::uniform(20.0);
+ assert_eq!(m, vec![(twenty, 1, false), (twenty, 1, false), (twenty, 3, true)], "own columns stay local");
+ s.execute("layout.marginsAndColumns", &json!({"parent": "A", "margins": 50})).unwrap();
+ let m = margins(&s.doc().unwrap().doc);
+ assert_eq!(m[1], (Margins::uniform(50.0), 1, false), "page 2 follows the parent page again");
+ assert_eq!(m[2], (twenty, 3, true));
+ }
+
+ #[test]
+ fn pages_follow_their_parent_pages_margins_unless_set_locally() {
+ let mut s = Session::new();
+ // Facing: [1] [2 3]; page 3 gets its own margins.
+ s.execute("file.new", &json!({"pages": 3})).unwrap();
+ s.execute("layout.marginsAndColumns", &json!({"pages": [2], "margins": 100})).unwrap();
+ // A's left page: only the left document page follows.
+ let left = json!({"top": 10, "bottom": 20, "inside": 30, "outside": 40});
+ s.execute("layout.marginsAndColumns", &json!({"parent": "A", "pages": [0], "margins": left, "columns": 2})).unwrap();
+ let l = Margins { top: 10.0, bottom: 20.0, inside: 30.0, outside: 40.0 };
+ let m = margins(&s.doc().unwrap().doc);
+ assert_eq!(m, vec![(Margins::uniform(36.0), 1, false), (l, 2, false), (Margins::uniform(100.0), 1, true)]);
+ // A's right page: page 1 follows, page 3 keeps its own.
+ s.execute("layout.marginsAndColumns", &json!({"parent": "A-Parent", "pages": [1], "margins": 50})).unwrap();
+ let m = margins(&s.doc().unwrap().doc);
+ assert_eq!(m, vec![(Margins::uniform(50.0), 1, false), (l, 2, false), (Margins::uniform(100.0), 1, true)]);
+ // A page inserted after page 1 pushes page 2 to the right: it takes the right parent page's.
+ s.execute("layout.pages.insert", &json!({"after": 0, "count": 1, "parent": "A"})).unwrap();
+ let m = margins(&s.doc().unwrap().doc);
+ assert_eq!(m[1], (l, 2, false), "the new left page");
+ assert_eq!(m[2], (Margins::uniform(50.0), 1, false), "old page 2, now a right page");
+ assert_eq!(m[3], (Margins::uniform(100.0), 1, true));
+ assert!(s.execute("layout.marginsAndColumns", &json!({"parent": "Z", "margins": 10})).is_err());
+ }
+
+ #[test]
+ fn parent_guides_show_on_pages_but_stay_on_the_parent() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"pages": 2})).unwrap();
+ // A vertical guide 100 pt into A's right page (x = 612 in the parent spread).
+ s.execute("guide.add", &json!({"spread": {"kind": "parent", "index": 0}, "page": 1, "orientation": "vertical", "position": 712})).unwrap();
+ let d = &s.doc().unwrap().doc;
+ let right = d.page(0).unwrap();
+ let shown: Vec<f64> = d.parent_guides(right).map(|g| g.position).collect();
+ assert_eq!(shown, vec![100.0], "moved to the document page's place");
+ assert_eq!(d.parent_guides(d.page(1).unwrap()).count(), 0, "the left page shows A's left page's guides");
+ // Not the document page's own: not listed, moved or deleted from there.
+ assert_eq!(s.execute("guide.list", &json!({"spread": 0})).unwrap(), json!([]));
+ assert!(s.execute("guide.move", &json!({"spread": 0, "page": 0, "index": 0, "position": 50})).is_err());
+ assert!(s.execute("guide.delete", &json!({"spread": 0, "page": 0, "index": 0})).is_err());
+ }
+}
++
+ #[cfg(test)]
+ mod parent_tests {
+ use serde_json::json;
+
+ fn parent_of(s: &crate::Session, page: usize) -> Option<u64> {
+ s.doc().unwrap().doc.page(page).unwrap().parent.map(|p| p.0)
+ }
+
+ #[test]
+ fn parents_with_one_prefix_stay_distinct() {
+ let mut s = crate::Session::new();
+ s.execute("file.new", &json!({"pages": 2})).unwrap();
+ let a = s.execute("layout.parents.new", &json!({"prefix": "IMG", "name": "Parent"})).unwrap()["id"].as_u64().unwrap();
+ let b = s.execute("layout.parents.new", &json!({"prefix": "IMG", "name": "Half"})).unwrap()["id"].as_u64().unwrap();
+ s.execute("layout.pages.applyParent", &json!({"pages": [0], "parent": b})).unwrap();
+ assert_eq!(parent_of(&s, 0), Some(b));
+ s.execute("layout.pages.applyParent", &json!({"pages": [1], "parent": "IMG-Half"})).unwrap();
+ assert_eq!(parent_of(&s, 1), Some(b));
+ s.execute("layout.pages.applyParent", &json!({"pages": [1], "parent": "IMG-Parent"})).unwrap();
+ assert_eq!(parent_of(&s, 1), Some(a));
+ // A prefix two parents share, or a name no parent has, is an error and changes nothing.
+ assert!(s.execute("layout.pages.applyParent", &json!({"pages": [1], "parent": "IMG"})).is_err());
+ assert!(s.execute("layout.pages.applyParent", &json!({"pages": [1], "parent": "Nope"})).is_err());
+ assert!(s.execute("layout.pages.applyParent", &json!({"pages": [1], "parent": 999_999})).is_err());
+ assert_eq!(parent_of(&s, 1), Some(a));
+ s.execute("layout.pages.applyParent", &json!({"pages": [1], "parent": "[None]"})).unwrap();
+ assert_eq!(parent_of(&s, 1), None);
+ }
+
+ #[test]
+ fn edit_parents_shows_the_named_parent() {
+ let mut s = crate::Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let ids: Vec<u64> =
+ ["B", "C", "D"].iter().map(|p| s.execute("layout.parents.new", &json!({"prefix": p})).unwrap()["id"].as_u64().unwrap()).collect();
+ s.ui_requests.clear();
+ let r = s.execute("layout.parents.edit", &json!({"parent": ids[2]})).unwrap();
+ assert_eq!(r, json!({"on": true, "parent": ids[2]}));
+ assert!(s.doc().unwrap().editing_parents);
+ let n = s.doc().unwrap().doc.parent_index(designcraft_doc::SpreadId(ids[2])).unwrap();
+ let shown: Vec<_> = s
+ .ui_requests
+ .iter()
+ .filter_map(|r| match r {
+ crate::UiRequest::View { params } => params.get("showSpread").cloned(),
+ _ => None,
+ })
+ .collect();
+ assert_eq!(shown, vec![json!({"kind": "parent", "index": n})]);
+ let r = s.execute("layout.parents.edit", &json!({"on": true, "parent": "C-Parent"})).unwrap();
+ assert_eq!(r["parent"], ids[1]);
+ assert!(s.execute("layout.parents.edit", &json!({"parent": "Z-Parent"})).is_err());
+ let r = s.execute("layout.parents.edit", &json!({"on": false})).unwrap();
+ assert_eq!(r, json!({"on": false, "parent": null}));
+ assert!(!s.doc().unwrap().editing_parents);
+ }
+ }
diff --cc crates/ui-egui/src/canvas.rs
index b0a1c479c,4b1394c88..3997f37ed
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@@ -219,29 -202,10 +240,32 @@@ pub fn set_zoom(app: &mut DesignApp, z
zoom_at(app, rect.center(), z / cur);
}
+/// Whether the wheel motion now arriving was made with Alt down. As egui does for Ctrl/Cmd, a
+/// motion keeps its key to its end: the wheel is smoothed over a few frames, and a trackpad swipe
+/// coasts on after the key is let go.
+fn wheel_alt(ui: &egui::Ui) -> bool {
+ let id = egui::Id::new("canvas_wheel_alt");
+ // Alt, and whether a trackpad swipe is under way.
+ let (mut alt, mut swipe): (bool, bool) = ui.data(|d| d.get_temp(id)).unwrap_or_default();
+ ui.input(|i| {
+ for e in &i.events {
+ if let egui::Event::MouseWheel { phase, modifiers, .. } = e {
+ (alt, swipe) = match phase {
+ egui::TouchPhase::Start => (modifiers.alt, true),
+ egui::TouchPhase::Move => (modifiers.alt || (swipe && alt), swipe),
+ egui::TouchPhase::End | egui::TouchPhase::Cancel => (false, false),
+ };
+ }
+ }
+ });
+ ui.data_mut(|d| d.insert_temp(id, (alt, swipe)));
+ alt
+}
+
pub fn apply_view_request(app: &mut DesignApp, p: &Value) {
+ if let Some(r) = p.get("showSpread").and_then(|v| serde_json::from_value::<SpreadRef>(v.clone()).ok()) {
+ show_spread(app, r);
+ }
// Power Zoom (Hand tool, Alt-press): zoom out to the spread, aim a view-sized rectangle, zoom
// back in where it was released.
if let Some(phase) = p.get("powerZoom").and_then(Value::as_str) {
diff --cc crates/ui-egui/src/panels/pages.rs
index 3fcc07c5e,dae2597ec..0e89b2366
--- a/crates/ui-egui/src/panels/pages.rs
+++ b/crates/ui-egui/src/panels/pages.rs
@@@ -21,20 -32,32 +32,32 @@@ fn thumb(app: &mut DesignApp, ctx: &egu
if let Some(t) = map.get(&key) {
return Some(t.clone());
}
- let page = st.doc.page(abs)?;
- let scale = (h as f64 * ctx.pixels_per_point() as f64) / page.height;
+ let px = h as f64 * ctx.pixels_per_point() as f64;
let mut r = designcraft_render::Renderer::new();
r.threads = 0;
- let img = r.render_page(
- &st.doc,
- &app.session.cache,
- abs,
- scale,
- false,
- &designcraft_render::RenderOptions { printing_only: true, ..Default::default() },
- )?;
+ let opts = designcraft_render::RenderOptions { printing_only: true, ..Default::default() };
+ let (img, name) = match of {
+ ThumbOf::Page(abs) => {
+ let page = st.doc.page(abs)?;
+ let img = r.render_page(&st.doc, &app.session.cache, abs, px / page.height.max(1e-6), false, &opts)?;
+ (img, format!("thumb{abs}"))
+ }
+ ThumbOf::Parent(id) => {
+ let i = st.doc.parent_index(id)?;
+ let b = st.doc.parents.get(i)?.bounds();
+ if !(b.width() > 0.0 && b.height() > 0.0) {
+ return None;
+ }
+ let scale = (px / b.height()).min(MAX_THUMB_W / b.width());
+ let (w, h) = ((b.width() * scale).round().max(1.0) as u32, (b.height() * scale).round().max(1.0) as u32);
+ let view = designcraft_geom::Affine::scale(scale) * designcraft_geom::Affine::translate(-b.origin().to_vec2());
+ let o = designcraft_render::RenderOptions { background: Some([255, 255, 255, 255]), ..opts };
+ let placed = [designcraft_render::Placed { spread: SpreadRef::Parent(i), xf: designcraft_geom::Affine::IDENTITY }];
+ (r.render(&st.doc, &app.session.cache, &placed, w, h, view, &o), format!("thumbp{}", id.0))
+ }
+ };
let ci = egui::ColorImage::from_rgba_premultiplied([img.width as usize, img.height as usize], &img.pixels);
- let tex = crate::widgets::load_texture(ctx, format!("thumb{abs}"), ci, egui::TextureOptions::LINEAR);
- let tex = ctx.load_texture(name, ci, egui::TextureOptions::LINEAR);
++ let tex = crate::widgets::load_texture(ctx, name, ci, egui::TextureOptions::LINEAR);
// Drop thumbnails of older revisions.
let (uid, rev) = (st.uid, st.revision);
map.retain(|k, _| !(k.0 == uid && k.1 != rev));