Garry's Mod Wiki

Revision Difference

Panel:Receiver#511048

<function name="Receiver" parent="Panel" type="classfunc">⤶ <description>Allows the panel to receive drag and drop events. Can be called multiple times with different names to receive multiple different draggable panel events.</description>⤶ <realm>Client</realm>⤶ <file line="311">lua/includes/extensions/client/panel/dragdrop.lua</file>⤶ <args>⤶ <arg name="name" type="string">Name of DnD panels to receive. This is set on the drag&#x27;n&#x27;drop-able panels via &lt;page&gt;Panel:Droppable&lt;/page&gt;</arg>⤶ <arg name="func" type="function">This function is called whenever a panel with valid name is hovering above and dropped on this panel. It has next arguments:&#xA;* &lt;page&gt;Panel&lt;/page&gt; pnl - The receiver panel&#xA;* &lt;page&gt;table&lt;/page&gt; tbl - A table of panels dropped onto receiver panel&#xA;* &lt;page&gt;boolean&lt;/page&gt; dropped - False if hovering over, true if dropped onto&#xA;* &lt;page&gt;number&lt;/page&gt; menuIndex - Index of clicked menu item from third argument of &lt;page&gt;Panel:Receiver&lt;/page&gt;&#xA;* &lt;page&gt;number&lt;/page&gt; x - Cursor pos, relative to the receiver&#xA;* &lt;page&gt;number&lt;/page&gt; y - Cursor pos, relative to the receiver</arg>⤶ <arg name="menu" type="table">A table of strings that will act as a menu if drag&#x27;n&#x27;drop was performed with a right click</arg>⤶ </args>⤶ </function>⤶ ⤶ <example>⤶ <description>A very simple drag'n'drop example without using <page>DDragBase</page>.</description>⤶ <code>⤶ local function DoDrop( self, panels, bDoDrop, Command, x, y )⤶ if ( bDoDrop ) then⤶ for k, v in pairs( panels ) do⤶ self:AddItem( v )⤶ end⤶ end⤶ end⤶ ⤶ concommand.Add( "test2", function()⤶ ⤶ local frame = vgui.Create( "DFrame" )⤶ frame:SetSize( 500, 300 )⤶ frame:SetTitle( "Frame" )⤶ frame:MakePopup()⤶ frame:Center()⤶ ⤶ local left = vgui.Create( "DScrollPanel", frame )⤶ left:Dock( LEFT )⤶ left:SetWidth( frame:GetWide() / 2 - 7 )⤶ left:SetPaintBackground( true )⤶ left:DockMargin( 0, 0, 4, 0 )⤶ left:Receiver( "myDNDname", DoDrop ) -- Make the panel a receiver for drag and drop events⤶ ⤶ local right = vgui.Create( "DScrollPanel", frame )⤶ right:Dock( FILL )⤶ right:SetPaintBackground( true )⤶ right:Receiver( "myDNDname", DoDrop )⤶ ⤶ for i = 1, 30 do⤶ local but = vgui.Create( "DButton" )⤶ but:SetText( i )⤶ but:SetSize( 36, 24 )⤶ but:Dock( TOP )⤶ but:Droppable( "myDNDname" ) -- make the panel be able to be drag'n'dropped onto other panels⤶ right:AddItem( but )⤶ end⤶ ⤶ end )⤶ </code>⤶ ⤶ </example>