This code does not justify the text, “Hello World!” when scrolled along with other longer and shorter strings.
f.Text = f:CreateFontString()
f.Text:SetFontObject( GameFontHighlight )
f.Text:SetJustifyH(“LEFT”)
f.Text:SetText( "Hello World! )
What am I missing?
A FontString will obey a JustifyH when there’s a width, either a direct width to the FontString or it has two anchors wider than the text.
f.Text:SetWidth(300)
or
f.Text:SetAllPoints(true)
(and of course height for JustifyV)
Just to reframe what Gello said:
- SetPoint() or SetWidth() control the dimensions of the FontString
- If you don’t specify an exact size, it will expand/shrink to fit the text
- SetJustifyH() or SetWordWrap() change how text flows inside the FontString
- If the FontString is expanding to variable width, then these have no impact
References:
https://wowpedia.fandom.com/wiki/UIOBJECT_Region
https://wowpedia.fandom.com/wiki/UIOBJECT_FontString
Thank you all. I get it and it all works now. Very grateful.