WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Change font size half way through string. (https://www.wowinterface.com/forums/showthread.php?t=37277)

Grimsin 12-02-10 10:47 AM

Change font size half way through string.
 
Okay so i have this function that follows, i want it to change the font size of the guild name when it shows guild names but leave the player font the same size. Is it possible? or do i have to make to separate font strings?
lua Code:
  1. targetNameGuildFrame:SetScript("OnEvent", function(self)
  2.     local targetName = UnitName("target")
  3.     local targetGuildName = GetGuildInfo("target")
  4.     local unitexists = UnitExists("target")
  5.     local targclass = UnitClass("target")
  6.  
  7.     if targetName then
  8.         if targetGuildName then
  9.             local namegstr = ("%s - %s"):format(getTargetNoU('target'), targetGuildName)
  10.             targetNameText:SetText(namegstr)
  11.         else
  12.             local namegstr = ("%s"):format(getTargetNoU('target'))
  13.             targetNameText:SetText(namegstr)
  14.         end
  15.     end
  16. end)

Dridzt 12-02-10 11:01 AM

Separate.

*blah ... to at least 10 chars

Xubera 12-02-10 04:46 PM

FontInstance:SetFont("path", height[,"flags"])
fontName, fontHeight, fontFlags = FontInstance:GetFont()
Code:

if GuildName then
  local fontName = targetNameText:GetFont()
  targetNameText:SetFont(fontName, GUILD_FONT_HEIGHT)
else
  local fontName = targetNameText:GetFont()
  targetNameText:SetFont(fontName, TARGET_FONT_HEIGHT)
end

GUILD _FH and TARGET_FH are w/e heights you want

I included the :GetFont() just incase you didnt know the name of your font file,

Dridzt 12-02-10 05:04 PM

Yea but that would still make that whole line height x or height y.

He's having a string of "ToonName of GuildName" when the target is guilded.

He was asking if he can have it be "ToonName of GuildName" without using 2 fontstrings.

Xubera 12-03-10 12:33 AM

oh i see,

well if you dont need to change a middle one like

<little Fontstring><Big Fontstring><little Fontstring>

then it should be easy to just make a string for the guild and slap it on the end there.

Grimsin 12-03-10 03:13 PM

yea making another string is what i did, why it would have been nice to maintain one string was for positioning reasons. It was a pain in the butt to make the two font strings align proper according to name length and then have it change according to if a guild name is present or not then make it calculate the name and the guild name lengths and position accordingly each time... I found though for gettextwidth and set points that the textwidth is about 3x that of the scaling for setpoint so if you divide the textwidths and use that number for the setpoints it'll align right, or rather always be centered. Or at lest real close to it. this was the end result
edit/note - adding some more math to this and feasibly you could change from small to big to small or any combination or extension of that idea.
lua Code:
  1. targetNameGuildFrame:SetScript("OnEvent", function(self)
  2.     local targetName = UnitName("target")
  3.     local targetGuildName = GetGuildInfo("target")
  4.     local unitexists = UnitExists("target")
  5.     local targclass = UnitClass("target")
  6.  
  7.     if targetName then
  8.         if targetGuildName then
  9.             local namegstr = ("%s"):format(getTargetNoU('target'))
  10.             targetNameText:SetText(namegstr)
  11.             local guildstr = ("- %s"):format(targetGuildName)
  12.             targetGuildText:SetText(guildstr)
  13.            
  14.             local Ntex = targetNameText:GetStringWidth()
  15.             local Gtex = targetGuildText:GetStringWidth()
  16.             local mathdone = ((Gtex / 3) - (Ntex / 3))
  17.            
  18.             targetNameText:SetJustifyH("RIGHT")
  19.             targetNameText:SetPoint("RIGHT", targetNameGuildFrame, "CENTER", -mathdone, 0)
  20.             targetNameText:SetPoint("LEFT", targetNameGuildFrame, "LEFT", -mathdone, 0)
  21.             targetGuildText:SetPoint("LEFT", targetNameText, "RIGHT", 0, 0)
  22.             targetGuildText:SetJustifyH("LEFT")
  23.         else
  24.             local namegstr = ("%s"):format(getTargetNoU('target'))
  25.             targetNameText:SetText(namegstr)
  26.             targetGuildText:SetText("")
  27.             targetNameText:SetJustifyH("CENTER")
  28.             targetNameText:SetPoint("RIGHT", targetNameGuildFrame, "RIGHT", 0, 0)
  29.             targetNameText:SetPoint("LEFT", targetNameGuildFrame, "LEFT", 0, 0)
  30.         end
  31.     end
  32. end)


All times are GMT -6. The time now is 10:53 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI