Garry's Mod Wiki

DGrid

Description

A really simple grid layout panel.

This panel will set its size automatically based on set column count. This makes it play badly with Panel:Dock and cause a PANEL:PerformLayout call every frame.

View source

Parent

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

Methods

DGrid:AddItem( Panel item )
Adds a new item to the grid.
number DGrid:GetCols()
Returns the number of columns of this DGrid. Set by DGrid:SetCols.
Returns the width of each column of the DGrid, which is set by DGrid:SetColWide.
table DGrid:GetItems()
Returns a list of panels in the grid.
Returns the height of each row of the DGrid, which is set by DGrid:SetRowHeight.
DGrid:RemoveItem( Panel item, boolean bDontDelete = false )
Removes given panel from the DGrid:GetItems.
DGrid:SetCols( number cols )
Sets the number of columns this panel should have. The DGrid will resize its width to match this value.
DGrid:SetColWide( number colWidth )
Sets the width of each column. The cell panels (grid items) will not be resized or centered.
DGrid:SetRowHeight( number rowHeight )
Sets the height of each row. The cell panels (grid items) will not be resized or centered.
DGrid:SortByMember( string key, boolean desc = true )
Sorts the items in the grid. Does not visually update the grid, use Panel:InvalidateLayout for that.

Example

Creates a simple grid with numbered buttons.

local frame = vgui.Create( "DFrame" ) frame:SetPos( 500, 500 ) frame:SetSize( 200, 300 ) frame:SetTitle( "Frame" ) frame:MakePopup() local grid = vgui.Create( "DGrid", frame ) grid:SetPos( 10, 30 ) grid:SetCols( 5 ) grid:SetColWide( 36 ) for i = 1, 30 do local but = vgui.Create( "DButton" ) but:SetText( i ) but:SetSize( 30, 20 ) grid:AddItem( but ) end