forked from HizurosWoWAddOns/LibDropDownMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibDropDownMenuTemplates.lua
100 lines (76 loc) · 3.14 KB
/
LibDropDownMenuTemplates.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
local CreateFromMixins,_G,select = CreateFromMixins,_G,select
local ExecuteFrameScript,PlaySound,SOUNDKIT = ExecuteFrameScript,PlaySound,SOUNDKIT;
setfenv(1,LibStub("LibDropDownMenu"));
-- start of content from UIDropDownMenuTemplates.lua
-- Custom dropdown buttons are instantiated by some external system.
-- When calling UIDropDownMenu_AddButton that system sets info.customFrame to the instance of the frame it wants to place on the menu.
-- The dropdown menu creates its button for the entry as it normally would, but hides all elements. The custom frame is then anchored
-- to that button and assumes responsibility for all relevant dropdown menu operations.
-- The hidden button will request a size that it should become from the custom frame.
DropDownMenuButtonMixin = {}
function DropDownMenuButtonMixin:OnEnter(...)
ExecuteFrameScript(self:GetParent(), "OnEnter", ...);
end
function DropDownMenuButtonMixin:OnLeave(...)
ExecuteFrameScript(self:GetParent(), "OnLeave", ...);
end
function DropDownMenuButtonMixin:OnMouseDown(button)
if self:IsEnabled() then
ToggleDropDownMenu(nil, nil, self:GetParent());
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
end
end
LargeDropDownMenuButtonMixin = CreateFromMixins(DropDownMenuButtonMixin);
function LargeDropDownMenuButtonMixin:OnMouseDown(button)
if self:IsEnabled() then
local parent = self:GetParent();
ToggleDropDownMenu(nil, nil, parent, parent, -8, 8);
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
end
end
DropDownExpandArrowMixin = {};
function DropDownExpandArrowMixin:OnEnter()
local level = self:GetParent():GetParent():GetID() + 1;
CloseDropDownMenus(level);
if self:IsEnabled() then
local listFrame = _G["LibDropDownMenu_List"..level];
if ( not listFrame or not listFrame:IsShown() or select(2, listFrame:GetPoint(1)) ~= self ) then
ToggleDropDownMenu(level, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self);
end
end
end
function DropDownExpandArrowMixin:OnMouseDown(button)
if self:IsEnabled() then
ToggleDropDownMenu(self:GetParent():GetParent():GetID() + 1, self:GetParent().value, nil, nil, nil, nil, self:GetParent().menuList, self);
end
end
UIDropDownCustomMenuEntryMixin = {};
function UIDropDownCustomMenuEntryMixin:OnEnter()
UIDropDownMenu_StopCounting(self:GetOwningDropdown());
end
function UIDropDownCustomMenuEntryMixin:OnLeave()
UIDropDownMenu_StartCounting(self:GetOwningDropdown());
end
function UIDropDownCustomMenuEntryMixin:GetPreferredEntryWidth()
return self:GetWidth();
end
function UIDropDownCustomMenuEntryMixin:GetPreferredEntryHeight()
return self:GetHeight();
end
function UIDropDownCustomMenuEntryMixin:OnSetOwningButton()
-- for derived objects to implement
end
function UIDropDownCustomMenuEntryMixin:SetOwningButton(button)
self:SetParent(button:GetParent());
self.owningButton = button;
self:OnSetOwningButton();
end
function UIDropDownCustomMenuEntryMixin:GetOwningDropdown()
return self.owningButton:GetParent();
end
function UIDropDownCustomMenuEntryMixin:SetContextData(contextData)
self.contextData = contextData;
end
function UIDropDownCustomMenuEntryMixin:GetContextData()
return self.contextData;
end