Use hooks for showing placeholder
This commit is contained in:
parent
9982e27050
commit
b6fede093b
|
@ -5,17 +5,12 @@ local myname, ns = ...
|
||||||
local BORDER_TEXTURE = "Interface\\Common\\Common-Input-Border"
|
local BORDER_TEXTURE = "Interface\\Common\\Common-Input-Border"
|
||||||
|
|
||||||
|
|
||||||
local function OnShow(self)
|
|
||||||
self.placeholder:Show()
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function OnEditFocusGained(self)
|
local function OnEditFocusGained(self)
|
||||||
self.placeholder:Hide()
|
self.placeholder:Hide()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function OnEditFocusLost(self)
|
local function ShowPlaceholderIfEmpty(self)
|
||||||
if self:GetText() == "" then self.placeholder:Show() end
|
if self:GetText() == "" then self.placeholder:Show() end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -51,9 +46,10 @@ function ns.NewTextInput(parent)
|
||||||
placeholder:SetTextColor(0.75, 0.75, 0.75, 1)
|
placeholder:SetTextColor(0.75, 0.75, 0.75, 1)
|
||||||
editbox.placeholder = placeholder
|
editbox.placeholder = placeholder
|
||||||
|
|
||||||
editbox:SetScript("OnShow", OnShow)
|
editbox:HookScript("OnEditFocusGained", OnEditFocusGained)
|
||||||
editbox:SetScript("OnEditFocusGained", OnEditFocusGained)
|
editbox:HookScript("OnEditFocusLost", ShowPlaceholderIfEmpty)
|
||||||
editbox:SetScript("OnEditFocusLost", OnEditFocusLost)
|
editbox:HookScript("OnTextSet", ShowPlaceholderIfEmpty)
|
||||||
|
|
||||||
editbox:SetScript("OnEscapePressed", editbox.ClearFocus)
|
editbox:SetScript("OnEscapePressed", editbox.ClearFocus)
|
||||||
editbox:SetScript("OnEnterPressed", editbox.ClearFocus)
|
editbox:SetScript("OnEnterPressed", editbox.ClearFocus)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue