🟑cl_textentry

Dlib.TextEntry is a custom text entry GUI component designed for Garry's Mod. This component has a modern look and supports placeholder text. The background color changes when the input field is focus

PANEL Class Definition:

Properties:

  • bgColor - Background color of the TextEntry.

  • placeholderColor - Color of the placeholder text.

  • placeholderText - Placeholder text when no input is provided.

Functions & Methods:

  • Init() - Initializes the TextEntry with default settings including size, colors, and text. Also sets up behaviors for focus gain and loss.

  • SetPlaceholderText(text) - Sets the placeholder text which will be displayed when the input field is empty.

    • text: Placeholder text to display.

  • Paint(w, h) - Custom paint function responsible for rendering the TextEntry. This function takes care of drawing the background, placeholder, and actual input text.

    • w: Width of the TextEntry.

    • h: Height of the TextEntry.

Example Usage:

To create and utilize a Dlib.TextEntry:

local frame = vgui.Create("Dlib.Frame")
frame:SetSize(400, 150)
frame:Center()
frame:SetTitle("TextEntry Example")
frame:MakePopup()

local textEntry = vgui.Create("Dlib.TextEntry", frame)
textEntry:SetSize(350, 40)
textEntry:SetPos(25, 50)
textEntry:SetPlaceholderText("Enter your name...")

Preview:

This code initializes a frame containing the Dlib.TextEntry. The TextEntry is set to display "Enter your name..." as a placeholder when no input is provided.

When the TextEntry field gains focus, its background color will shift to indicate it's active. When it loses focus, the background will revert to its default state.

Last updated