-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPhanxConfig-Button.lua
62 lines (48 loc) · 2.19 KB
/
PhanxConfig-Button.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
--[[--------------------------------------------------------------------
PhanxConfig-Button
Simple button widget generator. Requires LibStub.
https://github.com/Phanx/PhanxConfig-Button
Copyright (c) 2009-2015 Phanx <[email protected]>. All rights reserved.
Feel free to include copies of this file WITHOUT CHANGES inside World of
Warcraft addons that make use of it as a library, and feel free to use code
from this file in other projects as long as you DO NOT use my name or the
original name of this file anywhere in your project outside of an optional
credits line -- any modified versions must be renamed to avoid conflicts.
----------------------------------------------------------------------]]
local MINOR_VERSION = 20170904
local lib, oldminor = LibStub:NewLibrary("PhanxConfig-Button", MINOR_VERSION)
if not lib then return end
------------------------------------------------------------------------
local scripts = {}
function scripts:OnEnter() -- same as InterfaceOptionsCheckButtonTemplate
if self.tooltipText then
GameTooltip:SetOwner(self, self.tooltipOwnerPoint or "ANCHOR_RIGHT")
GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, true)
end
end
scripts.OnLeave = GameTooltip_Hide
function scripts:OnClick(button)
PlaySound(SOUNDKIT.GS_TITLE_OPTION_OK)
local callback = self.OnClick or self.Callback or self.callback
if callback then
callback(self, button)
end
end
------------------------------------------------------------------------
function lib:New(parent, name, tooltipText)
assert(type(parent) == "table" and parent.CreateFontString, "PhanxConfig-Button: Parent is not a valid frame!")
if type(name) ~= "string" then name = nil end
if type(tooltipText) ~= "string" then tooltipText = nil end
local button = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate")
button:GetFontString():SetPoint("CENTER", -1, 0)
button:SetMotionScriptsWhileDisabled(true)
button:RegisterForClicks("AnyUp")
for name, func in pairs(scripts) do
button:SetScript(name, func)
end
button:SetText(name)
button:SetWidth(max(110, button:GetFontString():GetStringWidth() + 24))
button.tooltipText = tooltipText
return button
end
function lib.CreateButton(...) return lib:New(...) end