-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtekKonfigCheckbox.lua
46 lines (35 loc) · 1.43 KB
/
tekKonfigCheckbox.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
local lib, oldminor = LibStub:NewLibrary("tekKonfig-Checkbox", 1)
if not lib then return end
local GameTooltip = GameTooltip
local function HideTooltip() GameTooltip:Hide() end
local function ShowTooltip(self)
if self.tiptext then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText(self.tiptext, nil, nil, nil, nil, true)
end
end
local function OnClick(self) PlaySound(self:GetChecked() and "igMainMenuOptionCheckBoxOn" or "igMainMenuOptionCheckBoxOff") end
-- Creates a checkbox.
-- All args optional but parent is highly recommended
function lib.new(parent, size, label, ...)
local check = CreateFrame("CheckButton", nil, parent)
check:SetWidth(size or 26)
check:SetHeight(size or 26)
if select(1, ...) then check:SetPoint(...) end
check:SetHitRectInsets(0, -100, 0, 0)
check:SetNormalTexture("Interface\\Buttons\\UI-CheckBox-Up")
check:SetPushedTexture("Interface\\Buttons\\UI-CheckBox-Down")
check:SetHighlightTexture("Interface\\Buttons\\UI-CheckBox-Highlight")
check:SetDisabledCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check-Disabled")
check:SetCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check")
-- Tooltip bits
check:SetScript("OnEnter", ShowTooltip)
check:SetScript("OnLeave", HideTooltip)
-- Sound
check:SetScript("OnClick", OnClick)
-- Label
local fs = check:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
fs:SetPoint("LEFT", check, "RIGHT", 0, 1)
fs:SetText(label)
return check, fs
end