cLib.DTextEntry
Styled text input with placeholder support.
Basic Usage
local input = vgui.Create("cLib.DTextEntry", parent)
input:SetSize(cLib.Scale(200), cLib.Scale(30))
input:Dock(TOP)
input.OnEnter = function(self)
print("Entered:", self:GetValue())
endMethods
| Method | Description |
|---|---|
SetValue(string) | Set text value |
GetValue() | Get text value |
SetPlaceholder(string) | Set placeholder text |
SetNumeric(bool) | Numbers only |
SetMaxLength(number) | Max characters |
SetFont(string) | Set font |
SetTextColor(Color) | Text color |
SetBackgroundColor(Color) | Background color |
SetFocusColor(Color) | Border color when focused |
With Placeholder
local nameInput = vgui.Create("cLib.DTextEntry", parent)
nameInput:SetPlaceholder("Enter your name...")
nameInput:Dock(TOP)
nameInput:DockMargin(0, 0, 0, cLib.Scale(10))Numeric Input
local amount = vgui.Create("cLib.DTextEntry", parent)
amount:SetPlaceholder("0")
amount:SetNumeric(true)
amount:SetMaxLength(10)Callbacks
local input = vgui.Create("cLib.DTextEntry", parent)
-- Called when Enter is pressed
input.OnEnter = function(self)
SubmitForm(self:GetValue())
end
-- Called on every change
input.OnValueChanged = function(self, value)
ValidateInput(value)
end
-- Called when focused
input.OnGetFocus = function(self)
self:SelectAll()
end
-- Called when unfocused
input.OnLoseFocus = function(self)
-- Auto-save or validate
endPassword Input
local password = vgui.Create("cLib.DTextEntry", parent)
password:SetPlaceholder("Password")
password:SetDrawLanguageID(false)
-- Mask characters
password.m_bAllowNonAsciiCharacters = false
password:SetValue = function(self, val)
-- Store real value
self._realValue = val
-- Show masked
DTextEntry.SetValue(self, string.rep("•", #val))
endForm Example
local function CreateForm(parent)
-- Name
local nameLabel = vgui.Create("DLabel", parent)
nameLabel:SetText("Name:")
nameLabel:Dock(TOP)
local nameInput = vgui.Create("cLib.DTextEntry", parent)
nameInput:SetPlaceholder("Enter name...")
nameInput:Dock(TOP)
nameInput:DockMargin(0, cLib.Scale(5), 0, cLib.Scale(15))
-- Email
local emailLabel = vgui.Create("DLabel", parent)
emailLabel:SetText("Email:")
emailLabel:Dock(TOP)
local emailInput = vgui.Create("cLib.DTextEntry", parent)
emailInput:SetPlaceholder("email@example.com")
emailInput:Dock(TOP)
emailInput:DockMargin(0, cLib.Scale(5), 0, cLib.Scale(15))
return nameInput, emailInput
end