You've already forked GnomishVendorShrinker
Move placeholder logic into ui-textinput
This commit is contained in:
27
externals/ui-textinput.lua
vendored
27
externals/ui-textinput.lua
vendored
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user