@quenty/iris 1.1.0 → 1.3.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.
- package/CHANGELOG.md +28 -4
- package/LICENSE.md +2 -3
- package/README.md +2 -12
- package/package.json +7 -8
- package/src/Shared/Immediate/IrisImmediateInstall.lua +194 -0
- package/src/Shared/IrisUtils.lua +11 -0
- package/src/node_modules.project.json +1 -1
- package/test/default.project.json +1 -1
- package/src/Shared/Iris.lua +0 -702
- package/src/Shared/iris_API.lua +0 -231
- package/src/Shared/iris_Internal.lua +0 -923
- package/src/Shared/iris_PubTypes.lua +0 -44
- package/src/Shared/iris_Types.lua +0 -674
- package/src/Shared/iris_WidgetTypes.lua +0 -522
- package/src/Shared/iris_config.lua +0 -306
- package/src/Shared/iris_demoWindow.lua +0 -2148
- package/src/Shared/widgets/iris_Button.lua +0 -91
- package/src/Shared/widgets/iris_Checkbox.lua +0 -116
- package/src/Shared/widgets/iris_Combo.lua +0 -498
- package/src/Shared/widgets/iris_Format.lua +0 -141
- package/src/Shared/widgets/iris_Image.lua +0 -156
- package/src/Shared/widgets/iris_Input.lua +0 -1430
- package/src/Shared/widgets/iris_Menu.lua +0 -603
- package/src/Shared/widgets/iris_Plot.lua +0 -642
- package/src/Shared/widgets/iris_RadioButton.lua +0 -127
- package/src/Shared/widgets/iris_Root.lua +0 -148
- package/src/Shared/widgets/iris_Tab.lua +0 -334
- package/src/Shared/widgets/iris_Table.lua +0 -641
- package/src/Shared/widgets/iris_Text.lua +0 -133
- package/src/Shared/widgets/iris_Tree.lua +0 -291
- package/src/Shared/widgets/iris_Window.lua +0 -1158
- package/src/Shared/widgets/iris_widgets.lua +0 -487
|
@@ -1,1430 +0,0 @@
|
|
|
1
|
-
--!nocheck
|
|
2
|
-
local Types = require(script.Parent.Parent.iris_Types)
|
|
3
|
-
|
|
4
|
-
type InputDataTypes =
|
|
5
|
-
"Num"
|
|
6
|
-
| "Vector2"
|
|
7
|
-
| "Vector3"
|
|
8
|
-
| "UDim"
|
|
9
|
-
| "UDim2"
|
|
10
|
-
| "Color3"
|
|
11
|
-
| "Color4"
|
|
12
|
-
| "Rect"
|
|
13
|
-
| "Enum"
|
|
14
|
-
| ""
|
|
15
|
-
| string
|
|
16
|
-
type InputType = "Input" | "Drag" | "Slider"
|
|
17
|
-
|
|
18
|
-
return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
|
|
19
|
-
local numberChanged = {
|
|
20
|
-
["Init"] = function(_thisWidget: Types.Widget) end,
|
|
21
|
-
["Get"] = function(thisWidget: Types.Input<any>)
|
|
22
|
-
return thisWidget.lastNumberChangedTick == Iris._cycleTick
|
|
23
|
-
end,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
local function getValueByIndex<T>(value: T, index: number, arguments: Types.Arguments)
|
|
27
|
-
local val = value :: unknown
|
|
28
|
-
if typeof(val) == "number" then
|
|
29
|
-
return val
|
|
30
|
-
elseif typeof(val) == "Vector2" then
|
|
31
|
-
if index == 1 then
|
|
32
|
-
return val.X
|
|
33
|
-
elseif index == 2 then
|
|
34
|
-
return val.Y
|
|
35
|
-
end
|
|
36
|
-
elseif typeof(val) == "Vector3" then
|
|
37
|
-
if index == 1 then
|
|
38
|
-
return val.X
|
|
39
|
-
elseif index == 2 then
|
|
40
|
-
return val.Y
|
|
41
|
-
elseif index == 3 then
|
|
42
|
-
return val.Z
|
|
43
|
-
end
|
|
44
|
-
elseif typeof(val) == "UDim" then
|
|
45
|
-
if index == 1 then
|
|
46
|
-
return val.Scale
|
|
47
|
-
elseif index == 2 then
|
|
48
|
-
return val.Offset
|
|
49
|
-
end
|
|
50
|
-
elseif typeof(val) == "UDim2" then
|
|
51
|
-
if index == 1 then
|
|
52
|
-
return val.X.Scale
|
|
53
|
-
elseif index == 2 then
|
|
54
|
-
return val.X.Offset
|
|
55
|
-
elseif index == 3 then
|
|
56
|
-
return val.Y.Scale
|
|
57
|
-
elseif index == 4 then
|
|
58
|
-
return val.Y.Offset
|
|
59
|
-
end
|
|
60
|
-
elseif typeof(val) == "Color3" then
|
|
61
|
-
local color = if arguments.UseHSV then { val:ToHSV() } else { val.R, val.G, val.B }
|
|
62
|
-
if index == 1 then
|
|
63
|
-
return color[1]
|
|
64
|
-
elseif index == 2 then
|
|
65
|
-
return color[2]
|
|
66
|
-
elseif index == 3 then
|
|
67
|
-
return color[3]
|
|
68
|
-
end
|
|
69
|
-
elseif typeof(val) == "Rect" then
|
|
70
|
-
if index == 1 then
|
|
71
|
-
return val.Min.X
|
|
72
|
-
elseif index == 2 then
|
|
73
|
-
return val.Min.Y
|
|
74
|
-
elseif index == 3 then
|
|
75
|
-
return val.Max.X
|
|
76
|
-
elseif index == 4 then
|
|
77
|
-
return val.Max.Y
|
|
78
|
-
end
|
|
79
|
-
elseif typeof(val) == "table" then
|
|
80
|
-
return val[index]
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
error(`Incorrect datatype or value: {value} {typeof(value)} {index}.`)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
local function updateValueByIndex<T>(value: T, index: number, newValue: number, arguments: Types.Arguments): T
|
|
87
|
-
local val = value :: unknown
|
|
88
|
-
if typeof(val) == "number" then
|
|
89
|
-
return newValue :: any
|
|
90
|
-
elseif typeof(val) == "Vector2" then
|
|
91
|
-
if index == 1 then
|
|
92
|
-
return Vector2.new(newValue, val.Y) :: any
|
|
93
|
-
elseif index == 2 then
|
|
94
|
-
return Vector2.new(val.X, newValue) :: any
|
|
95
|
-
end
|
|
96
|
-
elseif typeof(val) == "Vector3" then
|
|
97
|
-
if index == 1 then
|
|
98
|
-
return Vector3.new(newValue, val.Y, val.Z) :: any
|
|
99
|
-
elseif index == 2 then
|
|
100
|
-
return Vector3.new(val.X, newValue, val.Z) :: any
|
|
101
|
-
elseif index == 3 then
|
|
102
|
-
return Vector3.new(val.X, val.Y, newValue) :: any
|
|
103
|
-
end
|
|
104
|
-
elseif typeof(val) == "UDim" then
|
|
105
|
-
if index == 1 then
|
|
106
|
-
return UDim.new(newValue, val.Offset) :: any
|
|
107
|
-
elseif index == 2 then
|
|
108
|
-
return UDim.new(val.Scale, newValue) :: any
|
|
109
|
-
end
|
|
110
|
-
elseif typeof(val) == "UDim2" then
|
|
111
|
-
if index == 1 then
|
|
112
|
-
return UDim2.new(UDim.new(newValue, val.X.Offset), val.Y) :: any
|
|
113
|
-
elseif index == 2 then
|
|
114
|
-
return UDim2.new(UDim.new(val.X.Scale, newValue), val.Y) :: any
|
|
115
|
-
elseif index == 3 then
|
|
116
|
-
return UDim2.new(val.X, UDim.new(newValue, val.Y.Offset)) :: any
|
|
117
|
-
elseif index == 4 then
|
|
118
|
-
return UDim2.new(val.X, UDim.new(val.Y.Scale, newValue)) :: any
|
|
119
|
-
end
|
|
120
|
-
elseif typeof(val) == "Rect" then
|
|
121
|
-
if index == 1 then
|
|
122
|
-
return Rect.new(Vector2.new(newValue, val.Min.Y), val.Max) :: any
|
|
123
|
-
elseif index == 2 then
|
|
124
|
-
return Rect.new(Vector2.new(val.Min.X, newValue), val.Max) :: any
|
|
125
|
-
elseif index == 3 then
|
|
126
|
-
return Rect.new(val.Min, Vector2.new(newValue, val.Max.Y)) :: any
|
|
127
|
-
elseif index == 4 then
|
|
128
|
-
return Rect.new(val.Min, Vector2.new(val.Max.X, newValue)) :: any
|
|
129
|
-
end
|
|
130
|
-
elseif typeof(val) == "Color3" then
|
|
131
|
-
if arguments.UseHSV then
|
|
132
|
-
local h: number, s: number, v: number = val:ToHSV()
|
|
133
|
-
if index == 1 then
|
|
134
|
-
return Color3.fromHSV(newValue, s, v) :: any
|
|
135
|
-
elseif index == 2 then
|
|
136
|
-
return Color3.fromHSV(h, newValue, v) :: any
|
|
137
|
-
elseif index == 3 then
|
|
138
|
-
return Color3.fromHSV(h, s, newValue) :: any
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
if index == 1 then
|
|
142
|
-
return Color3.new(newValue, val.G, val.B) :: any
|
|
143
|
-
elseif index == 2 then
|
|
144
|
-
return Color3.new(val.R, newValue, val.B) :: any
|
|
145
|
-
elseif index == 3 then
|
|
146
|
-
return Color3.new(val.R, val.G, newValue) :: any
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
error(`Incorrect datatype or value {value} {typeof(value)} {index}.`)
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
local defaultIncrements: { [InputDataTypes]: { number } } = {
|
|
154
|
-
Num = { 1 },
|
|
155
|
-
Vector2 = { 1, 1 },
|
|
156
|
-
Vector3 = { 1, 1, 1 },
|
|
157
|
-
UDim = { 0.01, 1 },
|
|
158
|
-
UDim2 = { 0.01, 1, 0.01, 1 },
|
|
159
|
-
Color3 = { 1, 1, 1 },
|
|
160
|
-
Color4 = { 1, 1, 1, 1 },
|
|
161
|
-
Rect = { 1, 1, 1, 1 },
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
local defaultMin: { [InputDataTypes]: { number } } = {
|
|
165
|
-
Num = { 0 },
|
|
166
|
-
Vector2 = { 0, 0 },
|
|
167
|
-
Vector3 = { 0, 0, 0 },
|
|
168
|
-
UDim = { 0, 0 },
|
|
169
|
-
UDim2 = { 0, 0, 0, 0 },
|
|
170
|
-
Rect = { 0, 0, 0, 0 },
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
local defaultMax: { [InputDataTypes]: { number } } = {
|
|
174
|
-
Num = { 100 },
|
|
175
|
-
Vector2 = { 100, 100 },
|
|
176
|
-
Vector3 = { 100, 100, 100 },
|
|
177
|
-
UDim = { 1, 960 },
|
|
178
|
-
UDim2 = { 1, 960, 1, 960 },
|
|
179
|
-
Rect = { 960, 960, 960, 960 },
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
local defaultPrefx: { [InputDataTypes]: { string } } = {
|
|
183
|
-
Num = { "" },
|
|
184
|
-
Vector2 = { "X: ", "Y: " },
|
|
185
|
-
Vector3 = { "X: ", "Y: ", "Z: " },
|
|
186
|
-
UDim = { "", "" },
|
|
187
|
-
UDim2 = { "", "", "", "" },
|
|
188
|
-
Color3_RGB = { "R: ", "G: ", "B: " },
|
|
189
|
-
Color3_HSV = { "H: ", "S: ", "V: " },
|
|
190
|
-
Color4_RGB = { "R: ", "G: ", "B: ", "T: " },
|
|
191
|
-
Color4_HSV = { "H: ", "S: ", "V: ", "T: " },
|
|
192
|
-
Rect = { "X: ", "Y: ", "X: ", "Y: " },
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
local defaultSigFigs: { [InputDataTypes]: { number } } = {
|
|
196
|
-
Num = { 0 },
|
|
197
|
-
Vector2 = { 0, 0 },
|
|
198
|
-
Vector3 = { 0, 0, 0 },
|
|
199
|
-
UDim = { 3, 0 },
|
|
200
|
-
UDim2 = { 3, 0, 3, 0 },
|
|
201
|
-
Color3 = { 0, 0, 0 },
|
|
202
|
-
Color4 = { 0, 0, 0, 0 },
|
|
203
|
-
Rect = { 0, 0, 0, 0 },
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
local function generateAbstract<T>(
|
|
207
|
-
inputType: InputType,
|
|
208
|
-
dataType: InputDataTypes,
|
|
209
|
-
components: number,
|
|
210
|
-
defaultValue: T
|
|
211
|
-
): Types.WidgetClass
|
|
212
|
-
return {
|
|
213
|
-
hasState = true,
|
|
214
|
-
hasChildren = false,
|
|
215
|
-
Args = {
|
|
216
|
-
["Text"] = 1,
|
|
217
|
-
["Increment"] = 2,
|
|
218
|
-
["Min"] = 3,
|
|
219
|
-
["Max"] = 4,
|
|
220
|
-
["Format"] = 5,
|
|
221
|
-
},
|
|
222
|
-
Events = {
|
|
223
|
-
["numberChanged"] = numberChanged,
|
|
224
|
-
["hovered"] = widgets.EVENTS.hover(function(thisWidget: Types.Widget)
|
|
225
|
-
return thisWidget.Instance
|
|
226
|
-
end),
|
|
227
|
-
},
|
|
228
|
-
GenerateState = function(thisWidget: Types.Input<T>)
|
|
229
|
-
if thisWidget.state.number == nil then
|
|
230
|
-
thisWidget.state.number = Iris._widgetState(thisWidget, "number", defaultValue)
|
|
231
|
-
end
|
|
232
|
-
if thisWidget.state.editingText == nil then
|
|
233
|
-
thisWidget.state.editingText = Iris._widgetState(thisWidget, "editingText", 0)
|
|
234
|
-
end
|
|
235
|
-
end,
|
|
236
|
-
Update = function(thisWidget: Types.Input<T>)
|
|
237
|
-
local Input = thisWidget.Instance :: GuiObject
|
|
238
|
-
local TextLabel: TextLabel = Input.TextLabel
|
|
239
|
-
TextLabel.Text = thisWidget.arguments.Text or `Input {dataType}`
|
|
240
|
-
|
|
241
|
-
if thisWidget.arguments.Format and typeof(thisWidget.arguments.Format) ~= "table" then
|
|
242
|
-
thisWidget.arguments.Format = { thisWidget.arguments.Format }
|
|
243
|
-
elseif not thisWidget.arguments.Format then
|
|
244
|
-
-- we calculate the format for the s.f. using the max, min and increment arguments.
|
|
245
|
-
local format = {}
|
|
246
|
-
for index = 1, components do
|
|
247
|
-
local sigfigs = defaultSigFigs[dataType][index]
|
|
248
|
-
|
|
249
|
-
if thisWidget.arguments.Increment then
|
|
250
|
-
local value =
|
|
251
|
-
getValueByIndex(thisWidget.arguments.Increment, index, thisWidget.arguments :: any)
|
|
252
|
-
sigfigs = math.max(sigfigs, math.ceil(-math.log10(value == 0 and 1 or value)), sigfigs)
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
if thisWidget.arguments.Max then
|
|
256
|
-
local value = getValueByIndex(thisWidget.arguments.Max, index, thisWidget.arguments :: any)
|
|
257
|
-
sigfigs = math.max(sigfigs, math.ceil(-math.log10(value == 0 and 1 or value)), sigfigs)
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
if thisWidget.arguments.Min then
|
|
261
|
-
local value = getValueByIndex(thisWidget.arguments.Min, index, thisWidget.arguments :: any)
|
|
262
|
-
sigfigs = math.max(sigfigs, math.ceil(-math.log10(value == 0 and 1 or value)), sigfigs)
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
if sigfigs > 0 then
|
|
266
|
-
-- we know it's a float.
|
|
267
|
-
format[index] = `%.{sigfigs}f`
|
|
268
|
-
else
|
|
269
|
-
format[index] = "%d"
|
|
270
|
-
end
|
|
271
|
-
end
|
|
272
|
-
|
|
273
|
-
thisWidget.arguments.Format = format
|
|
274
|
-
thisWidget.arguments.Prefix = defaultPrefx[dataType]
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
if inputType == "Input" and dataType == "Num" then
|
|
278
|
-
Input.SubButton.Visible = not thisWidget.arguments.NoButtons
|
|
279
|
-
Input.AddButton.Visible = not thisWidget.arguments.NoButtons
|
|
280
|
-
local InputField: TextBox = Input.InputField1
|
|
281
|
-
local rightPadding = if thisWidget.arguments.NoButtons
|
|
282
|
-
then 0
|
|
283
|
-
else (2 * Iris._config.ItemInnerSpacing.X)
|
|
284
|
-
+ (2 * (Iris._config.TextSize + 2 * Iris._config.FramePadding.Y))
|
|
285
|
-
InputField.Size = UDim2.new(
|
|
286
|
-
UDim.new(Iris._config.ContentWidth.Scale, Iris._config.ContentWidth.Offset - rightPadding),
|
|
287
|
-
Iris._config.ContentHeight
|
|
288
|
-
)
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
if inputType == "Slider" then
|
|
292
|
-
for index = 1, components do
|
|
293
|
-
local SliderField = Input:FindFirstChild("SliderField" .. tostring(index)) :: TextButton
|
|
294
|
-
local GrabBar: Frame = SliderField.GrabBar
|
|
295
|
-
|
|
296
|
-
local increment = thisWidget.arguments.Increment
|
|
297
|
-
and getValueByIndex(thisWidget.arguments.Increment, index, thisWidget.arguments :: any)
|
|
298
|
-
or defaultIncrements[dataType][index]
|
|
299
|
-
local min = thisWidget.arguments.Min
|
|
300
|
-
and getValueByIndex(thisWidget.arguments.Min, index, thisWidget.arguments :: any)
|
|
301
|
-
or defaultMin[dataType][index]
|
|
302
|
-
local max = thisWidget.arguments.Max
|
|
303
|
-
and getValueByIndex(thisWidget.arguments.Max, index, thisWidget.arguments :: any)
|
|
304
|
-
or defaultMax[dataType][index]
|
|
305
|
-
|
|
306
|
-
local grabScaleSize = 1 / math.floor((1 + max - min) / increment)
|
|
307
|
-
|
|
308
|
-
GrabBar.Size = UDim2.fromScale(grabScaleSize, 1)
|
|
309
|
-
end
|
|
310
|
-
|
|
311
|
-
local callbackIndex = #Iris._postCycleCallbacks + 1
|
|
312
|
-
local desiredCycleTick = Iris._cycleTick + 1
|
|
313
|
-
Iris._postCycleCallbacks[callbackIndex] = function()
|
|
314
|
-
if Iris._cycleTick >= desiredCycleTick then
|
|
315
|
-
if thisWidget.lastCycleTick ~= -1 then
|
|
316
|
-
thisWidget.state.number.lastChangeTick = Iris._cycleTick
|
|
317
|
-
Iris._widgets[`Slider{dataType}`].UpdateState(thisWidget)
|
|
318
|
-
end
|
|
319
|
-
Iris._postCycleCallbacks[callbackIndex] = nil
|
|
320
|
-
end
|
|
321
|
-
end
|
|
322
|
-
end
|
|
323
|
-
end,
|
|
324
|
-
Discard = function(thisWidget: Types.Input<T>)
|
|
325
|
-
thisWidget.Instance:Destroy()
|
|
326
|
-
widgets.discardState(thisWidget)
|
|
327
|
-
end,
|
|
328
|
-
} :: Types.WidgetClass
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
local function focusLost<T>(thisWidget: Types.Input<T>, InputField: TextBox, index: number, dataType: InputDataTypes)
|
|
332
|
-
local newValue = tonumber(InputField.Text:match("-?%d*%.?%d*"))
|
|
333
|
-
local state = thisWidget.state.number
|
|
334
|
-
local widget = thisWidget
|
|
335
|
-
if dataType == "Color4" and index == 4 then
|
|
336
|
-
state = widget.state.transparency
|
|
337
|
-
elseif dataType == "Color3" or dataType == "Color4" then
|
|
338
|
-
state = widget.state.color
|
|
339
|
-
end
|
|
340
|
-
if newValue ~= nil then
|
|
341
|
-
if dataType == "Color3" or dataType == "Color4" and not widget.arguments.UseFloats then
|
|
342
|
-
newValue = newValue / 255
|
|
343
|
-
end
|
|
344
|
-
if thisWidget.arguments.Min ~= nil then
|
|
345
|
-
newValue =
|
|
346
|
-
math.max(newValue, getValueByIndex(thisWidget.arguments.Min, index, thisWidget.arguments :: any))
|
|
347
|
-
end
|
|
348
|
-
if thisWidget.arguments.Max ~= nil then
|
|
349
|
-
newValue =
|
|
350
|
-
math.min(newValue, getValueByIndex(thisWidget.arguments.Max, index, thisWidget.arguments :: any))
|
|
351
|
-
end
|
|
352
|
-
|
|
353
|
-
if thisWidget.arguments.Increment then
|
|
354
|
-
newValue = math.round(
|
|
355
|
-
newValue / getValueByIndex(thisWidget.arguments.Increment, index, thisWidget.arguments :: any)
|
|
356
|
-
) * getValueByIndex(thisWidget.arguments.Increment, index, thisWidget.arguments :: any)
|
|
357
|
-
end
|
|
358
|
-
|
|
359
|
-
state:set(updateValueByIndex(state.value, index, newValue, thisWidget.arguments :: any))
|
|
360
|
-
thisWidget.lastNumberChangedTick = Iris._cycleTick + 1
|
|
361
|
-
end
|
|
362
|
-
|
|
363
|
-
local value = getValueByIndex(state.value, index, thisWidget.arguments :: any)
|
|
364
|
-
if dataType == "Color3" or dataType == "Color4" and not widget.arguments.UseFloats then
|
|
365
|
-
value = math.round(value * 255)
|
|
366
|
-
end
|
|
367
|
-
|
|
368
|
-
local format = thisWidget.arguments.Format[index] or thisWidget.arguments.Format[1]
|
|
369
|
-
if thisWidget.arguments.Prefix then
|
|
370
|
-
format = thisWidget.arguments.Prefix[index] .. format
|
|
371
|
-
end
|
|
372
|
-
InputField.Text = string.format(format, value)
|
|
373
|
-
|
|
374
|
-
thisWidget.state.editingText:set(0)
|
|
375
|
-
InputField:ReleaseFocus(true)
|
|
376
|
-
end
|
|
377
|
-
|
|
378
|
-
--[[
|
|
379
|
-
Input
|
|
380
|
-
]]
|
|
381
|
-
local generateInputScalar: <T>(dataType: InputDataTypes, components: number, defaultValue: T) -> Types.WidgetClass
|
|
382
|
-
do
|
|
383
|
-
local function generateButtons(thisWidget: Types.Input<number>, parent: GuiObject, textHeight: number)
|
|
384
|
-
local SubButton = widgets.abstractButton.Generate(thisWidget) :: TextButton
|
|
385
|
-
SubButton.Name = "SubButton"
|
|
386
|
-
SubButton.Size =
|
|
387
|
-
UDim2.fromOffset(Iris._config.TextSize + 2 * Iris._config.FramePadding.Y, Iris._config.TextSize)
|
|
388
|
-
SubButton.Text = "-"
|
|
389
|
-
SubButton.TextXAlignment = Enum.TextXAlignment.Center
|
|
390
|
-
SubButton.ZIndex = 5
|
|
391
|
-
SubButton.LayoutOrder = 5
|
|
392
|
-
SubButton.Parent = parent
|
|
393
|
-
|
|
394
|
-
widgets.applyButtonClick(SubButton, function()
|
|
395
|
-
local isCtrlHeld = widgets.UserInputService:IsKeyDown(Enum.KeyCode.LeftControl)
|
|
396
|
-
or widgets.UserInputService:IsKeyDown(Enum.KeyCode.RightControl)
|
|
397
|
-
local changeValue = (
|
|
398
|
-
thisWidget.arguments.Increment
|
|
399
|
-
and getValueByIndex(thisWidget.arguments.Increment, 1, thisWidget.arguments :: Types.Argument)
|
|
400
|
-
or 1
|
|
401
|
-
) * (isCtrlHeld and 100 or 1)
|
|
402
|
-
local newValue = thisWidget.state.number.value - changeValue
|
|
403
|
-
if thisWidget.arguments.Min ~= nil then
|
|
404
|
-
newValue = math.max(
|
|
405
|
-
newValue,
|
|
406
|
-
getValueByIndex(thisWidget.arguments.Min, 1, thisWidget.arguments :: Types.Argument)
|
|
407
|
-
)
|
|
408
|
-
end
|
|
409
|
-
if thisWidget.arguments.Max ~= nil then
|
|
410
|
-
newValue = math.min(
|
|
411
|
-
newValue,
|
|
412
|
-
getValueByIndex(thisWidget.arguments.Max, 1, thisWidget.arguments :: Types.Argument)
|
|
413
|
-
)
|
|
414
|
-
end
|
|
415
|
-
thisWidget.state.number:set(newValue)
|
|
416
|
-
thisWidget.lastNumberChangedTick = Iris._cycleTick + 1
|
|
417
|
-
end)
|
|
418
|
-
|
|
419
|
-
local AddButton = widgets.abstractButton.Generate(thisWidget) :: TextButton
|
|
420
|
-
AddButton.Name = "AddButton"
|
|
421
|
-
AddButton.Size =
|
|
422
|
-
UDim2.fromOffset(Iris._config.TextSize + 2 * Iris._config.FramePadding.Y, Iris._config.TextSize)
|
|
423
|
-
AddButton.Text = "+"
|
|
424
|
-
AddButton.TextXAlignment = Enum.TextXAlignment.Center
|
|
425
|
-
AddButton.ZIndex = 6
|
|
426
|
-
AddButton.LayoutOrder = 6
|
|
427
|
-
AddButton.Parent = parent
|
|
428
|
-
|
|
429
|
-
widgets.applyButtonClick(AddButton, function()
|
|
430
|
-
local isCtrlHeld = widgets.UserInputService:IsKeyDown(Enum.KeyCode.LeftControl)
|
|
431
|
-
or widgets.UserInputService:IsKeyDown(Enum.KeyCode.RightControl)
|
|
432
|
-
local changeValue = (
|
|
433
|
-
thisWidget.arguments.Increment
|
|
434
|
-
and getValueByIndex(thisWidget.arguments.Increment, 1, thisWidget.arguments :: Types.Argument)
|
|
435
|
-
or 1
|
|
436
|
-
) * (isCtrlHeld and 100 or 1)
|
|
437
|
-
local newValue = thisWidget.state.number.value + changeValue
|
|
438
|
-
if thisWidget.arguments.Min ~= nil then
|
|
439
|
-
newValue = math.max(
|
|
440
|
-
newValue,
|
|
441
|
-
getValueByIndex(thisWidget.arguments.Min, 1, thisWidget.arguments :: Types.Argument)
|
|
442
|
-
)
|
|
443
|
-
end
|
|
444
|
-
if thisWidget.arguments.Max ~= nil then
|
|
445
|
-
newValue = math.min(
|
|
446
|
-
newValue,
|
|
447
|
-
getValueByIndex(thisWidget.arguments.Max, 1, thisWidget.arguments :: Types.Argument)
|
|
448
|
-
)
|
|
449
|
-
end
|
|
450
|
-
thisWidget.state.number:set(newValue)
|
|
451
|
-
thisWidget.lastNumberChangedTick = Iris._cycleTick + 1
|
|
452
|
-
end)
|
|
453
|
-
|
|
454
|
-
return 2 * Iris._config.ItemInnerSpacing.X + 2 * textHeight
|
|
455
|
-
end
|
|
456
|
-
|
|
457
|
-
local function generateField<T>(
|
|
458
|
-
thisWidget: Types.Input<T>,
|
|
459
|
-
index: number,
|
|
460
|
-
componentWidth: UDim,
|
|
461
|
-
dataType: InputDataTypes
|
|
462
|
-
)
|
|
463
|
-
local InputField = Instance.new("TextBox")
|
|
464
|
-
InputField.Name = "InputField" .. tostring(index)
|
|
465
|
-
InputField.AutomaticSize = Enum.AutomaticSize.Y
|
|
466
|
-
InputField.Size = UDim2.new(componentWidth, Iris._config.ContentHeight)
|
|
467
|
-
InputField.BackgroundColor3 = Iris._config.FrameBgColor
|
|
468
|
-
InputField.BackgroundTransparency = Iris._config.FrameBgTransparency
|
|
469
|
-
InputField.TextTruncate = Enum.TextTruncate.AtEnd
|
|
470
|
-
InputField.ClearTextOnFocus = false
|
|
471
|
-
InputField.ZIndex = index
|
|
472
|
-
InputField.LayoutOrder = index
|
|
473
|
-
InputField.ClipsDescendants = true
|
|
474
|
-
|
|
475
|
-
widgets.applyFrameStyle(InputField)
|
|
476
|
-
widgets.applyTextStyle(InputField)
|
|
477
|
-
widgets.UISizeConstraint(InputField, Vector2.xAxis)
|
|
478
|
-
|
|
479
|
-
InputField.FocusLost:Connect(function()
|
|
480
|
-
focusLost(thisWidget, InputField, index, dataType)
|
|
481
|
-
end)
|
|
482
|
-
|
|
483
|
-
InputField.Focused:Connect(function()
|
|
484
|
-
-- this highlights the entire field
|
|
485
|
-
InputField.CursorPosition = #InputField.Text + 1
|
|
486
|
-
InputField.SelectionStart = 1
|
|
487
|
-
|
|
488
|
-
thisWidget.state.editingText:set(index)
|
|
489
|
-
end)
|
|
490
|
-
|
|
491
|
-
return InputField
|
|
492
|
-
end
|
|
493
|
-
|
|
494
|
-
function generateInputScalar<T>(dataType: InputDataTypes, components: number, defaultValue: T)
|
|
495
|
-
local input = generateAbstract("Input", dataType, components, defaultValue)
|
|
496
|
-
|
|
497
|
-
return widgets.extend(input, {
|
|
498
|
-
Generate = function(thisWidget: Types.Input<T>)
|
|
499
|
-
local Input = Instance.new("Frame")
|
|
500
|
-
Input.Name = "Iris_Input" .. dataType
|
|
501
|
-
Input.AutomaticSize = Enum.AutomaticSize.Y
|
|
502
|
-
Input.Size = UDim2.new(Iris._config.ItemWidth, UDim.new())
|
|
503
|
-
Input.BackgroundTransparency = 1
|
|
504
|
-
Input.BorderSizePixel = 0
|
|
505
|
-
|
|
506
|
-
widgets.UIListLayout(
|
|
507
|
-
Input,
|
|
508
|
-
Enum.FillDirection.Horizontal,
|
|
509
|
-
UDim.new(0, Iris._config.ItemInnerSpacing.X)
|
|
510
|
-
).VerticalAlignment =
|
|
511
|
-
Enum.VerticalAlignment.Center
|
|
512
|
-
|
|
513
|
-
-- we add plus and minus buttons if there is only one box. This can be disabled through the argument.
|
|
514
|
-
local rightPadding = 0
|
|
515
|
-
local textHeight = Iris._config.TextSize + 2 * Iris._config.FramePadding.Y
|
|
516
|
-
|
|
517
|
-
if components == 1 then
|
|
518
|
-
rightPadding = generateButtons(thisWidget :: any, Input, textHeight)
|
|
519
|
-
end
|
|
520
|
-
|
|
521
|
-
-- we divide the total area evenly between each field. This includes accounting for any additional boxes and the offset.
|
|
522
|
-
-- for the final field, we make sure it's flush by calculating the space avaiable for it. This only makes the Vector2 box
|
|
523
|
-
-- 4 pixels shorter, all for the sake of flush.
|
|
524
|
-
local componentWidth = UDim.new(
|
|
525
|
-
Iris._config.ContentWidth.Scale / components,
|
|
526
|
-
(
|
|
527
|
-
Iris._config.ContentWidth.Offset
|
|
528
|
-
- (Iris._config.ItemInnerSpacing.X * (components - 1))
|
|
529
|
-
- rightPadding
|
|
530
|
-
) / components
|
|
531
|
-
)
|
|
532
|
-
local totalWidth = UDim.new(
|
|
533
|
-
componentWidth.Scale * (components - 1),
|
|
534
|
-
(componentWidth.Offset * (components - 1))
|
|
535
|
-
+ (Iris._config.ItemInnerSpacing.X * (components - 1))
|
|
536
|
-
+ rightPadding
|
|
537
|
-
)
|
|
538
|
-
local lastComponentWidth = Iris._config.ContentWidth - totalWidth
|
|
539
|
-
|
|
540
|
-
-- we handle each component individually since they don't need to interact with each other.
|
|
541
|
-
for index = 1, components do
|
|
542
|
-
generateField(
|
|
543
|
-
thisWidget,
|
|
544
|
-
index,
|
|
545
|
-
if index == components then lastComponentWidth else componentWidth,
|
|
546
|
-
dataType
|
|
547
|
-
).Parent =
|
|
548
|
-
Input
|
|
549
|
-
end
|
|
550
|
-
|
|
551
|
-
local TextLabel = Instance.new("TextLabel")
|
|
552
|
-
TextLabel.Name = "TextLabel"
|
|
553
|
-
TextLabel.AutomaticSize = Enum.AutomaticSize.XY
|
|
554
|
-
TextLabel.BackgroundTransparency = 1
|
|
555
|
-
TextLabel.BorderSizePixel = 0
|
|
556
|
-
TextLabel.LayoutOrder = 7
|
|
557
|
-
|
|
558
|
-
widgets.applyTextStyle(TextLabel)
|
|
559
|
-
|
|
560
|
-
TextLabel.Parent = Input
|
|
561
|
-
|
|
562
|
-
return Input
|
|
563
|
-
end,
|
|
564
|
-
UpdateState = function(thisWidget: Types.Input<T>)
|
|
565
|
-
local Input = thisWidget.Instance :: GuiObject
|
|
566
|
-
|
|
567
|
-
for index = 1, components do
|
|
568
|
-
local InputField: TextBox = Input:FindFirstChild("InputField" .. tostring(index))
|
|
569
|
-
local format = thisWidget.arguments.Format[index] or thisWidget.arguments.Format[1]
|
|
570
|
-
if thisWidget.arguments.Prefix then
|
|
571
|
-
format = thisWidget.arguments.Prefix[index] .. format
|
|
572
|
-
end
|
|
573
|
-
InputField.Text = string.format(
|
|
574
|
-
format,
|
|
575
|
-
getValueByIndex(thisWidget.state.number.value, index, thisWidget.arguments :: any)
|
|
576
|
-
)
|
|
577
|
-
end
|
|
578
|
-
end,
|
|
579
|
-
})
|
|
580
|
-
end
|
|
581
|
-
end
|
|
582
|
-
|
|
583
|
-
--[[
|
|
584
|
-
Drag
|
|
585
|
-
]]
|
|
586
|
-
local generateDragScalar: <T>(dataType: InputDataTypes, components: number, defaultValue: T) -> Types.WidgetClass
|
|
587
|
-
local generateColorDragScalar: (dataType: InputDataTypes, ...any) -> Types.WidgetClass
|
|
588
|
-
do
|
|
589
|
-
local PreviouseMouseXPosition = 0
|
|
590
|
-
local AnyActiveDrag = false
|
|
591
|
-
local ActiveDrag: Types.Input<Types.InputDataType>? = nil
|
|
592
|
-
local ActiveIndex = 0
|
|
593
|
-
local ActiveDataType: InputDataTypes | "" = ""
|
|
594
|
-
|
|
595
|
-
local function updateActiveDrag()
|
|
596
|
-
local currentMouseX = widgets.getMouseLocation().X
|
|
597
|
-
local mouseXDelta = currentMouseX - PreviouseMouseXPosition
|
|
598
|
-
PreviouseMouseXPosition = currentMouseX
|
|
599
|
-
if AnyActiveDrag == false then
|
|
600
|
-
return
|
|
601
|
-
end
|
|
602
|
-
if ActiveDrag == nil then
|
|
603
|
-
return
|
|
604
|
-
end
|
|
605
|
-
|
|
606
|
-
local state = ActiveDrag.state.number
|
|
607
|
-
if ActiveDataType == "Color3" or ActiveDataType == "Color4" then
|
|
608
|
-
local Drag = ActiveDrag
|
|
609
|
-
state = Drag.state.color
|
|
610
|
-
if ActiveIndex == 4 then
|
|
611
|
-
state = Drag.state.transparency
|
|
612
|
-
end
|
|
613
|
-
end
|
|
614
|
-
|
|
615
|
-
local increment = ActiveDrag.arguments.Increment
|
|
616
|
-
and getValueByIndex(ActiveDrag.arguments.Increment, ActiveIndex, ActiveDrag.arguments :: any)
|
|
617
|
-
or defaultIncrements[ActiveDataType][ActiveIndex]
|
|
618
|
-
increment *= (widgets.UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) or widgets.UserInputService:IsKeyDown(
|
|
619
|
-
Enum.KeyCode.RightShift
|
|
620
|
-
)) and 10 or 1
|
|
621
|
-
increment *= (widgets.UserInputService:IsKeyDown(Enum.KeyCode.LeftAlt) or widgets.UserInputService:IsKeyDown(
|
|
622
|
-
Enum.KeyCode.RightAlt
|
|
623
|
-
)) and 0.1 or 1
|
|
624
|
-
-- we increase the speed for Color3 and Color4 since it's too slow because the increment argument needs to be low.
|
|
625
|
-
increment *= (ActiveDataType == "Color3" or ActiveDataType == "Color4") and 5 or 1
|
|
626
|
-
|
|
627
|
-
local value = getValueByIndex(state.value, ActiveIndex, ActiveDrag.arguments :: any)
|
|
628
|
-
local newValue = value + (mouseXDelta * increment)
|
|
629
|
-
|
|
630
|
-
if ActiveDrag.arguments.Min ~= nil then
|
|
631
|
-
newValue = math.max(
|
|
632
|
-
newValue,
|
|
633
|
-
getValueByIndex(ActiveDrag.arguments.Min, ActiveIndex, ActiveDrag.arguments :: any)
|
|
634
|
-
)
|
|
635
|
-
end
|
|
636
|
-
if ActiveDrag.arguments.Max ~= nil then
|
|
637
|
-
newValue = math.min(
|
|
638
|
-
newValue,
|
|
639
|
-
getValueByIndex(ActiveDrag.arguments.Max, ActiveIndex, ActiveDrag.arguments :: any)
|
|
640
|
-
)
|
|
641
|
-
end
|
|
642
|
-
|
|
643
|
-
state:set(updateValueByIndex(state.value, ActiveIndex, newValue, ActiveDrag.arguments :: any))
|
|
644
|
-
ActiveDrag.lastNumberChangedTick = Iris._cycleTick + 1
|
|
645
|
-
end
|
|
646
|
-
|
|
647
|
-
local function DragMouseDown(
|
|
648
|
-
thisWidget: Types.Input<Types.InputDataType>,
|
|
649
|
-
dataTypes: InputDataTypes,
|
|
650
|
-
index: number,
|
|
651
|
-
x: number,
|
|
652
|
-
y: number
|
|
653
|
-
)
|
|
654
|
-
local currentTime = widgets.getTime()
|
|
655
|
-
local isTimeValid = currentTime - thisWidget.lastClickedTime < Iris._config.MouseDoubleClickTime
|
|
656
|
-
local isCtrlHeld = widgets.UserInputService:IsKeyDown(Enum.KeyCode.LeftControl)
|
|
657
|
-
or widgets.UserInputService:IsKeyDown(Enum.KeyCode.RightControl)
|
|
658
|
-
if
|
|
659
|
-
(
|
|
660
|
-
isTimeValid
|
|
661
|
-
and (Vector2.new(x, y) - thisWidget.lastClickedPosition).Magnitude
|
|
662
|
-
< Iris._config.MouseDoubleClickMaxDist
|
|
663
|
-
) or isCtrlHeld
|
|
664
|
-
then
|
|
665
|
-
thisWidget.state.editingText:set(index)
|
|
666
|
-
else
|
|
667
|
-
thisWidget.lastClickedTime = currentTime
|
|
668
|
-
thisWidget.lastClickedPosition = Vector2.new(x, y)
|
|
669
|
-
|
|
670
|
-
AnyActiveDrag = true
|
|
671
|
-
ActiveDrag = thisWidget
|
|
672
|
-
ActiveIndex = index
|
|
673
|
-
ActiveDataType = dataTypes
|
|
674
|
-
updateActiveDrag()
|
|
675
|
-
end
|
|
676
|
-
end
|
|
677
|
-
|
|
678
|
-
widgets.registerEvent("InputChanged", function()
|
|
679
|
-
if not Iris._started then
|
|
680
|
-
return
|
|
681
|
-
end
|
|
682
|
-
updateActiveDrag()
|
|
683
|
-
end)
|
|
684
|
-
|
|
685
|
-
widgets.registerEvent("InputEnded", function(inputObject: InputObject)
|
|
686
|
-
if not Iris._started then
|
|
687
|
-
return
|
|
688
|
-
end
|
|
689
|
-
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 and AnyActiveDrag then
|
|
690
|
-
AnyActiveDrag = false
|
|
691
|
-
ActiveDrag = nil
|
|
692
|
-
ActiveIndex = 0
|
|
693
|
-
end
|
|
694
|
-
end)
|
|
695
|
-
|
|
696
|
-
local function generateField<T>(
|
|
697
|
-
thisWidget: Types.Input<T>,
|
|
698
|
-
index: number,
|
|
699
|
-
componentSize: UDim2,
|
|
700
|
-
dataType: InputDataTypes
|
|
701
|
-
)
|
|
702
|
-
local DragField = Instance.new("TextButton")
|
|
703
|
-
DragField.Name = "DragField" .. tostring(index)
|
|
704
|
-
DragField.AutomaticSize = Enum.AutomaticSize.Y
|
|
705
|
-
DragField.Size = componentSize
|
|
706
|
-
DragField.BackgroundColor3 = Iris._config.FrameBgColor
|
|
707
|
-
DragField.BackgroundTransparency = Iris._config.FrameBgTransparency
|
|
708
|
-
DragField.Text = ""
|
|
709
|
-
DragField.AutoButtonColor = false
|
|
710
|
-
DragField.LayoutOrder = index
|
|
711
|
-
DragField.ClipsDescendants = true
|
|
712
|
-
|
|
713
|
-
widgets.applyFrameStyle(DragField)
|
|
714
|
-
widgets.applyTextStyle(DragField)
|
|
715
|
-
widgets.UISizeConstraint(DragField, Vector2.xAxis)
|
|
716
|
-
|
|
717
|
-
DragField.TextXAlignment = Enum.TextXAlignment.Center
|
|
718
|
-
|
|
719
|
-
widgets.applyInteractionHighlights("Background", DragField, DragField, {
|
|
720
|
-
Color = Iris._config.FrameBgColor,
|
|
721
|
-
Transparency = Iris._config.FrameBgTransparency,
|
|
722
|
-
HoveredColor = Iris._config.FrameBgHoveredColor,
|
|
723
|
-
HoveredTransparency = Iris._config.FrameBgHoveredTransparency,
|
|
724
|
-
ActiveColor = Iris._config.FrameBgActiveColor,
|
|
725
|
-
ActiveTransparency = Iris._config.FrameBgActiveTransparency,
|
|
726
|
-
})
|
|
727
|
-
|
|
728
|
-
local InputField = Instance.new("TextBox")
|
|
729
|
-
InputField.Name = "InputField"
|
|
730
|
-
InputField.Size = UDim2.fromScale(1, 1)
|
|
731
|
-
InputField.BackgroundTransparency = 1
|
|
732
|
-
InputField.ClearTextOnFocus = false
|
|
733
|
-
InputField.TextTruncate = Enum.TextTruncate.AtEnd
|
|
734
|
-
InputField.ClipsDescendants = true
|
|
735
|
-
InputField.Visible = false
|
|
736
|
-
|
|
737
|
-
widgets.applyFrameStyle(InputField, true)
|
|
738
|
-
widgets.applyTextStyle(InputField)
|
|
739
|
-
|
|
740
|
-
InputField.Parent = DragField
|
|
741
|
-
|
|
742
|
-
InputField.FocusLost:Connect(function()
|
|
743
|
-
focusLost(thisWidget, InputField, index, dataType)
|
|
744
|
-
end)
|
|
745
|
-
|
|
746
|
-
InputField.Focused:Connect(function()
|
|
747
|
-
-- this highlights the entire field
|
|
748
|
-
InputField.CursorPosition = #InputField.Text + 1
|
|
749
|
-
InputField.SelectionStart = 1
|
|
750
|
-
|
|
751
|
-
thisWidget.state.editingText:set(index)
|
|
752
|
-
end)
|
|
753
|
-
|
|
754
|
-
widgets.applyButtonDown(DragField, function(x: number, y: number)
|
|
755
|
-
DragMouseDown(thisWidget :: any, dataType, index, x, y)
|
|
756
|
-
end)
|
|
757
|
-
|
|
758
|
-
return DragField
|
|
759
|
-
end
|
|
760
|
-
|
|
761
|
-
function generateDragScalar<T>(dataType: InputDataTypes, components: number, defaultValue: T)
|
|
762
|
-
local input = generateAbstract("Drag", dataType, components, defaultValue)
|
|
763
|
-
|
|
764
|
-
return widgets.extend(input, {
|
|
765
|
-
Generate = function(thisWidget: Types.Input<T>)
|
|
766
|
-
thisWidget.lastClickedTime = -1
|
|
767
|
-
thisWidget.lastClickedPosition = Vector2.zero
|
|
768
|
-
|
|
769
|
-
local Drag = Instance.new("Frame")
|
|
770
|
-
Drag.Name = "Iris_Drag" .. dataType
|
|
771
|
-
Drag.AutomaticSize = Enum.AutomaticSize.Y
|
|
772
|
-
Drag.Size = UDim2.new(Iris._config.ItemWidth, UDim.new())
|
|
773
|
-
Drag.BackgroundTransparency = 1
|
|
774
|
-
Drag.BorderSizePixel = 0
|
|
775
|
-
|
|
776
|
-
widgets.UIListLayout(
|
|
777
|
-
Drag,
|
|
778
|
-
Enum.FillDirection.Horizontal,
|
|
779
|
-
UDim.new(0, Iris._config.ItemInnerSpacing.X)
|
|
780
|
-
).VerticalAlignment =
|
|
781
|
-
Enum.VerticalAlignment.Center
|
|
782
|
-
|
|
783
|
-
-- we add a color box if it is Color3 or Color4.
|
|
784
|
-
local rightPadding = 0
|
|
785
|
-
local textHeight = Iris._config.TextSize + 2 * Iris._config.FramePadding.Y
|
|
786
|
-
|
|
787
|
-
if dataType == "Color3" or dataType == "Color4" then
|
|
788
|
-
rightPadding += Iris._config.ItemInnerSpacing.X + textHeight
|
|
789
|
-
|
|
790
|
-
local ColorBox = Instance.new("ImageLabel")
|
|
791
|
-
ColorBox.Name = "ColorBox"
|
|
792
|
-
ColorBox.Size = UDim2.fromOffset(textHeight, textHeight)
|
|
793
|
-
ColorBox.BorderSizePixel = 0
|
|
794
|
-
ColorBox.Image = widgets.ICONS.ALPHA_BACKGROUND_TEXTURE
|
|
795
|
-
ColorBox.ImageTransparency = 1
|
|
796
|
-
ColorBox.LayoutOrder = 5
|
|
797
|
-
|
|
798
|
-
widgets.applyFrameStyle(ColorBox, true)
|
|
799
|
-
|
|
800
|
-
ColorBox.Parent = Drag
|
|
801
|
-
end
|
|
802
|
-
|
|
803
|
-
-- we divide the total area evenly between each field. This includes accounting for any additional boxes and the offset.
|
|
804
|
-
-- for the final field, we make sure it's flush by calculating the space avaiable for it. This only makes the Vector2 box
|
|
805
|
-
-- 4 pixels shorter, all for the sake of flush.
|
|
806
|
-
local componentWidth = UDim.new(
|
|
807
|
-
Iris._config.ContentWidth.Scale / components,
|
|
808
|
-
(
|
|
809
|
-
Iris._config.ContentWidth.Offset
|
|
810
|
-
- (Iris._config.ItemInnerSpacing.X * (components - 1))
|
|
811
|
-
- rightPadding
|
|
812
|
-
) / components
|
|
813
|
-
)
|
|
814
|
-
local totalWidth = UDim.new(
|
|
815
|
-
componentWidth.Scale * (components - 1),
|
|
816
|
-
(componentWidth.Offset * (components - 1))
|
|
817
|
-
+ (Iris._config.ItemInnerSpacing.X * (components - 1))
|
|
818
|
-
+ rightPadding
|
|
819
|
-
)
|
|
820
|
-
local lastComponentWidth = Iris._config.ContentWidth - totalWidth
|
|
821
|
-
|
|
822
|
-
for index = 1, components do
|
|
823
|
-
generateField(
|
|
824
|
-
thisWidget,
|
|
825
|
-
index,
|
|
826
|
-
if index == components
|
|
827
|
-
then UDim2.new(lastComponentWidth, Iris._config.ContentHeight)
|
|
828
|
-
else UDim2.new(componentWidth, Iris._config.ContentHeight),
|
|
829
|
-
dataType
|
|
830
|
-
).Parent =
|
|
831
|
-
Drag
|
|
832
|
-
end
|
|
833
|
-
|
|
834
|
-
local TextLabel = Instance.new("TextLabel")
|
|
835
|
-
TextLabel.Name = "TextLabel"
|
|
836
|
-
TextLabel.AutomaticSize = Enum.AutomaticSize.XY
|
|
837
|
-
TextLabel.BackgroundTransparency = 1
|
|
838
|
-
TextLabel.BorderSizePixel = 0
|
|
839
|
-
TextLabel.LayoutOrder = 6
|
|
840
|
-
|
|
841
|
-
widgets.applyTextStyle(TextLabel)
|
|
842
|
-
|
|
843
|
-
TextLabel.Parent = Drag
|
|
844
|
-
|
|
845
|
-
return Drag
|
|
846
|
-
end,
|
|
847
|
-
UpdateState = function(thisWidget: Types.Input<T>)
|
|
848
|
-
local Drag = thisWidget.Instance :: Frame
|
|
849
|
-
|
|
850
|
-
local widget = thisWidget :: any
|
|
851
|
-
for index = 1, components do
|
|
852
|
-
local state = thisWidget.state.number
|
|
853
|
-
if dataType == "Color3" or dataType == "Color4" then
|
|
854
|
-
state = widget.state.color
|
|
855
|
-
if index == 4 then
|
|
856
|
-
state = widget.state.transparency
|
|
857
|
-
end
|
|
858
|
-
end
|
|
859
|
-
local DragField = Drag:FindFirstChild("DragField" .. tostring(index)) :: TextButton
|
|
860
|
-
local InputField: TextBox = DragField.InputField
|
|
861
|
-
local value = getValueByIndex(state.value, index, thisWidget.arguments :: any)
|
|
862
|
-
if (dataType == "Color3" or dataType == "Color4") and not widget.arguments.UseFloats then
|
|
863
|
-
value = math.round(value * 255)
|
|
864
|
-
end
|
|
865
|
-
|
|
866
|
-
local format = thisWidget.arguments.Format[index] or thisWidget.arguments.Format[1]
|
|
867
|
-
if thisWidget.arguments.Prefix then
|
|
868
|
-
format = thisWidget.arguments.Prefix[index] .. format
|
|
869
|
-
end
|
|
870
|
-
DragField.Text = string.format(format, value)
|
|
871
|
-
InputField.Text = tostring(value)
|
|
872
|
-
|
|
873
|
-
if thisWidget.state.editingText.value == index then
|
|
874
|
-
InputField.Visible = true
|
|
875
|
-
InputField:CaptureFocus()
|
|
876
|
-
DragField.TextTransparency = 1
|
|
877
|
-
else
|
|
878
|
-
InputField.Visible = false
|
|
879
|
-
DragField.TextTransparency = Iris._config.TextTransparency
|
|
880
|
-
end
|
|
881
|
-
end
|
|
882
|
-
|
|
883
|
-
if dataType == "Color3" or dataType == "Color4" then
|
|
884
|
-
local ColorBox: ImageLabel = Drag.ColorBox
|
|
885
|
-
|
|
886
|
-
ColorBox.BackgroundColor3 = widget.state.color.value
|
|
887
|
-
|
|
888
|
-
if dataType == "Color4" then
|
|
889
|
-
ColorBox.ImageTransparency = 1 - widget.state.transparency.value
|
|
890
|
-
end
|
|
891
|
-
end
|
|
892
|
-
end,
|
|
893
|
-
})
|
|
894
|
-
end
|
|
895
|
-
|
|
896
|
-
function generateColorDragScalar(dataType: InputDataTypes, ...: any)
|
|
897
|
-
local defaultValues = { ... }
|
|
898
|
-
local input = generateDragScalar(dataType, dataType == "Color4" and 4 or 3, defaultValues[1])
|
|
899
|
-
|
|
900
|
-
return widgets.extend(input, {
|
|
901
|
-
Args = {
|
|
902
|
-
["Text"] = 1,
|
|
903
|
-
["UseFloats"] = 2,
|
|
904
|
-
["UseHSV"] = 3,
|
|
905
|
-
["Format"] = 4,
|
|
906
|
-
},
|
|
907
|
-
Update = function(thisWidget: Types.InputColor4)
|
|
908
|
-
local Input = thisWidget.Instance :: GuiObject
|
|
909
|
-
local TextLabel: TextLabel = Input.TextLabel
|
|
910
|
-
TextLabel.Text = thisWidget.arguments.Text or `Drag {dataType}`
|
|
911
|
-
|
|
912
|
-
if thisWidget.arguments.Format and typeof(thisWidget.arguments.Format) ~= "table" then
|
|
913
|
-
thisWidget.arguments.Format = { thisWidget.arguments.Format }
|
|
914
|
-
elseif not thisWidget.arguments.Format then
|
|
915
|
-
if thisWidget.arguments.UseFloats then
|
|
916
|
-
thisWidget.arguments.Format = { "%.3f" }
|
|
917
|
-
else
|
|
918
|
-
thisWidget.arguments.Format = { "%d" }
|
|
919
|
-
end
|
|
920
|
-
|
|
921
|
-
thisWidget.arguments.Prefix =
|
|
922
|
-
defaultPrefx[dataType .. if thisWidget.arguments.UseHSV then "_HSV" else "_RGB"]
|
|
923
|
-
end
|
|
924
|
-
|
|
925
|
-
thisWidget.arguments.Min = { 0, 0, 0, 0 }
|
|
926
|
-
thisWidget.arguments.Max = { 1, 1, 1, 1 }
|
|
927
|
-
thisWidget.arguments.Increment = { 0.001, 0.001, 0.001, 0.001 }
|
|
928
|
-
|
|
929
|
-
-- since the state values have changed display, we call an update. The check is because state is not
|
|
930
|
-
-- initialised on creation, so it would error otherwise.
|
|
931
|
-
if thisWidget.state then
|
|
932
|
-
thisWidget.state.color.lastChangeTick = Iris._cycleTick
|
|
933
|
-
if dataType == "Color4" then
|
|
934
|
-
thisWidget.state.transparency.lastChangeTick = Iris._cycleTick
|
|
935
|
-
end
|
|
936
|
-
Iris._widgets[thisWidget.type].UpdateState(thisWidget)
|
|
937
|
-
end
|
|
938
|
-
end,
|
|
939
|
-
GenerateState = function(thisWidget: Types.InputColor4)
|
|
940
|
-
if thisWidget.state.color == nil then
|
|
941
|
-
thisWidget.state.color = Iris._widgetState(thisWidget, "color", defaultValues[1])
|
|
942
|
-
end
|
|
943
|
-
if dataType == "Color4" then
|
|
944
|
-
if thisWidget.state.transparency == nil then
|
|
945
|
-
thisWidget.state.transparency =
|
|
946
|
-
Iris._widgetState(thisWidget, "transparency", defaultValues[2])
|
|
947
|
-
end
|
|
948
|
-
end
|
|
949
|
-
if thisWidget.state.editingText == nil then
|
|
950
|
-
thisWidget.state.editingText = Iris._widgetState(thisWidget, "editingText", false)
|
|
951
|
-
end
|
|
952
|
-
end,
|
|
953
|
-
})
|
|
954
|
-
end
|
|
955
|
-
end
|
|
956
|
-
|
|
957
|
-
--[[
|
|
958
|
-
Slider
|
|
959
|
-
]]
|
|
960
|
-
local generateSliderScalar: <T>(dataType: InputDataTypes, components: number, defaultValue: T) -> Types.WidgetClass
|
|
961
|
-
local generateEnumSliderScalar: (enum: Enum, item: EnumItem) -> Types.WidgetClass
|
|
962
|
-
do
|
|
963
|
-
local AnyActiveSlider = false
|
|
964
|
-
local ActiveSlider: Types.Input<Types.InputDataType>? = nil
|
|
965
|
-
local ActiveIndex = 0
|
|
966
|
-
local ActiveDataType: InputDataTypes | "" = ""
|
|
967
|
-
|
|
968
|
-
local function updateActiveSlider()
|
|
969
|
-
if AnyActiveSlider == false then
|
|
970
|
-
return
|
|
971
|
-
end
|
|
972
|
-
if ActiveSlider == nil then
|
|
973
|
-
return
|
|
974
|
-
end
|
|
975
|
-
|
|
976
|
-
local Slider = ActiveSlider.Instance :: Frame
|
|
977
|
-
local SliderField = Slider:FindFirstChild("SliderField" .. tostring(ActiveIndex)) :: TextButton
|
|
978
|
-
local GrabBar: Frame = SliderField.GrabBar
|
|
979
|
-
|
|
980
|
-
local increment = ActiveSlider.arguments.Increment
|
|
981
|
-
and getValueByIndex(ActiveSlider.arguments.Increment, ActiveIndex, ActiveSlider.arguments :: any)
|
|
982
|
-
or defaultIncrements[ActiveDataType][ActiveIndex]
|
|
983
|
-
local min = ActiveSlider.arguments.Min
|
|
984
|
-
and getValueByIndex(ActiveSlider.arguments.Min, ActiveIndex, ActiveSlider.arguments :: any)
|
|
985
|
-
or defaultMin[ActiveDataType][ActiveIndex]
|
|
986
|
-
local max = ActiveSlider.arguments.Max
|
|
987
|
-
and getValueByIndex(ActiveSlider.arguments.Max, ActiveIndex, ActiveSlider.arguments :: any)
|
|
988
|
-
or defaultMax[ActiveDataType][ActiveIndex]
|
|
989
|
-
|
|
990
|
-
local GrabWidth = GrabBar.AbsoluteSize.X
|
|
991
|
-
local Offset = widgets.getMouseLocation().X
|
|
992
|
-
- (SliderField.AbsolutePosition.X - widgets.GuiOffset.X + GrabWidth / 2)
|
|
993
|
-
local Ratio = Offset / (SliderField.AbsoluteSize.X - GrabWidth)
|
|
994
|
-
local Positions = math.floor((max - min) / increment)
|
|
995
|
-
local newValue = math.clamp(math.round(Ratio * Positions) * increment + min, min, max)
|
|
996
|
-
|
|
997
|
-
ActiveSlider.state.number:set(
|
|
998
|
-
updateValueByIndex(
|
|
999
|
-
ActiveSlider.state.number.value,
|
|
1000
|
-
ActiveIndex,
|
|
1001
|
-
newValue,
|
|
1002
|
-
ActiveSlider.arguments :: any
|
|
1003
|
-
)
|
|
1004
|
-
)
|
|
1005
|
-
ActiveSlider.lastNumberChangedTick = Iris._cycleTick + 1
|
|
1006
|
-
end
|
|
1007
|
-
|
|
1008
|
-
local function SliderMouseDown(
|
|
1009
|
-
thisWidget: Types.Input<Types.InputDataType>,
|
|
1010
|
-
dataType: InputDataTypes,
|
|
1011
|
-
index: number
|
|
1012
|
-
)
|
|
1013
|
-
local isCtrlHeld = widgets.UserInputService:IsKeyDown(Enum.KeyCode.LeftControl)
|
|
1014
|
-
or widgets.UserInputService:IsKeyDown(Enum.KeyCode.RightControl)
|
|
1015
|
-
if isCtrlHeld then
|
|
1016
|
-
thisWidget.state.editingText:set(index)
|
|
1017
|
-
else
|
|
1018
|
-
AnyActiveSlider = true
|
|
1019
|
-
ActiveSlider = thisWidget
|
|
1020
|
-
ActiveIndex = index
|
|
1021
|
-
ActiveDataType = dataType
|
|
1022
|
-
updateActiveSlider()
|
|
1023
|
-
end
|
|
1024
|
-
end
|
|
1025
|
-
|
|
1026
|
-
widgets.registerEvent("InputChanged", function()
|
|
1027
|
-
if not Iris._started then
|
|
1028
|
-
return
|
|
1029
|
-
end
|
|
1030
|
-
updateActiveSlider()
|
|
1031
|
-
end)
|
|
1032
|
-
|
|
1033
|
-
widgets.registerEvent("InputEnded", function(inputObject: InputObject)
|
|
1034
|
-
if not Iris._started then
|
|
1035
|
-
return
|
|
1036
|
-
end
|
|
1037
|
-
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 and AnyActiveSlider then
|
|
1038
|
-
AnyActiveSlider = false
|
|
1039
|
-
ActiveSlider = nil
|
|
1040
|
-
ActiveIndex = 0
|
|
1041
|
-
ActiveDataType = ""
|
|
1042
|
-
end
|
|
1043
|
-
end)
|
|
1044
|
-
|
|
1045
|
-
local function generateField<T>(
|
|
1046
|
-
thisWidget: Types.Input<T>,
|
|
1047
|
-
index: number,
|
|
1048
|
-
componentSize: UDim2,
|
|
1049
|
-
dataType: InputDataTypes
|
|
1050
|
-
)
|
|
1051
|
-
local SliderField = Instance.new("TextButton")
|
|
1052
|
-
SliderField.Name = "SliderField" .. tostring(index)
|
|
1053
|
-
SliderField.AutomaticSize = Enum.AutomaticSize.Y
|
|
1054
|
-
SliderField.Size = componentSize
|
|
1055
|
-
SliderField.BackgroundColor3 = Iris._config.FrameBgColor
|
|
1056
|
-
SliderField.BackgroundTransparency = Iris._config.FrameBgTransparency
|
|
1057
|
-
SliderField.Text = ""
|
|
1058
|
-
SliderField.AutoButtonColor = false
|
|
1059
|
-
SliderField.LayoutOrder = index
|
|
1060
|
-
SliderField.ClipsDescendants = true
|
|
1061
|
-
|
|
1062
|
-
widgets.applyFrameStyle(SliderField)
|
|
1063
|
-
widgets.applyTextStyle(SliderField)
|
|
1064
|
-
widgets.UISizeConstraint(SliderField, Vector2.xAxis)
|
|
1065
|
-
|
|
1066
|
-
local OverlayText = Instance.new("TextLabel")
|
|
1067
|
-
OverlayText.Name = "OverlayText"
|
|
1068
|
-
OverlayText.Size = UDim2.fromScale(1, 1)
|
|
1069
|
-
OverlayText.BackgroundTransparency = 1
|
|
1070
|
-
OverlayText.BorderSizePixel = 0
|
|
1071
|
-
OverlayText.ZIndex = 10
|
|
1072
|
-
OverlayText.ClipsDescendants = true
|
|
1073
|
-
|
|
1074
|
-
widgets.applyTextStyle(OverlayText)
|
|
1075
|
-
|
|
1076
|
-
OverlayText.TextXAlignment = Enum.TextXAlignment.Center
|
|
1077
|
-
|
|
1078
|
-
OverlayText.Parent = SliderField
|
|
1079
|
-
|
|
1080
|
-
widgets.applyInteractionHighlights("Background", SliderField, SliderField, {
|
|
1081
|
-
Color = Iris._config.FrameBgColor,
|
|
1082
|
-
Transparency = Iris._config.FrameBgTransparency,
|
|
1083
|
-
HoveredColor = Iris._config.FrameBgHoveredColor,
|
|
1084
|
-
HoveredTransparency = Iris._config.FrameBgHoveredTransparency,
|
|
1085
|
-
ActiveColor = Iris._config.FrameBgActiveColor,
|
|
1086
|
-
ActiveTransparency = Iris._config.FrameBgActiveTransparency,
|
|
1087
|
-
})
|
|
1088
|
-
|
|
1089
|
-
local InputField = Instance.new("TextBox")
|
|
1090
|
-
InputField.Name = "InputField"
|
|
1091
|
-
InputField.Size = UDim2.fromScale(1, 1)
|
|
1092
|
-
InputField.BackgroundTransparency = 1
|
|
1093
|
-
InputField.ClearTextOnFocus = false
|
|
1094
|
-
InputField.TextTruncate = Enum.TextTruncate.AtEnd
|
|
1095
|
-
InputField.ClipsDescendants = true
|
|
1096
|
-
InputField.Visible = false
|
|
1097
|
-
|
|
1098
|
-
widgets.applyFrameStyle(InputField, true)
|
|
1099
|
-
widgets.applyTextStyle(InputField)
|
|
1100
|
-
|
|
1101
|
-
InputField.Parent = SliderField
|
|
1102
|
-
|
|
1103
|
-
InputField.FocusLost:Connect(function()
|
|
1104
|
-
focusLost(thisWidget, InputField, index, dataType)
|
|
1105
|
-
end)
|
|
1106
|
-
|
|
1107
|
-
InputField.Focused:Connect(function()
|
|
1108
|
-
-- this highlights the entire field
|
|
1109
|
-
InputField.CursorPosition = #InputField.Text + 1
|
|
1110
|
-
InputField.SelectionStart = 1
|
|
1111
|
-
|
|
1112
|
-
thisWidget.state.editingText:set(index)
|
|
1113
|
-
end)
|
|
1114
|
-
|
|
1115
|
-
widgets.applyButtonDown(SliderField, function()
|
|
1116
|
-
SliderMouseDown(thisWidget :: any, dataType, index)
|
|
1117
|
-
end)
|
|
1118
|
-
|
|
1119
|
-
local GrabBar = Instance.new("Frame")
|
|
1120
|
-
GrabBar.Name = "GrabBar"
|
|
1121
|
-
GrabBar.AnchorPoint = Vector2.new(0.5, 0.5)
|
|
1122
|
-
GrabBar.Position = UDim2.fromScale(0, 0.5)
|
|
1123
|
-
GrabBar.BackgroundColor3 = Iris._config.SliderGrabColor
|
|
1124
|
-
GrabBar.Transparency = Iris._config.SliderGrabTransparency
|
|
1125
|
-
GrabBar.BorderSizePixel = 0
|
|
1126
|
-
GrabBar.ZIndex = 5
|
|
1127
|
-
|
|
1128
|
-
widgets.applyInteractionHighlights("Background", SliderField, GrabBar, {
|
|
1129
|
-
Color = Iris._config.SliderGrabColor,
|
|
1130
|
-
Transparency = Iris._config.SliderGrabTransparency,
|
|
1131
|
-
HoveredColor = Iris._config.SliderGrabColor,
|
|
1132
|
-
HoveredTransparency = Iris._config.SliderGrabTransparency,
|
|
1133
|
-
ActiveColor = Iris._config.SliderGrabActiveColor,
|
|
1134
|
-
ActiveTransparency = Iris._config.SliderGrabActiveTransparency,
|
|
1135
|
-
})
|
|
1136
|
-
|
|
1137
|
-
if Iris._config.GrabRounding > 0 then
|
|
1138
|
-
widgets.UICorner(GrabBar, Iris._config.GrabRounding)
|
|
1139
|
-
end
|
|
1140
|
-
|
|
1141
|
-
widgets.UISizeConstraint(GrabBar, Vector2.new(Iris._config.GrabMinSize, 0))
|
|
1142
|
-
|
|
1143
|
-
GrabBar.Parent = SliderField
|
|
1144
|
-
|
|
1145
|
-
return SliderField
|
|
1146
|
-
end
|
|
1147
|
-
|
|
1148
|
-
function generateSliderScalar<T>(dataType: InputDataTypes, components: number, defaultValue: T)
|
|
1149
|
-
local input = generateAbstract("Slider", dataType, components, defaultValue)
|
|
1150
|
-
|
|
1151
|
-
return widgets.extend(input, {
|
|
1152
|
-
Generate = function(thisWidget: Types.Input<T>)
|
|
1153
|
-
local Slider = Instance.new("Frame")
|
|
1154
|
-
Slider.Name = "Iris_Slider" .. dataType
|
|
1155
|
-
Slider.AutomaticSize = Enum.AutomaticSize.Y
|
|
1156
|
-
Slider.Size = UDim2.new(Iris._config.ItemWidth, UDim.new())
|
|
1157
|
-
Slider.BackgroundTransparency = 1
|
|
1158
|
-
Slider.BorderSizePixel = 0
|
|
1159
|
-
|
|
1160
|
-
widgets.UIListLayout(
|
|
1161
|
-
Slider,
|
|
1162
|
-
Enum.FillDirection.Horizontal,
|
|
1163
|
-
UDim.new(0, Iris._config.ItemInnerSpacing.X)
|
|
1164
|
-
).VerticalAlignment =
|
|
1165
|
-
Enum.VerticalAlignment.Center
|
|
1166
|
-
|
|
1167
|
-
-- we divide the total area evenly between each field. This includes accounting for any additional boxes and the offset.
|
|
1168
|
-
-- for the final field, we make sure it's flush by calculating the space avaiable for it. This only makes the Vector2 box
|
|
1169
|
-
-- 4 pixels shorter, all for the sake of flush.
|
|
1170
|
-
local componentWidth = UDim.new(
|
|
1171
|
-
Iris._config.ContentWidth.Scale / components,
|
|
1172
|
-
(Iris._config.ContentWidth.Offset - (Iris._config.ItemInnerSpacing.X * (components - 1)))
|
|
1173
|
-
/ components
|
|
1174
|
-
)
|
|
1175
|
-
local totalWidth = UDim.new(
|
|
1176
|
-
componentWidth.Scale * (components - 1),
|
|
1177
|
-
(componentWidth.Offset * (components - 1))
|
|
1178
|
-
+ (Iris._config.ItemInnerSpacing.X * (components - 1))
|
|
1179
|
-
)
|
|
1180
|
-
local lastComponentWidth = Iris._config.ContentWidth - totalWidth
|
|
1181
|
-
|
|
1182
|
-
for index = 1, components do
|
|
1183
|
-
generateField(
|
|
1184
|
-
thisWidget,
|
|
1185
|
-
index,
|
|
1186
|
-
if index == components
|
|
1187
|
-
then UDim2.new(lastComponentWidth, Iris._config.ContentHeight)
|
|
1188
|
-
else UDim2.new(componentWidth, Iris._config.ContentHeight),
|
|
1189
|
-
dataType
|
|
1190
|
-
).Parent =
|
|
1191
|
-
Slider
|
|
1192
|
-
end
|
|
1193
|
-
|
|
1194
|
-
local TextLabel = Instance.new("TextLabel")
|
|
1195
|
-
TextLabel.Name = "TextLabel"
|
|
1196
|
-
TextLabel.AutomaticSize = Enum.AutomaticSize.XY
|
|
1197
|
-
TextLabel.BackgroundTransparency = 1
|
|
1198
|
-
TextLabel.BorderSizePixel = 0
|
|
1199
|
-
TextLabel.LayoutOrder = 5
|
|
1200
|
-
|
|
1201
|
-
widgets.applyTextStyle(TextLabel)
|
|
1202
|
-
|
|
1203
|
-
TextLabel.Parent = Slider
|
|
1204
|
-
|
|
1205
|
-
return Slider
|
|
1206
|
-
end,
|
|
1207
|
-
UpdateState = function(thisWidget: Types.Input<T>)
|
|
1208
|
-
local Slider = thisWidget.Instance :: Frame
|
|
1209
|
-
|
|
1210
|
-
for index = 1, components do
|
|
1211
|
-
local SliderField = Slider:FindFirstChild("SliderField" .. tostring(index)) :: TextButton
|
|
1212
|
-
local InputField: TextBox = SliderField.InputField
|
|
1213
|
-
local OverlayText: TextLabel = SliderField.OverlayText
|
|
1214
|
-
local GrabBar: Frame = SliderField.GrabBar
|
|
1215
|
-
|
|
1216
|
-
local value = getValueByIndex(thisWidget.state.number.value, index, thisWidget.arguments :: any)
|
|
1217
|
-
local format = thisWidget.arguments.Format[index] or thisWidget.arguments.Format[1]
|
|
1218
|
-
if thisWidget.arguments.Prefix then
|
|
1219
|
-
format = thisWidget.arguments.Prefix[index] .. format
|
|
1220
|
-
end
|
|
1221
|
-
|
|
1222
|
-
OverlayText.Text = string.format(format, value)
|
|
1223
|
-
InputField.Text = tostring(value)
|
|
1224
|
-
|
|
1225
|
-
local increment = thisWidget.arguments.Increment
|
|
1226
|
-
and getValueByIndex(thisWidget.arguments.Increment, index, thisWidget.arguments :: any)
|
|
1227
|
-
or defaultIncrements[dataType][index]
|
|
1228
|
-
local min = thisWidget.arguments.Min
|
|
1229
|
-
and getValueByIndex(thisWidget.arguments.Min, index, thisWidget.arguments :: any)
|
|
1230
|
-
or defaultMin[dataType][index]
|
|
1231
|
-
local max = thisWidget.arguments.Max
|
|
1232
|
-
and getValueByIndex(thisWidget.arguments.Max, index, thisWidget.arguments :: any)
|
|
1233
|
-
or defaultMax[dataType][index]
|
|
1234
|
-
|
|
1235
|
-
local SliderWidth = SliderField.AbsoluteSize.X
|
|
1236
|
-
local PaddedWidth = SliderWidth - GrabBar.AbsoluteSize.X
|
|
1237
|
-
local Ratio = (value - min) / (max - min)
|
|
1238
|
-
local Positions = math.floor((max - min) / increment)
|
|
1239
|
-
local ClampedRatio = math.clamp(math.floor((Ratio * Positions)) / Positions, 0, 1)
|
|
1240
|
-
local PaddedRatio = ((PaddedWidth / SliderWidth) * ClampedRatio)
|
|
1241
|
-
+ ((1 - (PaddedWidth / SliderWidth)) / 2)
|
|
1242
|
-
|
|
1243
|
-
GrabBar.Position = UDim2.fromScale(PaddedRatio, 0.5)
|
|
1244
|
-
|
|
1245
|
-
if thisWidget.state.editingText.value == index then
|
|
1246
|
-
InputField.Visible = true
|
|
1247
|
-
OverlayText.Visible = false
|
|
1248
|
-
GrabBar.Visible = false
|
|
1249
|
-
InputField:CaptureFocus()
|
|
1250
|
-
else
|
|
1251
|
-
InputField.Visible = false
|
|
1252
|
-
OverlayText.Visible = true
|
|
1253
|
-
GrabBar.Visible = true
|
|
1254
|
-
end
|
|
1255
|
-
end
|
|
1256
|
-
end,
|
|
1257
|
-
})
|
|
1258
|
-
end
|
|
1259
|
-
|
|
1260
|
-
function generateEnumSliderScalar(enum: Enum, item: EnumItem)
|
|
1261
|
-
local input: Types.WidgetClass = generateSliderScalar("Enum", 1, item.Value)
|
|
1262
|
-
local valueToName = { string }
|
|
1263
|
-
|
|
1264
|
-
for _, enumItem in enum:GetEnumItems() do
|
|
1265
|
-
valueToName[enumItem.Value] = enumItem.Name
|
|
1266
|
-
end
|
|
1267
|
-
|
|
1268
|
-
return widgets.extend(input, {
|
|
1269
|
-
Args = {
|
|
1270
|
-
["Text"] = 1,
|
|
1271
|
-
},
|
|
1272
|
-
Update = function(thisWidget: Types.InputEnum)
|
|
1273
|
-
local Input = thisWidget.Instance :: GuiObject
|
|
1274
|
-
local TextLabel: TextLabel = Input.TextLabel
|
|
1275
|
-
TextLabel.Text = thisWidget.arguments.Text or "Input Enum"
|
|
1276
|
-
|
|
1277
|
-
thisWidget.arguments.Increment = 1
|
|
1278
|
-
thisWidget.arguments.Min = 0
|
|
1279
|
-
thisWidget.arguments.Max = #enum:GetEnumItems() - 1
|
|
1280
|
-
|
|
1281
|
-
local SliderField = Input:FindFirstChild("SliderField1") :: TextButton
|
|
1282
|
-
local GrabBar: Frame = SliderField.GrabBar
|
|
1283
|
-
|
|
1284
|
-
local grabScaleSize = 1 / math.floor(#enum:GetEnumItems())
|
|
1285
|
-
|
|
1286
|
-
GrabBar.Size = UDim2.fromScale(grabScaleSize, 1)
|
|
1287
|
-
end,
|
|
1288
|
-
GenerateState = function(thisWidget: Types.InputEnum)
|
|
1289
|
-
if thisWidget.state.number == nil then
|
|
1290
|
-
thisWidget.state.number = Iris._widgetState(thisWidget, "number", item.Value)
|
|
1291
|
-
end
|
|
1292
|
-
if thisWidget.state.enumItem == nil then
|
|
1293
|
-
thisWidget.state.enumItem = Iris._widgetState(thisWidget, "enumItem", item)
|
|
1294
|
-
end
|
|
1295
|
-
if thisWidget.state.editingText == nil then
|
|
1296
|
-
thisWidget.state.editingText = Iris._widgetState(thisWidget, "editingText", false)
|
|
1297
|
-
end
|
|
1298
|
-
end,
|
|
1299
|
-
})
|
|
1300
|
-
end
|
|
1301
|
-
end
|
|
1302
|
-
|
|
1303
|
-
do
|
|
1304
|
-
local inputNum: Types.WidgetClass = generateInputScalar("Num", 1, 0)
|
|
1305
|
-
inputNum.Args["NoButtons"] = 6
|
|
1306
|
-
Iris.WidgetConstructor("InputNum", inputNum)
|
|
1307
|
-
end
|
|
1308
|
-
Iris.WidgetConstructor("InputVector2", generateInputScalar("Vector2", 2, Vector2.zero))
|
|
1309
|
-
Iris.WidgetConstructor("InputVector3", generateInputScalar("Vector3", 3, Vector3.zero))
|
|
1310
|
-
Iris.WidgetConstructor("InputUDim", generateInputScalar("UDim", 2, UDim.new()))
|
|
1311
|
-
Iris.WidgetConstructor("InputUDim2", generateInputScalar("UDim2", 4, UDim2.new()))
|
|
1312
|
-
Iris.WidgetConstructor("InputRect", generateInputScalar("Rect", 4, Rect.new(0, 0, 0, 0)))
|
|
1313
|
-
|
|
1314
|
-
Iris.WidgetConstructor("DragNum", generateDragScalar("Num", 1, 0))
|
|
1315
|
-
Iris.WidgetConstructor("DragVector2", generateDragScalar("Vector2", 2, Vector2.zero))
|
|
1316
|
-
Iris.WidgetConstructor("DragVector3", generateDragScalar("Vector3", 3, Vector3.zero))
|
|
1317
|
-
Iris.WidgetConstructor("DragUDim", generateDragScalar("UDim", 2, UDim.new()))
|
|
1318
|
-
Iris.WidgetConstructor("DragUDim2", generateDragScalar("UDim2", 4, UDim2.new()))
|
|
1319
|
-
Iris.WidgetConstructor("DragRect", generateDragScalar("Rect", 4, Rect.new(0, 0, 0, 0)))
|
|
1320
|
-
|
|
1321
|
-
Iris.WidgetConstructor("InputColor3", generateColorDragScalar("Color3", Color3.fromRGB(0, 0, 0)))
|
|
1322
|
-
Iris.WidgetConstructor("InputColor4", generateColorDragScalar("Color4", Color3.fromRGB(0, 0, 0), 0))
|
|
1323
|
-
|
|
1324
|
-
Iris.WidgetConstructor("SliderNum", generateSliderScalar("Num", 1, 0))
|
|
1325
|
-
Iris.WidgetConstructor("SliderVector2", generateSliderScalar("Vector2", 2, Vector2.zero))
|
|
1326
|
-
Iris.WidgetConstructor("SliderVector3", generateSliderScalar("Vector3", 3, Vector3.zero))
|
|
1327
|
-
Iris.WidgetConstructor("SliderUDim", generateSliderScalar("UDim", 2, UDim.new()))
|
|
1328
|
-
Iris.WidgetConstructor("SliderUDim2", generateSliderScalar("UDim2", 4, UDim2.new()))
|
|
1329
|
-
Iris.WidgetConstructor("SliderRect", generateSliderScalar("Rect", 4, Rect.new(0, 0, 0, 0)))
|
|
1330
|
-
-- Iris.WidgetConstructor("SliderEnum", generateSliderScalar("Enum", 4, 0))
|
|
1331
|
-
|
|
1332
|
-
-- stylua: ignore
|
|
1333
|
-
Iris.WidgetConstructor("InputText", {
|
|
1334
|
-
hasState = true,
|
|
1335
|
-
hasChildren = false,
|
|
1336
|
-
Args = {
|
|
1337
|
-
["Text"] = 1,
|
|
1338
|
-
["TextHint"] = 2,
|
|
1339
|
-
["ReadOnly"] = 3,
|
|
1340
|
-
["MultiLine"] = 4,
|
|
1341
|
-
},
|
|
1342
|
-
Events = {
|
|
1343
|
-
["textChanged"] = {
|
|
1344
|
-
["Init"] = function(thisWidget: Types.InputText)
|
|
1345
|
-
thisWidget.lastTextChangedTick = 0
|
|
1346
|
-
end,
|
|
1347
|
-
["Get"] = function(thisWidget: Types.InputText)
|
|
1348
|
-
return thisWidget.lastTextChangedTick == Iris._cycleTick
|
|
1349
|
-
end,
|
|
1350
|
-
},
|
|
1351
|
-
["hovered"] = widgets.EVENTS.hover(function(thisWidget: Types.Widget)
|
|
1352
|
-
return thisWidget.Instance
|
|
1353
|
-
end),
|
|
1354
|
-
},
|
|
1355
|
-
Generate = function(thisWidget: Types.InputText)
|
|
1356
|
-
local InputText: Frame = Instance.new("Frame")
|
|
1357
|
-
InputText.Name = "Iris_InputText"
|
|
1358
|
-
InputText.AutomaticSize = Enum.AutomaticSize.Y
|
|
1359
|
-
InputText.Size = UDim2.new(Iris._config.ItemWidth, UDim.new())
|
|
1360
|
-
InputText.BackgroundTransparency = 1
|
|
1361
|
-
InputText.BorderSizePixel = 0
|
|
1362
|
-
widgets.UIListLayout(InputText, Enum.FillDirection.Horizontal, UDim.new(0, Iris._config.ItemInnerSpacing.X)).VerticalAlignment = Enum.VerticalAlignment.Center
|
|
1363
|
-
|
|
1364
|
-
local InputField: TextBox = Instance.new("TextBox")
|
|
1365
|
-
InputField.Name = "InputField"
|
|
1366
|
-
InputField.AutomaticSize = Enum.AutomaticSize.Y
|
|
1367
|
-
InputField.Size = UDim2.new(Iris._config.ContentWidth, Iris._config.ContentHeight)
|
|
1368
|
-
InputField.BackgroundColor3 = Iris._config.FrameBgColor
|
|
1369
|
-
InputField.BackgroundTransparency = Iris._config.FrameBgTransparency
|
|
1370
|
-
InputField.Text = ""
|
|
1371
|
-
InputField.TextYAlignment = Enum.TextYAlignment.Top
|
|
1372
|
-
InputField.PlaceholderColor3 = Iris._config.TextDisabledColor
|
|
1373
|
-
InputField.ClearTextOnFocus = false
|
|
1374
|
-
InputField.ClipsDescendants = true
|
|
1375
|
-
|
|
1376
|
-
widgets.applyFrameStyle(InputField)
|
|
1377
|
-
widgets.applyTextStyle(InputField)
|
|
1378
|
-
widgets.UISizeConstraint(InputField, Vector2.xAxis) -- prevents sizes beaking when getting too small.
|
|
1379
|
-
-- InputField.UIPadding.PaddingLeft = UDim.new(0, Iris._config.ItemInnerSpacing.X)
|
|
1380
|
-
-- InputField.UIPadding.PaddingRight = UDim.new(0, 0)
|
|
1381
|
-
InputField.Parent = InputText
|
|
1382
|
-
|
|
1383
|
-
InputField.FocusLost:Connect(function()
|
|
1384
|
-
thisWidget.state.text:set(InputField.Text)
|
|
1385
|
-
thisWidget.lastTextChangedTick = Iris._cycleTick + 1
|
|
1386
|
-
end)
|
|
1387
|
-
|
|
1388
|
-
local frameHeight: number = Iris._config.TextSize + 2 * Iris._config.FramePadding.Y
|
|
1389
|
-
|
|
1390
|
-
local TextLabel: TextLabel = Instance.new("TextLabel")
|
|
1391
|
-
TextLabel.Name = "TextLabel"
|
|
1392
|
-
TextLabel.AutomaticSize = Enum.AutomaticSize.X
|
|
1393
|
-
TextLabel.Size = UDim2.fromOffset(0, frameHeight)
|
|
1394
|
-
TextLabel.BackgroundTransparency = 1
|
|
1395
|
-
TextLabel.BorderSizePixel = 0
|
|
1396
|
-
TextLabel.LayoutOrder = 1
|
|
1397
|
-
|
|
1398
|
-
widgets.applyTextStyle(TextLabel)
|
|
1399
|
-
|
|
1400
|
-
TextLabel.Parent = InputText
|
|
1401
|
-
|
|
1402
|
-
return InputText
|
|
1403
|
-
end,
|
|
1404
|
-
GenerateState = function(thisWidget: Types.InputText)
|
|
1405
|
-
if thisWidget.state.text == nil then
|
|
1406
|
-
thisWidget.state.text = Iris._widgetState(thisWidget, "text", "")
|
|
1407
|
-
end
|
|
1408
|
-
end,
|
|
1409
|
-
Update = function(thisWidget: Types.InputText)
|
|
1410
|
-
local InputText = thisWidget.Instance :: Frame
|
|
1411
|
-
local TextLabel: TextLabel = InputText.TextLabel
|
|
1412
|
-
local InputField: TextBox = InputText.InputField
|
|
1413
|
-
|
|
1414
|
-
TextLabel.Text = thisWidget.arguments.Text or "Input Text"
|
|
1415
|
-
InputField.PlaceholderText = thisWidget.arguments.TextHint or ""
|
|
1416
|
-
InputField.TextEditable = not thisWidget.arguments.ReadOnly
|
|
1417
|
-
InputField.MultiLine = thisWidget.arguments.MultiLine or false
|
|
1418
|
-
end,
|
|
1419
|
-
UpdateState = function(thisWidget: Types.InputText)
|
|
1420
|
-
local InputText = thisWidget.Instance :: Frame
|
|
1421
|
-
local InputField: TextBox = InputText.InputField
|
|
1422
|
-
|
|
1423
|
-
InputField.Text = thisWidget.state.text.value
|
|
1424
|
-
end,
|
|
1425
|
-
Discard = function(thisWidget: Types.InputText)
|
|
1426
|
-
thisWidget.Instance:Destroy()
|
|
1427
|
-
widgets.discardState(thisWidget)
|
|
1428
|
-
end,
|
|
1429
|
-
} :: Types.WidgetClass)
|
|
1430
|
-
end
|