Part of TPG namespace
TPG.UI.Truncate(text, font, maxW)Description
Fit text to a width, ending in an ellipsis if it does not fit. Weapon names come from whatever packs are installed ("Carl Gustaf M2 (HEDP 502)" is a real one) so no box width is safe on its own. Clipping with a render scissor would hide the overflow but leave a word cut mid-glyph with no sign anything is missing; an ellipsis says "there is more name here" and the full one is in the tooltip. Trims from the end one character at a time. Names are short enough that a binary search would only save a few string compares per frame, and this stays correct for multi-byte names (it steps back over UTF-8 continuation bytes rather than splitting a codepoint in half). it plus "..."; a bare "..." if even that does not fit maxW.
Parameters
| Name | Type | Description |
|---|---|---|
text | string | |
font | string | A font name already created by `TPG.UI.BuildFonts`. |
maxW | number | Maximum width in pixels. |
Returns
| Type | Description |
|---|---|
string | `text` unchanged if it already fits; otherwise a prefix of |
Examples
No examples available.
Used In
No usages found in the codebase.