Skip to content

bidi: right-to-left and mixed-direction text in blocks-desktop (#304) - #315

Merged
jirathip-k merged 12 commits into
stagingfrom
issue-304
Nov 22, 2026
Merged

jirathip-k merged 12 commits into
stagingfrom
issue-304

Conversation

@jirathip-k

@jirathip-k jirathip-k commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #304

Built to the approved ADR in docs/architecture/rtl/ (egui stays; a bidi module in blocks-desktop cuts right-to-left text into runs with unicode-bidi, lets egui shape and wrap them, then puts each row in visual order).

For humans

Hebrew and Arabic in the desktop app now read in the right order, and a right-to-left paragraph lines up on the right edge. Mixed lines (an English word or a number inside Hebrew or Arabic) come out in the right order too.
Typing in a right-to-left text field moves the caret the way it looks: the left arrow moves left, and clicking puts the caret where you clicked.
Latin, Thai, Chinese and Japanese text look exactly as before, and Thai still wraps between words.

For apps

Right-to-left text is drawn in order and right-aligned; nothing else changes. An app's own kinds and islands that draw text with their own egui calls get the same by calling blocks_desktop::bidi::label, para, sensing, link, text or edit; these also break Thai between words (they fall back to words for text with no right-to-left character). The harness's --check now faults text drawn out of order, and --font may be given more than once.

What changed

  • Commit 0 (50f6da6), baseline: crates/blocks-desk/tests/scripts/ has a Latin, Thai and CJK screen and its 390 PNGs in light and dark, as staging draws them. tests/snap.rs compares them byte for byte, and Latin, Thai and CJK draw the same before and after bidi (AC 3). After staging's blocks-desktop: styled look from the web tokens, app faces, native composer (#303) #307 (the styled look) merged, both PNG sets were regenerated on it in one commit (5f2a011): the look changed, not the text order. Desk::font and --font take several fonts.
  • Slice 1, bidi: unicode-bidi = "0.3" in blocks-desktop only (owner-approved in the ADR review), plus its docs/deps.md line. bidi.rs holds lay, label, para, text, faults, Laid and the kept map. bidi/atoms.rs reads and cuts, bidi/place.rs puts runs in visual order. The Noto Sans Hebrew and Arabic fonts are under tests/rtl/ with their OFL text.
  • Slice 2, every text: each ui.label, ui.heading, button, chip, hint, picker, link, tooltip text and TextEdit in blocks-desktop now goes through bidi. That covers text, prose, row, card, message, tool, section, stat, chips, button, choice, form/config, secret, run, sheet, screen and the fallback. The harness keeps the last pass's bidi::faults per shot, and Run::check reports them. tests/rtl/screen.json holds every kind kinds() draws natively, with light and dark PNGs at 390. The perf test gains a right-to-left case.
  • Slice 3, fields: bidi::edit (plus area, and hidden for secrets, which stay egui's own) is egui's untouched TextEdit until the buffer holds a right-to-left character. From then on it lays out through bidi, swaps the arrows while the character before the caret is right-to-left, sets the caret from a press or drag, and paints its own caret and selection.
  • .drover/arch.toml: the desktop-bidi layer plus the four bans, exactly as written in the ADR. .drover/arch-baseline.txt raises arch.toml from 553 to 581 for those lines, as form v2 F4a: upload: the field type and the file handler in the crate, static page, HTML and React; the bans (design first) #188 and hotspots 2: web: one file per kind; the table of kinds generated #152 did for theirs. .drover/rules.md gains the layers-line change and the new "don't hand text to egui except through bidi" line (29 lines).
  • ADR: one written limit added. A right-to-left prose paragraph flows its spans from the right edge, so two left-to-right spans side by side come out in right-to-left span order. The native composer from blocks-desktop: styled look from the web tokens, app faces, native composer (#303) #307 now takes its field through bidi::area and its placeholder and button through bidi::text, as the ADR says; the right-to-left sample holds a composer with a Hebrew placeholder.

Decisions: the probe, order and field tests live in crates/blocks-desk/tests/rtl.rs rather than blocks-desktop/tests/edit.rs, because blocks-desktop links egui with no fonts and the tests need the Noto fonts. The RTL sample is 390x844, not 390x420, so that every native kind fits.

Merged with staging's #306 (Thai words): words sits under bidi (desktop-words <- desktop-bidi). Every draw file keeps calling bidi, and bidi hands text with no right-to-left character to words::label, sensing or link. A many-row field with no right-to-left text uses #306's Thai layouter, and a right-to-left field's layouter falls back to words::lay. The two ui.label( bans are now one that exempts both modules, hyperlink_to( also exempts bidi.rs, unicode-bidi has a line in .gatekeeper/deps.toml (staging moved the allow-list there), and the arch.toml baseline is 660. The new modal kind's title goes through bidi (it carried a banned ui.heading(), and the rtl sample holds a Hebrew modal. It sits below the 844 fold like the sheet and the message, so the PNGs are unchanged.

Review FAIL (Windows perf, right-to-left patch 4.02 ms over 4 ms): the right-to-left case is now its own test, the_200_row_screen_right_to_left_paints_every_pass_in_a_frame. It keeps the 16.7 ms frame budget for every pass and every patch, which is the rule staging's #306 set for its Thai case. The Latin case keeps its 4 ms patch budget, unchanged. Locally the right-to-left patch takes 1.62 ms at 1440, against 1.20 ms for Latin.

Lines: src/ net +854 (budget +650) against staging 26d0346. Splitting place and field under the 80-line function limit, and routing 17 kinds' texts plus message/tool/prose (#296, which landed after the ADR's count), cost more than estimated. core/cap passes under the 44000 cap after #308's raise.

Evidence at 20b57e0 (macOS arm64)

Command (at 20b57e0) Exit
just check (all 28 gates: core/arch, cap, deps, rules; rust/clippy, deny, fmt, bans; local/test, perf, soak, guard, gen, for-apps, bench; ts) 0
cargo test --release --locked -p blocks-desk --test perf -- --ignored --nocapture --test-threads=1 0

New tests:

  • rtl.rs: the probe strings אב גד and اب جد have x decreasing in reading order, with the fonts and with none (AC 1). Latin, Thai and CJK are not laid by bidi. Nine samples plus a paragraph wrapped at 390, 200 and 120 show no order fault, while egui's own labels for the same texts do fault. A right-to-left paragraph ends at the column's right edge on whole pixels. A right-to-left field takes ArrowLeft/Right in visual order, typing, End, Backspace and presses at both ends, all through egui's real events (AC 4).
  • snap.rs: the scripts and rtl PNGs match byte for byte, and the rtl sample holds every kind in kinds(), modal included (AC 2, 3). Staging's thai.rs and latin PNG tests pass unchanged through bidi.
  • apps.rs: --check faults an app kind's Hebrew drawn with a plain ui.label, and not when it is drawn with bidi::para.

Not verified here: Linux and Windows byte-identity and Windows perf, which the desktop workflow's three-OS run checks in CI. Also not tested: a real input method or screen reader (the ADR's limits).

…i's own layout (#304)

docs/architecture/rtl/: the ADR, the callers' usage, the shapes, boundaries and statecharts, and what was measured.
egui stays; a bidi module in blocks-desktop cuts a text with right-to-left characters into runs with unicode-bidi,
lets egui shape and wrap them, then puts each row in visual order. A text field draws its own caret.
proto/ is a throwaway crate outside every workspace that draws it; look/ has its two shots at 390.
…d dark, fields in visual order, a right-to-left perf case (#304)
…mposer in the right-to-left sample; both sample PNG sets regenerated on staging (#304)
# Conflicts:
#	.drover/arch-baseline.txt
#	.drover/arch.toml
#	.drover/rules.md
#	Cargo.lock
#	Cargo.toml
#	crates/blocks-desk/tests/perf.rs
#	crates/blocks-desktop/src/art.rs
#	crates/blocks-desktop/src/draw/card.rs
#	crates/blocks-desktop/src/draw/choice.rs
#	crates/blocks-desktop/src/draw/composer.rs
#	crates/blocks-desktop/src/draw/form.rs
#	crates/blocks-desktop/src/draw/message.rs
#	crates/blocks-desktop/src/draw/prose.rs
#	crates/blocks-desktop/src/draw/row.rs
#	crates/blocks-desktop/src/draw/run.rs
#	crates/blocks-desktop/src/draw/secret.rs
#	crates/blocks-desktop/src/draw/section.rs
#	crates/blocks-desktop/src/draw/sheet.rs
#	crates/blocks-desktop/src/draw/stat.rs
#	crates/blocks-desktop/src/draw/text.rs
#	crates/blocks-desktop/src/draw/tool.rs
#	crates/blocks-desktop/src/fallback.rs
#	docs/deps.md
# Conflicts:
#	.drover/arch-baseline.txt
@jirathip-k
jirathip-k merged commit a972a6b into staging Nov 22, 2026
20 checks passed
@jirathip-k
jirathip-k deleted the issue-304 branch November 22, 2026 00:25
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.

1 participant