-
Notifications
You must be signed in to change notification settings - Fork 4
/
ui-textinput.lua
57 lines (41 loc) · 1.58 KB
/
ui-textinput.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
local myname, ns = ...
local BORDER_TEXTURE = "Interface\\Common\\Common-Input-Border"
local function OnEditFocusGained(self)
self.placeholder:Hide()
end
local function ShowPlaceholderIfEmpty(self)
if self:GetText() == "" then self.placeholder:Show() end
end
local FONT = "GameFontHighlightSmall"
function ns.NewTextInput(parent)
local editbox = CreateFrame("EditBox", nil, parent)
editbox:SetAutoFocus(false)
editbox:SetSize(105, 32)
editbox:SetFontObject(FONT)
local left = editbox:CreateTexture(nil, "BACKGROUND")
left:SetSize(8, 20)
left:SetPoint("LEFT", -5, 0)
left:SetTexture(BORDER_TEXTURE)
left:SetTexCoord(0, 0.0625, 0, 0.625)
local right = editbox:CreateTexture(nil, "BACKGROUND")
right:SetSize(8, 20)
right:SetPoint("RIGHT")
right:SetTexture(BORDER_TEXTURE)
right:SetTexCoord(0.9375, 1, 0, 0.625)
local center = editbox:CreateTexture(nil, "BACKGROUND")
center:SetHeight(20)
center:SetPoint("TOPLEFT", left, "TOPRIGHT")
center:SetPoint("BOTTOMRIGHT", right, "BOTTOMLEFT")
center:SetTexture(BORDER_TEXTURE)
center:SetTexCoord(0.0625, 0.9375, 0, 0.625)
local placeholder = editbox:CreateFontString(nil, nil, FONT)
placeholder:SetPoint("LEFT")
placeholder:SetTextColor(0.75, 0.75, 0.75, 1)
editbox.placeholder = placeholder
editbox:HookScript("OnEditFocusGained", OnEditFocusGained)
editbox:HookScript("OnEditFocusLost", ShowPlaceholderIfEmpty)
editbox:HookScript("OnTextSet", ShowPlaceholderIfEmpty)
editbox:SetScript("OnEscapePressed", editbox.ClearFocus)
editbox:SetScript("OnEnterPressed", editbox.ClearFocus)
return editbox
end