This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
LibDropDown.lua
82 lines (70 loc) · 3 KB
/
LibDropDown.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
local MAJOR = 'LibDropDown'
assert(LibStub, MAJOR .. ' requires LibStub')
local MINOR = 8
local lib, oldMinor = LibStub:NewLibrary(MAJOR, MINOR)
if not lib then
return
end
lib.dropdowns = lib.dropdowns or {}
lib.styles = lib.styles or {}
--[[ LibDropDown:CloseAll(_ignore_)
Closes all open dropdowns, even ones made with [Blizzard voodoo](https://www.townlong-yak.com/framexml/live/UIDropDownMenu.lua).
* `ignore`: Menu to ignore when hiding _(frame/string)_
--]]
function lib:CloseAll(ignore)
if(type(ignore) == 'string') then
ignore = _G[ignore]
end
-- hide blizzard's
securecall('CloseDropDownMenus')
-- hide ours
for menu in next, lib.dropdowns do
if(menu ~= ignore) then
menu:Hide()
end
end
end
if not lib.hookedCloseMenus then
lib.hookedCloseMenus = true
hooksecurefunc('CloseMenus', function()
-- close all our menus too
for menu in next, lib.dropdowns do
menu:Hide()
end
end)
end
--[[ LibDropDown:RegisterStyle(_name, data_)
Register a style for use with [Button:SetStyle(name)](Button#buttonsetstylename) and [Menu:SetStyle(name)](Menu#menusetstylename).
* `name`: Any name _(string)_
* `data`: Table containing (all optional) values:
* `gap`: space between submenus _(number)_
* `padding`: space between menu contents and backdrop border _(number)_
* `spacing`: space between lines in menus _(number)_
* `minWidth`: minimum width of the menus _(number, default = 100)_
* `maxWidth`: maximum width of the menus _(number, optional)_
* `backdrop`: standard [Backdrop](http://wowprogramming.com/docs/widgets/Frame/SetBackdrop) _(table)_
* `backdropColor`: color object, see notes _(object)_
* `backdropBorderColor`: color object, see notes _(object)_
* `normalFont`: font object, see notes _(object/string)_
* `highlightFont`: font object, see notes _(object/string)_
* `disabledFont`: font object, see notes _(object/string)_
* `titleFont`: font object, see notes _(object/string)_
* `highlightTexture`: texture path to replace the highlight texture _(string)_
* `radioTexture`: texture path to replace the radio/checkbox texture _(string)_
* `expandTexture`: texture path to replace the expand arrow texture _(string)_
#### Notes
* All fonts must be [font objects](http://wowprogramming.com/docs/widgets/Font) (by reference or name).
See [CreateFont](http://wowprogramming.com/docs/api/CreateFont), and [SharedXML/SharedFontStyles.xml](https://www.townlong-yak.com/framexml/ptr/SharedFontStyles.xml).
* All colors must be color objects (by reference).
See [CreateColor](https://www.townlong-yak.com/framexml/live/go/CreateColor).
* `radioTexture` is dependant on texture coordinates, see [Interface/Common/UI-DropDownRadioChecks](https://github.com/Gethe/wow-ui-textures/blob/live/COMMON/UI-DropDownRadioChecks.PNG).
--]]
function lib:RegisterStyle(name, data)
self.styles[name] = data
end
--[[ LibDropDown:IsStyleRegistered(_name_)
Returns `true`/`false` whether a style with the given name is already registered or not.
--]]
function lib:IsStyleRegistered(name)
return not not self.styles[name]
end