@quenty/iris 1.1.0 → 1.2.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.
@@ -1,642 +0,0 @@
1
- --!nocheck
2
- local Types = require(script.Parent.Parent.iris_Types)
3
-
4
- return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
5
- -- stylua: ignore
6
- Iris.WidgetConstructor("ProgressBar", {
7
- hasState = true,
8
- hasChildren = false,
9
- Args = {
10
- ["Text"] = 1,
11
- ["Format"] = 2,
12
- },
13
- Events = {
14
- ["hovered"] = widgets.EVENTS.hover(function(thisWidget: Types.Widget)
15
- return thisWidget.Instance
16
- end),
17
- ["changed"] = {
18
- ["Init"] = function(_thisWidget: Types.ProgressBar) end,
19
- ["Get"] = function(thisWidget: Types.ProgressBar)
20
- return thisWidget.lastChangedTick == Iris._cycleTick
21
- end,
22
- },
23
- },
24
- Generate = function(_thisWidget: Types.ProgressBar)
25
- local ProgressBar = Instance.new("Frame")
26
- ProgressBar.Name = "Iris_ProgressBar"
27
- ProgressBar.AutomaticSize = Enum.AutomaticSize.Y
28
- ProgressBar.Size = UDim2.new(Iris._config.ItemWidth, UDim.new())
29
- ProgressBar.BackgroundTransparency = 1
30
-
31
- widgets.UIListLayout(ProgressBar, Enum.FillDirection.Horizontal, UDim.new(0, Iris._config.ItemInnerSpacing.X)).VerticalAlignment = Enum.VerticalAlignment.Center
32
-
33
- local Bar = Instance.new("Frame")
34
- Bar.Name = "Bar"
35
- Bar.AutomaticSize = Enum.AutomaticSize.Y
36
- Bar.Size = UDim2.new(Iris._config.ContentWidth, Iris._config.ContentHeight)
37
- Bar.BackgroundColor3 = Iris._config.FrameBgColor
38
- Bar.BackgroundTransparency = Iris._config.FrameBgTransparency
39
- Bar.BorderSizePixel = 0
40
- Bar.ClipsDescendants = true
41
-
42
- widgets.applyFrameStyle(Bar, true)
43
-
44
- Bar.Parent = ProgressBar
45
-
46
- local Progress = Instance.new("TextLabel")
47
- Progress.Name = "Progress"
48
- Progress.AutomaticSize = Enum.AutomaticSize.Y
49
- Progress.Size = UDim2.new(UDim.new(0, 0), Iris._config.ContentHeight)
50
- Progress.BackgroundColor3 = Iris._config.PlotHistogramColor
51
- Progress.BackgroundTransparency = Iris._config.PlotHistogramTransparency
52
- Progress.BorderSizePixel = 0
53
-
54
- widgets.applyTextStyle(Progress)
55
- widgets.UIPadding(Progress, Iris._config.FramePadding)
56
- widgets.UICorner(Progress, Iris._config.FrameRounding)
57
-
58
- Progress.Text = ""
59
- Progress.Parent = Bar
60
-
61
- local Value = Instance.new("TextLabel")
62
- Value.Name = "Value"
63
- Value.AutomaticSize = Enum.AutomaticSize.XY
64
- Value.Size = UDim2.new(UDim.new(0, 0), Iris._config.ContentHeight)
65
- Value.BackgroundTransparency = 1
66
- Value.BorderSizePixel = 0
67
- Value.ZIndex = 1
68
-
69
- widgets.applyTextStyle(Value)
70
- widgets.UIPadding(Value, Iris._config.FramePadding)
71
-
72
- Value.Parent = Bar
73
-
74
- local TextLabel = Instance.new("TextLabel")
75
- TextLabel.Name = "TextLabel"
76
- TextLabel.AutomaticSize = Enum.AutomaticSize.XY
77
- TextLabel.AnchorPoint = Vector2.new(0, 0.5)
78
- TextLabel.BackgroundTransparency = 1
79
- TextLabel.BorderSizePixel = 0
80
- TextLabel.LayoutOrder = 1
81
-
82
- widgets.applyTextStyle(TextLabel)
83
- widgets.UIPadding(Value, Iris._config.FramePadding)
84
-
85
- TextLabel.Parent = ProgressBar
86
-
87
- return ProgressBar
88
- end,
89
- GenerateState = function(thisWidget: Types.ProgressBar)
90
- if thisWidget.state.progress == nil then
91
- thisWidget.state.progress = Iris._widgetState(thisWidget, "Progress", 0)
92
- end
93
- end,
94
- Update = function(thisWidget: Types.ProgressBar)
95
- local Progress = thisWidget.Instance :: Frame
96
- local TextLabel: TextLabel = Progress.TextLabel
97
- local Bar = Progress.Bar :: Frame
98
- local Value: TextLabel = Bar.Value
99
-
100
- if thisWidget.arguments.Format ~= nil and typeof(thisWidget.arguments.Format) == "string" then
101
- Value.Text = thisWidget.arguments.Format
102
- end
103
-
104
- TextLabel.Text = thisWidget.arguments.Text or "Progress Bar"
105
- end,
106
- UpdateState = function(thisWidget: Types.ProgressBar)
107
- local ProgressBar = thisWidget.Instance :: Frame
108
- local Bar = ProgressBar.Bar :: Frame
109
- local Progress: TextLabel = Bar.Progress
110
- local Value: TextLabel = Bar.Value
111
-
112
- local progress = math.clamp(thisWidget.state.progress.value, 0, 1)
113
- local totalWidth = Bar.AbsoluteSize.X
114
- local textWidth = Value.AbsoluteSize.X
115
- if totalWidth * (1 - progress) < textWidth then
116
- Value.AnchorPoint = Vector2.xAxis
117
- Value.Position = UDim2.fromScale(1, 0)
118
- else
119
- Value.AnchorPoint = Vector2.zero
120
- Value.Position = UDim2.fromScale(progress, 0)
121
- end
122
-
123
- Progress.Size = UDim2.new(UDim.new(progress, 0), Progress.Size.Height)
124
- if thisWidget.arguments.Format ~= nil and typeof(thisWidget.arguments.Format) == "string" then
125
- Value.Text = thisWidget.arguments.Format
126
- else
127
- Value.Text = string.format("%d%%", progress * 100)
128
- end
129
- thisWidget.lastChangedTick = Iris._cycleTick + 1
130
- end,
131
- Discard = function(thisWidget: Types.ProgressBar)
132
- thisWidget.Instance:Destroy()
133
- widgets.discardState(thisWidget)
134
- end,
135
- } :: Types.WidgetClass)
136
-
137
- local function createLine(parent: Frame, index: number)
138
- local Block = Instance.new("Frame")
139
- Block.Name = tostring(index)
140
- Block.AnchorPoint = Vector2.new(0.5, 0.5)
141
- Block.BackgroundColor3 = Iris._config.PlotLinesColor
142
- Block.BackgroundTransparency = Iris._config.PlotLinesTransparency
143
- Block.BorderSizePixel = 0
144
-
145
- Block.Parent = parent
146
-
147
- return Block
148
- end
149
-
150
- local function clearLine(thisWidget: Types.PlotLines)
151
- if thisWidget.HoveredLine then
152
- thisWidget.HoveredLine.BackgroundColor3 = Iris._config.PlotLinesColor
153
- thisWidget.HoveredLine.BackgroundTransparency = Iris._config.PlotLinesTransparency
154
- thisWidget.HoveredLine = false
155
- thisWidget.state.hovered:set(nil)
156
- end
157
- end
158
-
159
- local function updateLine(thisWidget: Types.PlotLines, silent: true?)
160
- local PlotLines = thisWidget.Instance :: Frame
161
- local Background = PlotLines.Background :: Frame
162
- local Plot = Background.Plot :: Frame
163
-
164
- local mousePosition = widgets.getMouseLocation()
165
-
166
- local position = Plot.AbsolutePosition - widgets.GuiOffset
167
- local scale = (mousePosition.X - position.X) / Plot.AbsoluteSize.X
168
- local index = math.ceil(scale * #thisWidget.Lines)
169
- local line: Frame? = thisWidget.Lines[index]
170
-
171
- if line then
172
- if line ~= thisWidget.HoveredLine and not silent then
173
- clearLine(thisWidget)
174
- end
175
- local start: number? = thisWidget.state.values.value[index]
176
- local stop: number? = thisWidget.state.values.value[index + 1]
177
- if start and stop then
178
- if math.floor(start) == start and math.floor(stop) == stop then
179
- thisWidget.Tooltip.Text = ("%d: %d\n%d: %d"):format(index, start, index + 1, stop)
180
- else
181
- thisWidget.Tooltip.Text = ("%d: %.3f\n%d: %.3f"):format(index, start, index + 1, stop)
182
- end
183
- end
184
- thisWidget.HoveredLine = line
185
- line.BackgroundColor3 = Iris._config.PlotLinesHoveredColor
186
- line.BackgroundTransparency = Iris._config.PlotLinesHoveredTransparency
187
- if silent then
188
- thisWidget.state.hovered.value = { start, stop }
189
- else
190
- thisWidget.state.hovered:set({ start, stop })
191
- end
192
- end
193
- end
194
-
195
- -- stylua: ignore
196
- Iris.WidgetConstructor("PlotLines", {
197
- hasState = true,
198
- hasChildren = false,
199
- Args = {
200
- ["Text"] = 1,
201
- ["Height"] = 2,
202
- ["Min"] = 3,
203
- ["Max"] = 4,
204
- ["TextOverlay"] = 5,
205
- },
206
- Events = {
207
- ["hovered"] = widgets.EVENTS.hover(function(thisWidget: Types.Widget)
208
- return thisWidget.Instance
209
- end),
210
- },
211
- Generate = function(thisWidget: Types.PlotLines)
212
- local PlotLines = Instance.new("Frame")
213
- PlotLines.Name = "Iris_PlotLines"
214
- PlotLines.Size = UDim2.new(Iris._config.ItemWidth, UDim.new())
215
- PlotLines.BackgroundTransparency = 1
216
- PlotLines.BorderSizePixel = 0
217
-
218
- widgets.UIListLayout(PlotLines, Enum.FillDirection.Horizontal, UDim.new(0, Iris._config.ItemInnerSpacing.X)).VerticalAlignment = Enum.VerticalAlignment.Center
219
-
220
- local Background = Instance.new("Frame")
221
- Background.Name = "Background"
222
- Background.Size = UDim2.new(Iris._config.ContentWidth, UDim.new(1, 0))
223
- Background.BackgroundColor3 = Iris._config.FrameBgColor
224
- Background.BackgroundTransparency = Iris._config.FrameBgTransparency
225
- widgets.applyFrameStyle(Background)
226
-
227
- Background.Parent = PlotLines
228
-
229
- local Plot = Instance.new("Frame")
230
- Plot.Name = "Plot"
231
- Plot.Size = UDim2.fromScale(1, 1)
232
- Plot.BackgroundTransparency = 1
233
- Plot.BorderSizePixel = 0
234
- Plot.ClipsDescendants = true
235
-
236
- Plot:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
237
- thisWidget.state.values.lastChangeTick = Iris._cycleTick
238
- Iris._widgets.PlotLines.UpdateState(thisWidget)
239
- end)
240
-
241
- local OverlayText = Instance.new("TextLabel")
242
- OverlayText.Name = "OverlayText"
243
- OverlayText.AutomaticSize = Enum.AutomaticSize.XY
244
- OverlayText.AnchorPoint = Vector2.new(0.5, 0)
245
- OverlayText.Size = UDim2.fromOffset(0, 0)
246
- OverlayText.Position = UDim2.fromScale(0.5, 0)
247
- OverlayText.BackgroundTransparency = 1
248
- OverlayText.BorderSizePixel = 0
249
- OverlayText.ZIndex = 2
250
-
251
- widgets.applyTextStyle(OverlayText)
252
-
253
- OverlayText.Parent = Plot
254
-
255
- local Tooltip = Instance.new("TextLabel")
256
- Tooltip.Name = "Iris_Tooltip"
257
- Tooltip.AutomaticSize = Enum.AutomaticSize.XY
258
- Tooltip.Size = UDim2.fromOffset(0, 0)
259
- Tooltip.BackgroundColor3 = Iris._config.PopupBgColor
260
- Tooltip.BackgroundTransparency = Iris._config.PopupBgTransparency
261
- Tooltip.BorderSizePixel = 0
262
- Tooltip.Visible = false
263
-
264
- widgets.applyTextStyle(Tooltip)
265
- widgets.UIStroke(Tooltip, Iris._config.PopupBorderSize, Iris._config.BorderActiveColor, Iris._config.BorderActiveTransparency)
266
- widgets.UIPadding(Tooltip, Iris._config.WindowPadding)
267
- if Iris._config.PopupRounding > 0 then
268
- widgets.UICorner(Tooltip, Iris._config.PopupRounding)
269
- end
270
-
271
- local popup = Iris._rootInstance and Iris._rootInstance:FindFirstChild("PopupScreenGui")
272
- Tooltip.Parent = popup and popup:FindFirstChild("TooltipContainer")
273
-
274
- thisWidget.Tooltip = Tooltip
275
-
276
- widgets.applyMouseMoved(Plot, function()
277
- updateLine(thisWidget)
278
- end)
279
-
280
- widgets.applyMouseLeave(Plot, function()
281
- clearLine(thisWidget)
282
- end)
283
-
284
- Plot.Parent = Background
285
-
286
- thisWidget.Lines = {}
287
- thisWidget.HoveredLine = false
288
-
289
- local TextLabel = Instance.new("TextLabel")
290
- TextLabel.Name = "TextLabel"
291
- TextLabel.AutomaticSize = Enum.AutomaticSize.XY
292
- TextLabel.Size = UDim2.fromOffset(0, 0)
293
- TextLabel.BackgroundTransparency = 1
294
- TextLabel.BorderSizePixel = 0
295
- TextLabel.ZIndex = 3
296
- TextLabel.LayoutOrder = 3
297
-
298
- widgets.applyTextStyle(TextLabel)
299
-
300
- TextLabel.Parent = PlotLines
301
-
302
- return PlotLines
303
- end,
304
- GenerateState = function(thisWidget: Types.PlotLines)
305
- if thisWidget.state.values == nil then
306
- thisWidget.state.values = Iris._widgetState(thisWidget, "values", { 0, 1 })
307
- end
308
- if thisWidget.state.hovered == nil then
309
- thisWidget.state.hovered = Iris._widgetState(thisWidget, "hovered", nil)
310
- end
311
- end,
312
- Update = function(thisWidget: Types.PlotLines)
313
- local PlotLines = thisWidget.Instance :: Frame
314
- local TextLabel: TextLabel = PlotLines.TextLabel
315
- local Background = PlotLines.Background :: Frame
316
- local Plot = Background.Plot :: Frame
317
- local OverlayText: TextLabel = Plot.OverlayText
318
-
319
- TextLabel.Text = thisWidget.arguments.Text or "Plot Lines"
320
- OverlayText.Text = thisWidget.arguments.TextOverlay or ""
321
- PlotLines.Size = UDim2.new(1, 0, 0, thisWidget.arguments.Height or 0)
322
- end,
323
- UpdateState = function(thisWidget: Types.PlotLines)
324
- if thisWidget.state.hovered.lastChangeTick == Iris._cycleTick then
325
- if thisWidget.state.hovered.value then
326
- thisWidget.Tooltip.Visible = true
327
- else
328
- thisWidget.Tooltip.Visible = false
329
- end
330
- end
331
-
332
- if thisWidget.state.values.lastChangeTick == Iris._cycleTick then
333
- local PlotLines = thisWidget.Instance :: Frame
334
- local Background = PlotLines.Background :: Frame
335
- local Plot = Background.Plot :: Frame
336
-
337
- local values = thisWidget.state.values.value
338
- local count = #values - 1
339
- local numLines = #thisWidget.Lines
340
-
341
- local min = thisWidget.arguments.Min or math.huge
342
- local max = thisWidget.arguments.Max or -math.huge
343
-
344
- if min == nil or max == nil then
345
- for _, value in values do
346
- min = math.min(min, value)
347
- max = math.max(max, value)
348
- end
349
- end
350
-
351
- -- add or remove blocks depending on how many are needed
352
- if numLines < count then
353
- for index = numLines + 1, count do
354
- table.insert(thisWidget.Lines, createLine(Plot, index))
355
- end
356
- elseif numLines > count then
357
- for _ = count + 1, numLines do
358
- local line = table.remove(thisWidget.Lines)
359
- if line then
360
- line:Destroy()
361
- end
362
- end
363
- end
364
-
365
- local range = max - min
366
- local size = Plot.AbsoluteSize
367
-
368
- for index = 1, count do
369
- local start = values[index]
370
- local stop = values[index + 1]
371
- local a = size * Vector2.new((index - 1) / count, (max - start) / range)
372
- local b = size * Vector2.new(index / count, (max - stop) / range)
373
- local position = (a + b) / 2
374
-
375
- thisWidget.Lines[index].Size = UDim2.fromOffset((b - a).Magnitude + 1, 1)
376
- thisWidget.Lines[index].Position = UDim2.fromOffset(position.X, position.Y)
377
- thisWidget.Lines[index].Rotation = math.atan2(b.Y - a.Y, b.X - a.X) * (180 / math.pi)
378
- end
379
-
380
- -- only update the hovered block if it exists.
381
- if thisWidget.HoveredLine then
382
- updateLine(thisWidget, true)
383
- end
384
- end
385
- end,
386
- Discard = function(thisWidget: Types.PlotLines)
387
- thisWidget.Instance:Destroy()
388
- thisWidget.Tooltip:Destroy()
389
- widgets.discardState(thisWidget)
390
- end,
391
- } :: Types.WidgetClass)
392
-
393
- local function createBlock(parent: Frame, index: number)
394
- local Block = Instance.new("Frame")
395
- Block.Name = tostring(index)
396
- Block.BackgroundColor3 = Iris._config.PlotHistogramColor
397
- Block.BackgroundTransparency = Iris._config.PlotHistogramTransparency
398
- Block.BorderSizePixel = 0
399
-
400
- Block.Parent = parent
401
-
402
- return Block
403
- end
404
-
405
- local function clearBlock(thisWidget: Types.PlotHistogram)
406
- if thisWidget.HoveredBlock then
407
- thisWidget.HoveredBlock.BackgroundColor3 = Iris._config.PlotHistogramColor
408
- thisWidget.HoveredBlock.BackgroundTransparency = Iris._config.PlotHistogramTransparency
409
- thisWidget.HoveredBlock = false
410
- thisWidget.state.hovered:set(nil)
411
- end
412
- end
413
-
414
- local function updateBlock(thisWidget: Types.PlotHistogram, silent: true?)
415
- local PlotHistogram = thisWidget.Instance :: Frame
416
- local Background = PlotHistogram.Background :: Frame
417
- local Plot = Background.Plot :: Frame
418
-
419
- local mousePosition = widgets.getMouseLocation()
420
-
421
- local position = Plot.AbsolutePosition - widgets.GuiOffset
422
- local scale = (mousePosition.X - position.X) / Plot.AbsoluteSize.X
423
- local index = math.ceil(scale * #thisWidget.Blocks)
424
- local block: Frame? = thisWidget.Blocks[index]
425
-
426
- if block then
427
- if block ~= thisWidget.HoveredBlock and not silent then
428
- clearBlock(thisWidget)
429
- end
430
- local value: number? = thisWidget.state.values.value[index]
431
- if value then
432
- thisWidget.Tooltip.Text = if math.floor(value) == value
433
- then ("%d: %d"):format(index, value)
434
- else ("%d: %.3f"):format(index, value)
435
- end
436
- thisWidget.HoveredBlock = block
437
- block.BackgroundColor3 = Iris._config.PlotHistogramHoveredColor
438
- block.BackgroundTransparency = Iris._config.PlotHistogramHoveredTransparency
439
- if silent then
440
- thisWidget.state.hovered.value = value
441
- else
442
- thisWidget.state.hovered:set(value)
443
- end
444
- end
445
- end
446
-
447
- -- stylua: ignore
448
- Iris.WidgetConstructor("PlotHistogram", {
449
- hasState = true,
450
- hasChildren = false,
451
- Args = {
452
- ["Text"] = 1,
453
- ["Height"] = 2,
454
- ["Min"] = 3,
455
- ["Max"] = 4,
456
- ["TextOverlay"] = 5,
457
- ["BaseLine"] = 6,
458
- },
459
- Events = {
460
- ["hovered"] = widgets.EVENTS.hover(function(thisWidget: Types.Widget)
461
- return thisWidget.Instance
462
- end),
463
- },
464
- Generate = function(thisWidget: Types.PlotHistogram)
465
- local PlotHistogram = Instance.new("Frame")
466
- PlotHistogram.Name = "Iris_PlotHistogram"
467
- PlotHistogram.Size = UDim2.new(Iris._config.ItemWidth, UDim.new())
468
- PlotHistogram.BackgroundTransparency = 1
469
- PlotHistogram.BorderSizePixel = 0
470
-
471
- widgets.UIListLayout(PlotHistogram, Enum.FillDirection.Horizontal, UDim.new(0, Iris._config.ItemInnerSpacing.X)).VerticalAlignment = Enum.VerticalAlignment.Center
472
-
473
- local Background = Instance.new("Frame")
474
- Background.Name = "Background"
475
- Background.Size = UDim2.new(Iris._config.ContentWidth, UDim.new(1, 0))
476
- Background.BackgroundColor3 = Iris._config.FrameBgColor
477
- Background.BackgroundTransparency = Iris._config.FrameBgTransparency
478
- widgets.applyFrameStyle(Background)
479
-
480
- local UIPadding = (Background :: any).UIPadding
481
- UIPadding.PaddingRight = UDim.new(0, Iris._config.FramePadding.X - 1)
482
-
483
- Background.Parent = PlotHistogram
484
-
485
- local Plot = Instance.new("Frame")
486
- Plot.Name = "Plot"
487
- Plot.Size = UDim2.fromScale(1, 1)
488
- Plot.BackgroundTransparency = 1
489
- Plot.BorderSizePixel = 0
490
- Plot.ClipsDescendants = true
491
-
492
- local OverlayText = Instance.new("TextLabel")
493
- OverlayText.Name = "OverlayText"
494
- OverlayText.AutomaticSize = Enum.AutomaticSize.XY
495
- OverlayText.AnchorPoint = Vector2.new(0.5, 0)
496
- OverlayText.Size = UDim2.fromOffset(0, 0)
497
- OverlayText.Position = UDim2.fromScale(0.5, 0)
498
- OverlayText.BackgroundTransparency = 1
499
- OverlayText.BorderSizePixel = 0
500
- OverlayText.ZIndex = 2
501
-
502
- widgets.applyTextStyle(OverlayText)
503
-
504
- OverlayText.Parent = Plot
505
-
506
- local Tooltip = Instance.new("TextLabel")
507
- Tooltip.Name = "Iris_Tooltip"
508
- Tooltip.AutomaticSize = Enum.AutomaticSize.XY
509
- Tooltip.Size = UDim2.fromOffset(0, 0)
510
- Tooltip.BackgroundColor3 = Iris._config.PopupBgColor
511
- Tooltip.BackgroundTransparency = Iris._config.PopupBgTransparency
512
- Tooltip.BorderSizePixel = 0
513
- Tooltip.Visible = false
514
-
515
- widgets.applyTextStyle(Tooltip)
516
- widgets.UIStroke(Tooltip, Iris._config.PopupBorderSize, Iris._config.BorderActiveColor, Iris._config.BorderActiveTransparency)
517
- widgets.UIPadding(Tooltip, Iris._config.WindowPadding)
518
- if Iris._config.PopupRounding > 0 then
519
- widgets.UICorner(Tooltip, Iris._config.PopupRounding)
520
- end
521
-
522
- local popup = Iris._rootInstance and Iris._rootInstance:FindFirstChild("PopupScreenGui")
523
- Tooltip.Parent = popup and popup:FindFirstChild("TooltipContainer")
524
-
525
- thisWidget.Tooltip = Tooltip
526
-
527
- widgets.applyMouseMoved(Plot, function()
528
- updateBlock(thisWidget)
529
- end)
530
-
531
- widgets.applyMouseLeave(Plot, function()
532
- clearBlock(thisWidget)
533
- end)
534
-
535
- Plot.Parent = Background
536
-
537
- thisWidget.Blocks = {}
538
- thisWidget.HoveredBlock = false
539
-
540
- local TextLabel = Instance.new("TextLabel")
541
- TextLabel.Name = "TextLabel"
542
- TextLabel.AutomaticSize = Enum.AutomaticSize.XY
543
- TextLabel.Size = UDim2.fromOffset(0, 0)
544
- TextLabel.BackgroundTransparency = 1
545
- TextLabel.BorderSizePixel = 0
546
- TextLabel.ZIndex = 3
547
- TextLabel.LayoutOrder = 3
548
-
549
- widgets.applyTextStyle(TextLabel)
550
-
551
- TextLabel.Parent = PlotHistogram
552
-
553
- return PlotHistogram
554
- end,
555
- GenerateState = function(thisWidget: Types.PlotHistogram)
556
- if thisWidget.state.values == nil then
557
- thisWidget.state.values = Iris._widgetState(thisWidget, "values", { 1 })
558
- end
559
- if thisWidget.state.hovered == nil then
560
- thisWidget.state.hovered = Iris._widgetState(thisWidget, "hovered", nil)
561
- end
562
- end,
563
- Update = function(thisWidget: Types.PlotHistogram)
564
- local PlotLines = thisWidget.Instance :: Frame
565
- local TextLabel: TextLabel = PlotLines.TextLabel
566
- local Background = PlotLines.Background :: Frame
567
- local Plot = Background.Plot :: Frame
568
- local OverlayText: TextLabel = Plot.OverlayText
569
-
570
- TextLabel.Text = thisWidget.arguments.Text or "Plot Histogram"
571
- OverlayText.Text = thisWidget.arguments.TextOverlay or ""
572
- PlotLines.Size = UDim2.new(1, 0, 0, thisWidget.arguments.Height or 0)
573
- end,
574
- UpdateState = function(thisWidget: Types.PlotHistogram)
575
- if thisWidget.state.hovered.lastChangeTick == Iris._cycleTick then
576
- if thisWidget.state.hovered.value then
577
- thisWidget.Tooltip.Visible = true
578
- else
579
- thisWidget.Tooltip.Visible = false
580
- end
581
- end
582
-
583
- if thisWidget.state.values.lastChangeTick == Iris._cycleTick then
584
- local PlotHistogram = thisWidget.Instance :: Frame
585
- local Background = PlotHistogram.Background :: Frame
586
- local Plot = Background.Plot :: Frame
587
-
588
- local values = thisWidget.state.values.value
589
- local count = #values
590
- local numBlocks = #thisWidget.Blocks
591
-
592
- local min = thisWidget.arguments.Min or math.huge
593
- local max = thisWidget.arguments.Max or -math.huge
594
- local baseline = thisWidget.arguments.BaseLine or 0
595
-
596
- if min == nil or max == nil then
597
- for _, value in values do
598
- min = math.min(min or value, value)
599
- max = math.max(max or value, value)
600
- end
601
- end
602
-
603
- -- add or remove blocks depending on how many are needed
604
- if numBlocks < count then
605
- for index = numBlocks + 1, count do
606
- table.insert(thisWidget.Blocks, createBlock(Plot, index))
607
- end
608
- elseif numBlocks > count then
609
- for _ = count + 1, numBlocks do
610
- local block= table.remove(thisWidget.Blocks)
611
- if block then
612
- block:Destroy()
613
- end
614
- end
615
- end
616
-
617
- local range = max - min
618
- local width = UDim.new(1 / count, -1)
619
- for index = 1, count do
620
- local num = values[index]
621
- if num >= 0 then
622
- thisWidget.Blocks[index].Size = UDim2.new(width, UDim.new((num - baseline) / range))
623
- thisWidget.Blocks[index].Position = UDim2.fromScale((index - 1) / count, (max - num) / range)
624
- else
625
- thisWidget.Blocks[index].Size = UDim2.new(width, UDim.new((baseline - num) / range))
626
- thisWidget.Blocks[index].Position = UDim2.fromScale((index - 1) / count, (max - baseline) / range)
627
- end
628
- end
629
-
630
- -- only update the hovered block if it exists.
631
- if thisWidget.HoveredBlock then
632
- updateBlock(thisWidget, true)
633
- end
634
- end
635
- end,
636
- Discard = function(thisWidget: Types.PlotHistogram)
637
- thisWidget.Instance:Destroy()
638
- thisWidget.Tooltip:Destroy()
639
- widgets.discardState(thisWidget)
640
- end,
641
- } :: Types.WidgetClass)
642
- end