Part of TPG namespace
TPG.UI.TextInBox(text, font, x, y, w, h, color)Description
Draw text centred in a box, correcting for capital-letter line-box bias. The old point pips passed TEXT_ALIGN_CENTER for both axes and looked slightly high in their tiles. The math wasn't wrong: SimpleText centres the font's LINE BOX, ascender to descender. A lone capital letter has no descender, so the empty descender space all sits below it and pushes the visible glyph up by about half of it. GMod can't measure a glyph's actual bounding box (surface.GetTextSize returns the line height, not the ink), so the shift comes from the FACE's published metrics instead, via TPG.UI.CapMid (built in TPG.UI.BuildFonts). It's per-font because the two families here disagree by a tenth of a line height, which at pip size is around three pixels: a single number tuned until Roboto looked right left Exo 2 sitting low, and vice versa. Text with real descenders (a "g", a "p") sits a hair low as a result, which is why this is used for pips, badges and button captions (short, capital, centred things) and not for body text. Both coordinates are ROUNDED. Centring produces a half-pixel offset whenever the box and the glyph differ by an odd number of pixels, and a glyph rasterised on a half-pixel is blurred asymmetrically; it reads as being nudged up and to the left, which is exactly what the point pips looked like. (its CapMid entry must exist; an unknown font name falls back to 0 correction, i.e. plain line-box centring).
Parameters
| Name | Type | Description |
|---|---|---|
text | string | |
font | string | A font name already created by `TPG.UI.BuildFonts` |
x | number | |
y | number | |
w | number | |
h | number | |
color | Color |
Returns
No return values documented.
Examples
No examples available.
Used In
No usages found in the codebase.