rearrange stuff, import config
[QuestHelper.git] / libs / AceGUI-3.0 / widgets / AceGUIWidget-Button.lua
blobf9cc38261c1b30460c6c5f43293d33dda16865c9
1 local AceGUI = LibStub("AceGUI-3.0")
3 -- WoW APIs
4 local _G = _G
5 local CreateFrame, UIParent = CreateFrame, UIParent
7 --------------------------
8 -- Button --
9 --------------------------
11 local Type = "Button"
12 local Version = 12
14 local function OnAcquire(self)
15 -- restore default values
16 self:SetHeight(24)
17 self:SetWidth(200)
18 end
20 local function OnRelease(self)
21 self.frame:ClearAllPoints()
22 self.frame:Hide()
23 self:SetDisabled(false)
24 end
26 local function Button_OnClick(this, ...)
27 this.obj:Fire("OnClick", ...)
28 AceGUI:ClearFocus()
29 end
31 local function Button_OnEnter(this)
32 this.obj:Fire("OnEnter")
33 end
35 local function Button_OnLeave(this)
36 this.obj:Fire("OnLeave")
37 end
39 local function SetText(self, text)
40 self.text:SetText(text or "")
41 end
43 local function SetDisabled(self, disabled)
44 self.disabled = disabled
45 if disabled then
46 self.frame:Disable()
47 else
48 self.frame:Enable()
49 end
50 end
52 local function Constructor()
53 local num = AceGUI:GetNextWidgetNum(Type)
54 local name = "AceGUI30Button"..num
55 local frame = CreateFrame("Button",name,UIParent,"UIPanelButtonTemplate2")
56 local self = {}
57 self.num = num
58 self.type = Type
59 self.frame = frame
61 local left = _G[name .. "Left"]
62 local right = _G[name .. "Right"]
63 local middle = _G[name .. "Middle"]
65 left:SetPoint("TOP", frame, "TOP", 0, 0)
66 left:SetPoint("BOTTOM", frame, "BOTTOM", 0, 0)
68 right:SetPoint("TOP", frame, "TOP", 0, 0)
69 right:SetPoint("BOTTOM", frame, "BOTTOM", 0, 0)
71 middle:SetPoint("TOP", frame, "TOP", 0, 0)
72 middle:SetPoint("BOTTOM", frame, "BOTTOM", 0, 0)
74 local text = frame:GetFontString()
75 self.text = text
76 text:ClearAllPoints()
77 text:SetPoint("TOPLEFT",frame,"TOPLEFT", 15, -1)
78 text:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT", -15, 1)
79 text:SetJustifyV("MIDDLE")
81 frame:SetScript("OnClick",Button_OnClick)
82 frame:SetScript("OnEnter",Button_OnEnter)
83 frame:SetScript("OnLeave",Button_OnLeave)
85 self.SetText = SetText
86 self.SetDisabled = SetDisabled
88 frame:EnableMouse(true)
90 frame:SetHeight(24)
91 frame:SetWidth(200)
93 self.OnRelease = OnRelease
94 self.OnAcquire = OnAcquire
96 self.frame = frame
97 frame.obj = self
99 AceGUI:RegisterAsWidget(self)
100 return self
103 AceGUI:RegisterWidgetType(Type,Constructor,Version)