Garry's Mod Wiki

DCheckBoxLabel

Description

The DCheckBoxLabel is a DCheckBox with a DLabel next to it. It allows you to get a boolean value from the user (true/false - yes/no)

View source

Parent

Derives methods, etc not listed on this page from DPanel.

Implements

Implements or overrides the following hooks/methods. If you want to override these, you probably want to call the original function too.

Events

DCheckBoxLabel:OnChange( boolean bVal )
Called when the "checked" state is changed. This is meant to be Overriden

Methods

boolean DCheckBoxLabel:GetChecked()
Gets the checked state of the checkbox. This calls the checkbox's DCheckBox:GetChecked function.
number DCheckBoxLabel:GetIndent()
An AccessorFunc that gets the indentation of the element on the X axis. See also DCheckBoxLabel:SetIndent
DCheckBoxLabel:SetBright( boolean bright )
Sets the color of the DCheckBoxLabel's text to the bright text color defined in the skin.
DCheckBoxLabel:SetChecked( boolean checked )
Sets the checked state of the checkbox. Does not call DCheckBoxLabel:OnChange or Panel:ConVarChanged, unlike DCheckBoxLabel:SetValue.
DCheckBoxLabel:SetConVar( string convar )
Sets the console variable to be set when the checked state of the DCheckBoxLabel changes.
DCheckBoxLabel:SetDark( boolean darkify )
Sets the text of the DCheckBoxLabel to be dark colored in accordance with the currently active Derma skin.
DCheckBoxLabel:SetFont( string font )
Sets the font of the text part of the DCheckBoxLabel.
DCheckBoxLabel:SetIndent( number ident )
An AccessorFunc that sets the indentation of the element on the X axis.
DCheckBoxLabel:SetTextColor( table color )
Sets the text color for the DCheckBoxLabel.
DCheckBoxLabel:SetValue( boolean checked )
Sets the checked state of the checkbox, and calls DCheckBoxLabel:OnChange and the checkbox's Panel:ConVarChanged methods.
DCheckBoxLabel:SizeToContents()
Sizes the panel to the size of the internal DLabel and DButton
DCheckBoxLabel:Toggle()
Toggles the checked state of the DCheckBoxLabel.

Example

Creates a DCheckBoxLabel, ties it to a convar, and sets its initial value.

concommand.Add( "example_checkboxlabel", function( ply, cmd, args ) local window = vgui.Create( "DFrame" ) window:SetSize( 300, 200 ) window:Center() window:MakePopup() local DermaCheckbox = window:Add( "DCheckBoxLabel" ) -- Create the checkbox DermaCheckbox:SetPos( 25, 50 ) -- Set the position DermaCheckbox:SetText("God Mode") -- Set the text next to the box DermaCheckbox:SetConVar("sbox_godmode") -- Change a ConVar when the box it ticked/unticked DermaCheckbox:SetValue( true ) -- Initial value DermaCheckbox:SizeToContents() -- Make its size the same as the contents end )
Output: