Panel/SizeToChildren

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

Contents

Description

Resizes the panel to fit the bounds of its children.

NOTE

Your panel must have its layout updated (Panel:InvalidateLayout) for this function to work properly.

NOTE

The sizeW and sizeH parameters are false by default. Therefore, calling this function with no arguments will result in a no-op.

Arguments

boolean sizeW=false

Resize with width of the panel.

Arguments

boolean sizeH=false

Resize the height of the panel.

Examples

Example

Using Panel:InvalidateLayout

local Frame = vgui.Create( "DFrame" )
Frame:SetSize( 300, 400 )
Frame:Center()
Frame:MakePopup()
Frame:SetSizable( true )

-- with :InvalidateLayout(true)
local backgroundPanel = vgui.Create( "DPanel", Frame )
backgroundPanel:Dock( TOP )
backgroundPanel:DockPadding( 4, 4, 4, 4 )
backgroundPanel:DockMargin( 0, 0, 0, 4 )

local button1 = vgui.Create( "DButton", backgroundPanel )
button1:Dock( TOP )
button1:DockMargin( 0, 0, 0, 4 )
button1:SetTall( 60 )
button1:SetText( "c1" )

local button2 = vgui.Create( "DButton", backgroundPanel )
button2:Dock( TOP )
button2:SetTall( 60 )
button2:SetText( "c2" )

backgroundPanel:InvalidateLayout( true )
backgroundPanel:SizeToChildren( false, true )


-- now w/o :InvalidateLayout
local backgroundPanel = vgui.Create( "DPanel", Frame )
backgroundPanel:Dock( TOP )
backgroundPanel:DockPadding( 4, 4, 4, 4 )

local button1 = vgui.Create( "DButton", backgroundPanel )
button1:Dock( TOP )
button1:DockMargin( 0, 0, 0, 4 )
button1:SetTall( 60 )
button1:SetText( "c1" )

local button2 = vgui.Create( "DButton", backgroundPanel )
button2:Dock( TOP )
button2:SetTall( 60 )
button2:SetText( "c2" )

backgroundPanel:SizeToChildren( false, true )

Output:

panel stc invalidation ex1.png
Personal tools
Navigation