Garry's Mod Wiki

DTileLayout

Description

Similarly to DIconLayout, this lays out panels in two dimensions as tiles.

The difference between this and DIconLayout is that DIconLayout items all have the same height while DTileLayout items do not have this enforcement. DTileLayout will find the best way to "pack" its children.
For example, in a two column layout, a item of height 2 units will be placed in one column while two items of height 1 unit will be placed in the other column.

It is worth noting however that because this panel iterates through its children in an undefined order and lays out while it is iterating, there is no guarantee that this packing will lead to the lowest possible height.

This is used by the spawnmenu to arrange spawnicons.

The base size defines the smallest a tile can be, and it will resize vertically to accommodate all child panels. The number of elements in each row is determined by the base size and width.

It also optionally permits the rearrangement of these tiles. To enable this functionality, call DDragBase:MakeDroppable on the DTileLayout with a unique identifier. All panels added following this will be moveable.

View source

Parent

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

Events

DTileLayout:OnModified()
Called when anything is dropped on or rearranged within the DTileLayout.

Methods

DTileLayout:ClearTiles()
This is used internally - although you're able to use it you probably shouldn't. Clears the panel's tile table. Used by DTileLayout:LayoutTiles.
DTileLayout:ConsumeTiles( number x, number y, number w, number h )
This is used internally - although you're able to use it you probably shouldn't. Called to designate a range of tiles as occupied by a panel.
Panel DTileLayout:Copy()
Creates and returns an exact copy of the DTileLayout.
DTileLayout:CopyContents( Panel source )
Creates copies of all the children from the given panel object and parents them to this one.
number, number DTileLayout:FindFreeTile( number x, number y, number w, number h )
This is used internally - although you're able to use it you probably shouldn't. Finds the coordinates of the first group of free tiles that fit the given size.
boolean DTileLayout:FitsInTile( number x, number y, number w, number h )
This is used internally - although you're able to use it you probably shouldn't. Determines if a group of tiles is vacant.
number DTileLayout:GetBaseSize()
Returns the size of each single tile, set with DTileLayout:SetBaseSize.
number DTileLayout:GetBorder()
Returns the border spacing set by DTileLayout:SetBorder.
number DTileLayout:GetMinHeight()
Returns the minimum height the DTileLayout can resize to.
number DTileLayout:GetSpaceX()
Returns the X axis spacing between 2 elements set by DTileLayout:SetSpaceX.
number DTileLayout:GetSpaceY()
Returns the Y axis spacing between 2 elements set by DTileLayout:SetSpaceY.
any DTileLayout:GetTile( number x, number y )
This is used internally - although you're able to use it you probably shouldn't. Gets the occupied state of a tile.
DTileLayout:Layout()
Resets the last width/height info, and invalidates the panel's layout, causing it to recalculate all child positions. It is called whenever a child is added or removed, and can be called to refresh the panel.
DTileLayout:LayoutTiles()
This is used internally - although you're able to use it you probably shouldn't. Called by PANEL:PerformLayout to arrange and lay out the child panels, if it has changed in size.
DTileLayout:SetBaseSize( number size )
Sets the size of a single tile. If a child panel is larger than this size, it will occupy several tiles. If you are setting the size of the children properly then you probably don't need to change this.
DTileLayout:SetBorder( number border )
Sets the spacing between the border/edge of the DTileLayout and all the elements inside.
DTileLayout:SetMinHeight( number minH )
Determines the minimum height the DTileLayout will resize to. This is useful if child panels will be added/removed often.
DTileLayout:SetSpaceX( number spacingX )
Sets the spacing between 2 elements in the DTileLayout on the X axis.
DTileLayout:SetSpaceY( number spaceY )
Sets the spacing between 2 elements in the DTileLayout on the Y axis.
DTileLayout:SetTile( number x, number y, any state )
This is used internally - although you're able to use it you probably shouldn't. Called to set the occupied state of a tile.

Example

Creates a DTileLayout within a DFrame, sets the base size and adds 32 DLabels.

local frame = vgui.Create("DFrame") frame:SetSize(300, 300) frame:SetTitle("DTileLayout Example") frame:MakePopup() frame:Center() local layout = vgui.Create("DTileLayout", frame) layout:SetBaseSize(32) -- Tile size layout:Dock(FILL) //Draw a background so we can see what it's doing layout:SetDrawBackground(true) layout:SetBackgroundColor(Color(0, 100, 100)) layout:MakeDroppable("unique_name") -- Allows us to rearrange children for i = 1, 32 do layout:Add(Label(" Label " .. i)) end
Output:
DTileLayout.png