What I'm trying to do:
I'm creating a variable sized window, with a variable amount of buttons inside of it, which have text of varied lengths. I was just curious if there is an easy way to get the
width of the text inside of a button. So that if the width of the text changes, due to font/size changes the button text changes, I can reset the width of
ALL of the buttons.
Right now I'm just grabbing the string length of every buttons text &
'roughly estimating' the width needed for the buttons, but it seemed like there should be an easier way for something like this.
If it helps, this is what I'm doing:
Lua Code:
-- Create the parent window --
local function CreateQuickClickWindow()
if not Click4Info.QuickClickWindow then
Click4Info.QuickClickWindow = WINDOW_MANAGER:CreateTopLevelWindow("Click4InfoQuickClickWindow")
local qcWin = Click4Info.QuickClickWindow
qcWin:SetDimensions(windowWidth, ((#QuickClickCommands+1) * Click4Info.QuickClickButtonHeight))
qcWin:ClearAnchors()
qcWin:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, Click4Info.QuickClickOffsetX, Click4Info.QuickClickOffsetY)
qcWin:SetHidden(false)
qcWin:SetMovable(true)
qcWin:SetMouseEnabled(true)
qcWin:SetClampedToScreen(true)
qcWinBG = WINDOW_MANAGER:CreateControlFromVirtual("Click4InfoQuickClickWindowBG", qcWin, "ZO_DefaultBackdrop")
qcWinBG:ClearAnchors()
qcWinBG:SetAnchorFill(qcWin)
end
end
and create buttons like this:
Lua Code:
-- Create the Buttons --
local function CreateQuickClickButtons()
for i = 1, #QuickClickCommands do
local button = CreateControlFromVirtual("Click4InfoQuickClickButton", Click4Info.QuickClickWindow, "ZO_BladeHeader", i)
button:SetHidden(false)
button:ClearAnchors()
button:SetDimensions(windowWidth, Click4Info.QuickClickButtonHeight)
button:SetAnchor(TOPLEFT, Click4Info.QuickClickWindow, TOPLEFT, 0, Click4Info.QuickClickButtonHeight * (i-1))
button:SetText(" "..QuickClickCommands[i])
if i == 1 then
button:SetHandler("OnClicked", function() Click4Info.freeMouse = (not Click4Info.freeMouse) end)
else
button:SetHandler("OnClicked", function() QuickClickBtnClick(i) end)
end
button:SetHorizontalAlignment(TEXT_ALIGN_LEFT)
end
end
XML:
xml Code:
<GuiXml>
<Controls>
<Button name="MY_BladeHeader" font="ZoFontGame" endCapWidth="22" verticalAlignment="LEFT" virtual="true">
<Dimensions x="200" y="28"/>
<PressedOffset x="2" y="2" />
<OnInitialized>
ZO_ToggleButton_Initialize(self, TOGGLE_BUTTON_TYPE_BLADE)
</OnInitialized>
<OnClicked>
ZO_CheckButton_OnClicked(self, button)
</OnClicked>
<FontColors
normalColor="INTERFACE_COLOR_TYPE_TEXT_COLORS:INTERFACE_TEXT_COLOR_NORMAL"
pressedColor="INTERFACE_COLOR_TYPE_TEXT_COLORS:INTERFACE_TEXT_COLOR_SELECTED"
mouseOverColor="INTERFACE_COLOR_TYPE_TEXT_COLORS:INTERFACE_TEXT_COLOR_HIGHLIGHT"
disabledColor="INTERFACE_COLOR_TYPE_TEXT_COLORS:INTERFACE_TEXT_COLOR_DISABLED"
/>
</Button>
</Controls>
</GuiXml>