WoW:UIOBJECT FontString: Difference between revisions

m
no edit summary
No edit summary
mNo edit summary
Line 1: Line 1:
{{widget}}
{{widget}}
''Note: FontString:Get/SetWidth() and Get/SetHeight() behave very differently compared to usual base type funcitonality.''


== FontStrings and anchor points, GetHeight() and SetHeight() ==
== anchor points and height ==
<div style="margin-left: 3%;">
 
FontString objects behave a little differently where SetHeight(), GetHeight(), SetWidth() and GetWidth() are concerned.
FontString objects behave a little differently where SetHeight(), GetHeight(), SetWidth() and GetWidth() are concerned.


Line 9: Line 8:


=== Anchoring 1 corner ===
=== Anchoring 1 corner ===
<div style="margin-left: 3%;">
Let's assume we have a frame that is 100x100, and that we anchor our fontstring to the topleft corner only, and tell it to display a sizeable chunk of text in a 10 point font, that is ~250 pixels long if nonwrapped (i.e. [[API FontString GetStringWidth|GetStringWidth()]] would return 250).
Let's assume we have a frame that is 100x100, and that we anchor our fontstring to the topleft corner only, and tell it to display a sizeable chunk of text in a 10 point font, that is ~250 pixels long if nonwrapped (i.e. [[API FontString GetStringWidth|GetStringWidth()]] would return 250).


Line 45: Line 42:


So far, no real surprises, except for the fact that fontstrings will display without a width and height set, while other objects do not. The fun starts when we anchor more points.
So far, no real surprises, except for the fact that fontstrings will display without a width and height set, while other objects do not. The fun starts when we anchor more points.
</div>


=== Anchoring more points ===
=== Anchoring more points ===
<div style="margin-left: 3%;">


When you control the dimensions by anchoring more than one point, the drawn text will obey your points. But GetWidth() and GetHeight() continue to operate in their own little world.
When you control the dimensions by anchoring more than one point, the drawn text will obey your points. But GetWidth() and GetHeight() continue to operate in their own little world.
Line 83: Line 77:


If you want to completely clear width or height once set to have WoW start returning computed values for you, you need to call SetWidth(0) or SetHeight(0).
If you want to completely clear width or height once set to have WoW start returning computed values for you, you need to call SetWidth(0) or SetHeight(0).
</div>


=== Code example ===
=== Code example ===
<div style="margin-left: 3%;">
 
This example will rescale a frame to fit the text. On all four sides a 5px margin is made.
This example will rescale a frame to fit the text. On all four sides a 5px margin is made.
  text:SetPoint("TOPLEFT",frame,"TOPLEFT",5,-5)
  text:SetPoint("TOPLEFT",frame,"TOPLEFT",5,-5)
Line 92: Line 85:
  frame:SetHeight(text:GetHeight() + 15)
  frame:SetHeight(text:GetHeight() + 15)
Note that the number returned by text:GetHeight() will typically be slighly less than the actual height of the text. Including a 5px margin (both top and bottom), the height of the frame is therefor set to the text height plus 15px.
Note that the number returned by text:GetHeight() will typically be slighly less than the actual height of the text. Including a 5px margin (both top and bottom), the height of the frame is therefor set to the text height plus 15px.
</div>
</div>
[[Category:Widgets]]
[[Category:Widgets]]