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:
targetNameGuildFrame:SetScript("OnEvent", function(self)
local targetName = UnitName("target")
local targetGuildName = GetGuildInfo("target")
local unitexists = UnitExists("target")
local targclass = UnitClass("target")
if targetName then
if targetGuildName then
local namegstr = ("%s"):format(getTargetNoU('target'))
targetNameText:SetText(namegstr)
local guildstr = ("- %s"):format(targetGuildName)
targetGuildText:SetText(guildstr)
local Ntex = targetNameText:GetStringWidth()
local Gtex = targetGuildText:GetStringWidth()
local mathdone = ((Gtex / 3) - (Ntex / 3))
targetNameText:SetJustifyH("RIGHT")
targetNameText:SetPoint("RIGHT", targetNameGuildFrame, "CENTER", -mathdone, 0)
targetNameText:SetPoint("LEFT", targetNameGuildFrame, "LEFT", -mathdone, 0)
targetGuildText:SetPoint("LEFT", targetNameText, "RIGHT", 0, 0)
targetGuildText:SetJustifyH("LEFT")
else
local namegstr = ("%s"):format(getTargetNoU('target'))
targetNameText:SetText(namegstr)
targetGuildText:SetText("")
targetNameText:SetJustifyH("CENTER")
targetNameText:SetPoint("RIGHT", targetNameGuildFrame, "RIGHT", 0, 0)
targetNameText:SetPoint("LEFT", targetNameGuildFrame, "LEFT", 0, 0)
end
end
end)