This is a list of hooks that are available on all panels.
Specific panels can have their own hooks, they are listed on their category.
These hooks are called on your panel. They can't be hooked
PANEL:ActionSignal( string signalName, string signalValue )
Called whenever a panel receives a command signal from one of its children. This hook is called when using Panel:Command, when clicking a Button with Panel:SetCommand set, and when clicking text within a RichText panel that is marked as click-able.
Called every frame unless Panel:IsVisible is set to false. Similar to PANEL:Think, but can be disabled by Panel:SetAnimationEnabled as explained below. If you are overriding this, you must call Panel:AnimationThinkInternal every frame, else animations will cease to work. If you want to "disable" this hook with Panel:SetAnimationEnabled, you must call it after defining this hook. Once disabled, a custom hook will not be re-enabled by Panel:SetAnimationEnabled again - the hook will have to be re-d..
Called whenever the panel should apply its scheme (colors, fonts, style). It is called a few frames after Panel's creation once.
PANEL:DragHoverClick( number hoverTime )
Called when an object is dragged and hovered over this panel for 0.1 seconds. This is used by DPropertySheet and DTree, for example to open a tab or expand a node when an object is hovered over it.
PANEL:DroppedOn( Panel pnl )
Called when this panel is dropped onto another panel. Only works for panels derived from DDragBase.
PANEL:GenerateExample( string class, Panel dpropertysheet, number width, number height )
Called when the panel should generate example use case / example code to use for this panel. Used in the panel opened by derma_controls console command.
Called when the panel is created. This is called for each base type that the panel has.
Called after Panel:SetCookieName is called on this panel to apply the just loaded cookie values for this panel.
This is used internally - although you're able to use it you probably shouldn't. Called when we are activated during level load. Used by the loading screen panel.
PANEL:OnChildAdded( Panel child )
Called whenever a child was parented to the panel. This is called before the panel's metatable is set.Issue Tracker: 2759
Called whenever the cursor entered the panels bounds.
Called whenever the cursor left the panels bounds.
boolean PANEL:OnCursorMoved( number cursorX, number cursorY )
Called whenever the cursor was moved with the panels bounds.
This is used internally - although you're able to use it you probably shouldn't. Called when we are deactivated during level load. Used by the loading screen panel.
We're being dropped on something We can create a new panel here and return it, so that instead of dropping us - it drops the new panel instead! We remain where we are! Only works for panels derived from DDragBase.
PANEL:OnFocusChanged( boolean gained )
Called whenever the panel gained or lost focus. Panel:HasFocus will only be updated on the next frame and will return the "old" value at the time this hook is run. Same goes for vgui. GetKeyboardFocus.
boolean PANEL:OnKeyCodePressed( number keyCode )
Called whenever a keyboard key was pressed while the panel is focused. This is not run for ESC/"cancelselect" binding.Issue Tracker: 2886
boolean PANEL:OnKeyCodeReleased( number keyCode )
Called whenever a keyboard key was released while the panel is focused. This is not run for TILDE/"toggleconsole" binding.Issue Tracker: 2886
boolean PANEL:OnMousePressed( number keyCode )
Called whenever a mouse key was pressed while the panel is focused.
boolean PANEL:OnMouseReleased( number keyCode )
Called whenever a mouse key was released while the panel is focused.
Called when the panel is about to be removed.
PANEL:OnScreenSizeChanged( number oldWidth, number oldHeight )
Called when the player's screen resolution of the game changes. ScrW and ScrH will return the new values when this hook is called.
PANEL:OnSizeChanged( number newWidth, number newHeight )
Called just after the panel size changes. All size functions will return the new values when this hook is called. Changing the panel size in this hook will cause an infinite loop!
This is used internally - although you're able to use it you probably shouldn't. Called by dragndrop. StartDragging when the panel starts being dragged.
This is used internally - although you're able to use it you probably shouldn't. Called by Panel:DragMouseRelease when the panel object is released after being dragged.
boolean PANEL:Paint( number width, number height )
Called whenever the panel should be drawn. You can create panels with a customized appearance by overriding their Paint() function, which will prevent the default appearance from being drawn. Render operations from the surface (and consequentially the draw) are always offset by the global position of this panel, as seen in the example belowThis hook will not run if the panel is completely off the screen. The hook will still run however if any parts of the panel are still on screen.
boolean PANEL:PaintOver( number width, number height )
Called whenever the panel and all its children were drawn, return true to override the default drawing.
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!ExampleCreating 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 https://github. com/Facepunch/garrysmod/blob/master/garrysmod/lua/vgui/dframe. lua#L234-L258 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!")
Only works on elements defined with derma.DefineControl and only if the panel has AllowAutoRefresh set to true. Called after derma.DefineControl is called with panel's class name. See also PANEL:PreAutoRefresh
Only works on elements defined with derma.DefineControl and only if the panel has AllowAutoRefresh set to true. Called when derma.DefineControl is called with this panel's class name before applying changes to this panel. See also PANEL:PostAutoRefresh
boolean PANEL:TestHover( number x, number y )
Called to test if the panel is being hovered by the mouse. This will only be called if the panel's parent is being hovered.
Called every frame while Panel:IsVisible is true.