From f925cb584a5b64b7e546ef0169ceabc95e277953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tekkub=20=CA=95=20=C2=B4=E1=B4=A5=60=20=CA=94?= Date: Sun, 11 Sep 2016 19:28:15 -0600 Subject: [PATCH] Move placeholder logic into ui-textinput --- externals/ui-textinput.lua | 27 ++++++++++++++++++++++++++- frames/SearchField.lua | 21 +++------------------ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/externals/ui-textinput.lua b/externals/ui-textinput.lua index eceaef8..c4970b2 100644 --- a/externals/ui-textinput.lua +++ b/externals/ui-textinput.lua @@ -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) diff --git a/frames/SearchField.lua b/frames/SearchField.lua index 0d76371..e65753c 100644 --- a/frames/SearchField.lua +++ b/frames/SearchField.lua @@ -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