Garry's Mod Wiki

DIconLayout

Description

DIconLayout is what replaced DPanelList in Garry's Mod 13. DPanelList still exists in GMod but is deprecated and does not support the new GWEN skin.

DIconLayout is used to make a list of panels. Unlike DPanelList, DIconLayout does not automatically add a scroll bar - the example below shows you how you can do this.

View source

Parent

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

Events

DIconLayout:OnModified()
Called when the panel is modified.

Methods

Panel DIconLayout:Copy()
Creates a replica of the DIconLayout it is called on.
DIconLayout:CopyContents( Panel from )
Copies the contents (Child elements) of another DIconLayout to itself.
number DIconLayout:GetBorder()
Returns the size of the border.
number DIconLayout:GetLayoutDir()
Returns the direction that it will be layed out, using the DOCK enumerations.
number DIconLayout:GetSpaceX()
Returns the distance between two 'icons' on the X axis.
number DIconLayout:GetSpaceY()
Returns distance between two "Icons" on the Y axis.
Returns whether the icon layout will stretch its height to fit all the children. See also DIconLayout:GetStretchWidth
boolean DIconLayout:GetStretchWidth()
Returns whether the icon layout will stretch its width to fit all the children. See also DIconLayout:GetStretchHeight
DIconLayout:Layout()
Resets layout vars before calling Panel:InvalidateLayout. This is called when children are added or removed, and must be called when the spacing, border or layout direction is changed.
DIconLayout:LayoutIcons_LEFT()
This is used internally - although you're able to use it you probably shouldn't. Used internally to layout the child elements if the DIconLayout:SetLayoutDir is set to LEFT (See DOCK enum).
DIconLayout:LayoutIcons_TOP()
This is used internally - although you're able to use it you probably shouldn't. Used internally to layout the child elements if the DIconLayout:SetLayoutDir is set to TOP (See DOCK enum).
DIconLayout:SetBorder( number width )
Sets the internal border (padding) within the DIconLayout. This will not change its size, only the positioning of children. You must call DIconLayout:Layout in order for the changes to take effect.
DIconLayout:SetLayoutDir( number direction )
Sets the direction that it will be layed out, using the DOCK enum. Currently only TOP and LEFT are supported.
DIconLayout:SetSpaceX( number xSpacing )
Sets the horizontal (x) spacing between children within the DIconLayout. You must call DIconLayout:Layout in order for the changes to take effect.
DIconLayout:SetSpaceY( number ySpacing )
Sets the vertical (y) spacing between children within the DIconLayout. You must call DIconLayout:Layout in order for the changes to take effect.
DIconLayout:SetStretchHeight( boolean do_stretch )
If set to true, the icon layout will stretch its height to fit all the children. See also DIconLayout:SetStretchWidth
DIconLayout:SetStretchWidth( boolean stretchW )
If set to true, the icon layout will stretch its width to fit all the children. See also DIconLayout:SetStretchHeight

Example

local Frame = vgui.Create( "DFrame" ) -- Create a Frame to contain everything. Frame:SetTitle( "DIconLayout Example" ) Frame:SetSize( 365, 240 ) Frame:Center() Frame:MakePopup() local Scroll = vgui.Create( "DScrollPanel", Frame ) -- Create the Scroll panel Scroll:Dock( FILL ) local List = vgui.Create( "DIconLayout", Scroll ) List:Dock( FILL ) List:SetSpaceY( 5 ) -- Sets the space in between the panels on the Y Axis by 5 List:SetSpaceX( 5 ) -- Sets the space in between the panels on the X Axis by 5 for i = 1, 20 do -- Make a loop to create a bunch of panels inside of the DIconLayout local ListItem = List:Add( "DPanel" ) -- Add DPanel to the DIconLayout ListItem:SetSize( 80, 40 ) -- Set the size of it -- You don't need to set the position, that is done automatically. end local ListLabel = List:Add( "DLabel" ) -- Add a label that will be the only panel on its row ListLabel.OwnLine = true -- The magic variable that specifies this item has its own line all for itself ListLabel:SetText( "Hello World!" ) for i = 1, 5 do local ListItem = List:Add( "DPanel" ) ListItem:SetSize( 80, 40 ) end
Output: