Back to TPG

TPG.UI.Truncate

C🏷️ Palette

Part of TPG namespace

TPG.UI.Truncate(text, font, maxW)
View on GitHub|gamemode/config/sh_palette.lua:376-397
📋 Has LDoc👁️ 0 viewsUpdated 1 month ago

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

NameTypeDescription
textstring
fontstringA font name already created by `TPG.UI.BuildFonts`.
maxWnumberMaximum width in pixels.

Returns

TypeDescription
string`text` unchanged if it already fits; otherwise a prefix of

Examples

No examples available.

Used In

No usages found in the codebase.