Use hooks for showing placeholder

This commit is contained in:
tekkub ʕ ´ᴥ` ʔ 2016-09-11 19:50:09 -06:00
parent 9982e27050
commit b6fede093b
1 changed files with 5 additions and 9 deletions

View File

@ -5,17 +5,12 @@ local myname, ns = ...
local BORDER_TEXTURE = "Interface\\Common\\Common-Input-Border"
local function OnShow(self)
self.placeholder:Show()
end
local function OnEditFocusGained(self)
self.placeholder:Hide()
end
local function OnEditFocusLost(self)
local function ShowPlaceholderIfEmpty(self)
if self:GetText() == "" then self.placeholder:Show() end
end
@ -51,9 +46,10 @@ function ns.NewTextInput(parent)
placeholder:SetTextColor(0.75, 0.75, 0.75, 1)
editbox.placeholder = placeholder
editbox:SetScript("OnShow", OnShow)
editbox:SetScript("OnEditFocusGained", OnEditFocusGained)
editbox:SetScript("OnEditFocusLost", OnEditFocusLost)
editbox:HookScript("OnEditFocusGained", OnEditFocusGained)
editbox:HookScript("OnEditFocusLost", ShowPlaceholderIfEmpty)
editbox:HookScript("OnTextSet", ShowPlaceholderIfEmpty)
editbox:SetScript("OnEscapePressed", editbox.ClearFocus)
editbox:SetScript("OnEnterPressed", editbox.ClearFocus)