Skip to content

View: Page Layout view with rulers and in-place headers and footers (#329) - #334

Merged
h-a-n-a-s-h-i merged 2 commits into
storytold:mainfrom
vangel76:feat/page-layout-view
Oct 11, 2026
Merged

h-a-n-a-s-h-i merged 2 commits into
storytold:mainfrom
vangel76:feat/page-layout-view

Conversation

@vangel76

Copy link
Copy Markdown
Contributor

Fixes #329

What

view.pageLayout used to overlay the Page Break Preview outlines on the normal grid. It now shows the sheet as printed pages, as Excel's Page Layout view does:

  • Per-sheet view mode (normal / pageLayout / pageBreakPreview) in the model. It's saved as <sheetView view="…"> in XLSX and read back. view.normal, view.pageLayout and view.pageBreakPreview take {sheet?}. They don't record an undo step and don't mark a clean workbook as changed, the same as zoom. The Session::view_mode string is gone; the status-bar buttons read the active sheet's view.
  • Pagination comes from one place. The new engine::paper::PageGrid runs the print pagination (print::split_bands, which layout_sheet now uses too) over the sheet from A1. It goes as far right and down as the view needs, and it maps cells to page positions and back (cell ↔ layout point, page/margin/gap hit tests, header/footer zones, printed page numbers).
  • Paper view in the grid. Geo carries the page grid, so painting, hit-testing, selection, the in-cell editor, objects, fill handle, resizing and scrolling all go through the page transform:
    • pages on a desk with gaps and margins, cells at the print scale
    • pages past the data are faded and show "Click to add data"
    • only visible pages are painted, with at most 96 pages of cells per frame
    • frozen panes are ignored in this view, as in Excel
  • Rulers (horizontal and vertical) in inches for English and centimetres for the other languages. Margins are shaded and the numbers count from the margin. View › Show › Ruler (view.ruler, an app option) turns them off.
  • Headers and footers are drawn in the page margins in three sections. Field substitution uses the same expand_header_footer as PDF export.
    • Hovering a margin outlines its sections and shows "Add header" / "Add footer" when it's empty.
    • Clicking a section edits it in place. The three sections are shown as boxes, and codes appear as &[Page], &[Pages], &[Date], &[Time], &[Path], &[File], &[Tab].
    • A click elsewhere commits through pageLayout.headerFooter as one undo step. Escape cancels.
  • Header & Footer contextual tab while editing:
    • Header and Footer presets (dropdowns)
    • Page Number, Number of Pages, Current Date, Current Time, File Path, File Name, Sheet Name (inserted at the caret)
    • Go to Header, Go to Footer
  • pageLayout.headerFooter also takes {sheet?, part: header|footer, section: left|center|right, text} (field names or codes) so agents can set one section. Header and footer strings are capped at 255 characters.
  • New shared helpers: print::split_header_footer, join_header_footer, codes_to_fields, fields_to_codes and hf_date_time.
  • New code-drawn icons (Header, Footer, Page Number, Page Count, Calendar, Clock, File Name), a desk theme token, and the new strings in every catalog (ja, zh, ko, ru, pt).
  • The Draw-tab pen now maps the pointer through the cell under it, so ink lands correctly with frozen panes and on pages.

Tests

  • engine::paper::tests (3):
    • view page edges equal the printed ones
    • cell ↔ layout point round trip
    • margins, gaps and header zones, printed page numbers
    • hostile print settings (NaN/huge margins, odd breaks, full-sheet coverage) stay bounded
  • cmd::print::tests::header_sections_split_join_and_field_names: split/join/field round trip, dangling &, expansion and hostile strings.
  • cmd::print::tests::header_footer_section_edits_are_undoable_and_views_are_per_sheet: section edits, undo, bad params, the 255 cap, the per-sheet view, clean workbook stays clean, view.ruler.
  • xlsx round trip: sheetView view="pageLayout" is written and read back.
  • UI (crates/ui-egui/tests/page_layout_view.rs):
    • a click on a cell selects it through the page transform; a click in the gap selects nothing
    • clicking the top margin edits the centre header section and shows the Header & Footer tab
    • typing and inserting &[Page], then clicking a cell, commits &LLeft&CReport &P and selects the cell
    • undo restores the header; Escape cancels
  • I looked at offscreen snapshots in light, dark and Japanese, including header editing in dark mode.

Commands run (touched crates only):

cargo test -p gridcraft-engine -p gridcraft-model
cargo test -p gridcraft-xlsx roundtrip
cargo test -p gridcraft-ui-egui --lib --test page_layout_view --test selection --test interaction --test text_box_editing --test header_autofit
cargo clippy -p gridcraft-ui-egui -p gridcraft-engine -p gridcraft-model -p gridcraft-xlsx --all-targets -- -D warnings
cargo fmt -p gridcraft-ui-egui -p gridcraft-engine -p gridcraft-model -p gridcraft-xlsx -- --check
cargo xtask layers; cargo xtask parity (no change)
cargo check -p gridcraft-web -p gridcraft-engine --target wasm32-unknown-unknown

I didn't run the full cargo xtask ci; CI covers it.

Not done

  • Pictures in headers and footers (&G shows as &[Picture] but isn't drawn), Different First Page, Different Odd & Even Pages, Scale with Document and Align with Page Margins options.
  • Print titles aren't repeated on screen; their space is reserved as in print, so pages end where they print. Center on page isn't applied on screen.
  • Margins can't be dragged on the ruler. There's no separate Page Layout zoom (zoomScalePageLayoutView).
  • The horizontal scrollbar in the sheet-tab bar still measures in sheet units in this view, so it's approximate.
  • No Page Break Preview polish (unchanged).
  • The ruler setting isn't saved across restarts.

Unverified assumptions (need confirmation in Excel)

  • Pages start at A1 even when the print area or the used range starts later. When the print area doesn't start at A1, page numbers on screen can differ from the printed ones.
  • The horizontal ruler sits above the column headings and the vertical ruler left of the row numbers. Ruler numbers count from the margin.
  • Empty pages show no header or footer text; headers can still be edited from them.
  • Escape cancels a header edit, and Enter inserts a new line.
  • Excel asks to unfreeze panes when you switch to Page Layout; here frozen panes are kept and only ignored while the view is on.
  • Translations of the new labels (Header & Footer elements, "Click to add data", "Add header/footer", "Ruler") follow common Office terms but weren't checked against localized Excel.

🤖 Generated with Claude Code

vangel76 and others added 2 commits October 11, 2026 13:24
…torytold#329)

View › Page Layout (and the status-bar button) now shows the sheet as printed
pages on a desk instead of overlaying page outlines on the grid.

- Model/XLSX: per-sheet view mode (normal / pageLayout / pageBreakPreview),
  saved as <sheetView view="…"> and read back. view.* commands set it per
  sheet ({sheet?}) without an undo step or dirtying a clean workbook.
- Engine: paper::PageGrid paginates the sheet from A1 with the print
  pagination (print::split_bands, shared with PDF export and printing) and
  maps cells to pages and back; header/footer section helpers
  (split/join, &[Page] field names) shared with the PDF header code.
  pageLayout.headerFooter takes {part, section, text} for one section and a
  sheet; header/footer strings are capped at 255 characters.
  view.ruler toggles the rulers.
- UI: Geo carries the page grid, so painting, hit-testing, selection,
  editing, objects and scrolling work through the page transform; frozen
  panes are ignored in this view. Pages with margins and gaps, "Click to add
  data" pages, rulers in inches (English) or centimetres, headers/footers
  drawn on printed pages, click a margin section to edit it in place; a
  click elsewhere commits (one undo step), Escape cancels. Header & Footer
  contextual tab: presets, Page Number, Number of Pages, Current Date/Time,
  File Path, File Name, Sheet Name, Go to Header/Footer. View › Ruler.
- New strings in every catalog; new code-drawn icons; desk colour token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…torytold#266), frozen-pane clipping (storytold#217), right-to-left mirroring and freeze handles (storytold#310, storytold#309); es/de/cs strings for headers and footers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 2648986 into storytold:main Oct 11, 2026
@echelon

echelon commented Oct 11, 2026

Copy link
Copy Markdown
Member

Merged — thank you for the contribution! (I merged main into your branch: pages now keep the gliding selection from #266, frozen-pane clipping from #217, and right-to-left mirroring and freeze handles from #310/#309; I also added Spanish/German/Czech strings for the header/footer UI.)

If you haven't already, come join us on the ArtCraft Discord: https://discord.gg/artcraft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parity: View › Page Layout view (paper view, rulers, in-place header/footer)

3 participants