Download
(4Kb)
Download
Updated: 12-06-20 06:05 PM
Compatibility:
Shadowlands patch (9.0.2)
Shadowlands pre-patch (9.0.1)
Visions of N'Zoth (8.3.0)
Updated:12-06-20 06:05 PM
Created:11-13-10 09:51 AM
Downloads:2,341
Favorites:4
MD5:

LibMenuAssist-1.0

Version: 1.0.6
by: Vrul [More]

An alternative to using Blizzard's UIDropDownMenuTemplate and EasyMenu.

Example usage:

Code:
local menu = LibStub('LibMenuAssist-1.0'):New()

menu:SetAnchor(0, 0, 'TOP', myAddon.button, 'BOTTOM')

menu.initialize = function(self, level)
	-- Do stuff
end

myAddon.button:SetScript('OnClick', function()
	menu:Open()
end)

Example using the built-in initialize function:
Code:
local menu = LibStub('LibMenuAssist-1.0'):New()

menu:SetAnchor(0, 0, 'TOP', myAddon.button, 'BOTTOM')

menu[0] = function(self, level)
	-- Called first each time menu.initialize is called
end

menu[1] = function(self, level)
	-- Called when menu.initialize is called and level == 1 (*)
end

menu[2] = function(self, level)
	-- Called when menu.initialize is called and level == 2 (*)
end

myAddon.button:SetScript('OnClick', function()
	menu:Open()
end)
(*) - menu[1+] can be assigned a table instead, which will be processed via EasyMenu_Initialize.


API

menu = lib:New()

Create a new menu object.

Returns:
menu - (table) The menu object to be used by the calling code (see Menu Objects below).

Menu Objects

Any menu created by lib:New() is a normal table that emulates certain frame behaviors to allow it to work with the Blizzard's UIDropDownMenu code. A metatable provides the following frame-like methods: GetScript, HasScript, Hide, IsShown, IsVisible, SetScript, SetShown, and Show. The only scripts supported by a menu are OnHide and OnShow. The metatable also defaults the field displayMode to 'MENU', set it to false to override. Menus also have the following additional methods:

menu:AddFocusFrame(frame)

Add a frame that is to be considered a part of the menu when calling the methods HasMouseFocus and UpdateAutoHide.

Arguments:
frame - (table) The frame to be added.

wasOpen = menu:Close()

Close the menu.

Returns:
wasOpen - (boolean or nil) True if the menu was open, nil otherwise.

hasFocus = menu:HasMouseFocus()

Determines if GetMouseFocus() returns any portion of the menu or a frame added with the method AddFocusFrame.

Returns:
hasFocus - (boolean or nil) True if the mouse focus is part of the menu, nil otherwise.

isOpen = menu:IsOpen()

Determines if the menu is open.

Returns:
isOpen - (boolean or nil) True if the menu is open, nil otherwise.

level = menu:Open([...])

Open the menu to level 1 and attempt to open additional menu levels with any values passed as arguements.

Arguments:
... - Optional values leading to sub-menu levels.
Returns:
level - (number or nil) The highest menu level that is open, nil otherwise.

menu:Recycle()

Removes the metatable from menu as well as removing all internal references so that it may be be garbage collected.


level = menu:Refresh()

Force a display update of menu.

Returns:
level - (number or nil) The highest menu level that is open, nil otherwise.

menu:RemoveAllFocusFrames()

Remove all frames previously added with AddFocusFrame.


menu:RemoveFocusFrame(frame)

Remove a frame previously added with AddFocusFrame.

Arguments:
frame - (table) The frame to be removed.

updated = menu:SetAnchor(xOffset, yOffset, point, relativeTo, relativePoint)

Similar to UIDropDownMenu_SetAnchor, it updates the menu values but also automatically updates the menu's position if any values have changed.

Arguments:
xOffset - (number or nil) The new value for menu.xOffset.
yOffset - (number or nil) The new value for menu.yOffset.
point - (string or nil) The new value for menu.point.
relativeTo - (string, table, or nil) The new value for menu.relativeTo.
relativePoint - (string or nil) The new value for menu.relativePoint.
Returns:
updated - (boolean or nil) True if the menu was updated, nil otherwise.

isOpen = menu:Toggle()

Close the menu if it is open, otherwise opens it.

Returns:
isOpen - (boolean or nil) True if the menu is open, nil otherwise.

Version 1.0.6 (12/06/2020)
- Fixed an issue with OnHide scripts when a newer version is loaded
- Added the method SetShown
- UpdateAutoHide is deprecated

Version 1.0.5 (01/14/2020)
- Commented out references to UIDropDownMenu_StartCounting and UIDropDownMenu_StopCounting

Version 1.0.4 (12/25/2013)
- Menus opened at the cursor will now stay put when refreshed

Version 1.0.3 (10/06/2012)
- Rewrote the menu method Refresh to better handle major changes to a menu
- Added the ability to open directly to a sub-menu with the menu method Open

Version 1.0.2 (10/01/2012)
- Added the menu method RemoveAllFocusFrames
- The menu methods AddFocusFrame, RemoveAllFocusFrames, and RemovFocusFrame now all call UpdateAutoHide if menu is open

Version 1.0.1 (11/13/2010)
- Initial public release
Optional Files (0)


Post A Reply Comment Options
Unread 10-01-12, 09:42 PM  
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1359
File comments: 829
Uploads: 55
Favorite so I can check it out soon
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: