Thread Tools Display Modes
03-28-23, 02:51 AM   #1
Platine
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2010
Posts: 72
fontString:SetFont()

I have an object from game to which I assign text:
Code:
object:SetText("my text")
I can also assign a font to it right away:
Code:
object:SetFont(My_Font, size)
But some objects don't allow me to assign a font so explicitly:
attempt to call method "SetFont" (a nill value)
The object receives, for example, the function:
Code:
for _,GTxtframe in GossipFrame.GreetingPanel.ScrollBox:EnumerateFrames() do
How to specify the exact name of the fontString element of object?

Last edited by Platine : 03-28-23 at 02:53 AM.
  Reply With Quote
03-29-23, 12:25 AM   #2
Platine
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2010
Posts: 72
Here's the code snippet I'm having problems with:
Code:
      for _,GTxtframe in GossipFrame.GreetingPanel.ScrollBox:EnumerateFrames() do
         if (GTxtframe.GreetingText) then    -- Greeting Text
            GTxtframe.GreetingText:SetText(Greeting_PL);
            GTxtframe.GreetingText:SetFont(QTR_Font2, 13);
         elseif (GTxtframe.GetElementData().buttonType==3) then   -- Options
            GTxtframe:SetText(GS_Gossip[OptHash]);
            GTxtframe:SetFont(QTR_Font2, 13);     -- ERROR: attempt to call method "SetFont" (a nill value)
         end
      end
It's similar here:
Code:
      for GText in QuestFrameGreetingPanel.titleButtonPool:EnumerateActive() do
           GText:SetText(prefix .. GS_Gossip[TitleHash] .. sufix);
           GText:SetFont(QTR_Font2, 13);        -- ERROR: attempt to call method "SetFont" (a nill value)
      end

Last edited by Platine : 03-29-23 at 03:55 AM.
  Reply With Quote
03-29-23, 09:18 AM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,857
That's because the widget type you're "getting" is a Button. Buttons don't have a SetText or Setfont method by default but in some case they are "given" a SetText method to update a FontString they have also been given.
Lua Code:
  1. local Button = CreateFrame("Button", "SomeButton", UIParent)
  2. Button.Text = Button:CreateFontString(GameFontNormal)
  3. Button.Text:SetPoint("CENTER")
  4. function Button:SetText(text)
  5.     self.Text:SetText(text)
  6. end

You can
Code:
Button:SetText("Something")
but you can't
Code:
Button:SetFont(SomeFont)
but you could
Code:
Button.Text:SetFont(SomeFont)
In this case, you need to find the FontString "sub-widget" of GTxtframe you want to effect (like .GreetingText, it may be something other than .Text).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 03-29-23 at 10:06 AM.
  Reply With Quote
03-29-23, 11:42 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,857
Taking a look at the templates you could probably use:
Lua Code:
  1. for _,GTxtframe in GossipFrame.GreetingPanel.ScrollBox:EnumerateFrames() do
  2.     if (GTxtframe.GreetingText) then    -- Greeting Text
  3.         GTxtframe.GreetingText:SetText(Greeting_PL);
  4.         GTxtframe.GreetingText:SetFont(QTR_Font2, 13);
  5.     elseif (GTxtframe.GetElementData().buttonType==GOSSIP_BUTTON_TYPE_OPTION) then   -- Options
  6.         GTxtframe:SetText(GS_Gossip[OptHash]);
  7.         local regions = { GTxtframe:GetRegions() }
  8.         for k, v in pairs(regions) do
  9.             if v:GetObjectType() == "FontString" then
  10.                 v:SetFont(QTR_Font2, 13)
  11.             end
  12.         end
  13.     end
  14. end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 03-29-23 at 11:45 AM.
  Reply With Quote
03-31-23, 03:23 AM   #5
Platine
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2010
Posts: 72
Yes, yes. I searched for this FontString object by different names e.g. .Text, .text, .title etc. But nothing matched. But regions, it's the perfect method. I didn't come up with it before.

Your code works perfectly.
Thank you Fizzlemizz for your help.
  Reply With Quote
03-31-23, 08:44 AM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,857
Originally Posted by Platine View Post
Yes, yes. I searched for this FontString object by different names e.g. .Text, .text, .title etc. But nothing matched.
In the XML for the template it's just a
Code:
<ButtonText>
    ...
</ButtonText>
With no name or parentKey attribute to use, you just have to search the child regions of the parent frame and hope there is some easy way to identiy what you want, like being the only FontString child.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » fontString:SetFont()

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off