PluginGui

Show Deprecated
Not Creatable
Not Replicated

PluginGui is an abstract class for GUIs that allow the display of GuiObjects in various Roblox Studio widgets. As of right now, the only available PluginGui type is DockWidgetPluginGui, but there may be more in the future!

Summary

Properties

Properties inherited from LayerCollectorProperties inherited from GuiBase2d

Methods

Events

Events inherited from GuiBase2d

Properties

Title

Read Parallel

The title that is displayed above the contents of the PluginGui. Defaults to empty string.

Methods

BindToClose

void

This function binds a function to the PluginGui close button, overriding the default behavior.

By default, when the user clicks the 'x' button in the top right corner of the PluginGui the Enabled property is set to false, closing the window. When a custom function is bound using BindToClose this behavior is overwritten, allowing you to check if the user really wants to close the window or give them an opportunity to save their work.

As the default closing behavior is overwritten by this function, you'll need to configure the PluginGui to close manually by setting PluginGui.Enabled to false. For example, in the below snippet users are required to click a confirm button to close the GUI:


local closing = false
pluginGui:BindToClose(function()
-- make sure we haven't already made a button
if closing then
return
end
closing = true
-- create confirm button
local confirmButton = Instance.new("TextButton")
confirmButton.AnchorPoint = Vector2.new(0.5, 0.5)
confirmButton.Size = UDim2.new(0.5, 0, 0.5, 0)
confirmButton.Position = UDim2.new(0.5, 0, 0.5, 0)
confirmButton.BackgroundColor3 = Color3.new(1, 0, 0)
confirmButton.Text = "Close?"
confirmButton.Parent = pluginGui
-- listen for click
confirmButton.Activated:Connect(function()
-- close the gui
pluginGui.Enabled = false
-- remove confirm button
confirmButton:Destroy()
end)
end)

You can call BindToClose with no argument to 'unbind' and revert to the default behavior described above. For example:


pluginGui:BindToClose()

See also:

Parameters

function: function

The function to bind the close button to. If no function is specified then any previously specified function will be unbound.

Default Value: "nil"

Returns

void

GetRelativeMousePosition

Plugin Security

GetRelativeMousePosition returns the position of the mouse relative to the top-left corner of the PluginGui. The returned value changes only if a mouse input began on the PluginGui, or if the mouse is presently hovering over the window.


Returns

The screen position of the mouse relative to the PluginGui in pixels.

Code Samples

PluginGui:GetRelativeMousePosition

local RunService = game:GetService("RunService")
local widgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Float,
true,
false, -- Enabled state, override
200,
300, -- Size
150,
150 -- Minimum size
)
local testWidget = plugin:CreateDockWidgetPluginGui("TestWidget", widgetInfo)
function update()
local v2 = testWidget:GetRelativeMousePosition()
testWidget.Title = ("(%d, %d)"):format(v2.x, v2.y)
end
RunService.Stepped:Connect(update)
update()

Events

PluginDragDropped

Plugin Security

PluginDragDropped fires when the user releases their mouse over a PluginGui during a drag operation started by Plugin:StartDrag().

See also:

Parameters

dragData: Dictionary

Code Samples

Plugin Drag and Drop

assert(plugin, "This script must be run as a Studio plugin")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGui("Drag Source", widgetInfo)
dragSourceWidget.Title = "Drag Source"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "Hello, plugin drags"
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)

PluginDragEntered

Plugin Security

PluginDragEntered fires when the user's mouse enters the PluginGui during a drag operation started by Plugin:StartDrag().

This event is useful for displaying a "Drop Here" UI on PluginGuis where a drag operation can be dropped. Such a UI should be hidden when either PluginDragLeft or PluginDragDropped fire.

See also:

Parameters

dragData: Dictionary

A copy of the data originally passed to Plugin:StartDrag().


Code Samples

Plugin Drag and Drop

assert(plugin, "This script must be run as a Studio plugin")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGui("Drag Source", widgetInfo)
dragSourceWidget.Title = "Drag Source"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "Hello, plugin drags"
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)

PluginDragLeft

Plugin Security

PluginDragLeft fires when the user's mouse leaves a PluginGui during a drag operation started by Plugin:StartDrag().

This event and PluginDragDropped are useful for hiding a "Drop Here" UI on PluginGuis where a drag operation can be dropped. Such a UI should be shown when either PluginDragEntered fires.

See also:

Parameters

dragData: Dictionary

A copy of the data originally passed to Plugin:StartDrag().


Code Samples

Plugin Drag and Drop

assert(plugin, "This script must be run as a Studio plugin")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGui("Drag Source", widgetInfo)
dragSourceWidget.Title = "Drag Source"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "Hello, plugin drags"
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)

PluginDragMoved

Plugin Security

PluginDragMoved fires when the user's mouse moves within a PluginGui during a drag operation started by Plugin:StartDrag().

See also:

Parameters

dragData: Dictionary

WindowFocusReleased

Plugin Security

WindowFocusReleased fires immediately when the user stops interacting with the PluginGui's window, usually by clicking on something not in the window. This functions works similarly to the similarly-named UserInputService.WindowFocusReleased event.

If focus is moving to another PluginGui while the user had this PluginGui in focus, then this event fires before the other's WindowFocused event. However, if the main game window is being put in focus, this event fires after UserInputService.WindowFocused.


Code Samples

Detecting PluginGui Focus State

local info = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 200, 50, 1, 1)
local widget = plugin:CreateDockWidgetPluginGui("TestWidget", info)
local function onFocusReleased()
widget.Title = "I'm not in focus :("
end
local function onFocused()
widget.Title = "I'm in focus :D"
end
widget.WindowFocusReleased:Connect(onFocusReleased)
widget.WindowFocused:Connect(onFocused)

WindowFocused

Plugin Security

WindowFocused fires immediately when the user starts interacting with the PluginGui's window, usually by clicking on it. This functions works similarly to the similarly-named UserInputService.WindowFocused event. It fires before any GuiObject.InputBegan events related to mouse buttons.

If another PluginGui is in focus and the user focuses this PluginGui, then this event fires after the other's WindowFocusReleased event. However, if the main game window was in focus, this event fires after UserInputService.WindowFocusReleased.


Code Samples

Detecting PluginGui Focus State

local info = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 200, 50, 1, 1)
local widget = plugin:CreateDockWidgetPluginGui("TestWidget", info)
local function onFocusReleased()
widget.Title = "I'm not in focus :("
end
local function onFocused()
widget.Title = "I'm in focus :D"
end
widget.WindowFocusReleased:Connect(onFocusReleased)
widget.WindowFocused:Connect(onFocused)