Skip to content

v1.4.0

Latest

Choose a tag to compare

@d12frosted d12frosted released this 18 Aug 15:36
· 172 commits to master since this release
v1.4.0

This release is about one idea: layout should trust what the display engine draws, not what a character count predicts. It started as a small PR and turned into the most interesting change vui has had in a while.

Pixel-accurate layout

vui has always measured text in characters. That is what a terminal does, and it is right as long as every glyph is exactly one column wide. It stops being right the moment a table cell has an emoji, a CJK name, a Nerd Font icon, or a proportional face: the character count says one thing, the font draws another, and the columns drift.

vui-width-mode fixes that. Set it to pixel and every layout primitive, tables, boxes, flex rows, stack indents, button truncation, field placeholders, measures with string-pixel-width and pads to the exact pixel. All width-aware code goes through two internal primitives, so it is one switch, not a per-component choice, and pure ASCII in a monospace font renders byte-identically in both modes.

Getting there took a few rounds, and each one taught something:

  • widths that survive text-scale-mode (the padding spacers scale with the text around them) and measurement in the buffer's own face context, so a table inside a variable-pitch-mode buffer is laid out for the font it is actually shown in
  • bordered tables in a proportional font. A font's box-drawing glyphs rarely share a width (Helvetica draws the rules at 12px and falls back to Arial for the junctions at 9px), so border rows are now laid out by position: each junction centred on the separator below it, the rules made of whole glyphs plus a small spacer. In monospace nothing changes
  • a test suite that can see pixels. In batch a pixel is a column and both modes render the same, which is how the first version shipped a bug through a green suite; the suite now runs every width-aware site under a mocked font with realistic per-glyph metrics

It is opt in for now, at about 1.15x the cost of char mode on tables and the same allocation. Whether it should become the default is an open question in #144; the docs, an example (17-pixel-width.el, with a live toggle) and a second one for proportional fonts (18-variable-pitch.el) are there so you can judge for yourself.

Sticky table headers

vui-table takes :sticky-header t: while a window is scrolled into the table's body, a copy of the header row is pinned in the header line, read live from the buffer so it always matches the current widths, borders and faces. Several sticky tables in one buffer hand the header over as you scroll between them.

Faster, everywhere

Investigating "pixel mode is GC-heavy on large tables" found that it mostly was not pixel mode: every whole-buffer render recorded itself in the undo list, copying the entire erased buffer, text properties included, into undo, and widget-setup then threw it away. Renders no longer record undo, padding strings are shared, and table cells are measured once per render instead of two or three times. On a 1000x5 table at Emacs's default GC threshold a re-render went from 63ms to 47ms in char mode and from 84ms to 47ms in pixel mode. Every vui-mount buffer benefits, tables or not.

Everything else

A dozen fixes: text properties are now part of vnode and memo equality (a face change alone re-renders), mouse-1 on buttons works again, vui-stream-update-last no longer allocates the prefix per chunk, and more. See the CHANGELOG for the full list.

Thanks

Huge thanks to @ginqi7, who opened #121 with a small PR to switch tables to pixel widths and then stayed for six rounds of review while it grew into vui-width-mode and everything above. Patient, fast, and open to every "one more thing" I threw at it. This release is theirs as much as mine.

Thanks also to @fleimgruber for the question about push notifications in the pomodoro example (#119), and to @gajama for reporting the mouse-1 click error on the quickstart article, which is fixed here.