@quenty/iris 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +33 -0
  4. package/default.project.json +14 -0
  5. package/package.json +42 -0
  6. package/src/Shared/Iris.lua +702 -0
  7. package/src/Shared/iris_API.lua +231 -0
  8. package/src/Shared/iris_Internal.lua +923 -0
  9. package/src/Shared/iris_PubTypes.lua +44 -0
  10. package/src/Shared/iris_Types.lua +674 -0
  11. package/src/Shared/iris_WidgetTypes.lua +522 -0
  12. package/src/Shared/iris_config.lua +306 -0
  13. package/src/Shared/iris_demoWindow.lua +2148 -0
  14. package/src/Shared/widgets/iris_Button.lua +91 -0
  15. package/src/Shared/widgets/iris_Checkbox.lua +116 -0
  16. package/src/Shared/widgets/iris_Combo.lua +498 -0
  17. package/src/Shared/widgets/iris_Format.lua +141 -0
  18. package/src/Shared/widgets/iris_Image.lua +156 -0
  19. package/src/Shared/widgets/iris_Input.lua +1430 -0
  20. package/src/Shared/widgets/iris_Menu.lua +603 -0
  21. package/src/Shared/widgets/iris_Plot.lua +642 -0
  22. package/src/Shared/widgets/iris_RadioButton.lua +127 -0
  23. package/src/Shared/widgets/iris_Root.lua +148 -0
  24. package/src/Shared/widgets/iris_Tab.lua +334 -0
  25. package/src/Shared/widgets/iris_Table.lua +641 -0
  26. package/src/Shared/widgets/iris_Text.lua +133 -0
  27. package/src/Shared/widgets/iris_Tree.lua +291 -0
  28. package/src/Shared/widgets/iris_Window.lua +1158 -0
  29. package/src/Shared/widgets/iris_widgets.lua +487 -0
  30. package/src/jest.config.lua +3 -0
  31. package/src/node_modules.project.json +7 -0
  32. package/test/default.project.json +25 -0
  33. package/test/scripts/Server/ServerMain.server.lua +13 -0
