Repository navigation
bidi: right-to-left and mixed-direction text in blocks-desktop (#304) - #315
Merged
Merged
Conversation
…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.
… harness takes several fonts (#304)
…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
…e keeps the frame budget, as Thai's does (#304)
# Conflicts: # .drover/arch-baseline.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #304
Built to the approved ADR in
docs/architecture/rtl/(egui stays; abidimodule inblocks-desktopcuts right-to-left text into runs withunicode-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,textoredit; these also break Thai between words (they fall back towordsfor text with no right-to-left character). The harness's--checknow faults text drawn out of order, and--fontmay be given more than once.What changed
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.rscompares them byte for byte, and Latin, Thai and CJK draw the same before and afterbidi(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::fontand--fonttake several fonts.bidi:unicode-bidi = "0.3"inblocks-desktoponly (owner-approved in the ADR review), plus itsdocs/deps.mdline.bidi.rsholdslay,label,para,text,faults,Laidand the kept map.bidi/atoms.rsreads and cuts,bidi/place.rsputs runs in visual order. The Noto Sans Hebrew and Arabic fonts are undertests/rtl/with their OFL text.ui.label,ui.heading, button, chip, hint, picker, link, tooltip text andTextEditinblocks-desktopnow goes throughbidi. 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'sbidi::faultsper shot, andRun::checkreports them.tests/rtl/screen.jsonholds every kindkinds()draws natively, with light and dark PNGs at 390. The perf test gains a right-to-left case.bidi::edit(plusarea, andhiddenfor secrets, which stay egui's own) is egui's untouchedTextEdituntil the buffer holds a right-to-left character. From then on it lays out throughbidi, 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: thedesktop-bidilayer plus the four bans, exactly as written in the ADR..drover/arch-baseline.txtraises 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.mdgains the layers-line change and the new "don't hand text to egui except through bidi" line (29 lines).bidi::areaand its placeholder and button throughbidi::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.rsrather thanblocks-desktop/tests/edit.rs, becauseblocks-desktoplinks 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):
wordssits underbidi(desktop-words <- desktop-bidi). Every draw file keeps callingbidi, andbidihands text with no right-to-left character towords::label,sensingorlink. 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 towords::lay. The twoui.label(bans are now one that exempts both modules,hyperlink_to(also exemptsbidi.rs,unicode-bidihas a line in.gatekeeper/deps.toml(staging moved the allow-list there), and the arch.toml baseline is 660. The newmodalkind's title goes throughbidi(it carried a bannedui.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. Splittingplaceandfieldunder 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/cappasses under the 44000 cap after #308's raise.Evidence at 20b57e0 (macOS arm64)
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)cargo test --release --locked -p blocks-desk --test perf -- --ignored --nocapture --test-threads=1New 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 bybidi. 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 inkinds(),modalincluded (AC 2, 3). Staging'sthai.rsand latin PNG tests pass unchanged throughbidi.apps.rs:--checkfaults an app kind's Hebrew drawn with a plainui.label, and not when it is drawn withbidi::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).