Quantcast WoWInterface - View Single Post - Change font size half way through string.
View Single Post
12-03-10, 03:13 PM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
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)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 12-03-10 at 03:15 PM.
  Reply With Quote