@@ -0,0 +1,603 @@
1
+ --!nocheck
2
+ local Types = require(script.Parent.Parent.iris_Types)
3
+
4
+ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
5
+ local AnyMenuOpen = false
6
+ local ActiveMenu: Types.Menu? = nil
7
+ local MenuStack: { Types.Menu } = {}
8
+
9
+ local function EmptyMenuStack(menuIndex: number?)
10
+ for index = #MenuStack, menuIndex and menuIndex + 1 or 1, -1 do
11
+ local widget = MenuStack[index]
12
+ widget.state.isOpened:set(false)
13
+
14
+ widget.Instance.BackgroundColor3 = Iris._config.HeaderColor
15
+ widget.Instance.BackgroundTransparency = 1
16
+
17
+ table.remove(MenuStack, index)
18
+ end
19
+
20
+ if #MenuStack == 0 then
21
+ AnyMenuOpen = false
22
+ ActiveMenu = nil
23
+ end
24
+ end
25
+
26
+ local function UpdateChildContainerTransform(thisWidget: Types.Menu)
27
+ local submenu = thisWidget.parentWidget.type == "Menu"
28
+
29
+ local Menu = thisWidget.Instance :: Frame
30
+ local ChildContainer = thisWidget.ChildContainer :: ScrollingFrame
31
+ ChildContainer.Size = UDim2.fromOffset(Menu.AbsoluteSize.X, 0)
32
+ if ChildContainer.Parent == nil then
33
+ return
34
+ end
35
+
36
+ local menuPosition = Menu.AbsolutePosition - widgets.GuiOffset
37
+ local menuSize = Menu.AbsoluteSize
38
+ local containerSize = ChildContainer.AbsoluteSize
39
+ local borderSize = Iris._config.PopupBorderSize
40
+ local screenSize: Vector2 = ChildContainer.Parent.AbsoluteSize
41
+
42
+ local x = menuPosition.X
43
+ local y
44
+ local anchor = Vector2.zero
45
+
46
+ if submenu then
47
+ if menuPosition.X + containerSize.X > screenSize.X then
48
+ anchor = Vector2.xAxis
49
+ else
50
+ x = menuPosition.X + menuSize.X
51
+ end
52
+ end
53
+
54
+ if menuPosition.Y + containerSize.Y > screenSize.Y then
55
+ -- too low.
56
+ y = menuPosition.Y - borderSize + (submenu and menuSize.Y or 0)
57
+ anchor += Vector2.yAxis
58
+ else
59
+ y = menuPosition.Y + borderSize + (submenu and 0 or menuSize.Y)
60
+ end
61
+
62
+ ChildContainer.Position = UDim2.fromOffset(x, y)
63
+ ChildContainer.AnchorPoint = anchor
64
+ end
65
+
66
+ widgets.registerEvent("InputBegan", function(inputObject: InputObject)
67
+ if not Iris._started then
68
+ return
69
+ end
70
+ if
71
+ inputObject.UserInputType ~= Enum.UserInputType.MouseButton1
72
+ and inputObject.UserInputType ~= Enum.UserInputType.MouseButton2
73
+ then
74
+ return
75
+ end
76
+ if AnyMenuOpen == false then
77
+ return
78
+ end
79
+ if ActiveMenu == nil then
80
+ return
81
+ end
82
+
83
+ -- this only checks if we clicked outside all the menus. If we clicked in any menu, then the hover function handles this.
84
+ local isInMenu = false
85
+ local MouseLocation = widgets.getMouseLocation()
86
+ for _, menu in MenuStack do
87
+ for _, container in { menu.ChildContainer, menu.Instance } do
88
+ local rectMin = container.AbsolutePosition - widgets.GuiOffset
89
+ local rectMax = rectMin + container.AbsoluteSize
90
+ if widgets.isPosInsideRect(MouseLocation, rectMin, rectMax) then
91
+ isInMenu = true
92
+ break
93
+ end
94
+ end
95
+ if isInMenu then
96
+ break
97
+ end
98
+ end
99
+
100
+ if not isInMenu then
101
+ EmptyMenuStack()
102
+ end
103
+ end)
104
+
105
+ --stylua: ignore
106
+ Iris.WidgetConstructor("MenuBar", {
107
+ hasState = false,
108
+ hasChildren = true,
109
+ Args = {},
110
+ Events = {},
111
+ Generate = function(_thisWidget: Types.MenuBar)
112
+ local MenuBar = Instance.new("Frame")
113
+ MenuBar.Name = "Iris_MenuBar"
114
+ MenuBar.AutomaticSize = Enum.AutomaticSize.Y
115
+ MenuBar.Size = UDim2.fromScale(1, 0)
116
+ MenuBar.BackgroundColor3 = Iris._config.MenubarBgColor
117
+ MenuBar.BackgroundTransparency = Iris._config.MenubarBgTransparency
118
+ MenuBar.BorderSizePixel = 0
119
+ MenuBar.ClipsDescendants = true
120
+
121
+ widgets.UIPadding(MenuBar, Vector2.new(Iris._config.WindowPadding.X, 1))
122
+ widgets.UIListLayout(MenuBar, Enum.FillDirection.Horizontal, UDim.new()).VerticalAlignment = Enum.VerticalAlignment.Center
123
+ widgets.applyFrameStyle(MenuBar, true, true)
124
+
125
+ return MenuBar
126
+ end,
127
+ Update = function(_thisWidget: Types.Widget)
128
+
129
+ end,
130
+ ChildAdded = function(thisWidget: Types.MenuBar, _thisChild: Types.Widget)
131
+ return thisWidget.Instance
132
+ end,
133
+ Discard = function(thisWidget: Types.MenuBar)
134
+ thisWidget.Instance:Destroy()
135
+ end,
136
+ } :: Types.WidgetClass)
137
+
138
+ --stylua: ignore
139
+ Iris.WidgetConstructor("Menu", {
140
+ hasState = true,
141
+ hasChildren = true,
142
+ Args = {
143
+ ["Text"] = 1,
144
+ },
145
+ Events = {
146
+ ["clicked"] = widgets.EVENTS.click(function(thisWidget: Types.Widget)
147
+ return thisWidget.Instance
148
+ end),
149
+ ["hovered"] = widgets.EVENTS.hover(function(thisWidget: Types.Widget)
150
+ return thisWidget.Instance
151
+ end),
152
+ ["opened"] = {
153
+ ["Init"] = function(_thisWidget: Types.Menu) end,
154
+ ["Get"] = function(thisWidget: Types.Menu)
155
+ return thisWidget.lastOpenedTick == Iris._cycleTick
156
+ end,
157
+ },
158
+ ["closed"] = {
159
+ ["Init"] = function(_thisWidget: Types.Menu) end,
160
+ ["Get"] = function(thisWidget: Types.Menu)
161
+ return thisWidget.lastClosedTick == Iris._cycleTick
162
+ end,
163
+ },
164
+ },
165
+ Generate = function(thisWidget: Types.Menu)
166
+ local Menu: TextButton
167
+ thisWidget.ButtonColors = {
168
+ Color = Iris._config.HeaderColor,
169
+ Transparency = 1,
170
+ HoveredColor = Iris._config.HeaderHoveredColor,
171
+ HoveredTransparency = Iris._config.HeaderHoveredTransparency,
172
+ ActiveColor = Iris._config.HeaderHoveredColor,
173
+ ActiveTransparency = Iris._config.HeaderHoveredTransparency,
174
+ }
175
+ if thisWidget.parentWidget.type == "Menu" then
176
+ -- this Menu is a sub-Menu
177
+ Menu = Instance.new("TextButton")
178
+ Menu.Name = "Menu"
179
+ Menu.AutomaticSize = Enum.AutomaticSize.Y
180
+ Menu.Size = UDim2.fromScale(1, 0)
181
+ Menu.BackgroundColor3 = Iris._config.HeaderColor
182
+ Menu.BackgroundTransparency = 1
183
+ Menu.BorderSizePixel = 0
184
+ Menu.Text = ""
185
+ Menu.AutoButtonColor = false
186
+
187
+ local UIPadding = widgets.UIPadding(Menu, Iris._config.FramePadding)
188
+ UIPadding.PaddingTop = UIPadding.PaddingTop - UDim.new(0, 1)
189
+ widgets.UIListLayout(Menu, Enum.FillDirection.Horizontal, UDim.new(0, Iris._config.ItemInnerSpacing.X)).VerticalAlignment = Enum.VerticalAlignment.Center
190
+
191
+ local TextLabel = Instance.new("TextLabel")
192
+ TextLabel.Name = "TextLabel"
193
+ TextLabel.AutomaticSize = Enum.AutomaticSize.XY
194
+ TextLabel.BackgroundTransparency = 1
195
+ TextLabel.BorderSizePixel = 0
196
+
197
+ widgets.applyTextStyle(TextLabel)
198
+
199
+ TextLabel.Parent = Menu
200
+
201
+ local frameSize = Iris._config.TextSize + 2 * Iris._config.FramePadding.Y
202
+ local padding = math.round(0.2 * frameSize)
203
+ local iconSize = frameSize - 2 * padding
204
+
205
+ local Icon = Instance.new("ImageLabel")
206
+ Icon.Name = "Icon"
207
+ Icon.Size = UDim2.fromOffset(iconSize, iconSize)
208
+ Icon.BackgroundTransparency = 1
209
+ Icon.BorderSizePixel = 0
210
+ Icon.ImageColor3 = Iris._config.TextColor
211
+ Icon.ImageTransparency = Iris._config.TextTransparency
212
+ Icon.Image = widgets.ICONS.RIGHT_POINTING_TRIANGLE
213
+ Icon.LayoutOrder = 1
214
+
215
+ Icon.Parent = Menu
216
+ else
217
+ Menu = Instance.new("TextButton")
218
+ Menu.Name = "Menu"
219
+ Menu.AutomaticSize = Enum.AutomaticSize.XY
220
+ Menu.Size = UDim2.fromScale(0, 0)
221
+ Menu.BackgroundColor3 = Iris._config.HeaderColor
222
+ Menu.BackgroundTransparency = 1
223
+ Menu.BorderSizePixel = 0
224
+ Menu.Text = ""
225
+ Menu.AutoButtonColor = false
226
+ Menu.ClipsDescendants = true
227
+
228
+ widgets.applyTextStyle(Menu)
229
+ widgets.UIPadding(Menu, Vector2.new(Iris._config.ItemSpacing.X, Iris._config.FramePadding.Y))
230
+ end
231
+ widgets.applyInteractionHighlights("Background", Menu, Menu, thisWidget.ButtonColors)
232
+
233
+ widgets.applyButtonClick(Menu, function()
234
+ local openMenu = if #MenuStack <= 1 then not thisWidget.state.isOpened.value else true
235
+ thisWidget.state.isOpened:set(openMenu)
236
+
237
+ AnyMenuOpen = openMenu
238
+ ActiveMenu = openMenu and thisWidget or nil
239
+ -- the hovering should handle all of the menus after the first one.
240
+ if #MenuStack <= 1 then
241
+ if openMenu then
242
+ table.insert(MenuStack, thisWidget)
243
+ else
244
+ table.remove(MenuStack)
245
+ end
246
+ end
247
+ end)
248
+
249
+ widgets.applyMouseEnter(Menu, function()
250
+ if AnyMenuOpen and ActiveMenu and ActiveMenu ~= thisWidget then
251
+ local parentMenu = thisWidget.parentWidget :: Types.Menu
252
+ local parentIndex = table.find(MenuStack, parentMenu)
253
+
254
+ EmptyMenuStack(parentIndex)
255
+ thisWidget.state.isOpened:set(true)
256
+ ActiveMenu = thisWidget
257
+ AnyMenuOpen = true
258
+ table.insert(MenuStack, thisWidget)
259
+ end
260
+ end)
261
+
262
+ local ChildContainer = Instance.new("ScrollingFrame")
263
+ ChildContainer.Name = "MenuContainer"
264
+ ChildContainer.AutomaticSize = Enum.AutomaticSize.XY
265
+ ChildContainer.Size = UDim2.fromOffset(0, 0)
266
+ ChildContainer.BackgroundColor3 = Iris._config.PopupBgColor
267
+ ChildContainer.BackgroundTransparency = Iris._config.PopupBgTransparency
268
+ ChildContainer.BorderSizePixel = 0
269
+
270
+ ChildContainer.AutomaticCanvasSize = Enum.AutomaticSize.Y
271
+ ChildContainer.ScrollBarImageTransparency = Iris._config.ScrollbarGrabTransparency
272
+ ChildContainer.ScrollBarImageColor3 = Iris._config.ScrollbarGrabColor
273
+ ChildContainer.ScrollBarThickness = Iris._config.ScrollbarSize
274
+ ChildContainer.CanvasSize = UDim2.fromScale(0, 0)
275
+ ChildContainer.VerticalScrollBarInset = Enum.ScrollBarInset.ScrollBar
276
+ ChildContainer.TopImage = widgets.ICONS.BLANK_SQUARE
277
+ ChildContainer.MidImage = widgets.ICONS.BLANK_SQUARE
278
+ ChildContainer.BottomImage = widgets.ICONS.BLANK_SQUARE
279
+
280
+ ChildContainer.ZIndex = 6
281
+ ChildContainer.LayoutOrder = 6
282
+ ChildContainer.ClipsDescendants = true
283
+
284
+ -- Unfortunatley, ScrollingFrame does not work with UICorner
285
+ -- if Iris._config.PopupRounding > 0 then
286
+ -- widgets.UICorner(ChildContainer, Iris._config.PopupRounding)
287
+ -- end
288
+
289
+ widgets.UIStroke(ChildContainer, Iris._config.WindowBorderSize, Iris._config.BorderColor, Iris._config.BorderTransparency)
290
+ widgets.UIPadding(ChildContainer, Vector2.new(2, Iris._config.WindowPadding.Y - Iris._config.ItemSpacing.Y))
291
+
292
+ widgets.UIListLayout(ChildContainer, Enum.FillDirection.Vertical, UDim.new(0, 1)).VerticalAlignment = Enum.VerticalAlignment.Top
293
+
294
+ local RootPopupScreenGui = Iris._rootInstance and Iris._rootInstance:FindFirstChild("PopupScreenGui") :: GuiObject
295
+ ChildContainer.Parent = RootPopupScreenGui
296
+
297
+
298
+ thisWidget.ChildContainer = ChildContainer
299
+ return Menu
300
+ end,
301
+ Update = function(thisWidget: Types.Menu)
302
+ local Menu = thisWidget.Instance :: TextButton
303
+ local TextLabel: TextLabel
304
+ if thisWidget.parentWidget.type == "Menu" then
305
+ TextLabel = Menu.TextLabel
306
+ else
307
+ TextLabel = Menu
308
+ end
309
+ TextLabel.Text = thisWidget.arguments.Text or "Menu"
310
+ end,
311
+ ChildAdded = function(thisWidget: Types.Menu, _thisChild: Types.Widget)
312
+ UpdateChildContainerTransform(thisWidget)
313
+ return thisWidget.ChildContainer
314
+ end,
315
+ ChildDiscarded = function(thisWidget: Types.Menu, _thisChild: Types.Widget)
316
+ UpdateChildContainerTransform(thisWidget)
317
+ end,
318
+ GenerateState = function(thisWidget: Types.Menu)
319
+ if thisWidget.state.isOpened == nil then
320
+ thisWidget.state.isOpened = Iris._widgetState(thisWidget, "isOpened", false)
321
+ end
322
+ end,
323
+ UpdateState = function(thisWidget: Types.Menu)
324
+ local ChildContainer = thisWidget.ChildContainer :: ScrollingFrame
325
+
326
+ if thisWidget.state.isOpened.value then
327
+ thisWidget.lastOpenedTick = Iris._cycleTick + 1
328
+ thisWidget.ButtonColors.Transparency = Iris._config.HeaderTransparency
329
+ ChildContainer.Visible = true
330
+
331
+ UpdateChildContainerTransform(thisWidget)
332
+ else
333
+ thisWidget.lastClosedTick = Iris._cycleTick + 1
334
+ thisWidget.ButtonColors.Transparency = 1
335
+ ChildContainer.Visible = false
336
+ end
337
+ end,
338
+ Discard = function(thisWidget: Types.Menu)
339
+ -- properly handle removing a menu if open and deleted
340
+ if AnyMenuOpen then
341
+ local parentMenu = thisWidget.parentWidget :: Types.Menu
342
+ local parentIndex = table.find(MenuStack, parentMenu)
343
+ if parentIndex then
344
+ EmptyMenuStack(parentIndex)
345
+ if #MenuStack ~= 0 then
346
+ ActiveMenu = parentMenu
347
+ AnyMenuOpen = true
348
+ end
349
+ end
350
+ end
351
+
352
+ thisWidget.Instance:Destroy()
353
+ thisWidget.ChildContainer:Destroy()
354
+ widgets.discardState(thisWidget)
355
+ end,
356
+ } :: Types.WidgetClass)
357
+
358
+ --stylua: ignore
359
+ Iris.WidgetConstructor("MenuItem", {
360
+ hasState = false,
361
+ hasChildren = false,
362
+ Args = {
363
+ Text = 1,
364
+ KeyCode = 2,
365
+ ModifierKey = 3,
366
+ },
367
+ Events = {
368
+ ["clicked"] = widgets.EVENTS.click(function(thisWidget: Types.Widget)
369
+ return thisWidget.Instance
370
+ end),
371
+ ["hovered"] = widgets.EVENTS.hover(function(thisWidget: Types.Widget)
372
+ return thisWidget.Instance
373
+ end),
374
+ },
375
+ Generate = function(thisWidget: Types.MenuItem)
376
+ local MenuItem = Instance.new("TextButton")
377
+ MenuItem.Name = "Iris_MenuItem"
378
+ MenuItem.AutomaticSize = Enum.AutomaticSize.Y
379
+ MenuItem.Size = UDim2.fromScale(1, 0)
380
+ MenuItem.BackgroundTransparency = 1
381
+ MenuItem.BorderSizePixel = 0
382
+ MenuItem.Text = ""
383
+ MenuItem.AutoButtonColor = false
384
+
385
+ local UIPadding = widgets.UIPadding(MenuItem, Iris._config.FramePadding)
386
+ UIPadding.PaddingTop = UIPadding.PaddingTop - UDim.new(0, 1)
387
+ widgets.UIListLayout(MenuItem, Enum.FillDirection.Horizontal, UDim.new(0, Iris._config.ItemInnerSpacing.X))
388
+
389
+ widgets.applyInteractionHighlights("Background", MenuItem, MenuItem, {
390
+ Color = Iris._config.HeaderColor,
391
+ Transparency = 1,
392
+ HoveredColor = Iris._config.HeaderHoveredColor,
393
+ HoveredTransparency = Iris._config.HeaderHoveredTransparency,
394
+ ActiveColor = Iris._config.HeaderHoveredColor,
395
+ ActiveTransparency = Iris._config.HeaderHoveredTransparency,
396
+ })
397
+
398
+ widgets.applyButtonClick(MenuItem, function()
399
+ EmptyMenuStack()
400
+ end)
401
+
402
+ widgets.applyMouseEnter(MenuItem, function()
403
+ local parentMenu = thisWidget.parentWidget :: Types.Menu
404
+ if AnyMenuOpen and ActiveMenu and ActiveMenu ~= parentMenu then
405
+ local parentIndex = table.find(MenuStack, parentMenu)
406
+
407
+ EmptyMenuStack(parentIndex)
408
+ ActiveMenu = parentMenu
409
+ AnyMenuOpen = true
410
+ end
411
+ end)
412
+
413
+ local TextLabel = Instance.new("TextLabel")
414
+ TextLabel.Name = "TextLabel"
415
+ TextLabel.AutomaticSize = Enum.AutomaticSize.XY
416
+ TextLabel.BackgroundTransparency = 1
417
+ TextLabel.BorderSizePixel = 0
418
+
419
+ widgets.applyTextStyle(TextLabel)
420
+
421
+ TextLabel.Parent = MenuItem
422
+
423
+ local Shortcut = Instance.new("TextLabel")
424
+ Shortcut.Name = "Shortcut"
425
+ Shortcut.AutomaticSize = Enum.AutomaticSize.XY
426
+ Shortcut.BackgroundTransparency = 1
427
+ Shortcut.BorderSizePixel = 0
428
+ Shortcut.LayoutOrder = 1
429
+
430
+ widgets.applyTextStyle(Shortcut)
431
+
432
+ Shortcut.Text = ""
433
+ Shortcut.TextColor3 = Iris._config.TextDisabledColor
434
+ Shortcut.TextTransparency = Iris._config.TextDisabledTransparency
435
+
436
+ Shortcut.Parent = MenuItem
437
+
438
+ return MenuItem
439
+ end,
440
+ Update = function(thisWidget: Types.MenuItem)
441
+ local MenuItem = thisWidget.Instance :: TextButton
442
+ local TextLabel: TextLabel = MenuItem.TextLabel
443
+ local Shortcut: TextLabel = MenuItem.Shortcut
444
+
445
+ TextLabel.Text = thisWidget.arguments.Text
446
+ if thisWidget.arguments.KeyCode then
447
+ if thisWidget.arguments.ModifierKey then
448
+ Shortcut.Text = thisWidget.arguments.ModifierKey.Name .. " + " .. thisWidget.arguments.KeyCode.Name
449
+ else
450
+ Shortcut.Text = thisWidget.arguments.KeyCode.Name
451
+ end
452
+ end
453
+ end,
454
+ Discard = function(thisWidget: Types.MenuItem)
455
+ thisWidget.Instance:Destroy()
456
+ end,
457
+ } :: Types.WidgetClass)
458
+
459
+ --stylua: ignore
460
+ Iris.WidgetConstructor("MenuToggle", {
461
+ hasState = true,
462
+ hasChildren = false,
463
+ Args = {
464
+ Text = 1,
465
+ KeyCode = 2,
466
+ ModifierKey = 3,
467
+ },
468
+ Events = {
469
+ ["checked"] = {
470
+ ["Init"] = function(_thisWidget: Types.MenuToggle) end,
471
+ ["Get"] = function(thisWidget: Types.MenuToggle): boolean
472
+ return thisWidget.lastCheckedTick == Iris._cycleTick
473
+ end,
474
+ },
475
+ ["unchecked"] = {
476
+ ["Init"] = function(_thisWidget: Types.MenuToggle) end,
477
+ ["Get"] = function(thisWidget: Types.MenuToggle): boolean
478
+ return thisWidget.lastUncheckedTick == Iris._cycleTick
479
+ end,
480
+ },
481
+ ["hovered"] = widgets.EVENTS.hover(function(thisWidget: Types.Widget)
482
+ return thisWidget.Instance
483
+ end),
484
+ },
485
+ Generate = function(thisWidget: Types.MenuToggle)
486
+ local MenuToggle = Instance.new("TextButton")
487
+ MenuToggle.Name = "Iris_MenuToggle"
488
+ MenuToggle.AutomaticSize = Enum.AutomaticSize.Y
489
+ MenuToggle.Size = UDim2.fromScale(1, 0)
490
+ MenuToggle.BackgroundTransparency = 1
491
+ MenuToggle.BorderSizePixel = 0
492
+ MenuToggle.Text = ""
493
+ MenuToggle.AutoButtonColor = false
494
+
495
+ local UIPadding = widgets.UIPadding(MenuToggle, Iris._config.FramePadding)
496
+ UIPadding.PaddingTop = UIPadding.PaddingTop - UDim.new(0, 1)
497
+ widgets.UIListLayout(MenuToggle, Enum.FillDirection.Horizontal, UDim.new(0, Iris._config.ItemInnerSpacing.X)).VerticalAlignment = Enum.VerticalAlignment.Center
498
+
499
+ widgets.applyInteractionHighlights("Background", MenuToggle, MenuToggle, {
500
+ Color = Iris._config.HeaderColor,
501
+ Transparency = 1,
502
+ HoveredColor = Iris._config.HeaderHoveredColor,
503
+ HoveredTransparency = Iris._config.HeaderHoveredTransparency,
504
+ ActiveColor = Iris._config.HeaderHoveredColor,
505
+ ActiveTransparency = Iris._config.HeaderHoveredTransparency,
506
+ })
507
+
508
+ widgets.applyButtonClick(MenuToggle, function()
509
+ thisWidget.state.isChecked:set(not thisWidget.state.isChecked.value)
510
+ EmptyMenuStack()
511
+ end)
512
+
513
+ widgets.applyMouseEnter(MenuToggle, function()
514
+ local parentMenu = thisWidget.parentWidget :: Types.Menu
515
+ if AnyMenuOpen and ActiveMenu and ActiveMenu ~= parentMenu then
516
+ local parentIndex = table.find(MenuStack, parentMenu)
517
+
518
+ EmptyMenuStack(parentIndex)
519
+ ActiveMenu = parentMenu
520
+ AnyMenuOpen = true
521
+ end
522
+ end)
523
+
524
+ local TextLabel = Instance.new("TextLabel")
525
+ TextLabel.Name = "TextLabel"
526
+ TextLabel.AutomaticSize = Enum.AutomaticSize.XY
527
+ TextLabel.BackgroundTransparency = 1
528
+ TextLabel.BorderSizePixel = 0
529
+
530
+ widgets.applyTextStyle(TextLabel)
531
+
532
+ TextLabel.Parent = MenuToggle
533
+
534
+ local Shortcut = Instance.new("TextLabel")
535
+ Shortcut.Name = "Shortcut"
536
+ Shortcut.AutomaticSize = Enum.AutomaticSize.XY
537
+ Shortcut.BackgroundTransparency = 1
538
+ Shortcut.BorderSizePixel = 0
539
+ Shortcut.LayoutOrder = 1
540
+
541
+ widgets.applyTextStyle(Shortcut)
542
+
543
+ Shortcut.Text = ""
544
+ Shortcut.TextColor3 = Iris._config.TextDisabledColor
545
+ Shortcut.TextTransparency = Iris._config.TextDisabledTransparency
546
+
547
+ Shortcut.Parent = MenuToggle
548
+
549
+ local frameSize = Iris._config.TextSize + 2 * Iris._config.FramePadding.Y
550
+ local padding = math.round(0.2 * frameSize)
551
+ local iconSize = frameSize - 2 * padding
552
+
553
+ local Icon = Instance.new("ImageLabel")
554
+ Icon.Name = "Icon"
555
+ Icon.Size = UDim2.fromOffset(iconSize, iconSize)
556
+ Icon.BackgroundTransparency = 1
557
+ Icon.BorderSizePixel = 0
558
+ Icon.ImageColor3 = Iris._config.TextColor
559
+ Icon.ImageTransparency = Iris._config.TextTransparency
560
+ Icon.Image = widgets.ICONS.CHECKMARK
561
+ Icon.LayoutOrder = 2
562
+
563
+ Icon.Parent = MenuToggle
564
+
565
+ return MenuToggle
566
+ end,
567
+ GenerateState = function(thisWidget: Types.MenuToggle)
568
+ if thisWidget.state.isChecked == nil then
569
+ thisWidget.state.isChecked = Iris._widgetState(thisWidget, "isChecked", false)
570
+ end
571
+ end,
572
+ Update = function(thisWidget: Types.MenuToggle)
573
+ local MenuToggle = thisWidget.Instance :: TextButton
574
+ local TextLabel: TextLabel = MenuToggle.TextLabel
575
+ local Shortcut: TextLabel = MenuToggle.Shortcut
576
+
577
+ TextLabel.Text = thisWidget.arguments.Text
578
+ if thisWidget.arguments.KeyCode then
579
+ if thisWidget.arguments.ModifierKey then
580
+ Shortcut.Text = thisWidget.arguments.ModifierKey.Name .. " + " .. thisWidget.arguments.KeyCode.Name
581
+ else
582
+ Shortcut.Text = thisWidget.arguments.KeyCode.Name
583
+ end
584
+ end
585
+ end,
586
+ UpdateState = function(thisWidget: Types.MenuToggle)
587
+ local MenuItem = thisWidget.Instance :: TextButton
588
+ local Icon: ImageLabel = MenuItem.Icon
589
+
590
+ if thisWidget.state.isChecked.value then
591
+ Icon.ImageTransparency = Iris._config.TextTransparency
592
+ thisWidget.lastCheckedTick = Iris._cycleTick + 1
593
+ else
594
+ Icon.ImageTransparency = 1
595
+ thisWidget.lastUncheckedTick = Iris._cycleTick + 1
596
+ end
597
+ end,
598
+ Discard = function(thisWidget: Types.MenuToggle)
599
+ thisWidget.Instance:Destroy()
600
+ widgets.discardState(thisWidget)
601
+ end,
602
+ } :: Types.WidgetClass)
603
+ end