annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-Button.lua @ 63:3552946c0b9a tip

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