976f219 - Add major aura indicator
[wowui.git] / OmaRFConfig / libs / AceGUI-3.0 / widgets / AceGUIWidget-Button.lua
1 --[[-----------------------------------------------------------------------------
2 Button Widget
3 Graphical Button.
4 -------------------------------------------------------------------------------]]
5 local Type, Version = "Button", 24
6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
8
9 -- Lua APIs
10 local pairs = pairs
11
12 -- WoW APIs
13 local _G = _G
14 local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent
15
16 --[[-----------------------------------------------------------------------------
17 Scripts
18 -------------------------------------------------------------------------------]]
19 local function Button_OnClick(frame, ...)
20         AceGUI:ClearFocus()
21         PlaySound(PlaySoundKitID and "igMainMenuOption" or 852) -- SOUNDKIT.IG_MAINMENU_OPTION
22         frame.obj:Fire("OnClick", ...)
23 end
24
25 local function Control_OnEnter(frame)
26         frame.obj:Fire("OnEnter")
27 end
28
29 local function Control_OnLeave(frame)
30         frame.obj:Fire("OnLeave")
31 end
32
33 --[[-----------------------------------------------------------------------------
34 Methods
35 -------------------------------------------------------------------------------]]
36 local methods = {
37         ["OnAcquire"] = function(self)
38                 -- restore default values
39                 self:SetHeight(24)
40                 self:SetWidth(200)
41                 self:SetDisabled(false)
42                 self:SetAutoWidth(false)
43                 self:SetText()
44         end,
45
46         -- ["OnRelease"] = nil,
47
48         ["SetText"] = function(self, text)
49                 self.text:SetText(text)
50                 if self.autoWidth then
51                         self:SetWidth(self.text:GetStringWidth() + 30)
52                 end
53         end,
54         
55         ["SetAutoWidth"] = function(self, autoWidth)
56                 self.autoWidth = autoWidth
57                 if self.autoWidth then
58                         self:SetWidth(self.text:GetStringWidth() + 30)
59                 end
60         end,
61
62         ["SetDisabled"] = function(self, disabled)
63                 self.disabled = disabled
64                 if disabled then
65                         self.frame:Disable()
66                 else
67                         self.frame:Enable()
68                 end
69         end
70 }
71
72 --[[-----------------------------------------------------------------------------
73 Constructor
74 -------------------------------------------------------------------------------]]
75 local function Constructor()
76         local name = "AceGUI30Button" .. AceGUI:GetNextWidgetNum(Type)
77         local frame = CreateFrame("Button", name, UIParent, "UIPanelButtonTemplate")
78         frame:Hide()
79
80         frame:EnableMouse(true)
81         frame:SetScript("OnClick", Button_OnClick)
82         frame:SetScript("OnEnter", Control_OnEnter)
83         frame:SetScript("OnLeave", Control_OnLeave)
84
85         local text = frame:GetFontString()
86         text:ClearAllPoints()
87         text:SetPoint("TOPLEFT", 15, -1)
88         text:SetPoint("BOTTOMRIGHT", -15, 1)
89         text:SetJustifyV("MIDDLE")
90
91         local widget = {
92                 text  = text,
93                 frame = frame,
94                 type  = Type
95         }
96         for method, func in pairs(methods) do
97                 widget[method] = func
98         end
99
100         return AceGUI:RegisterAsWidget(widget)
101 end
102
103 AceGUI:RegisterWidgetType(Type, Constructor, Version)