The goal is create a custom combobox template, where the dropdown menu appears with the click on the button. I followed this
guide, but the UIDropDownMenu is not shown when button is clicked.
XML code:
Code:
<Frame name="combobox_template" virtual="true">
<Size x="1" y="1" />
<Frames>
<EditBox name="$parentEditbox" parentKey="editbox">
<Size x="125" y="18" />
<Anchors>
<Anchor point="CENTER" >
<Offset>
<AbsDimension x="27" y="5"/>
</Offset>
</Anchor>
</Anchors>
<Backdrop bgFile="Interface\Buttons\WHITE8X8" edgeFile="Interface\Buttons\WHITE8X8" tile="true">
<EdgeSize>
<AbsValue val="1"/>
</EdgeSize>
</Backdrop>
<Scripts>
<OnLoad>
self:SetBackdropColor(0, 0, 0, 0.75)
self:SetBackdropBorderColor(0.3, 0.3, 0.3, 1)
self:EnableMouse(false)
self:EnableKeyboard(false)
</OnLoad>
</Scripts>
<Frames>
<Button name="$parentButton" parentKey="button" enableMouse="true">
<Size>
<AbsDimension x="25" y="25"/>
</Size>
<Anchors>
<Anchor point="RIGHT" 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>
<Frame name="flag_dd" inherits="UIDropDownMenuTemplate">
<Scripts>
<OnLoad>
UIDropDownMenu_Initialize(self, flag_dd_OnLoad, "MENU");
</OnLoad>
</Scripts>
</Frame>
</Frames>
</EditBox>
</Frames>
</Frame>
Lua code:
Lua Code:
local main = CreateFrame("Frame", nil, UIParent)
main:SetSize(200, 100)
main:SetPoint("CENTER")
main:SetFrameStrata("HIGH")
local backdrop = {
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 8,
edgeSize = 16,
insets = {
left = 3,
right = 3,
top = 3,
bottom = 3
}
}
main:SetBackdrop(backdrop)
main.conditions = CreateFrame("Frame", nil, main, "combobox_template")
main.conditions:SetSize(125,25)
main.conditions:SetPoint("CENTER")
function flag_dd_OnLoad(frame, level, menuList)
local info = UIDropDownMenu_CreateInfo()
info.text = "Blue Pill"
UIDropDownMenu_AddButton(info)
info.text = "Red Pill"
UIDropDownMenu_AddButton(info)
end
function flag_dd_OnClick()
ToggleDropDownMenu(1, nil, flag_dd, "cursor", 0, 0);
end