Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
(→‎Arguments: fix anchor description)
No edit summary
Line 1: Line 1:
{{framexmlfunc|FrameXML/EasyMenu.lua}}
+
{{framexmlfunc|FrameXML/EasyMenu.lua}} __NOTOC__
 
Easily create context menus on the fly with clickable items.
 
Easily create context menus on the fly with clickable items.
 
EasyMenu(menuList, menuFrame, anchor, x, y, displayMode, autoHideDelay)
 
EasyMenu(menuList, menuFrame, anchor, x, y, displayMode, autoHideDelay)

Revision as of 00:49, 8 April 2010

This function is implemented in FrameXML/EasyMenu.lua.

Easily create context menus on the fly with clickable items.

EasyMenu(menuList, menuFrame, anchor, x, y, displayMode, autoHideDelay)

Arguments

menuList
Table - a table describing the menu to be created.
menuFrame
Frame - the UI frame to populate.
anchor
String/Frame - Specify what to anchor the menu relative to: either "cursor" or a frame reference.
x
Number - x offset from the anchor.
y
Number - y offset from the anchor.
displayMode
String - "MENU" enables a tooltip-styled context menu, any other value the dropdown style.
autoHideDelay
Number - Automatically hide the menu after this many seconds.

Details

menuList
This needs to be a table in the following format.
{
    {
        text = "Menu Item 1", -- string. This is the text to put on this menu item.
        func = function() DoStuff() end, -- function. This is the function that will fire when you click on this menu item.
    },
    {
        text = "Menu Item 2",
        func = function() DoOtherStuff() end,
    },
    -- ...
}
See "List of button attributes" in the FrameXML file UIDropDownMenu.lua for the full list of available table elements.

Notes

  • The menu becomes visible as soon as you call the function and goes away after you click a menu item unless keepShownOnClick in menuList was set to 1.

Examples

local menu_frame = CreateFrame("Frame", "ExampleMenuFrame", UIParent, "UIDropDownMenuTemplate")

local function onOption1()
  -- do stuff
end
local function onOption2()
  -- do stuff
end

local menuList = {
  { text = "Option 1", func = onOption1 },
  { text = "Option 2", func = onOption2 }
}

menu_frame:SetPoint("Center", UIParent, "Center") -- setup position of menu. Not needed if 'cursor' is used as anchor in EasyMenu
EasyMenu(menuList, menuFrame, "ExampleMenuFrame", 0 , 0, "MENU")

Above example creates "MENU" type poupup menu. To crate standard menu:

local menu_frame = CreateFrame("Frame", "ExampleMenuFrame", UIParent)
...
EasyMenu(menuList, menuFrame, "ExampleMenuFrame", 0 , 0)

Note: You must give the frame a name (argument 2 to CreateFrame()) for menus to work.

See Also