Move placeholder logic into ui-textinput
This commit is contained in:
parent
b8a0891478
commit
f925cb584a
|
@ -5,11 +5,28 @@ local myname, ns = ...
|
||||||
local BORDER_TEXTURE = "Interface\\Common\\Common-Input-Border"
|
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)
|
function ns.NewTextInput(parent)
|
||||||
local editbox = CreateFrame("EditBox", nil, parent)
|
local editbox = CreateFrame("EditBox", nil, parent)
|
||||||
editbox:SetAutoFocus(false)
|
editbox:SetAutoFocus(false)
|
||||||
editbox:SetSize(105, 32)
|
editbox:SetSize(105, 32)
|
||||||
editbox:SetFontObject("GameFontHighlightSmall")
|
editbox:SetFontObject(FONT)
|
||||||
|
|
||||||
local left = editbox:CreateTexture(nil, "BACKGROUND")
|
local left = editbox:CreateTexture(nil, "BACKGROUND")
|
||||||
left:SetSize(8, 20)
|
left:SetSize(8, 20)
|
||||||
|
@ -30,6 +47,14 @@ function ns.NewTextInput(parent)
|
||||||
center:SetTexture(BORDER_TEXTURE)
|
center:SetTexture(BORDER_TEXTURE)
|
||||||
center:SetTexCoord(0.0625, 0.9375, 0, 0.625)
|
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("OnEscapePressed", editbox.ClearFocus)
|
||||||
editbox:SetScript("OnEnterPressed", editbox.ClearFocus)
|
editbox:SetScript("OnEnterPressed", editbox.ClearFocus)
|
||||||
|
|
||||||
|
|
|
@ -6,30 +6,13 @@ function ns.MakeSearchField(GVS, Refresh)
|
||||||
local editbox = ns.NewTextInput(GVS)
|
local editbox = ns.NewTextInput(GVS)
|
||||||
editbox:SetPoint("BOTTOMLEFT", GVS, "TOPLEFT", 55, 9)
|
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)
|
editbox:SetScript("OnTextChanged", function(self)
|
||||||
local t = self:GetText()
|
local t = self:GetText()
|
||||||
GVS.searchstring = t ~= "" and t ~= "Search..." and t:lower() or nil
|
GVS.searchstring = t ~= "" and t ~= "Search..." and t:lower() or nil
|
||||||
Refresh()
|
Refresh()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
editbox:SetScript("OnShow", function(self)
|
editbox.placeholder:SetText("Search...")
|
||||||
self:SetText("Search...")
|
|
||||||
self:SetTextColor(0.75, 0.75, 0.75, 1)
|
|
||||||
end)
|
|
||||||
|
|
||||||
editbox:SetScript("OnEnter", function(self)
|
editbox:SetScript("OnEnter", function(self)
|
||||||
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
|
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
|
||||||
|
@ -49,4 +32,6 @@ function ns.MakeSearchField(GVS, Refresh)
|
||||||
editbox:SetScript("OnLeave", GameTooltip_Hide)
|
editbox:SetScript("OnLeave", GameTooltip_Hide)
|
||||||
|
|
||||||
ns.MakeSearchField = nil
|
ns.MakeSearchField = nil
|
||||||
|
|
||||||
|
return editbox
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue