toolkit: make font metrics runtime-pluggable (Font interface)#17
Merged
Conversation
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>
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.
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
Fontinterface (Advance/Height/Draw) + a scalable built-in bitmap font.SetFont(NewBitmapFont(2))doubles all text ("retina");SetFont(nil)restores the default.GlyphHeight/GlyphAdvancebecame functions returning the active font's metrics.Breaking change (pre-1.0, 0.x)
A
constcan't call a function, soGlyphHeight/GlyphAdvanceand 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, pinsv0.6.2and 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 vetclean; builds on all 6 arches + js/wasm.🤖 Generated with Claude Code