Garry's Mod Wiki

Panel:Receiver

Panel:Receiver( string name, function func, table menu )

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.

Arguments

1 string name
Name of DnD panels to receive. This is set on the drag'n'drop-able panels via Panel:Droppable
2 function func
This function is called whenever a panel with valid name is hovering above and dropped on this panel. It has next arguments:

  • Panel pnl - The receiver panel
  • table tbl - A table of panels dropped onto receiver panel
  • boolean dropped - False if hovering over, true if dropped onto
  • number menuIndex - Index of clicked menu item from third argument of Panel:Receiver
  • number x - Cursor pos, relative to the receiver
  • number y - Cursor pos, relative to the receiver
3 table menu
A table of strings that will act as a menu if drag'n'drop was performed with a right click

Example

A very simple drag'n'drop example without using DDragBase.

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 )

Page Links


Special Pages


Wikis

?

Render Time: 58ms

DB GetPage 4
Generate Html 29
SaveChanges 11
Render Body 0
Render Sidebar 12