StartDrag
This member cannot be used in scripts, but is usable in the command bar and plugins.
StartDrag initiates a drag action using a dictionary of parameters. The parameters are as follows:
Name | Type | Default | Description |
---|---|---|---|
Sender | string | "" | Identifies the source of the drag action to the drop target |
MimeType | string | "" | The MIME type of Data. |
Data | string | "" | Information about the drag action (eg. what is being dragged). Should be used by the drop target. |
MouseIcon | Content | "" | The icon to use for the mouse cursor during the drag. If empty, uses the default cursor. |
DragIcon | Content | "" | An image to render under the mouse cursor during the drag. This should represent the item being dragged. |
HotSpot | Vector2 | Vector2.new(0, 0) | The pixel offset from the top-left where the cursor should "hold" the DragIcon. |
See Also
articles/Drag and Drop in Studio Widgets
PluginGui/PluginDragEntered
PluginGui/PluginDragMoved
PluginGui/PluginDragDropped
PluginGui/PluginDragLeft
Parameters
Name | Type | Default | Description |
---|---|---|---|
|
Returns
Return Type | Summary |
---|---|
Code Samples
Plugin Drag and Drop
This code sample creates two plugin widget windows: a drag source and a drop target. In the source window, the script creates a TextBox
and TextButton
to allow the user to begin a plugin drag action. The drop target window will display the MimeType of whatever is dragged into it using a TextLabel
. If the MimeType is text/plain, it will display the plain text data instead. Pictured below is an animation of the drag and drop action.
To run this code sample as a plugin, paste it into a Script
. Then, right-click the script in the Explorer window and choose “Save as Local Plugin”.
-- This script must be run as a Studio plugin
assert(plugin)
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
-- We'll start drags from this widget
local dragSourceWidget = plugin:CreateDockWidgetPluginGui("Drag Source", widgetInfo)
dragSourceWidget.Title = "Drag Source"
-- This TextBox allows the user to type the text to drag
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "Hello, plugin drags"
-- This TextButton will allow the user to start the drag
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1,0,1,-32)
dragButton.Position = UDim2.new(0,0,0,32)
dragButton.Text = "Edit the text above, then start drag here"
dragButton.Parent = dragSourceWidget
function onMouseButton1Down()
local dragData = {
Sender = "SomeDragSource";
MimeType = "text/plain";
Data = textBox.Text;
MouseIcon = "";
DragIcon = "";
HotSpot = Vector2.new(0, 0);
}
plugin:StartDrag(dragData)
end
dragButton.MouseButton1Down:connect(onMouseButton1Down)
-- This widget will receive drops
local dragTargetWidget = plugin:CreateDockWidgetPluginGui("Drop Target", widgetInfo)
dragTargetWidget.Title = "Drop Target"
-- This TextLabel will display what was dropped
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.Text = "Drop here..."
textLabel.Parent = dragTargetWidget
local function onDragDrop(dragData)
if dragData.MimeType == "text/plain" then
textLabel.Text = dragData.Data
else
textLabel.Text = dragData.MimeType
end
end
dragTargetWidget.PluginDragDropped:connect(onDragDrop)
dragTargetWidget.PluginDragEntered:connect(function (dragData)
print("PluginDragEntered")
end)
dragTargetWidget.PluginDragLeft:connect(function (dragData)
print("PluginDragLeft")
end)
dragTargetWidget.PluginDragMoved:connect(function (dragData)
print("PluginDragMoved")
end)