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)

View File

@ -6,30 +6,13 @@ function ns.MakeSearchField(GVS, Refresh)
local editbox = ns.NewTextInput(GVS)
editbox:SetPoint("BOTTOMLEFT", GVS, "TOPLEFT", 55, 9)
editbox:SetScript("OnEditFocusGained", function(self)
if not GVS.searchstring then
self:SetText("")
self:SetTextColor(1,1,1,1)
end
end)
editbox:SetScript("OnEditFocusLost", function(self)
if self:GetText() == "" then
self:SetText("Search...")
self:SetTextColor(0.75, 0.75, 0.75, 1)
end
end)
editbox:SetScript("OnTextChanged", function(self)
local t = self:GetText()
GVS.searchstring = t ~= "" and t ~= "Search..." and t:lower() or nil
Refresh()
end)
editbox:SetScript("OnShow", function(self)
self:SetText("Search...")
self:SetTextColor(0.75, 0.75, 0.75, 1)
end)
editbox.placeholder:SetText("Search...")
editbox:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
@ -49,4 +32,6 @@ function ns.MakeSearchField(GVS, Refresh)
editbox:SetScript("OnLeave", GameTooltip_Hide)
ns.MakeSearchField = nil
return editbox
end