API:LabelGetTextDimensions
From RoR Wiki
UI Lua API · Label functions
Version: WAR 1.4.8
Defined in Lua: interfacecore/source/windowstate.lua
Returns the width and height of the text in a Label.
width, height = LabelGetTextDimensions(labelName)
Arguments
- labelName
string– Name of a Label window.
Returns
- width
number– Width of the widest line of text.- height
number– Height of all lines: the number of lines times the line height.
Details
- Both values are divided by the label's scale (see WindowGetScale).
- A label that has no text layout yet returns
0, 0. - The client registers the C function as
_LabelGetTextDimensions. TheLabelGetTextDimensionsthat addons call is a Lua function defined ininterfacecore/source/windowstate.lua:- If the global table named after the window (
_G[labelName]) has aSTATEtable, it returnsSTATE.LABEL_TEXTDIMS_XandSTATE.LABEL_TEXTDIMS_Ywithout calling into the client. - Otherwise it calls
_LabelGetTextDimensions(labelName).
- If the global table named after the window (
- For windows with state tracking enabled, the client writes the same two values to
labelName.STATE.LABEL_TEXTDIMS_XandLABEL_TEXTDIMS_Ywhen it lays out the label's text. - Avoid using
STATEas a field name on a global table that has the same name as a label.
Errors
Raised by _LabelGetTextDimensions:
Error in function call 'LabelGetTextDimensions': Window %s does not existError in function call 'LabelGetTextDimensions': Window %s is not a Label
Example
Sizing a tooltip to its text, from easystem_tooltips/source/abilitytooltips.lua:
local nameWidth, nameHeight = LabelGetTextDimensions(windowName.."Name") local typeWidth, typeHeight = LabelGetTextDimensions(windowName.."Type") ... local width1 = nameWidth + typeWidth + c_TOOLTIP_BUFFER
