Determining the width of rendered text
User Question :
I have a set of controls arranged horizontally and the width of the control is proportional to the width of the rendered text. This will cause a problem when translations are applied. Is there a way of determining the width of the rendered text so that the controls can be dynamically resized?
Answer :
I've attached a Lua module (measure.lua) that you can try using. You could do something like:
local data = gre.get_control_attrs(CONTROL_NAME, "width", "height")
local metrics = Measure.create(FONT, FONT_SIZE, WRAP, TEXT)
metrics:init(data["width"])
print("Max Width: " .. metrics:getMaxWidth())
Where,
CONTROL_NAME is the path to your control holding your text,
FONT is the name of your font, eg. "fonts/Roboto-Bold.ttf",
FONT_SIZE if a number,
WRAP is a boolean whether the text is wrapped or not,
and TEXT is the actual body of your text you are using in your control.
Hope this helps.
Comments
Please sign in to leave a comment.