Skip to content

Return of Reckoning

Wiki

RoR Wiki

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. The LabelGetTextDimensions that addons call is a Lua function defined in interfacecore/source/windowstate.lua:
    • If the global table named after the window (_G[labelName]) has a STATE table, it returns STATE.LABEL_TEXTDIMS_X and STATE.LABEL_TEXTDIMS_Y without calling into the client.
    • Otherwise it calls _LabelGetTextDimensions(labelName).
  • For windows with state tracking enabled, the client writes the same two values to labelName.STATE.LABEL_TEXTDIMS_X and LABEL_TEXTDIMS_Y when it lays out the label's text.
  • Avoid using STATE as 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 exist
  • Error 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

See also