Garry's Mod Wiki

Revision Difference

DLabel:OnDepressed#513641

<function name="OnDepressed" parent="DLabel" type="panelfunc">⤶ <ispanel>yes</ispanel>⤶ <description>⤶ Called when the player presses the label with any mouse button.⤶ ⤶ This works as an alternative to <page>PANEL:OnMousePressed</page> as that hook is used heavily by <page>DLabel</page> and overriding it will break functionality.⤶ ⤶ See also <page>DLabel:DoClick</page>, <page>DLabel:DoMiddleClick</page>, <page>DLabel:DoRightClick</page>, <page>DLabel:OnReleased</page> and <page>DLabel:DoDoubleClick</page>.⤶ </description>⤶ <realm>Client</realm>⤶ </function>⤶ ⤶ <example>⤶ <description>Changes the text of the label when the hook is called.</description>⤶ <code>⤶ 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⤶ </code>⤶ ⤶ </example>