UISimpleMenu:AddButton
From Nomad DB
Revision as of 23:06, 16 April 2020 by Jan (talk | contribs) (Created page with "Adds a Button to a UISimpleMenu. == Syntax == <syntaxhighlight lang="lua"> menu:AddButton(text) menu:AddButton(text, hint[, callback]) menu:AddButton(text[, callback]) </...")
Adds a Button to a UISimpleMenu.
Syntax
menu:AddButton(text)
menu:AddButton(text, hint[, callback])
menu:AddButton(text[, callback])
- text (string) Button Text
- Optional: hint (string) "Hint Text" is displayed while the Button is in focus
- Optional: callback (function) The function to execute when the Button is pressed
- Returns: index (number) Entry Index
Examples
local menu = UI.SimpleMenu()
menu:AddButton("Basic Button")
menu:AddButton("Button with hint", "more info on this button")
menu:AddButton("Basic & Callback", function() print("Hello!") end)
menu:AddButton("Powerful Button", "with hint", function() print("and callback") end)
Callback
The callback has the following arguments:
function(menu, text, hint, index)
- menu (UISimpleMenu)
- text (string) Button Text
- hint (string) Hint
- index (number) Entry Index
When you return a UISimpleMenu instance inside the callback, this menu will become a "sub-menu". This allows the user to press Numpad 0 / Backspace to return to the "parent" menu. When you use :Toggle on a parent-menu (or any higher-up menus), it will automatically restore the active menu. This is useful when you use Key Binds.
Example
local menu = UI.SimpleMenu()
menu:SetTitle("Parent Menu")
menu:AddButton("Open Submenu", "my submenu", function()
local sub_menu = UI.SimpleMenu()
sub_menu:SetTitle("Sub-Menu")
return sub_menu
end)