VGUI Register
From GMod Wiki
Lua: Using VGUI Register |
Description: | How to make your own VGUI Controls in GMod Lua |
Original Author: | garry |
Created: | 9th January 2007 |
vgui.Register( "MyButton", PANEL, "Button" )
It takes 3 parameters
- The name of your panel
- The table of your panel
- The control your panel will be derived from
Once registered you can create an instance of your panel in the normal way, using vgui.Create
local button = vgui.Create( "MyButton" )
Customizing your control
You can add functions to your PANEL table to customize how it behaves.
PANEL:Paint() Overrides paint function for panel. Return true to cause it to not draw the default panel PANEL::OnMousePressed( mousecode ) PANEL::OnMouseReleased( mousecode ) Called when the mouse is pressed/released on the panel. Return true to not allow any default actions PANEL::OnMouseWheeled( delta ) Called when the mouse is wheeled over the panel PANEL::OnKeyCodePressed( keycode ) Called when a key is pressed Return true to swallow the key PANEL:Think() Called every frame the panel is visible PANEL::ApplySchemeSettings( ///todo/// ) You should use this to apply colours/fonts to your panel and its children PANEL::PerformLayout( ) Use this to position your panel and its children PANEL::ActionSignal( key, value, ... ) Receive an ActionSignal (various things are broadcast here) -------- Button -------- PANEL::DoClick() Called when a the button is clicked --------------- - Member Vars - --------------- Button Selected - bool (true if button is selected) Depressed - bool (true if button is depressed) Armed - bool (true if button is hovered) DefaultButton - bool (true if button is default button)