WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   UIDropDownMenu doesn't show (https://www.wowinterface.com/forums/showthread.php?t=59426)

Benalish 12-31-22 09:08 AM

UIDropDownMenu doesn't show
 
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:
  1. local main = CreateFrame("Frame", nil, UIParent)
  2. main:SetSize(200, 100)
  3. main:SetPoint("CENTER")
  4. main:SetFrameStrata("HIGH")
  5. local backdrop = {
  6.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  7.     edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  8.     tile = true,
  9.     tileSize = 8,
  10.     edgeSize = 16,
  11.     insets = {
  12.         left = 3,
  13.         right = 3,
  14.         top = 3,
  15.         bottom = 3
  16.     }
  17. }
  18. main:SetBackdrop(backdrop)
  19.  
  20. main.conditions = CreateFrame("Frame", nil, main, "combobox_template")
  21. main.conditions:SetSize(125,25)
  22. main.conditions:SetPoint("CENTER")
  23.  
  24. function flag_dd_OnLoad(frame, level, menuList)
  25.     local info = UIDropDownMenu_CreateInfo()
  26.     info.text = "Blue Pill"
  27.     UIDropDownMenu_AddButton(info)
  28.     info.text = "Red Pill"
  29.     UIDropDownMenu_AddButton(info)
  30.  end
  31.  
  32. function flag_dd_OnClick()
  33.     ToggleDropDownMenu(1, nil, flag_dd, "cursor", 0, 0);
  34. end

Vecamia 01-26-23 03:48 PM

One issue I can see is that the guide you are using is from the old wowwiki archives.
Sadly, a lot on that website is outdated and no longer working.


I suggest instead to use https://wowpedia.fandom.com


Here is their more up to date guide on a dropdown menu:
https://wowpedia.fandom.com/wiki/Using_UIDropDownMenu


If you follow that guide, should be able to get a working version.


(the code from their guide)
Code:

local favoriteNumber = 42 -- A user-configurable setting
 
-- Create the dropdown, and configure its appearance
    local dropDown = CreateFrame("FRAME", "WPDemoDropDown", UIParent, "UIDropDownMenuTemplate")
    dropDown:SetPoint("CENTER")
    UIDropDownMenu_SetWidth(dropDown, 200)
    UIDropDownMenu_SetText(dropDown, "Favorite number: " .. favoriteNumber)
 
-- Create and bind the initialization function to the dropdown menu
    UIDropDownMenu_Initialize(dropDown, function(self, level, menuList)
    local info = UIDropDownMenu_CreateInfo()
        if (level or 1) == 1 then
        -- Display the 0-9, 10-19, ... groups
            for i=0,4 do
            info.text, info.checked = i*10 .. " - " .. (i*10+9), favoriteNumber >= i*10 and favoriteNumber <= (i*10+9)
            info.menuList, info.hasArrow = i, true
            UIDropDownMenu_AddButton(info)
            end
 
        else
        -- Display a nested group of 10 favorite number options
        info.func = self.SetValue
            for i=menuList*10, menuList*10+9 do
            info.text, info.arg1, info.checked = i, i, i == favoriteNumber
            UIDropDownMenu_AddButton(info, level)
            end
        end
end)
 
-- Implement the function to change the favoriteNumber
function dropDown:SetValue(newValue)
    favoriteNumber = newValue
    -- Update the text; if we merely wanted it to display newValue, we would not need to do this
    UIDropDownMenu_SetText(dropDown, "Favorite number: " .. favoriteNumber)
    -- Because this is called from a sub-menu, only that menu level is closed by default.
    -- Close the entire menu with this next call
    CloseDropDownMenus()
end



All times are GMT -6. The time now is 08:17 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI