Skip to content

Grid: mirror right-to-left sheets (#146) - #310

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
vangel76:fix/sheet-right-to-left
Oct 11, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
vangel76:fix/sheet-right-to-left

Conversation

@vangel76

Copy link
Copy Markdown
Contributor

Part of #146 (the sheet layout part; Arabic letter joining / bidi is separate text-shaping work, see #260).

Root cause

view.rightToLeft (Page Layout › Sheet Options), the Sheet::right_to_left flag and the XLSX <sheetView rightToLeft="1"> round trip already existed on main, but the grid ignored the flag: an RTL sheet still drew column A on the left, and there was no ribbon control for it.

What changed

  • Grid mirroring (crates/ui-egui/src/grid.rs): the grid still computes its layout in logical left-to-right coordinates (Geo::x, cell_rect, col_at…) and then mirrors it across the grid's vertical centre line on screen:
    • painted shapes are reflected after painting (mirror_painted/mirror_shape). Rects, lines, paths and circles are flipped. Text galleys and meshes (pictures in cells) are only moved, so glyphs and images keep their direction. Default alignment therefore comes out as text on the right and numbers on the left, overflow runs to the left, and filter buttons, data bars, CF icons and the fill handle sit on the mirrored side;
    • floating charts, pictures and shapes move as a whole (chartview::paint_objects now reports the shape range each object painted), so a chart keeps its axes;
    • pointer input is mirrored back (Geo::mirror_pos) before hit-testing, so clicks, drags, header selection/resize, fill, move, object drag and context menus hit the right cells. Popup positions are converted back to screen coordinates;
    • the in-cell editor, text box editor, validation list/input message and note popups are placed on the mirrored side (the cell editor grows to the left);
    • the vertical scrollbar moves to the left. A horizontal trackpad swipe moves the content the way the fingers go;
    • Left/Right arrows follow the screen (Left goes to the next column), in the grid and in the editor's Enter/Point modes. Tab is unchanged.
  • Ribbon: Page Layout › Sheet Options › Sheet Right-to-Left button (outlined when on), with a new icon drawn in code (Icon::SheetRtl). The label is translated in all catalogs (ja, zh, ko, ru, pt).
  • The control channel's cell-click helper uses the on-screen (mirrored) cell rect.
  • docs/localization-parity.md updated.

Tests and commands run

  • New crates/ui-egui/tests/right_to_left.rs: column A is drawn right of B and next to the right-hand row headers, a drag between the on-screen positions of C3 and F7 selects C3:F7, and Left/Right arrows move to the next/previous column.
  • cargo test -p gridcraft-ui-egui --test right_to_left, --test selection, --test interaction, --test header_autofit, --test text_box_editing, --test popup_dismissal, --test cell_pictures, --lib (all pass)
  • cargo clippy -p gridcraft-ui-egui --all-targets -- -D warnings, cargo fmt -p gridcraft-ui-egui -- --check, cargo check --target wasm32-unknown-unknown -p gridcraft-ui-egui
  • Looked at an offscreen snapshot (--example snapshot -- --sample sales --tab "Page Layout" --cmd 'view.rightToLeft={"on":true}' --cmd 'view.freezePanes={"cell":"B2"}'): column A and the row numbers are on the right, the frozen pane and select-all corner are on the right, the scrollbar is on the left, table filter buttons and data bars are mirrored, and charts are moved but not flipped.

Not done

  • Arabic/Hebrew text shaping and bidirectional runs inside a cell (needs a shaping engine; Improve Arabic XLSX text rendering and font compatibility #260 covers Arabic font fallback).
  • Format Cells › Alignment › Text direction (Context / LTR / RTL) per cell.
  • Mirroring of the sheet tab bar and the horizontal scrollbar, Page Layout view page frames beyond the grid, and printing/PDF export of RTL sheets.
  • Sparklines are reflected with the cells (time runs right to left). Wrapped multi-line text keeps its line alignment inside the mirrored box.

Unverified assumptions (needs confirmation in Excel)

  • Explicit Left/Right horizontal alignment on an RTL sheet: this PR mirrors it (Left shows on the right edge), the same as General text.
  • Left/Right arrow keys moving visually (Left → next column) on an RTL sheet.
  • Sparklines and data bars running right to left.
  • Translations of the button label are mine, not checked against Excel's localized UI.

🤖 Generated with Claude Code

Sheet Right-to-Left (view.rightToLeft, XLSX rightToLeft) was stored and
round-tripped but never rendered. The grid now lays out in logical
left-to-right coordinates and mirrors on screen: painted shapes are
reflected (text and pictures only moved), floating objects move as a
whole, pointer input is mirrored back for hit-testing, Left/Right arrows
follow the screen, and the cell editor, text box editor, popups and the
vertical scrollbar are placed on the mirrored side. Page Layout gets a
Sheet Right-to-Left button.

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 1302ec7 into storytold:main Oct 11, 2026
@echelon

echelon commented Oct 11, 2026

Copy link
Copy Markdown
Member

Merged — thank you for the contribution! (I resolved a conflict with the freeze-handle drag from #309 in grid.rs: the press origin is mirrored first, then the freeze handles are checked.)

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

h-a-n-a-s-h-i pushed a commit that referenced this pull request Oct 11, 2026
…pect frozen panes (#217) and right-to-left sheets (#310); es/de/cs strings for Animations

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
h-a-n-a-s-h-i pushed a commit that referenced this pull request Oct 11, 2026
), frozen-pane clipping (#217), right-to-left mirroring and freeze handles (#310, #309); es/de/cs strings for headers and footers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

3 participants