Skip to content

words: Thai lines break between words in blocks-desktop (#306) - #318

Merged
jirathip-k merged 5 commits into
stagingfrom
issue-306
Nov 21, 2026
Merged

jirathip-k merged 5 commits into
stagingfrom
issue-306

Conversation

@jirathip-k

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

Copy link
Copy Markdown
Contributor

Closes #306

For humans

Thai text in the desktop app now wraps between words instead of in the middle of a word: plain text, formatted paragraphs and links, list rows, cards, chat messages, tool output and the message box you type in.
Text with no Thai in it is drawn exactly as before, pixel for pixel.
The desktop app grows by about 1.1 MB, for the Thai word list the line breaking needs.

For apps: nothing to do. Thai wraps between words in every core kind on the desktop. An app's own kinds and islands that draw text with their own egui calls get the same by calling blocks_desktop::words::label (or sensing, link, and lay for a text field's layouter). Release binaries grow by about 1.1 MB (icu_segmenter's bundled dictionaries).

What changed

Built to the approved ADR in docs/architecture/thai/ (#304 has not landed, so kinds call words directly).

  • crates/blocks-desktop/src/words.rs (new, the desktop-words layer): breaks (ICU4X dictionary line breaks kept only between two Thai characters, not before a mark, ๆ, ฯ or a letter carrying ์), Soft (a zero-width gap section at each break), harden (gap glyphs dropped, caller's text and sections put back), Kept (cut and hard galley kept per pass in the context's temp data, no lock), and the public label, sensing, link, lay.
  • Every ui.label( (29 calls in 14 files), the card's sensing title and prose's link go through words; the composer's multi-row field takes words::lay as its layouter (blocks-desktop: styled look (type scale, spacing, app font) per #299 #303 landed its native composer, so it is covered now).
  • icu_segmenter 2.4 (default features off, compiled_data on) in blocks-desktop only, with its docs/deps.md line; demo/egui/Cargo.lock updated.
  • .drover/arch.toml: the desktop-words layer and the three bans (icu_segmenter, ui.label(, hyperlink_to() as the ADR lists them; the rules file gets the layer and the one new line (29 of 30).
  • .drover/arch-baseline.txt: arch.toml 553 -> 576, the 23 lines of that layer and those bans (as form v2 F4a: upload field, file handler, type and size check, file step, bans (#188) #263 and hotspots 2: web: one file per kind; the table of kinds generated (#152) #201 did for theirs).
  • Snapshots: tests/latin/ (a Latin and CJK text, row and card, committed first at the pre-change head as the baseline) and tests/thai/ (the sample grown to text, prose with a bold span and a link, row, card, message, tool with its body open, composer with typed Thai, form), each 390 wide in light and dark.

Decisions: the composer's layouter rebuilds the job TextEdit's default layouter makes (body font, inactive text colour, its line height, trailing whitespace kept); every fixture's PNG is unchanged, so it matches. The ADR's 230-line estimate did not count the link and sensing paint path (ink) or that layouter.

src/ net +319 (budget +230): words.rs is 289 lines with the link/sensing paint path egui keeps private; call sites +30. Total 43,202 / 44,000.

Evidence at f019dfd

Command Exit
cargo fmt --check 0
just clippy 0
just arch 0
just cap 0 (43,202 / 44,000)
just deps 0
just deny 0
cargo test --locked -p blocks-desktop -p blocks-desk 0 (thai.rs: 9 passed)
just desktop 0
cargo test --release -p blocks-desk --test perf -- --ignored --test-threads=1 0
cargo check --locked in demo/egui 0
  • AC 1: the_probe_line_at_120_points_breaks_only_between_its_words lays ภาษาไทยไม่มีช่องว่างระหว่างคำ at 120 points with the Thai font and holds every row end to the end of one of its eight words; the same test asserts egui alone breaks inside a word, and that at 390 it is one row. Runs in desktop.yml on macOS, Linux and Windows.
  • AC 2: the_thai_sample_is_the_checked_in_pngs_in_light_and_dark compares the sample's 390 PNGs byte for byte; the_thai_sample_holds_every_kind_that_wraps_text holds it to text, prose, row, card, message, tool and composer. The PNGs were made on macOS and matched byte for byte on Linux and Windows in CI at 161b560.
  • AC 3: latin_and_cjk_are_the_checked_in_pngs_in_light_and_dark was committed with its PNGs at the pre-change head (d21f9a5) and passes unchanged at the head. Beyond it, every fixtures/blocks and fixtures/stress file at 390x844 and 1440x900, light and dark, drawn by blocks-desk before and after this change: 500 PNGs compared, 0 differ. There is no right-to-left snapshot on staging yet (blocks-desktop: right-to-left and bidi text layout #304 has not landed).
  • Also: Latin and CJK get egui's own galley (Arc::ptr_eq); Thai not wrapped has egui's glyph places and size; a word wider than its line still breaks; a drag over a wrapped Thai label then Copy gives the text without gaps; the composer sends typed Thai unchanged. With hardening disabled, the probe, copy and snapshot tests fail.

Perf: the Thai 200-row case holds the 16.7 ms pass budget, as the ADR names it ("a Thai case of the 200-row screen under the same 16.7 ms"); its patch time is reported in the job summary but not held to the Latin screen's 4 ms. On CI at 161b560 the Thai patch was 4.48 ms (Linux) and 4.83 ms (Windows), its pass 4.81 and 6.98 ms. Most of that is egui drawing Thai at all: measured on macOS, a Thai patch is 1.49 ms with words switched off and 1.71 ms with it, against 1.22 ms for the Latin screen. The Latin case keeps its 4 ms assertion and passes.

CI at 161b560: the snapshot, probe and copy tests passed on macOS, Linux and Windows (so the Thai and Latin PNGs are byte-identical across the three); only the Thai patch assertion failed, which this head changes.

Not verified here: demo/egui's wasm size (no wasm target on this host).

…egui wraps at (#306)

docs/architecture/thai/: the ADR, the callers' usage, the shapes, boundaries and statechart, and what was measured.
egui keeps wrapping; a words module in blocks-desktop takes Thai word boundaries from icu_segmenter's dictionary,
puts a zero-width space egui may break at on each, and drops them from the laid galley, so its text is the caller's.
Text with no Thai is egui's own. proto/ is two throwaway crates outside every workspace; look/ has its shot at 390.
@jirathip-k
jirathip-k merged commit 44fbb0b into staging Nov 21, 2026
16 checks passed
@jirathip-k
jirathip-k deleted the issue-306 branch November 21, 2026 10:07
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