Move placeholder logic into ui-textinput

This commit is contained in:
tekkub ʕ ´ᴥ` ʔ
2016-09-11 19:28:15 -06:00
parent b8a0891478
commit f925cb584a
2 changed files with 29 additions and 19 deletions

View File

@ -5,11 +5,28 @@ local myname, ns = ...
local BORDER_TEXTURE = "Interface\\Common\\Common-Input-Border"
local function OnShow(self)
self:SetText("")
self.placeholder:Show()
end
local function OnEditFocusGained(self)
self.placeholder:Hide()
end
local function OnEditFocusLost(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("GameFontHighlightSmall")
editbox:SetFontObject(FONT)
local left = editbox:CreateTexture(nil, "BACKGROUND")
left:SetSize(8, 20)
@ -30,6 +47,14 @@ function ns.NewTextInput(parent)
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:SetScript("OnShow", OnShow)
editbox:SetScript("OnEditFocusGained", OnEditFocusGained)
editbox:SetScript("OnEditFocusLost", OnEditFocusLost)
editbox:SetScript("OnEscapePressed", editbox.ClearFocus)
editbox:SetScript("OnEnterPressed", editbox.ClearFocus)