Panel/Dock

From Garry's Mod
Jump to: navigation, search
 Panel:Dock( )

Contents

Description

Sets the dock type of the panel.

NOTE

After using this function, if you want to get the correct panel's bounds (position, size), use Panel:InvalidateParent (use true as argument if you need to update immediately)

Arguments

number dockType

Dock type using DOCK_ Enums.

Examples

Example

Example docking including DockMargin. Provided by Walrus Viking in this Facepunch post.

local f = vgui.Create( "DFrame" )
f:SetTitle( "Dock Test" )
f:SetSize( 256, 256 )
f:Center()
f:MakePopup()

local p = vgui.Create( "DPanel", f )
p:Dock( FILL )
p:DockMargin( 0, 0, 0, 0 )

for i = 0, 10, 1 do
	local l = vgui.Create( "DLabel", p )
	l:Dock( TOP )
	l:DockMargin( 4, 0, 0, 0 ) -- shift to the right
	l:SetColor( color_black )
	l:SetText( "Hi! I'm a label!" )
end

Output:


panel dock example1.png

Examples

Example

Example showing how multiple docked elements behave.

local frame = vgui.Create("DFrame")
frame:SetSize(600, 300)
frame:SetTitle("Docking Demonstration")
frame:Center()
frame:MakePopup(true)

local panel = vgui.Create("DPanel", frame) --Create a panel on the left
panel:SetSize(300, 0) --Height doesn't matter since we're docking it to the left anyways
panel:Dock(LEFT)
local fill = vgui.Create("DButton", panel) --Create a button and dock it
fill:SetText("FILL")
fill:Dock(FILL)
local left = vgui.Create("DButton", panel)
left:SetText("LEFT")
left:Dock(LEFT)
local right = vgui.Create("DButton", panel)
right:SetText("RIGHT")
right:Dock(RIGHT)
local top = vgui.Create("DButton", panel)
top:SetText("TOP")
top:Dock(TOP)
local bottom = vgui.Create("DButton", panel)
bottom:SetText("BOTTOM")
bottom:Dock(BOTTOM)

local panel = vgui.Create("DPanel", frame) --Do the same thing on the right, but this time with top and bottom before left and right
panel:SetSize(300, 0)
panel:Dock(RIGHT)
local fill = vgui.Create("DButton", panel)
fill:SetText("FILL")
fill:Dock(FILL)
local top = vgui.Create("DButton", panel)
top:SetText("TOP")
top:Dock(TOP)
local bottom = vgui.Create("DButton", panel)
bottom:SetText("BOTTOM")
bottom:Dock(BOTTOM)
local left = vgui.Create("DButton", panel)
left:SetText("LEFT")
left:Dock(LEFT)
local right = vgui.Create("DButton", panel)
right:SetText("RIGHT")
right:Dock(RIGHT)

Output:



panel dock example 2.png
Personal tools
Navigation