Basically you want to trim your text if it exceeds a width…
Shouldn’t be hard to write a custom one.
Here’s a simple one which I use
local function trim(text,options) local txt = text.text local trimW = options.width local trimSuffix = options.suffix or "" local align = options.align or "left" local bounds = text.contentBounds local xMin,xMax = bounds.xMin,bounds.xMax local yMin,yMax = bounds.yMin,bounds.yMax local w,h = xMax - xMin, yMax - yMin local l = text.x - w/2 local x = text.x local r = text.x + w/2 local c = 0 local trimmed while text.width \> trimW do trimmed = true txt = txt:sub(1,-2) text.text = txt if align == "left" then text.x = l + text.width/2 elseif align == "center" then text.x = x elseif align == "right" then text.x = r - text.width/2 end c = c + 1 if c \> 100 then break end end if trimmed then text.text = text.text .. trimSuffix end end
A bit clumsy, but gets the job done.
Takes 2 parameters : the first is the text object
The second is a set of options.
Options takes 3 values
- width - the width above which the text should be trimmed(this is compulsory)
- align - how to align the trimmed text : “left”,“right”,“center” (optional)
- suffix - if you want to append some text after trimming (for eg. a few dots “…” ) (optional)
eg;
trim(text, {width = 100})