DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Layout: First/Previous/Next/Last Page and Next/Previous Spread with InDesign's shortcuts
moppeeere001b4122101
diff --git a/ROADMAP.md b/ROADMAP.mdindex d60a6bf49..b656875c1 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -347,6 +347,7 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.mNewest first.+- 2026-10-15: Layout › First Page, Previous Page, Next Page, Last Page, Next Spread and Previous Spread, with InDesign's shortcuts (Shift+Page Up/Down, Shift+Cmd+Page Up/Down, Alt+Page Up/Down).- **2026-10-14** · The Type tool draws a new text frame over a locked empty frame, as InDesign does, instead of turning the locked frame into a text frame. No readiness percentage change.- **2026-10-14** · 100% black shows as pure black on screen by default, as InDesign's Appearance of Black does out of the box (Display All Blacks as Rich Black); Preferences › Appearance of Black › Display All Blacks Accurately still shows it as the dark grey it prints, and a saved choice is kept. No readiness percentage change.- **2026-10-14** · Pathfinder keeps the frontmost object, as InDesign does: a photo placed over shapes and intersected with them shows through the shapes (it was dropped, and the shapes kept their black fill); Add, Exclude Overlap and Minus Back take the front object's fill too, Subtract still keeps the back one. No readiness percentage change.diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 40b146f56..1c550a197 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -221,6 +221,20 @@ pub fn go_to_page(app: &mut DesignApp, abs: usize) {}}+/// Centre the spread `delta` spreads after (or before) the one in view (keeps zoom); stops at the+/// first and last spread. Parent spreads while they are being edited.+pub fn step_spread(app: &mut DesignApp, delta: isize) {+ let Some(st) = app.session.active() else { return };+ let layout = CanvasLayout::new(&st.doc, st.editing_parents);+ let Some(cur) = current_slot(app, &layout) else { return };+ let to = cur.saturating_add_signed(delta).min(layout.slots.len().saturating_sub(1));+ let Some(b) = layout.slots.get(to).map(|s| s.bounds) else { return };+ let Some(rect) = app.canvas_rect else { return };+ if let Some(v) = app.view_mut() {+ v.origin = Point::new(b.center().x - rect.width() as f64 / 2.0 / v.zoom, b.center().y - rect.height() as f64 / 2.0 / v.zoom);+ }+}+pub fn zoom_at(app: &mut DesignApp, screen: Pos2, factor: f64) {let Some(rect) = app.canvas_rect else { return };let Some(v) = app.view_mut() else { return };diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rsindex 245a6e287..a20b30dcb 100644--- a/crates/ui-egui/src/i18n.rs+++ b/crates/ui-egui/src/i18n.rs@@ -58,6 +58,10 @@ const TABLE: &[(&str, [&str; 5])] = &[("Cut", ["Ausschneiden", "Couper", "Cortar", "カット", "剪切"]),("Copy", ["Kopieren", "Copier", "Copiar", "コピー", "复制"]),("Paste", ["Einfügen", "Coller", "Pegar", "ペースト", "粘贴"]),+ ("First Page", ["Erste Seite", "Première page", "Primera página", "最初のページ", "第一页"]),+ ("Previous Page", ["Vorherige Seite", "Page précédente", "Página anterior", "前のページ", "上一页"]),+ ("Next Page", ["Nächste Seite", "Page suivante", "Página siguiente", "次のページ", "下一页"]),+ ("Last Page", ["Letzte Seite", "Dernière page", "Última página", "最後のページ", "最后一页"]),("Bulleted & Numbered Lists",[diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex a35261d59..423b72be9 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -157,6 +157,12 @@ pub const UI_COMMANDS: &[(&str, &str, Option<&str>, &str)] = &[("view.fastDisplay", "Fast Display", Some("Cmd+Alt+Shift+Z"), "{} — placed graphics as grey boxes, no effects"),("view.typicalDisplay", "Typical Display", Some("Cmd+Alt+Z"), "{} — low-resolution image proxies"),("view.highQualityDisplay", "High Quality Display", Some("Cmd+Alt+H"), "{} — full-resolution images"),+ ("view.firstPage", "First Page", Some("Cmd+Shift+PageUp"), "{} — scroll to the document's first page (zoom kept)"),+ ("view.previousPage", "Previous Page", Some("Shift+PageUp"), "{} — scroll to the page before the one in view"),+ ("view.nextPage", "Next Page", Some("Shift+PageDown"), "{} — scroll to the page after the one in view"),+ ("view.lastPage", "Last Page", Some("Cmd+Shift+PageDown"), "{} — scroll to the document's last page"),+ ("view.nextSpread", "Next Spread", Some("Alt+PageDown"), "{} — centre the spread after the one in view"),+ ("view.previousSpread", "Previous Spread", Some("Alt+PageUp"), "{} — centre the spread before the one in view"),("view.goToPage", "Go to Page…", Some("Cmd+J"), "{page: number (position) | \"name\" (section page name, or \"+n\" for a position)}"),("window.panel",@@ -338,6 +344,12 @@ pub const MENUS: &[(&str, &[&str])] = &["cmd:layout.createGuides","cmd:layout.createAlternate","-",+ "ui:view.firstPage",+ "ui:view.previousPage",+ "ui:view.nextPage",+ "ui:view.lastPage",+ "ui:view.nextSpread",+ "ui:view.previousSpread","ui:view.goToPage","-","cmd:layout.section",@@ -1358,6 +1370,24 @@ fn run_ui_inner(app: &mut DesignApp, id: &str, p: &Value) -> Option<Result<Valueapp.canvas.shown = None;Ok(Value::Null)}+ "view.firstPage" | "view.previousPage" | "view.nextPage" | "view.lastPage" => {+ let n = app.session.active().map_or(0, |d| d.doc.page_count());+ if n > 0 {+ let cur = crate::canvas::current_page(app).unwrap_or(0);+ let to = match id {+ "view.firstPage" => 0,+ "view.previousPage" => cur.saturating_sub(1),+ "view.nextPage" => cur.saturating_add(1).min(n - 1),+ _ => n - 1,+ };+ crate::canvas::go_to_page(app, to);+ }+ Ok(Value::Null)+ }+ "view.nextSpread" | "view.previousSpread" => {+ crate::canvas::step_spread(app, if id == "view.nextSpread" { 1 } else { -1 });+ Ok(Value::Null)+ }"view.goToPage" => {match p.get("page") {Some(Value::Number(n)) => crate::canvas::go_to_page(app, (n.as_u64().unwrap_or(1) as usize).saturating_sub(1)),@@ -3296,6 +3326,82 @@ mod tests {assert_eq!(items(&app), items0, "the tool saw nothing");}+ #[test]+ fn layout_menu_goes_through_pages_and_spreads_with_their_shortcuts() {+ let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.session.execute("file.new", &json!({"pages": 7, "facingPages": true})).unwrap();+ let ctx = egui::Context::default();+ let frame = |app: &mut crate::DesignApp, events: Vec<egui::Event>| {+ let input = egui::RawInput {+ screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1400.0, 900.0))),+ events,+ ..Default::default()+ };+ let mut out = ctx.run_ui(input, |ui| {+ app.logic(&ui.ctx().clone());+ app.ui(ui);+ });+ out.textures_delta.clear();+ };+ let key = |k: egui::Key, modifiers: egui::Modifiers| {+ vec![+ egui::Event::Key { key: k, physical_key: None, pressed: true, repeat: false, modifiers },+ egui::Event::Key { key: k, physical_key: None, pressed: false, repeat: false, modifiers },+ ]+ };+ let page = |app: &crate::DesignApp| crate::canvas::current_page(app).unwrap();+ let spread = |app: &crate::DesignApp| {+ let st = app.session.active().unwrap();+ crate::canvas::current_slot(app, &designcraft_tools::layout::CanvasLayout::new(&st.doc, false)).unwrap()+ };+ frame(&mut app, vec![]);+ frame(&mut app, vec![]);+ // The Layout menu lists them, as InDesign's does, before Go to Page.+ let layout = MENUS.iter().find(|m| m.0 == "Layout").unwrap().1;+ let at = |id: &str| layout.iter().position(|e| e.starts_with(&format!("ui:{id}"))).unwrap();+ assert!(at("view.firstPage") < at("view.previousPage"));+ assert!(at("view.previousPage") < at("view.nextPage"));+ assert!(at("view.nextPage") < at("view.lastPage"));+ assert!(at("view.lastPage") < at("view.nextSpread"));+ assert!(at("view.nextSpread") < at("view.previousSpread"));+ assert!(at("view.previousSpread") < at("view.goToPage"));+ let shift = egui::Modifiers::SHIFT;+ let cmd_shift = egui::Modifiers { shift: true, command: true, ctrl: true, ..Default::default() };+ let alt = egui::Modifiers::ALT;+ // Pages 1 | 2-3 | 4-5 | 6-7.+ frame(&mut app, key(egui::Key::PageDown, shift));+ assert_eq!(page(&app), 1, "Next Page");+ frame(&mut app, key(egui::Key::PageDown, shift));+ assert_eq!(page(&app), 2, "Next Page goes to the right page of the spread");+ frame(&mut app, key(egui::Key::PageUp, shift));+ assert_eq!(page(&app), 1, "Previous Page");+ frame(&mut app, key(egui::Key::PageDown, cmd_shift));+ assert_eq!(page(&app), 6, "Last Page");+ frame(&mut app, key(egui::Key::PageDown, shift));+ assert_eq!(page(&app), 6, "Next Page stops at the last page");+ frame(&mut app, key(egui::Key::PageUp, cmd_shift));+ assert_eq!(page(&app), 0, "First Page");+ frame(&mut app, key(egui::Key::PageUp, shift));+ assert_eq!(page(&app), 0, "Previous Page stops at the first page");+ frame(&mut app, key(egui::Key::PageDown, alt));+ assert_eq!(spread(&app), 1, "Next Spread");+ frame(&mut app, key(egui::Key::PageDown, alt));+ frame(&mut app, key(egui::Key::PageDown, alt));+ frame(&mut app, key(egui::Key::PageDown, alt));+ assert_eq!(spread(&app), 3, "Next Spread stops at the last spread");+ frame(&mut app, key(egui::Key::PageUp, alt));+ assert_eq!(spread(&app), 2, "Previous Spread");+ // The spread is centred, the zoom kept.+ let zoom = app.view().unwrap().zoom;+ app.run("view.previousSpread", json!({})).unwrap();+ let st = app.session.active().unwrap();+ let slot = designcraft_tools::layout::CanvasLayout::new(&st.doc, false).slots[1];+ let (v, r) = (*app.view().unwrap(), app.canvas_rect.unwrap());+ let centre = (v.origin.x + r.width() as f64 / 2.0 / v.zoom, v.origin.y + r.height() as f64 / 2.0 / v.zoom);+ assert!((centre.0 - slot.bounds.center().x).abs() < 1e-6 && (centre.1 - slot.bounds.center().y).abs() < 1e-6);+ assert_eq!(v.zoom, zoom);+ }+#[test]fn tool_shortcuts_work_after_drawing_on_the_canvas() {// Clicking the canvas gives it keyboard focus; single-key tool shortcuts must still switch