Garry's Mod Wiki


  PANEL:PerformLayout( number width, number height )


Called whenever the panels' layout needs to be performed again. This means all child panels must be re-positioned to fit the possibly new size of this panel.

This can be triggered in numerous ways:

  • Panel:InvalidateLayout was called this or previous frame (depending on the argument)
  • A child element was added to this panel (TODO: Verify me)
  • The size of this panel has changed
Do NOT call this function directly. Use Panel:InvalidateLayout instead!


Creating a resizeable DFrame with a 'sidebar' that rescales along with the DFrame

local frame = vgui.Create("DFrame") frame:SetSize(500, 400) frame:Center() frame:SetSizable(true) -- oPerformLayout stores the original PerformLayout function -- We store it because we are going to overwrite it with our own to scale the Sidebar -- We then call the original function to maintain proper functionality of the frame -- You can find the original PerformLayout here local oPerformLayout = frame.PerformLayout frame.PerformLayout = function(pnl, w, h) oPerformLayout(pnl, w, h) pnl.Sidebar:SetWide(w * 0.5) end frame.Sidebar = frame:Add("DPanel") frame.Sidebar:Dock(LEFT) frame.Sidebar.Paint = function(pnl, w, h) surface.SetDrawColor(255, 0, 0) surface.DrawRect(0, 0, w, h) end frame.Sidebar.PerformLayout = function(pnl, w, h) local buttonWidth = w * 0.5 local buttonHeight = h * 0.5 pnl.Button:SetSize(buttonWidth, buttonHeight) -- now we center our button pnl.Button:SetPos(w / 2 - buttonWidth / 2, h / 2 - buttonHeight / 2) end frame.Sidebar.Button = frame.Sidebar:Add("DButton") frame.Sidebar.Button:SetText("Hello!")


1 number width
The panels current width.
2 number height
The panels current height.