Finally I created my combobox template. Only one thing missing: since the dropdown menu width is automatic, how can I make the editbox and the dropdown menu have the same width?
Code:
<Frame name="combobox_template" virtual="true">
<Size x="1" y="1" />
<Frames>
<EditBox name="$parent_flageditbox" parentKey="flageditbox">
<Size x="75" y="20" />
<Anchors>
<Anchor point="LEFT" >
<Offset>
<AbsDimension x="27" y="5"/>
</Offset>
</Anchor>
</Anchors>
<Backdrop bgFile="Interface\Buttons\WHITE8X8" edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true">
<BackgroundInsets>
<AbsInset left="2" right="2" top="2" bottom="2" />
</BackgroundInsets>
<EdgeSize>
<AbsValue val="10"/>
</EdgeSize>
</Backdrop>
<Scripts>
<OnLoad>
self:EnableKeyboard(false)
self:EnableMouse(false)
self:SetTextInsets(0,0,-3,0)
self:SetBackdropColor(0, 0, 0, 0.75)
self:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
</OnLoad>
</Scripts>
<FontString justifyH="CENTER" justifyV="TOP" inherits="GameFontNormal"/>
<Frames>
<Button name="$parentFlagButton" parentKey="button" enableMouse="true">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="LEFT" relativeTo="$parent" relativePoint="RIGHT">
<Offset x="-3" y="0"/>
</Anchor>
</Anchors>
<Scripts>
<OnMouseDown> flag_dd_OnClick() </OnMouseDown>
</Scripts>
<HighlightTexture file="Interface/Buttons/UI-Common-MouseHilight" alphaMode="ADD"/>
<NormalTexture file="Interface/CHATFRAME/UI-ChatIcon-ScrollDown-Up" setAllPoints="true"/>
<PushedTexture file="Interface/CHATFRAME/UI-ChatIcon-ScrollDown-Down" setAllPoints="true"/>
</Button>
</Frames>
</EditBox>
<Frame name="flag_dd" inherits="UIDropDownMenuTemplate" enableMouse="true" hidden="true">
<Anchors>
<Anchor point="TOP"/>
</Anchors>
<Scripts>
<OnLoad>
UIDropDownMenu_Initialize(self, flag_dd_OnLoad, "MENU");
</OnLoad>
</Scripts>
</Frame>
</Frames>
</Frame>
Lua Code:
CreateFrame("Frame", nil, UIParent, "combobox_template")
main:SetSize(100,25)
main:SetPoint("CENTER")
local flags = { "player", "target", "focus", "pet", "mouseover", "arena1", "arena2" }
function flag_dd_OnLoad(self)
for _, flag in ipairs(flags) do
local info = UIDropDownMenu_CreateInfo()
info.text = flag
function info.func(button)
main.flageditbox:SetText(flag)
end
UIDropDownMenu_AddButton(info)
end
end
function flag_dd_OnClick()
ToggleDropDownMenu(1, nil, flag_dd, main.flageditbox, 0, 1);
end