Skip to content

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

#1620: Restore parent margins and pre-canvas page defaults

makesomethingshit90bbec39d1a0
diff --git a/ROADMAP.md b/ROADMAP.md
index dbf91dc8e..b5c4a15e2 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -388,7 +388,7 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.m
Newest first.
-- **2026-11-01** · Parent page resizing (#1620): Properties, the Page Tool Control panel and on-page handles resize the selected parent page independently of document pages. Stable parent IDs, repeated resizing, anchors and liquid rules are preserved on the current command modules. No readiness percentage change.
+- **2026-11-01** · Parent page resizing (#1620): Properties, the Page Tool Control panel and on-page handles resize the selected parent page independently of document pages. Stable parent IDs, repeated resizing, anchors and liquid rules are preserved on the current command modules. Inline parent margin editing remains available; document commands retain their first-page default before the canvas is initialized. No readiness percentage change.
- **2026-10-30** · Import warnings about a story have a Show button: it closes the warnings (the status line keeps them) and selects the story's first frame, fitted in the window. `file.open` returns `warningItems`, the frame each IDML or InDesign warning is about (or null), matching the converter's INDD story numbers (`story 30892`, written to IDML as `u78ac`) and IDML `Self` names to the imported stories. No readiness percentage change.
- **2026-10-30** · Parent pages: a running-header variable shows its name in angle brackets on the parent itself (it was blank), as InDesign shows it; on the document pages, and in text with no page, it shows its text as before. No readiness percentage change.
diff --git a/crates/ui-egui/src/chrome/tests.rs b/crates/ui-egui/src/chrome/tests.rs
index 73a943330..99704c1d7 100644
--- a/crates/ui-egui/src/chrome/tests.rs
+++ b/crates/ui-egui/src/chrome/tests.rs
@@ -913,7 +913,7 @@ fn caption_buttons_fit_the_minimum_window_width() {
}
#[test]
-fn parent_resize_properties_changes_the_parent_not_document_page_zero() {
+fn parent_resize_properties_keep_size_and_inline_parent_margins() {
parent_resize_panel(true);
}
@@ -974,6 +974,18 @@ fn parent_resize_panel(properties: bool) {
let parents = d.parents.clone();
if properties {
let saved = d.clone();
+ assert_eq!(h.get_by_role_and_label(egui::accesskit::Role::TextInput, "Top").value().as_deref(), Some("3p0"));
+ edit_parent_resize_field(&mut h, "3p0", "72 pt");
+ let edited = &h.state().session.doc().unwrap().doc;
+ for page in &edited.parents[1].pages {
+ assert_eq!(page.margins, designcraft_doc::Margins { top: 72.0, bottom: 72.0, inside: 72.0, outside: 72.0 });
+ }
+ assert_eq!(edited.parents[0], saved.parents[0]);
+ assert_eq!(edited.spreads, saved.spreads);
+ assert_eq!(edited.settings, saved.settings);
+ h.state_mut().run("edit.undo", json!({})).unwrap();
+ h.run_steps(3);
+ assert_eq!(h.state().session.doc().unwrap().doc, saved);
h.get_by_label("Back").click();
h.run_steps(3);
assert!(!h.state().session.doc().unwrap().editing_parents, "Back returns to document properties");
diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs
index 7032f6810..d70a79695 100644
--- a/crates/ui-egui/src/control.rs
+++ b/crates/ui-egui/src/control.rs
@@ -421,7 +421,7 @@ fn handle_request(app: &mut DesignApp, ctx: &egui::Context, req: &ControlRequest
let Some(st) = app.session.active() else { return err("no document") };
let current = match crate::canvas::current_page(app) {
Some(page) => page,
- None if p.get("page").is_some() => 0,
+ None if !st.editing_parents || p.get("page").is_some() => 0,
None => return err("select a document page or give an explicit page"),
};
let page = match page_index(p, current, st.doc.page_count()) {
@@ -695,19 +695,82 @@ mod automation_contract_tests {
assert_eq!(app.session.execute("story.get", &json!({"story":f["story"]})).unwrap()["text"], "Hello");
}
#[test]
- fn parent_resize_mode_does_not_default_document_actions_to_page_zero() {
+ fn parent_resize_no_canvas_render_keeps_document_page_zero_default() {
let mut app = app();
let ctx = egui::Context::default();
- app.canvas_rect = Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1400.0, 900.0)));
- app.run("layout.parents.edit", json!({"on":true,"parent":"A"})).unwrap();
+ app.run("layout.pageSize", json!({"pages": [2], "width": 700})).unwrap();
+ assert!(app.canvas_rect.is_none());
+ let before = app.session.doc().unwrap().doc.clone();
+ let omitted = call(&mut app, &ctx, "ui.render", json!({"scale": 0.1}));
+ assert_eq!(omitted["ok"], true, "{omitted}");
+ let first = call(&mut app, &ctx, "ui.render", json!({"page": 0, "scale": 0.1}));
+ let second = call(&mut app, &ctx, "ui.render", json!({"page": 1, "scale": 0.1}));
+ assert_eq!(omitted, first);
+ assert_ne!(omitted, second);
+ assert_eq!(app.session.doc().unwrap().doc, before);
+ }
+
+ #[test]
+ fn parent_resize_no_canvas_delete_uses_first_document_page() {
+ let mut app = app();
+ assert!(app.canvas_rect.is_none());
+ let before = app.session.doc().unwrap().doc.clone();
+ app.run("app.deletePage", json!({})).unwrap();
+ let after = &app.session.doc().unwrap().doc;
+ assert_eq!(after.page_count(), 1);
+ assert_eq!(after.page(0).unwrap().id, before.page(1).unwrap().id);
+ assert_eq!(after.parents, before.parents);
+ assert!(app.ui.dialog.is_none());
+ }
+
+ #[test]
+ fn parent_resize_no_canvas_delete_keeps_the_object_warning() {
+ let mut app = app();
+ app.run("frame.create", json!({"rect": [36, 36, 100, 100]})).unwrap();
+ assert!(app.canvas_rect.is_none());
let before = app.session.doc().unwrap().doc.clone();
- assert!(app.run("app.deletePage", json!({})).is_err());
- assert!(app.run("app.duplicateSpread", json!({})).is_err());
- assert_eq!(call(&mut app, &ctx, "ui.render", json!({"scale":0.1}))["ok"], false);
- assert_eq!(call(&mut app, &ctx, "ui.render", json!({"page":0,"scale":0.1}))["ok"], true);
+ app.run("app.deletePage", json!({})).unwrap();
+ let dialog = app.ui.dialog.as_ref().unwrap();
+ assert_eq!(dialog.id, "deletePages");
+ assert_eq!(dialog.fields["pages"], json!([0]));
assert_eq!(app.session.doc().unwrap().doc, before);
}
+ #[test]
+ fn parent_resize_no_canvas_duplicate_uses_first_document_spread() {
+ let mut app = app();
+ assert!(app.canvas_rect.is_none());
+ let before = app.session.doc().unwrap().doc.clone();
+ let ids: Vec<_> = before.spreads.iter().flat_map(|sp| sp.pages.iter().map(|p| p.id)).collect();
+ let result = app.run("app.duplicateSpread", json!({})).unwrap();
+ let after = &app.session.doc().unwrap().doc;
+ let first = result["page"].as_u64().unwrap() as usize;
+ assert_eq!(first, before.spreads[0].pages.len());
+ assert_eq!(after.page_count(), before.page_count() + first);
+ for i in first..first * 2 {
+ assert!(!ids.contains(&after.page(i).unwrap().id));
+ }
+ let retained: Vec<_> = after.spreads.iter().flat_map(|sp| sp.pages.iter().map(|p| p.id)).filter(|id| ids.contains(id)).collect();
+ assert_eq!(retained, ids);
+ assert_eq!(after.parents, before.parents);
+ }
+
+ #[test]
+ fn parent_resize_mode_does_not_default_document_actions_to_page_zero() {
+ for canvas in [None, Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1400.0, 900.0)))] {
+ let mut app = app();
+ let ctx = egui::Context::default();
+ app.canvas_rect = canvas;
+ app.run("layout.parents.edit", json!({"on":true,"parent":"A"})).unwrap();
+ let before = app.session.doc().unwrap().doc.clone();
+ assert!(app.run("app.deletePage", json!({})).is_err());
+ assert!(app.run("app.duplicateSpread", json!({})).is_err());
+ assert_eq!(call(&mut app, &ctx, "ui.render", json!({"scale":0.1}))["ok"], false);
+ assert_eq!(call(&mut app, &ctx, "ui.render", json!({"page":0,"scale":0.1}))["ok"], true);
+ assert_eq!(app.session.doc().unwrap().doc, before);
+ }
+ }
+
#[test]
fn control_pages_validate_before_writer_and_preserve_omission() {
let mut app = app();
diff --git a/crates/ui-egui/src/menus/run.rs b/crates/ui-egui/src/menus/run.rs
index d2a87be3c..f26532ebf 100644
--- a/crates/ui-egui/src/menus/run.rs
+++ b/crates/ui-egui/src/menus/run.rs
@@ -462,7 +462,11 @@ fn run_ui_part2(app: &mut DesignApp, id: &str, p: &Value) -> Option<Result<Value
}
"app.deletePage" | "app.duplicateSpread" => {
let Some(st) = app.session.active() else { return Some(Err("no document open".into())) };
- let Some(page) = crate::canvas::current_page(app) else { return Some(Err("select a document page".into())) };
+ let page = match crate::canvas::current_page(app) {
+ Some(page) => page,
+ None if !st.editing_parents => 0,
+ None => return Some(Err("select a document page".into())),
+ };
let r = if id == "app.deletePage" {
crate::dialogs::delete_pages(app, vec![page])
} else {
diff --git a/crates/ui-egui/src/panels/properties/document.rs b/crates/ui-egui/src/panels/properties/document.rs
index f8ea15451..bb7111e48 100644
--- a/crates/ui-egui/src/panels/properties/document.rs
+++ b/crates/ui-egui/src/panels/properties/document.rs
@@ -136,6 +136,9 @@ pub(super) fn page_sections(app: &mut DesignApp, ui: &mut Ui, spread: designcraf
{
let _ = app.run(cmd, params);
}
+ if matches!(spread, designcraft_doc::SpreadRef::Parent(_)) {
+ margin_section(app, ui);
+ }
ui.add_space(6.0);
let fw = full_width(ui);
if outline_button(ui, crate::i18n::tr(&lang, "Margins and Columns"), fw).clicked() {
@@ -201,60 +204,11 @@ fn page_box_field(app: &mut DesignApp, ui: &mut Ui, b: Rect) {
}
}
-pub(super) fn document_sections(app: &mut DesignApp, ui: &mut Ui) {
+fn margin_section(app: &mut DesignApp, ui: &mut Ui) {
let u = units(app);
let Some(st) = app.session.active() else { return };
let d = st.doc.clone();
- let (pw, ph) = (d.settings.page_width, d.settings.page_height);
- section(ui, crate::i18n::tr(&app.ui.language, "Document"), true);
- // Preset dropdown + orientation.
- let b = block(ui, FIELD_H);
- let preset = place(ui, sub(b, 0.0, 0.0, 93.0, FIELD_H), |ui| page_preset_menu(ui, pw, ph));
- let landscape = pw > ph;
- let mut orient = None;
- place(ui, sub(b, 126.0, 0.0, 52.0, FIELD_H), |ui| {
- ui.spacing_mut().item_spacing.x = 4.0;
- if icon_toggle(ui, "orient-portrait", !landscape, crate::i18n::tr(&app.ui.language, "Portrait")).clicked() && landscape {
- orient = Some(());
- }
- if icon_toggle(ui, "orient-landscape", landscape, crate::i18n::tr(&app.ui.language, "Landscape")).clicked() && !landscape {
- orient = Some(());
- }
- });
- if let Some((w, h)) = preset {
- let (w, h) = if landscape { (h, w) } else { (w, h) };
- let _ = app.run("layout.documentSetup", json!({"width": w, "height": h}));
- }
- if orient.is_some() {
- let _ = app.run("layout.documentSetup", json!({"width": ph, "height": pw}));
- }
- ui.add_space(3.0);
- // W / H, page count, facing pages.
- let b = block(ui, 2.0 * FIELD_H + 5.0);
- for (row, (label, v, key)) in [("W:", pw, "width"), ("H:", ph, "height")].into_iter().enumerate() {
- let y = row as f32 * 26.0;
- place(ui, sub(b, 0.0, y, 20.0, FIELD_H), |ui| widgets::caption_w(ui, label, 20.0));
- let nv =
- place(ui, sub(b, 21.0, y, 72.0, FIELD_H), |ui| NumField::measure(key, Some(v), u).width(72.0).spinner().range(1.0, 15552.0).show(ui));
- if let Some(nv) = nv {
- let _ = app.run("layout.documentSetup", json!({key: nv}));
- }
- }
- let n = d.page_count();
let t = Tokens::get(ui.ctx());
- icons::paint(ui.painter(), sub(b, 127.0, 2.0, 17.0, 17.0), "page-count", t.icon);
- let nv = place(ui, sub(b, 150.0, 0.0, 68.0, FIELD_H), |ui| number(ui, "pagecount", Some(n as f64), "", 68.0, 0));
- if let Some(nv) = nv {
- resize_document(app, n, nv);
- }
- let mut facing = d.settings.facing_pages;
- let changed = place(ui, sub(b, 126.0, 26.0, 100.0, FIELD_H), |ui| {
- widgets::checkbox(ui, &mut facing, crate::i18n::tr(&app.ui.language, "Facing Pages")).changed()
- });
- if changed {
- let _ = app.run("layout.documentSetup", json!({"facingPages": facing}));
- }
- // Margins.
section(ui, crate::i18n::tr(&app.ui.language, "Margins"), true);
let cur = crate::canvas::current_page(app).unwrap_or(0);
// While parent spreads are edited the fields belong to the parent page in view; they used to
@@ -307,6 +261,63 @@ pub(super) fn document_sections(app: &mut DesignApp, ui: &mut Ui) {
let _ = app.run("layout.marginsAndColumns", params);
}
}
+}
+
+pub(super) fn document_sections(app: &mut DesignApp, ui: &mut Ui) {
+ let u = units(app);
+ let Some(st) = app.session.active() else { return };
+ let d = st.doc.clone();
+ let (pw, ph) = (d.settings.page_width, d.settings.page_height);
+ section(ui, crate::i18n::tr(&app.ui.language, "Document"), true);
+ // Preset dropdown + orientation.
+ let b = block(ui, FIELD_H);
+ let preset = place(ui, sub(b, 0.0, 0.0, 93.0, FIELD_H), |ui| page_preset_menu(ui, pw, ph));
+ let landscape = pw > ph;
+ let mut orient = None;
+ place(ui, sub(b, 126.0, 0.0, 52.0, FIELD_H), |ui| {
+ ui.spacing_mut().item_spacing.x = 4.0;
+ if icon_toggle(ui, "orient-portrait", !landscape, crate::i18n::tr(&app.ui.language, "Portrait")).clicked() && landscape {
+ orient = Some(());
+ }
+ if icon_toggle(ui, "orient-landscape", landscape, crate::i18n::tr(&app.ui.language, "Landscape")).clicked() && !landscape {
+ orient = Some(());
+ }
+ });
+ if let Some((w, h)) = preset {
+ let (w, h) = if landscape { (h, w) } else { (w, h) };
+ let _ = app.run("layout.documentSetup", json!({"width": w, "height": h}));
+ }
+ if orient.is_some() {
+ let _ = app.run("layout.documentSetup", json!({"width": ph, "height": pw}));
+ }
+ ui.add_space(3.0);
+ // W / H, page count, facing pages.
+ let b = block(ui, 2.0 * FIELD_H + 5.0);
+ for (row, (label, v, key)) in [("W:", pw, "width"), ("H:", ph, "height")].into_iter().enumerate() {
+ let y = row as f32 * 26.0;
+ place(ui, sub(b, 0.0, y, 20.0, FIELD_H), |ui| widgets::caption_w(ui, label, 20.0));
+ let nv =
+ place(ui, sub(b, 21.0, y, 72.0, FIELD_H), |ui| NumField::measure(key, Some(v), u).width(72.0).spinner().range(1.0, 15552.0).show(ui));
+ if let Some(nv) = nv {
+ let _ = app.run("layout.documentSetup", json!({key: nv}));
+ }
+ }
+ let n = d.page_count();
+ let t = Tokens::get(ui.ctx());
+ icons::paint(ui.painter(), sub(b, 127.0, 2.0, 17.0, 17.0), "page-count", t.icon);
+ let nv = place(ui, sub(b, 150.0, 0.0, 68.0, FIELD_H), |ui| number(ui, "pagecount", Some(n as f64), "", 68.0, 0));
+ if let Some(nv) = nv {
+ resize_document(app, n, nv);
+ }
+ let mut facing = d.settings.facing_pages;
+ let changed = place(ui, sub(b, 126.0, 26.0, 100.0, FIELD_H), |ui| {
+ widgets::checkbox(ui, &mut facing, crate::i18n::tr(&app.ui.language, "Facing Pages")).changed()
+ });
+ if changed {
+ let _ = app.run("layout.documentSetup", json!({"facingPages": facing}));
+ }
+ margin_section(app, ui);
+ let cur = crate::canvas::current_page(app).unwrap_or(0);
ui.add_space(6.0);
let fw = full_width(ui);
if outline_button(ui, crate::i18n::tr(&app.ui.language, "Adjust Layout"), fw).clicked() {
diff --git a/docs/control-protocol.md b/docs/control-protocol.md
index 2d8fb7718..e886c07ab 100644
--- a/docs/control-protocol.md
+++ b/docs/control-protocol.md
@@ -49,7 +49,7 @@ so only enable it while you use it. Transport: `apps/designcraft/src/control_ser
| `ui.dialog.set` / `ui.dialog.confirm` / `ui.dialog.cancel` | `{field, value}` | Fill and confirm the open dialog |
| `ui.resize`, `ui.focus` | | Window control |
| `ui.screenshot` | `{path?}` | PNG of the whole window |
-| `ui.render` | `{path?, page?, scale?, bleed?}` | Render a document page headlessly (PNG; base64 if no path); parent editing mode requires an explicit 0-based `page` |
+| `ui.render` | `{path?, page?, scale?, bleed?}` | Render a document page headlessly (PNG; base64 if no path); without a canvas, document mode defaults to page 0; parent editing mode requires an explicit 0-based `page` |
| `app.open` / `app.save` / `app.export` | | Files |
| `app.quit` | | Quit without asking about unsaved changes (the `app.quit` command, like ⌘Q, asks) |