Garry's Mod Wiki

vgui.CreateFromTable

  Panel vgui.CreateFromTable( table metatable, Panel parent = nil, string name = nil )

Description

Creates a panel from a table, used alongside vgui.RegisterFile and vgui.RegisterTable to efficiently define, register, and instantiate custom panels.

Arguments

1 table metatable
Your PANEL table.
2 Panel parent = nil
Which panel to parent the newly created panel to.
3 string name = nil
Custom name of the created panel for scripting/debugging purposes. Can be retrieved with Panel:GetName.

Returns

1 Panel
The created panel, or nil if creation failed for whatever reason.

Example

local CustomPanel = { Init = function( self ) self:SetSize( 200, 100 ) end, Paint = function( self, w, h ) surface.SetDrawColor( 0, 255, 0, 255 ) surface.DrawRect( 0, 0, w, h) end, } local my_custom_panel = vgui.RegisterTable( CustomPanel, "Panel" ) -- Register the panel class from a table local panel = vgui.CreateFromTable( my_custom_panel ) -- Create an instance of the panel panel:SetPos( 50, 50 )