Garry's Mod Wiki

Panel:GetContentSize

  number, number Panel:GetContentSize()

Description

Gets the size of the content/children within a panel object.

Only works with Label derived panels by default such as DLabel.

Will also work on any panel that manually implements this method.

Returns

1 number
The content width of the object.
2 number
The content height of the object.

Example

Demonstrates how to implement this function in your own panel.

local PANEL = {} function PANEL:GetContentSize() surface.SetFont( self:GetFont() ) return surface.GetTextSize( self:GetText() ) end vgui.Register( "DTextEntry_Edit", PANEL, "DTextEntry" ) -- Somewhere else, to test the newly created panel local frame = vgui.Create( "DFrame" ) frame:SetSize( 500, 200 ) frame:Center() frame:MakePopup() local txt = vgui.Create( "DTextEntry_Edit", frame ) txt:SetPos( 5, 25 ) txt:SetSize( 100, 10 ) txt:SetText( "Really long string that is bigger than 100 pixels" ) txt:SizeToContentsX( 5 ) -- Must be called after setting the text txt:SizeToContentsY( 5 ) -- These two functions will not have effect on a normal DTextEntry