Wowpedia
Advertisement
Wowpedia
240,483
pages

FontString (inherits from LayeredRegion and FontInstance, created with Frame:CreateFontString) draws a block of text on the screen.

FontStrings are used widely through the UI, to display labels on controls, the names of units, keybindings on action buttons, health and mana values, and most other text data. You can change the text contents of it, set it to use a new FontObject, and set how it handles text that doesn't fit in its normal dimensions, such as how to wrap the text and whether to indent subsequent lines.

FontStrings must have a font assigned before they appear, either with SetFont() or SetFontObject(). FrameXML includes several fonts to choose from:

local f = CreateFrame("Frame")
local text = f:CreateFontString(nil, "ARTWORK", "GameFontNormal")
text:SetText("HelloWorld")

Or with a <FontString> element in an xml file

<FontString inherits="GameFontNormal" text="HelloWorld!">
	<!-- set anchors, font color, shadow and other properties here -->
</FontString>

Defined Methods

FontString:CalculateScreenAreaFromCharacterSpan(leftCharacterIndex, rightCharacterIndex)
FontString:CanNonSpaceWrap() - Get whether long strings without spaces are wrapped or truncated - New in 1.11.
FontString:CanWordWrap()
FontString:FindCharacterIndexAtCoordinate(x, y)
FontString:GetFieldSize()
FontString:GetLineHeight()
FontString:GetMaxLines()
FontString:GetNumLines() - Returns the number of lines
FontString:GetStringHeight() - Returns the height of the text in its current font, ignoring line wrapping
FontString:GetStringWidth() - Returns the length of the text, ignoring line wrapping
FontString:GetText() - Get the displayed text.
FontString:GetUnboundedStringWidth() - Returns the length of the text, ignoring line wrapping and truncation
FontString:GetWrappedWidth() - Returns the width of the longest line resulting from line wrapping
FontString:IsTruncated() - Returns whether the string is truncated because it lacked space
FontString:SetAlphaGradient(start, length) - Create or remove an alpha gradient over the text.
FontString:SetFixedColor()
FontString:SetFormattedText(formatstring[, ...]) - Set the formatted display text. - New in 2.3.
FontString:SetMaxLines()
FontString:SetNonSpaceWrap(wrapFlag) - Set whether long strings without spaces are wrapped or truncated.
FontString:SetText(text) - Set the displayed text.
FontString:SetTextHeight(pixelHeight) - Set the height of the text by scaling graphics (Note: Can distort text).
FontString:SetWordWrap(wrapFlag) - Set whether long strings of words are wrapped onto other lines.

Patch changes

  • Warlords of Draenor Patch 6.1.0 / API (2015-02-24): A bug circa 6.1 was attributed erroneous height calculations when "TOP" cand "CENTER" were the only anchored points.[1]
  • Cataclysm Patch 4.1.0 / API (2011-04-26): Methods added to calculate string length independently from Region:GetWidth().
    Previously, GetWidth() gave inconsistent results based on the order in which :Set() functions were used.[citation needed] 

External links

References

 
  1. ^ Guillotine (addon author at WoWInterface) 2015-02-25. IRC log for #wowuidev on 20150225.​ “So what happened was that we fixed font strings to calculate height like every other object in the game. Unfortunately, some code relied on the old, broken behavior. The main difference is when "TOP" and "CENTER" were the only points anchored and there wasn't an absolute height. For every other frame, it would set the height to be 2 * the distance between TOP and CENTER. For font strings, it just didn't update the height. The fix is to just add wordwrap="false" to the things you don't want to wrap [or] actually use anchors that fit what you want more accurately. If you still have both TOP and CENTER anchored, setting an absolute height might not do much, but you could remove one of the anchors and then set an absolute height. (19:39.26)
Advertisement