WoW:API EasyMenu: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
m (→‎Examples: fix comment)
m (→‎Examples: yank howto link; it's also in see also)
Line 1: Line 1:
<br>{{framexmlfunc|FrameXML/EasyMenu.lua}}
{{framexmlfunc|FrameXML/EasyMenu.lua}}
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)


==Arguments==
==Arguments==
 
;menuList : Table - see [[#Details|Details]] for key/value descriptions.
:(menuList, menuFrame, anchor, x, y, displayMode, autoHideDelay)
;menuFrame : Frame - the UI frame to populate.
:;menuList : Table (see [[#Details|Details]])
;anchor : String - Just like in the [[UIOBJECT_GameTooltip|GameTooltip]] this is the anchor point.
:;menuFrame : the UI frame to populate.
;x : Number - x offset.
:;anchor : Just like in the [[UIOBJECT_GameTooltip|GameTooltip]] this is the anchor point.
;y : Number - y offset
:;x : X position.
;displayMode : String - "MENU" enables a tooltip-styled context menu, any other value the dropdown style.
:;y : Y position.
;autoHideDelay : Number - Automatically hide the menu after this many seconds.
:;displayMode : The display mode. Usually "MENU".
:;autoHideDelay : Automatically hide the menu after this many seconds.


==Details==
==Details==
 
;menuList : This needs to be a table in the following format.
:;menuList : This needs to be a table in the following format.
  {
  {
     {
     {
Line 42: Line 38:
   -- do stuff
   -- do stuff
  end
  end
  local function onOption2()
  local function onOption2()
   -- do stuff
   -- do stuff
Line 55: Line 50:
  EasyMenu(menuList, menuFrame, "ExampleMenuFrame", 0 , 0, "MENU")
  EasyMenu(menuList, menuFrame, "ExampleMenuFrame", 0 , 0, "MENU")


Above example creates "MENU" type poupup menu (see [[HOWTO: Use UIDropDownMenu]]).  
Above example creates "MENU" type poupup menu.  
To crate standard menu:
To crate standard menu:
  local menu_frame = CreateFrame("Frame", "ExampleMenuFrame", UIParent)
  local menu_frame = CreateFrame("Frame", "ExampleMenuFrame", UIParent)
Line 62: Line 57:


== See Also ==  
== See Also ==  
*[[UI Object UIDropDownMenu]]
* [[UI Object UIDropDownMenu]]
*[[HOWTO: Use UIDropDownMenu]]
* [[Using UIDropDownMenu]]

Revision as of 16:41, 13 November 2009

WoW API < EasyMenu

"I" iconThis function is implemented in Lua here FrameXML/EasyMenu.lua.

Easily create context menus on the fly with clickable items.

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

Arguments

menuList
Table - see Details for key/value descriptions.
menuFrame
Frame - the UI frame to populate.
anchor
String - Just like in the GameTooltip this is the anchor point.
x
Number - x offset.
y
Number - y offset
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)

See Also