Skip to content

Visualize: a page is laid out as a browser lays it out - #1201

Merged
Tryanks merged 1 commit into
mainfrom
claude/visualize-rendering
Nov 27, 2026
Merged

Tryanks merged 1 commit into
mainfrom
claude/visualize-rendering

Conversation

@Tryanks

@Tryanks Tryanks commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Summary

Every page tcode_visualize has drawn on the maintainer's machine (76 calls, 50 distinct pages that could still be read and compared) was drawn again by the renderer and by Chrome at the same width, side by side. What differed is fixed in crates/ui/src/html/ where GPUI can draw it.

 HtmlView::render
   computed styles (once for a theme)
+  measure (once for a theme)
+    for each grid with an `auto` track, each table:
+      lay each item out alone -> the width of each column's widest item
   render_document
-    inline run with a box in it: each text node is one box of a wrapping row
+    inline run with a box in it: a wrapping row of the boxes and of the text between them, word by word
-    grid of named tracks: `auto` shares the row like `1fr`; items centred at their own height
+    grid of named tracks: `auto` is the measured width in every row; an item fills its area
-    table: every row divides its own width evenly
+    table: a column has the same room in every row (a named width, else its measured width)

What a page now gets that it did not:

  • Lines of text: text beside a badge, an icon, <code> or a highlighted <ins> wraps around it; no line begins with what closes a phrase; a box on a line sits on the line's baseline.
  • Flex: an item of bare text narrows to its row and wraps; an item that cannot wrap is not made narrower than what it holds; white space around an item's text is not part of it; an empty item on a baseline row sits on the baseline.
  • Grid: place-items/justify-items set an item across its column as well as down its row.
  • Box: width/height size the content box unless box-sizing: border-box; a transparent border keeps its room and is not drawn; a border of another colour than the box's is drawn; linear-gradient of more than two stops along an axis is drawn stop by stop; line-clamp, transform: translate(), vertical-align, table-layout: fixed.
  • SVG: color-mix()/light-dark() as a paint (was black); <use> of a <symbol> in another <svg>; a zero-size sheet of symbols draws nothing (was an error box); an <svg> sized only by CSS is drawn to that size; <g fill> reaches its <text>; the theme's fonts as families usvg can look up; fill/stroke the page's rules give the <svg> itself.
  • Defaults: <ins> and other phrasing tags are inline; <code> has no background of its own, as in a browser.

measure is the one new mechanism: GPUI lays each row out by itself, so what the rows of a column share has to be known before they are built. It is bounded (MAX_MEASURED cells, past which columns fall back to even shares), as are the word boxes of a line (MAX_WORDS).

Lead::Space and TextSink::space go: the white space between two boxes of a line is now a run of the page's text.

Evidence

  • Before: on main, the six tests added here fail:
    an_auto_track_is_as_wide_as_what_it_holds, a_table_column_is_as_wide_in_every_row, a_width_is_the_content_box_unless_the_page_says, text_beside_a_box_wraps_in_its_line, an_svg_draws_a_symbol_of_another, an_svg_is_painted_in_a_colour_css_mixes (9 passed, 6 failed).
    After: cargo nextest run -p tcode-ui --locked: 505 passed. cargo clippy -p tcode-ui --all-targets --locked -- -D warnings and cargo fmt --all --check clean.
  • Before: of the 50 pages at 720 px, most differed from Chrome in structure: unequal column widths, text clipped or drawn over its neighbour, icons missing, black SVG fills.
    After: all 50 are within 41 px of Chrome's height, 49 within 25 px; a second page-by-page comparison found no structural difference on most of them. The pages were also drawn at 360 px and one in the dark theme.

Each test states a contract a recorded page depends on and drives HtmlView in a window as the chat does; none existed for these, and each fails without the change.

Not checked: the running app. The pages were drawn offscreen through HtmlView with the macOS Metal renderer and the system text system, not looked at in a Tcode window. Windows and Linux were not drawn; the one platform branch (the half width CoreText leaves off a full-width mark at a word's end) is cfg!(target_vendor = "apple").

Left as it is, with the cause:

  • GPUI has no equivalent: transform: rotate(), radial-gradient, backdrop-filter, a border of another colour on a rounded box.
  • Tcode's text everywhere, not this renderer: the interpunct · is drawn wide, a gap stands before ( after a CJK character, emoji are drawn large.
  • A 1fr track is not widened by content that does not wrap, which a browser's automatic minimum does; one row of one page is still clipped.

Merge Danger

Door: two-way

One commit in one module; reverting it restores the previous drawing. Nothing is stored and the wire is unchanged.

Blast Radius: visuals

Every stored tcode_visualize page is drawn differently on every client. A page that relied on the old behaviour (a padded box sized as border-box, <code> with a grey background) changes with it. Pages with grids of auto tracks or tables are laid out once more than before for each theme.

Every page the tool has drawn on this machine was drawn again beside
Chrome, and what differed is fixed where GPUI can draw it.

A line of text with boxes in it wraps word by word around them. A grid's
auto track is as wide as its widest item, an item fills its area, and a
table's column has the same room in every row; both widths are measured
once for a theme. A flex item of text narrows to its row, and one that
cannot wrap is not made narrower than what it holds. A width is the
content box's. A transparent border keeps its room, a border of another
colour is drawn, and a gradient is drawn stop by stop. An <svg> draws a
<symbol> of another, takes the size and the paint the page's styles give
it, and is painted in a colour CSS mixes; a sheet of symbols draws
nothing. line-clamp, translate(), vertical-align, justify-items and
table-layout are read. <ins> is inline, and <code> has no background of
its own.
@Tryanks
Tryanks merged commit f19d367 into main Nov 27, 2026
13 checks passed
@Tryanks
Tryanks deleted the claude/visualize-rendering branch November 27, 2026 07:47
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