Download
(4 Kb)
Download
Updated: 12-25-13 09:44 PM
Compatibility:
Siege of Orgrimmar (5.4)
Escalation (5.3)
Thunder Isle (5.2)
Landfall (5.1)
Mists of Pandaria (5.0.4)
Updated:12-25-13 09:44 PM
Created:11-13-10 09:51 AM
Downloads:1,091
Favorites:3
MD5:
5.4
LibMenuAssist-1.0
Version: 1.0.4
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, 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.

isOpen = menu:UpdateAutoHide()

Starts, stops, or resets the menu's countdown to auto-hide based on the return value of the method HasMouseFocus.

Returns:
isOpen - (boolean or nil) True if the menu is open, nil otherwise.
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)


Archived Files (3)
File Name
Version
Size
Author
Date
1.0.3
4kB
Vrul
10-06-12 05:37 PM
1.0.2
3kB
Vrul
10-01-12 02:26 PM
1.0.1
4kB
Vrul
11-13-10 09:55 AM


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: 1191
File comments: 783
Uploads: 82
Favorite so I can check it out soon
Dridzt is offline Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: