-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.luau
102 lines (84 loc) · 2.11 KB
/
widget.luau
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
--!strict
local class = {} :: class
class.__index = class
export type WidgetParams = {
id: string?,
title: string?,
state: Enum.InitialDockState?,
size: Vector2?,
min_size: Vector2?,
enabled: boolean?,
restore: boolean?,
}
type class = {
new: (plugin: Plugin, params:WidgetParams) -> Widget,
destroy: (self: Widget) -> (),
show: (self: Widget) -> (),
hide: (self: Widget) -> (),
visible: (self: Widget) -> boolean,
set_title: (self: Widget, title: string) -> (),
get: (self: Widget) -> DockWidgetPluginGui,
clear: (self: Widget) -> (),
mount: (self: Widget, ...Instance) -> (),
unmount: (self: Widget, ...Instance) -> (),
__index: class,
}
export type Widget = typeof(setmetatable({} :: {
widget: DockWidgetPluginGui,
}, class :: class))
function class.new(plugin: Plugin, params: WidgetParams): Widget
local size = params.size or Vector2.new(250, 250)
local min_size = params.size or Vector2.new(100, 100)
local info: DockWidgetPluginGuiInfo = DockWidgetPluginGuiInfo.new(
params.state or Enum.InitialDockState.Float,
params.enabled or true,
params.restore or true,
size.X,
size.Y,
min_size.X,
min_size.Y
)
local widget: DockWidgetPluginGui = plugin:CreateDockWidgetPluginGui(
params.id or plugin.Name,
info
)
widget.Title = params.title or plugin.Name
widget.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
return setmetatable({
widget = widget,
}, class :: class) :: Widget
end
function class:show()
self.widget.Enabled = true
end
function class:hide()
self.widget.Enabled = false
end
function class:visible()
return self.widget.Enabled
end
function class:destroy()
self.widget:Destroy()
end
function class:set_title(title: string)
self.widget.Title = title
end
function class:mount(...: Instance)
for _, v: Instance in {...} do
v.Parent = self.widget
end
end
function class:unmount(...: Instance)
for _, v: Instance in {...} do
if v.Parent == self.widget then
v:Destroy()
end
end
end
function class:clear()
self.widget:ClearAllChildren()
end
function class:get()
return self.widget
end
return class