Skip to content

toolkit: make font metrics runtime-pluggable (Font interface)#17

Merged
tannevaled merged 1 commit into
mainfrom
toolkit-font-metrics
Jul 10, 2026
Merged

toolkit: make font metrics runtime-pluggable (Font interface)#17
tannevaled merged 1 commit into
mainfrom
toolkit-font-metrics

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

The final pre-1.0 "model edge" item, and the one invasive refactor of the set — done as a single atomic PR (a half-conversion won't compile).

What

  • Font interface (Advance/Height/Draw) + a scalable built-in bitmap font. SetFont(NewBitmapFont(2)) doubles all text ("retina"); SetFont(nil) restores the default.
  • Metrics are now read at draw time, so a font swap re-lays-out every widget — the whole point. GlyphHeight / GlyphAdvance became functions returning the active font's metrics.

Breaking change (pre-1.0, 0.x)

A const can't call a function, so GlyphHeight / GlyphAdvance and the six metric-derived dimensions — CardHeaderH, CardFooterH, DatePickerFieldH, DiffLineH, FormFieldLabelH, TimelineEventH — are now functions. All 197 internal call sites were updated; downstream consumers append () when they adopt v0.20. (The only sibling that references these, gallery, pins v0.6.2 and is unaffected until it bumps.)

Safety

The default scale-1 bitmap renders pixel-identical to the old fixed font (each lit bit is a 1×1 block), so there are no golden regressions. 100% coverage retained (added a font-metrics test covering SetFont/CurrentFont/NewBitmapFont + scaled rendering + the clamp + cell-painter delegation); go vet clean; builds on all 6 arches + js/wasm.

🤖 Generated with Claude Code

Completes the last pre-1.0 model-edge item. Introduces a Font interface
(Advance/Height/Draw) with a scalable built-in bitmap font: SetFont(
NewBitmapFont(2)) doubles all text ('retina' rendering), and every widget
re-lays-out because GlyphHeight/GlyphAdvance are now read from the active
font at draw time instead of being compile-time constants.

BREAKING (pre-1.0): GlyphHeight and GlyphAdvance become functions, as do the
six metric-derived dimensions (CardHeaderH, CardFooterH, DatePickerFieldH,
DiffLineH, FormFieldLabelH, TimelineEventH) — a const can't call a function.
All 197 internal call sites updated; consumers append () when upgrading.

The default (scale-1) bitmap renders pixel-identical to before, so no golden
regressions. 100% coverage retained; go vet clean; 6 arches + wasm build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit b5cd874 into main Jul 10, 2026
1 check passed
@tannevaled
tannevaled deleted the toolkit-font-metrics branch July 10, 2026 13:05
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