Garry's Mod Wiki

DLabel:OnDepressed

  DLabel:OnDepressed()

Description

Called when the player presses the label with any mouse button.

This works as an alternative to PANEL:OnMousePressed as that hook is used heavily by DLabel and overriding it will break functionality.

See also DLabel:DoClick, DLabel:DoMiddleClick, DLabel:DoRightClick, DLabel:OnReleased and DLabel:DoDoubleClick.

Example

Changes the text of the label when the hook is called.

local frame = vgui.Create( "DFrame" ) frame:SetTitle( "OnDepressed/Released Example" ) frame:SetSize( 300, 100 ) frame:Center() frame:MakePopup() local frame_label = vgui.Create( "DLabel", frame ) frame_label:SetPos( 10, 30 ) frame_label:SetTextColor( Color( 255, 255, 255 ) ) frame_label:SetText( "Click me!" ) frame_label:SizeToContents() frame_label:SetMouseInputEnabled( true ) frame_label.OnDepressed = function( s ) s:SetText( "OnDepressed" ) frame_label:SizeToContents() end frame_label.OnReleased = function( s ) s:SetText( "OnReleased" ) frame_label:SizeToContents() end