annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-Button.lua @ 25:ac501d71c890 tip

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