🟡cl_custombutton

Dlib.Button is a custom button GUI component for Garry's Mod, which extends the base DButton. It offers customizable properties like font, text color, and hover color, providing a refined and moderniz

PANEL Class Definition:

Properties:

  • customText - The text that appears on the button.

  • font - The font of the displayed text.

  • textColor - Color of the button's text.

  • hoverColor - Color of the button when it's hovered over.

  • defaultColor - Default color of the button when not being hovered over.

Functions & Methods:

  • Init() - Initializes the button with default settings, including text, font, and colors.

  • SetCustomText(txt) - Sets the custom text for the button.

    • txt: The text string.

  • GetCustomText() - Returns the current custom text of the button.

  • SetFontCustom(fontName) - Sets the font of the button's text.

    • fontName: The name of the desired font.

  • SetTextColorCustom(col) - Sets the color of the button's text.

    • col: Color object.

  • Paint(w, h) - Custom paint function responsible for rendering the button. It changes the button's color based on whether it's hovered over and draws the text in the center.

    • w: Width of the button.

    • h: Height of the button.

Example Usage:

To create and utilize a Dlib.Button:

concommand.Add("test", function()
    -- Creating a Dlib.Frame instance
    local frame = vgui.Create("Dlib.Frame")
    frame:SetSize(500, 500)
    frame:Center()

    local DermaButton = vgui.Create("Dlib.Button", frame) -- Create the button and parent it to the frame
    DermaButton.customText = "hi" -- Set the button's text
    DermaButton:SetPos(25, 50) -- Set its position on the frame
    DermaButton:SetSize(250, 30) -- Set the button's size
    DermaButton.DoClick = function() -- A custom function run when the button is clicked
        RunConsoleCommand("say", "Hi") -- This makes the player say "Hi" in the chat
    end
end)

This command, when executed, will create a new Dlib.Frame with a Dlib.Button inside it. The button will have the text "hi", and when clicked, the player will say "Hi" in the console.

Preview:

Note:

Consider using the provided setter methods (e.g., SetCustomText()) rather than directly modifying properties (e.g., DermaButton.customText = "hi") for better encapsulation and potential future-proofing.

Last updated