@quenty/colorpicker 10.4.0 → 10.4.1-canary.472.c5ee856.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 CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [10.4.1-canary.472.c5ee856.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpicker@10.4.0...@quenty/colorpicker@10.4.1-canary.472.c5ee856.0) (2024-05-13)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Fix drag model in color picker code ([a46b6fd](https://github.com/Quenty/NevermoreEngine/commit/a46b6fd06a7a385cdbca1ec6e6102becd499e579))
12
+
13
+
14
+
15
+
16
+
6
17
  # [10.4.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpicker@10.3.0...@quenty/colorpicker@10.4.0) (2024-05-09)
7
18
 
8
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/colorpicker",
3
- "version": "10.4.0",
3
+ "version": "10.4.1-canary.472.c5ee856.0",
4
4
  "description": "Color picking UI system for Roblox.",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -28,17 +28,17 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@quenty/baseobject": "^10.3.0",
32
- "@quenty/basicpane": "^13.3.0",
33
- "@quenty/blend": "^12.3.0",
34
- "@quenty/buttondragmodel": "^1.1.0",
35
- "@quenty/color3utils": "^11.3.0",
36
- "@quenty/inputobjectutils": "^4.4.0",
37
- "@quenty/instanceutils": "^13.3.0",
38
- "@quenty/loader": "^10.3.0",
39
- "@quenty/maid": "^3.2.0",
40
- "@quenty/math": "^2.7.0",
41
- "@quenty/valueobject": "^13.3.0"
31
+ "@quenty/baseobject": "10.3.0",
32
+ "@quenty/basicpane": "13.3.0",
33
+ "@quenty/blend": "12.3.0",
34
+ "@quenty/buttondragmodel": "1.1.1-canary.472.c5ee856.0",
35
+ "@quenty/color3utils": "11.3.0",
36
+ "@quenty/inputobjectutils": "4.4.0",
37
+ "@quenty/instanceutils": "13.3.0",
38
+ "@quenty/loader": "10.3.0",
39
+ "@quenty/maid": "3.2.0",
40
+ "@quenty/math": "2.7.0",
41
+ "@quenty/valueobject": "13.3.0"
42
42
  },
43
- "gitHead": "3fd5cdca3128bf34c8d9dfae1e92d62533b6e6f5"
43
+ "gitHead": "c5ee856d8d75948a21e30b90872bbad28d09e23f"
44
44
  }
@@ -20,23 +20,12 @@ ColorPickerCursorPreview.__index = ColorPickerCursorPreview
20
20
  function ColorPickerCursorPreview.new()
21
21
  local self = setmetatable(BasicPane.new(), ColorPickerCursorPreview)
22
22
 
23
- self._backgroundColorHint = ValueObject.new(Color3.new(0, 0, 0), "Color3")
24
- self._maid:GiveTask(self._backgroundColorHint)
25
-
26
- self._heightAbs = ValueObject.new(60, "number")
27
- self._maid:GiveTask(self._heightAbs)
28
-
29
- self._offsetAbs = ValueObject.new(-20, "number")
30
- self._maid:GiveTask(self._offsetAbs)
31
-
32
- self._position = ValueObject.new(Vector2.zero, "Vector2")
33
- self._maid:GiveTask(self._position)
34
-
35
- self._transparency = ValueObject.new(0, "number")
36
- self._maid:GiveTask(self._transparency)
37
-
38
- self._colorValue = ValueObject.new(Color3.new(0, 0, 0), "Color3")
39
- self._maid:GiveTask(self._colorValue)
23
+ self._backgroundColorHint = self._maid:Add(ValueObject.new(Color3.new(0, 0, 0), "Color3"))
24
+ self._heightAbs = self._maid:Add(ValueObject.new(60, "number"))
25
+ self._offsetAbs = self._maid:Add(ValueObject.new(-20, "number"))
26
+ self._position = self._maid:Add(ValueObject.new(Vector2.zero, "Vector2"))
27
+ self._transparency = self._maid:Add(ValueObject.new(0, "number"))
28
+ self._colorValue = self._maid:Add(ValueObject.new(Color3.new(0, 0, 0), "Color3"))
40
29
 
41
30
  self._maid:GiveTask(self:_render():Subscribe(function(gui)
42
31
  self.Gui = gui
@@ -99,43 +88,43 @@ function ColorPickerCursorPreview:_render()
99
88
  return UDim2.new(pos.x, 0, pos.y, offsetAbs - heightAbs/2)
100
89
  end);
101
90
  ZIndex = 3;
102
- [Blend.Children] = {
103
- Blend.New "UIAspectRatioConstraint" {
104
- AspectRatio = 1;
91
+
92
+ Blend.New "UIAspectRatioConstraint" {
93
+ AspectRatio = 1;
94
+ };
95
+
96
+ Blend.New "Frame" {
97
+ BackgroundTransparency = transparency;
98
+ BackgroundColor3 = self._colorValue;
99
+ AnchorPoint = Vector2.new(0.5, 0.5);
100
+ Position = UDim2.fromScale(0.5, 0.5);
101
+ Size = UDim2.fromScale(1, 1);
102
+
103
+ Blend.New "UIScale" {
104
+ Scale = percentVisible;
105
105
  };
106
106
 
107
- Blend.New "Frame" {
108
- BackgroundTransparency = transparency;
109
- BackgroundColor3 = self._colorValue;
110
- AnchorPoint = Vector2.new(0.5, 0.5);
111
- Position = UDim2.fromScale(0.5, 0.5);
112
- Size = UDim2.fromScale(1, 1);
113
- [Blend.Children] = {
114
- Blend.New "UIScale" {
115
- Scale = percentVisible;
116
- };
117
- Blend.New "UICorner" {
118
- CornerRadius = UDim.new(1, 0);
119
- };
120
- Blend.New "UIStroke" {
121
- Color = Blend.Spring(Blend.Computed(
122
- self._colorValue,
123
- self._backgroundColorHint,
124
- isOutlineVisible,
125
- function(color, backingColor, needed)
126
- if needed then
127
- return ColorPickerUtils.getOutlineWithContrast(color, backingColor)
128
- else
129
- return color
130
- end
131
- end), 20);
132
- Transparency = transparency;
133
- Thickness = Blend.Computed(percentVisible, function(percent)
134
- return percent*3
135
- end);
136
- };
137
- };
138
- }
107
+ Blend.New "UICorner" {
108
+ CornerRadius = UDim.new(1, 0);
109
+ };
110
+
111
+ Blend.New "UIStroke" {
112
+ Color = Blend.Spring(Blend.Computed(
113
+ self._colorValue,
114
+ self._backgroundColorHint,
115
+ isOutlineVisible,
116
+ function(color, backingColor, needed)
117
+ if needed then
118
+ return ColorPickerUtils.getOutlineWithContrast(color, backingColor)
119
+ else
120
+ return color
121
+ end
122
+ end), 20);
123
+ Transparency = transparency;
124
+ Thickness = Blend.Computed(percentVisible, function(percent)
125
+ return percent*3
126
+ end);
127
+ };
139
128
  }
140
129
  }
141
130
  end
@@ -1,4 +1,6 @@
1
1
  --[=[
2
+ Color picker triangle
3
+
2
4
  @class ColorPickerTriangle
3
5
  ]=]
4
6
 
@@ -16,17 +18,10 @@ ColorPickerTriangle.__index = ColorPickerTriangle
16
18
  function ColorPickerTriangle.new()
17
19
  local self = setmetatable(BaseObject.new(), ColorPickerTriangle)
18
20
 
19
- self._transparency = ValueObject.new(0, "number")
20
- self._maid:GiveTask(self._transparency)
21
-
22
- self._backgroundColorHint = ValueObject.new(Color3.new(0, 0, 0), "Color3")
23
- self._maid:GiveTask(self._backgroundColorHint)
24
-
25
- self._color = ValueObject.new(Color3.new(1, 1, 1), "Color3")
26
- self._maid:GiveTask(self._color)
27
-
28
- self._sizeValue = ValueObject.new(Vector2.new(0.05, 0.1), "Vector2")
29
- self._maid:GiveTask(self._sizeValue)
21
+ self._transparency = self._maid:Add(ValueObject.new(0, "number"))
22
+ self._backgroundColorHint = self._maid:Add(ValueObject.new(Color3.new(0, 0, 0), "Color3"))
23
+ self._color = self._maid:Add(ValueObject.new(Color3.new(1, 1, 1), "Color3"))
24
+ self._sizeValue = self._maid:Add(ValueObject.new(Vector2.new(0.05, 0.1), "Vector2"))
30
25
 
31
26
  self._maid:GiveTask(self:_render():Subscribe(function(gui)
32
27
  self.Gui = gui
@@ -62,26 +57,26 @@ function ColorPickerTriangle:_render()
62
57
  Name = "ColorPickerTriangle";
63
58
  Size = UDim2.new(1, 0, 1, 0);
64
59
  BackgroundTransparency = 1;
65
- [Blend.Children] = {
66
- Blend.New "ImageLabel" {
67
- BackgroundTransparency = 1;
68
- Size = UDim2.new(1, 0, 1, 0);
69
- ImageColor3 = Blend.Computed(self._color, self._backgroundColorHint, function(color, backingColor)
70
- return ColorPickerUtils.getOutlineWithContrast(color, backingColor)
71
- end);
72
- ImageTransparency = self._transparency;
73
- Image = "rbxassetid://9291514809";
74
- };
75
- Blend.New "UIAspectRatioConstraint" {
76
- AspectRatio = Blend.Computed(self._sizeValue, function(size)
77
- if size.x <= 0 or size.y <= 0 then
78
- return 1
79
- else
80
- return size.x/size.y
81
- end
82
- end);
83
- };
84
- }
60
+
61
+ Blend.New "ImageLabel" {
62
+ BackgroundTransparency = 1;
63
+ Size = UDim2.new(1, 0, 1, 0);
64
+ ImageColor3 = Blend.Computed(self._color, self._backgroundColorHint, function(color, backingColor)
65
+ return ColorPickerUtils.getOutlineWithContrast(color, backingColor)
66
+ end);
67
+ ImageTransparency = self._transparency;
68
+ Image = "rbxassetid://9291514809";
69
+ };
70
+
71
+ Blend.New "UIAspectRatioConstraint" {
72
+ AspectRatio = Blend.Computed(self._sizeValue, function(size)
73
+ if size.x <= 0 or size.y <= 0 then
74
+ return 1
75
+ else
76
+ return size.x/size.y
77
+ end
78
+ end);
79
+ };
85
80
  }
86
81
  end
87
82
 
@@ -106,47 +106,41 @@ function HSColorPickerCursor:_render()
106
106
  return UDim2.fromScale(pos.x, pos.y)
107
107
  end);
108
108
 
109
- [Blend.Children] = {
110
- Blend.New "UIAspectRatioConstraint" {
111
- AspectRatio = 1;
112
- };
109
+ Blend.New "UIAspectRatioConstraint" {
110
+ AspectRatio = 1;
111
+ };
113
112
 
114
- Blend.New "Frame" {
115
- AnchorPoint = Vector2.new(0.5, 0.5);
116
- Position = UDim2.fromScale(0.5, 0.5);
117
- Visible = self._horizontalHairVisible;
118
- Size = Blend.Computed(self._crossHairWidthAbs, function(width)
119
- return UDim2.new(1, 0, 0, width)
120
- end);
121
- BackgroundColor3 = Blend.Computed(self._backgroundColorHint, function(backingColor)
122
- return ColorPickerUtils.getOutlineWithContrast(Color3.new(0, 0, 0), backingColor)
123
- end);
124
- BackgroundTransparency = self._transparency;
125
-
126
- [Blend.Children] = {
127
- Blend.New "UICorner" {
128
- CornerRadius = UDim.new(1, 0);
129
- };
130
- };
113
+ Blend.New "Frame" {
114
+ AnchorPoint = Vector2.new(0.5, 0.5);
115
+ Position = UDim2.fromScale(0.5, 0.5);
116
+ Visible = self._horizontalHairVisible;
117
+ Size = Blend.Computed(self._crossHairWidthAbs, function(width)
118
+ return UDim2.new(1, 0, 0, width)
119
+ end);
120
+ BackgroundColor3 = Blend.Computed(self._backgroundColorHint, function(backingColor)
121
+ return ColorPickerUtils.getOutlineWithContrast(Color3.new(0, 0, 0), backingColor)
122
+ end);
123
+ BackgroundTransparency = self._transparency;
124
+
125
+ Blend.New "UICorner" {
126
+ CornerRadius = UDim.new(1, 0);
131
127
  };
128
+ };
132
129
 
133
- Blend.New "Frame" {
134
- AnchorPoint = Vector2.new(0.5, 0.5);
135
- Position = UDim2.fromScale(0.5, 0.5);
136
- Visible = self._verticalHairVisible;
137
- Size = Blend.Computed(self._crossHairWidthAbs, function(width)
138
- return UDim2.new(0, width, 1, 0)
139
- end);
140
- BackgroundColor3 = Blend.Spring(Blend.Computed(self._backgroundColorHint, function(backingColor)
141
- return ColorPickerUtils.getOutlineWithContrast(Color3.new(0, 0, 0), backingColor)
142
- end), 20);
143
- BackgroundTransparency = self._transparency;
144
-
145
- [Blend.Children] = {
146
- Blend.New "UICorner" {
147
- CornerRadius = UDim.new(1, 0);
148
- };
149
- };
130
+ Blend.New "Frame" {
131
+ AnchorPoint = Vector2.new(0.5, 0.5);
132
+ Position = UDim2.fromScale(0.5, 0.5);
133
+ Visible = self._verticalHairVisible;
134
+ Size = Blend.Computed(self._crossHairWidthAbs, function(width)
135
+ return UDim2.new(0, width, 1, 0)
136
+ end);
137
+ BackgroundColor3 = Blend.Spring(Blend.Computed(self._backgroundColorHint, function(backingColor)
138
+ return ColorPickerUtils.getOutlineWithContrast(Color3.new(0, 0, 0), backingColor)
139
+ end), 20);
140
+ BackgroundTransparency = self._transparency;
141
+
142
+ Blend.New "UICorner" {
143
+ CornerRadius = UDim.new(1, 0);
150
144
  };
151
145
  };
152
146
  };
@@ -2,6 +2,7 @@
2
2
  Picker for hue and Saturation in HSV. See [HSVColorPicker] for the full color picker,
3
3
  which also allows you to select "Value".
4
4
 
5
+ @client
5
6
  @class HSColorPicker
6
7
  ]=]
7
8
 
@@ -9,8 +10,8 @@ local require = require(script.Parent.loader).load(script)
9
10
 
10
11
  local BaseObject = require("BaseObject")
11
12
  local Blend = require("Blend")
12
- local ColorPickerCursorPreview = require("ColorPickerCursorPreview")
13
13
  local ButtonDragModel = require("ButtonDragModel")
14
+ local ColorPickerCursorPreview = require("ColorPickerCursorPreview")
14
15
  local HSColorPickerCursor = require("HSColorPickerCursor")
15
16
  local ValueObject = require("ValueObject")
16
17
 
@@ -18,6 +19,9 @@ local HSColorPicker = setmetatable({}, BaseObject)
18
19
  HSColorPicker.ClassName = "HSColorPicker"
19
20
  HSColorPicker.__index = HSColorPicker
20
21
 
22
+ --[=[
23
+ @return HSColorPicker
24
+ ]=]
21
25
  function HSColorPicker.new()
22
26
  local self = setmetatable(BaseObject.new(), HSColorPicker)
23
27
 
@@ -59,7 +63,7 @@ function HSColorPicker.new()
59
63
  end))
60
64
 
61
65
  -- Setup preview
62
- self._maid:GiveTask(self._dragModel:ObserveIsDragging():Subscribe(function(isDragging)
66
+ self._maid:GiveTask(self._dragModel:ObserveIsPressed():Subscribe(function(isDragging)
63
67
  self._preview:SetVisible(isDragging)
64
68
  end))
65
69
  self._maid:GiveTask(self._cursor.PositionChanged:Connect(function()
@@ -175,27 +179,27 @@ function HSColorPicker:_render()
175
179
  Active = true;
176
180
  Image = "rbxassetid://9290917908";
177
181
  ImageTransparency = self._transparency;
182
+
178
183
  [Blend.Instance] = function(inst)
179
184
  self._dragModel:SetButton(inst)
180
185
  end;
181
- [Blend.Children] = {
182
- Blend.New "UIAspectRatioConstraint" {
183
- AspectRatio = Blend.Computed(self._sizeValue, function(size)
184
- if size.x <= 0 or size.y <= 0 then
185
- return 1
186
- else
187
- return size.x/size.y
188
- end
189
- end);
190
- };
191
-
192
- Blend.New "UICorner" {
193
- CornerRadius = UDim.new(0, 4);
194
- };
195
-
196
- self._preview.Gui;
197
- self._cursor.Gui;
186
+
187
+ Blend.New "UIAspectRatioConstraint" {
188
+ AspectRatio = Blend.Computed(self._sizeValue, function(size)
189
+ if size.x <= 0 or size.y <= 0 then
190
+ return 1
191
+ else
192
+ return size.x/size.y
193
+ end
194
+ end);
195
+ };
196
+
197
+ Blend.New "UICorner" {
198
+ CornerRadius = UDim.new(0, 4);
198
199
  };
200
+
201
+ self._preview.Gui;
202
+ self._cursor.Gui;
199
203
  };
200
204
  end
201
205
 
@@ -10,13 +10,12 @@ local HSColorPicker = require("HSColorPicker")
10
10
  return function(target)
11
11
  local maid = Maid.new()
12
12
 
13
- local picker = HSColorPicker.new()
13
+ local picker = maid:Add(HSColorPicker.new())
14
14
  picker:SetColor(Color3.new(1, 1, 1))
15
15
  picker.Gui.AnchorPoint = Vector2.new(0.5, 0.5)
16
16
  picker.Gui.Position = UDim2.fromScale(0.5, 0.5);
17
17
  picker.Gui.Size = UDim2.fromScale(0.8, 0.8)
18
18
  picker.Gui.Parent = target
19
- maid:GiveTask(picker)
20
19
 
21
20
  return function()
22
21
  maid:DoCleaning()
@@ -2,6 +2,7 @@
2
2
  A HSV color picker component which can be used to select colors using
3
3
  an interface standard to Roblox Studio.
4
4
 
5
+ @client
5
6
  @class HSVColorPicker
6
7
  ]=]
7
8
 
@@ -10,8 +11,8 @@ local require = require(script.Parent.loader).load(script)
10
11
  local BaseObject = require("BaseObject")
11
12
  local Blend = require("Blend")
12
13
  local HSColorPicker = require("HSColorPicker")
13
- local ValueColorPicker = require("ValueColorPicker")
14
14
  local Maid = require("Maid")
15
+ local ValueColorPicker = require("ValueColorPicker")
15
16
  local ValueObject = require("ValueObject")
16
17
 
17
18
  local HSVColorPicker = setmetatable({}, BaseObject)
@@ -32,27 +33,15 @@ HSVColorPicker.__index = HSVColorPicker
32
33
  function HSVColorPicker.new()
33
34
  local self = setmetatable(BaseObject.new(), HSVColorPicker)
34
35
 
35
- self._hsvColorValue = Instance.new("Vector3Value")
36
- self._hsvColorValue.Value = Vector3.zero
37
- self._maid:GiveTask(self._hsvColorValue)
36
+ self._hsvColorValue = self._maid:Add(ValueObject.new(Vector3.zero, "Vector3"))
37
+ self._sizeValue = self._maid:Add(ValueObject.new(Vector2.new(6, 4), "Vector2"))
38
+ self._innerPadding = self._maid:Add(ValueObject.new(0.2, "number"))
39
+ self._transparency = self._maid:Add(ValueObject.new(0, "number"))
40
+ self._hueSaturationPicker = self._maid:Add(HSColorPicker.new())
41
+ self._valuePicker = self._maid:Add(ValueColorPicker.new())
38
42
 
39
43
  self.ColorChanged = self._hsvColorValue.Changed
40
44
 
41
- self._sizeValue = ValueObject.new(Vector2.new(6, 4), "Vector2")
42
- self._maid:GiveTask(self._sizeValue)
43
-
44
- self._innerPadding = ValueObject.new(0.2, "number")
45
- self._maid:GiveTask(self._innerPadding)
46
-
47
- self._transparency = ValueObject.new(0, "number")
48
- self._maid:GiveTask(self._transparency)
49
-
50
- self._hueSaturationPicker = HSColorPicker.new()
51
- self._maid:GiveTask(self._hueSaturationPicker)
52
-
53
- self._valuePicker = ValueColorPicker.new()
54
- self._maid:GiveTask(self._valuePicker)
55
-
56
45
  self._maid:GiveTask(self:_render():Subscribe(function(gui)
57
46
  self.Gui = gui
58
47
  end))
@@ -226,28 +215,11 @@ function HSVColorPicker:_render()
226
215
  ZIndex = Blend.Computed(picker:ObserveIsPressed(), function(isPressed)
227
216
  return isPressed and 2 or 1
228
217
  end);
229
- [Blend.Children] = {
230
- picker.Gui;
231
- Blend.New "UIAspectRatioConstraint" {
232
- AspectRatio = Blend.Computed(picker:GetSizeValue(), function(size)
233
- if size.x <= 0 or size.y <= 0 then
234
- return 1
235
- else
236
- return size.x/size.y
237
- end
238
- end);
239
- };
240
- };
241
- };
242
- end
243
218
 
244
- return Blend.New "Frame" {
245
- Name = "HSVColorPicker";
246
- Size = UDim2.new(1, 0, 1, 0);
247
- BackgroundTransparency = 1;
248
- [Blend.Children] = {
219
+ picker.Gui;
220
+
249
221
  Blend.New "UIAspectRatioConstraint" {
250
- AspectRatio = Blend.Computed(self._sizeValue, function(size)
222
+ AspectRatio = Blend.Computed(picker:GetSizeValue(), function(size)
251
223
  if size.x <= 0 or size.y <= 0 then
252
224
  return 1
253
225
  else
@@ -255,16 +227,33 @@ function HSVColorPicker:_render()
255
227
  end
256
228
  end);
257
229
  };
230
+ };
231
+ end
232
+
233
+ return Blend.New "Frame" {
234
+ Name = "HSVColorPicker";
235
+ Size = UDim2.new(1, 0, 1, 0);
236
+ BackgroundTransparency = 1;
258
237
 
259
- container(self._hueSaturationPicker, {
260
- AnchorPoint = Vector2.zero;
261
- Position = UDim2.fromScale(0, 0);
262
- });
263
- container(self._valuePicker, {
264
- AnchorPoint = Vector2.new(1, 0);
265
- Position = UDim2.fromScale(1, 0);
266
- });
238
+ Blend.New "UIAspectRatioConstraint" {
239
+ AspectRatio = Blend.Computed(self._sizeValue, function(size)
240
+ if size.x <= 0 or size.y <= 0 then
241
+ return 1
242
+ else
243
+ return size.x/size.y
244
+ end
245
+ end);
267
246
  };
247
+
248
+ container(self._hueSaturationPicker, {
249
+ AnchorPoint = Vector2.zero;
250
+ Position = UDim2.fromScale(0, 0);
251
+ });
252
+
253
+ container(self._valuePicker, {
254
+ AnchorPoint = Vector2.new(1, 0);
255
+ Position = UDim2.fromScale(1, 0);
256
+ });
268
257
  };
269
258
  end
270
259
 
@@ -10,13 +10,12 @@ local HSVColorPicker = require("HSVColorPicker")
10
10
  return function(target)
11
11
  local maid = Maid.new()
12
12
 
13
- local picker = HSVColorPicker.new()
13
+ local picker = maid:Add(HSVColorPicker.new())
14
14
  picker:SetColor(Color3.new(0.5, 0.8, 0.3))
15
15
  picker.Gui.AnchorPoint = Vector2.new(0.5, 0.5)
16
16
  picker.Gui.Position = UDim2.fromScale(0.5, 0.5);
17
17
  picker.Gui.Size = UDim2.fromScale(0.8, 0.8)
18
18
  picker.Gui.Parent = target
19
- maid:GiveTask(picker)
20
19
 
21
20
  return function()
22
21
  maid:DoCleaning()
@@ -1,5 +1,7 @@
1
1
  --[=[
2
- Picker for value in HSV. See [HSVColorPicker]
2
+ Picker for value in HSV. See [HSVColorPicker] for usage.
3
+
4
+ @client
3
5
  @class ValueColorPicker
4
6
  ]=]
5
7
 
@@ -35,13 +37,11 @@ function ValueColorPicker.new()
35
37
  -- self._cursor:SetPosition(Vector3.new(0.5, 0, 1))
36
38
  -- self._maid:GiveTask(self._cursor)
37
39
 
38
- self._triangle = ColorPickerTriangle.new()
40
+ self._triangle = self._maid:Add(ColorPickerTriangle.new())
39
41
  self._triangle.Gui.AnchorPoint = Vector2.new(0, 0.5)
40
42
  self._triangle.Gui.Position = UDim2.fromScale(0, 1)
41
- self._maid:GiveTask(self._triangle)
42
43
 
43
- self._preview = ColorPickerCursorPreview.new()
44
- self._maid:GiveTask(self._preview)
44
+ self._preview = self._maid:Add(ColorPickerCursorPreview.new())
45
45
 
46
46
  self._maid:GiveTask(self:_render():Subscribe(function(gui)
47
47
  self.Gui = gui
@@ -72,7 +72,7 @@ function ValueColorPicker.new()
72
72
  end))
73
73
 
74
74
  -- Setup preview
75
- self._maid:GiveTask(self._dragModel:ObserveIsDragging():Subscribe(function(isDragging)
75
+ self._maid:GiveTask(self._dragModel:ObserveIsPressed():Subscribe(function(isDragging)
76
76
  self._preview:SetVisible(isDragging)
77
77
  end))
78
78
  self._maid:GiveTask(self._hsvColorValue.Changed:Connect(function()
@@ -102,58 +102,64 @@ function ValueColorPicker.new()
102
102
  return self
103
103
  end
104
104
 
105
+ --[=[
106
+ Sets the size (height) of the value color picker
107
+
108
+ @param height number
109
+ ]=]
105
110
  function ValueColorPicker:SetSize(height)
106
111
  assert(type(height) == "number", "Bad height")
107
112
 
108
113
  self:_updateSize(height)
109
114
  end
110
115
 
111
- function ValueColorPicker:HintBackgroundColor(color)
112
- self._backgroundColorHint.Value = color
113
- end
114
-
115
- function ValueColorPicker:_updatePreviewPosition()
116
- self._preview:SetPosition(Vector2.new(0.5, 1 - self._hsvColorValue.Value.z))
117
- end
118
-
119
- function ValueColorPicker:_updateSize(newHeight)
120
- local triangleSize = self._triangle:GetSizeValue().Value
121
- local width = self._leftWidth.Value + triangleSize.y
122
- local height = newHeight or self._sizeValue.Value.y
123
-
124
- self._sizeValue.Value = Vector2.new(width, height)
125
- end
126
-
127
- function ValueColorPicker:_updateHintedColors()
128
- local current = self._hsvColorValue.Value
129
- local h, s, v = current.x, current.y, current.z
130
- local color = Color3.fromHSV(h, s, v)
116
+ --[=[
117
+ Hints what the background color should be to ensure contrast
131
118
 
132
- -- self._cursor:HintBackgroundColor(color)
133
- self._preview:HintBackgroundColor(color)
134
- self._preview:SetColor(color)
119
+ @param color
120
+ ]=]
121
+ function ValueColorPicker:HintBackgroundColor(color: Color3)
122
+ self._backgroundColorHint.Value = color
135
123
  end
136
124
 
137
125
  function ValueColorPicker:ObserveIsPressed()
138
126
  return self._dragModel:ObserveIsPressed()
139
127
  end
140
128
 
141
- function ValueColorPicker:SetHSVColor(hsvColor)
129
+ --[=[
130
+ Sets the HSV Color for the value picker
131
+
132
+ @param hsvColor
133
+ ]=]
134
+ function ValueColorPicker:SetHSVColor(hsvColor: Vector3)
142
135
  assert(typeof(hsvColor) == "Vector3", "Bad hsvColor")
143
136
 
144
137
  self._hsvColorValue.Value = hsvColor
145
138
  end
146
139
 
140
+ --[=[
141
+ Returns the HSV color3
142
+
143
+ @return Vector3
144
+ ]=]
147
145
  function ValueColorPicker:GetHSVColor()
148
146
  return self._hsvColorValue.Value
149
147
  end
150
148
 
151
- function ValueColorPicker:SetColor(color)
149
+ --[=[
150
+ Setes the current color
151
+
152
+ @param color
153
+ ]=]
154
+ function ValueColorPicker:SetColor(color: Color3)
152
155
  local h, s, v = Color3.toHSV(color)
153
156
  self._hsvColorValue.Value = Vector3.new(h, s, v)
154
157
  end
155
158
 
156
- function ValueColorPicker:GetColor()
159
+ --[=[
160
+ Gets the current color
161
+ ]=]
162
+ function ValueColorPicker:GetColor(): Color3
157
163
  local current = self._hsvColorValue.Value
158
164
  local h, s, v = current.x, current.y, current.z
159
165
  return Color3.fromHSV(h, s, v)
@@ -173,71 +179,91 @@ function ValueColorPicker:SetTransparency(transparency)
173
179
  self._transparency.Value = transparency
174
180
  end
175
181
 
182
+ function ValueColorPicker:_updatePreviewPosition()
183
+ self._preview:SetPosition(Vector2.new(0.5, 1 - self._hsvColorValue.Value.z))
184
+ end
185
+
186
+ function ValueColorPicker:_updateSize(newHeight)
187
+ local triangleSize = self._triangle:GetSizeValue().Value
188
+ local width = self._leftWidth.Value + triangleSize.y
189
+ local height = newHeight or self._sizeValue.Value.y
190
+
191
+ self._sizeValue.Value = Vector2.new(width, height)
192
+ end
193
+
194
+ function ValueColorPicker:_updateHintedColors()
195
+ local current = self._hsvColorValue.Value
196
+ local h, s, v = current.x, current.y, current.z
197
+ local color = Color3.fromHSV(h, s, v)
198
+
199
+ -- self._cursor:HintBackgroundColor(color)
200
+ self._preview:HintBackgroundColor(color)
201
+ self._preview:SetColor(color)
202
+ end
203
+
176
204
  function ValueColorPicker:_render()
177
205
  return Blend.New "ImageButton" {
178
206
  Name = "HSColorPicker";
179
207
  Size = UDim2.new(1, 0, 1, 0);
180
208
  BackgroundTransparency = 1;
181
209
  Active = true;
210
+
182
211
  [Blend.Instance] = function(inst)
183
212
  self._dragModel:SetButton(inst)
184
213
  end;
185
- [Blend.Children] = {
186
- Blend.New "UIAspectRatioConstraint" {
187
- AspectRatio = Blend.Computed(self._sizeValue, function(size)
188
- if size.x <= 0 or size.y <= 0 then
189
- return 1
190
- else
191
- return size.x/size.y
192
- end
193
- end);
194
- };
195
214
 
196
- Blend.New "Frame" {
197
- BackgroundColor3 = Color3.new(1, 1, 1);
198
- BackgroundTransparency = self._transparency;
199
- Size = Blend.Computed(self._leftWidth, self._sizeValue, function(width, sizeValue)
200
- if sizeValue.x == 0 then
201
- return UDim2.new(0, 0, 1, 0)
202
- end
215
+ Blend.New "UIAspectRatioConstraint" {
216
+ AspectRatio = Blend.Computed(self._sizeValue, function(size)
217
+ if size.x <= 0 or size.y <= 0 then
218
+ return 1
219
+ else
220
+ return size.x/size.y
221
+ end
222
+ end);
223
+ };
203
224
 
204
- return UDim2.new(width/sizeValue.x, 0, 1, 0)
225
+ Blend.New "Frame" {
226
+ BackgroundColor3 = Color3.new(1, 1, 1);
227
+ BackgroundTransparency = self._transparency;
228
+ Size = Blend.Computed(self._leftWidth, self._sizeValue, function(width, sizeValue)
229
+ if sizeValue.x == 0 then
230
+ return UDim2.new(0, 0, 1, 0)
231
+ end
232
+
233
+ return UDim2.new(width/sizeValue.x, 0, 1, 0)
234
+ end);
235
+
236
+ Blend.New "UIGradient" {
237
+ Color = Blend.Computed(self._hsvColorValue, function(color)
238
+ local h, s = color.x, color.y
239
+ local start = Color3.fromHSV(h, s, 0)
240
+ local finish = Color3.fromHSV(h, s, 1)
241
+ return ColorSequence.new(start, finish)
205
242
  end);
206
- [Blend.Children] = {
207
- Blend.New "UIGradient" {
208
- Color = Blend.Computed(self._hsvColorValue, function(color)
209
- local h, s = color.x, color.y
210
- local start = Color3.fromHSV(h, s, 0)
211
- local finish = Color3.fromHSV(h, s, 1)
212
- return ColorSequence.new(start, finish)
213
- end);
214
- Rotation = -90;
215
- };
216
- Blend.New "UICorner" {
217
- CornerRadius = UDim.new(0, 4);
218
- };
219
-
220
- self._preview.Gui;
221
- -- self._cursor.Gui;
222
- }
243
+ Rotation = -90;
244
+ };
245
+ Blend.New "UICorner" {
246
+ CornerRadius = UDim.new(0, 4);
223
247
  };
224
248
 
225
- Blend.New "Frame" {
226
- BackgroundTransparency = 1;
227
- Position = UDim2.fromScale(1, 0);
228
- AnchorPoint = Vector2.new(1, 0);
229
- Size = Blend.Computed(self._leftWidth, self._sizeValue, function(width, sizeValue)
230
- if sizeValue.x == 0 then
231
- return UDim2.new(0, 0, 1, 0)
232
- end
233
-
234
- return UDim2.new((sizeValue.x - width)/sizeValue.x, 0, 1, 0)
235
- end);
236
- [Blend.Children] = {
237
- self._triangle.Gui;
238
- };
239
- }
249
+ self._preview.Gui;
250
+ -- self._cursor.Gui;
240
251
  };
252
+
253
+ Blend.New "Frame" {
254
+ BackgroundTransparency = 1;
255
+ Position = UDim2.fromScale(1, 0);
256
+ AnchorPoint = Vector2.new(1, 0);
257
+ Size = Blend.Computed(self._leftWidth, self._sizeValue, function(width, sizeValue)
258
+ if sizeValue.x == 0 then
259
+ return UDim2.new(0, 0, 1, 0)
260
+ end
261
+
262
+ return UDim2.new((sizeValue.x - width)/sizeValue.x, 0, 1, 0)
263
+ end);
264
+
265
+ self._triangle.Gui;
266
+ }
241
267
  };
242
268
  end
243
269
 
@@ -10,13 +10,12 @@ local ValueColorPicker = require("ValueColorPicker")
10
10
  return function(target)
11
11
  local maid = Maid.new()
12
12
 
13
- local picker = ValueColorPicker.new()
13
+ local picker = maid:Add(ValueColorPicker.new())
14
14
  picker:SetHSVColor(Vector3.new(1, 0.5, 1))
15
15
  picker.Gui.AnchorPoint = Vector2.new(0.5, 0.5)
16
16
  picker.Gui.Position = UDim2.fromScale(0.5, 0.5);
17
17
  picker.Gui.Size = UDim2.fromScale(0.8, 0.8)
18
18
  picker.Gui.Parent = target
19
- maid:GiveTask(picker)
20
19
 
21
20
  return function()
22
21
  maid:DoCleaning()
@@ -11,18 +11,16 @@ local ValueObject = require("ValueObject")
11
11
  local ColorPickerStoryUtils = {}
12
12
 
13
13
  function ColorPickerStoryUtils.createPicker(maid, valueSync, labelText, currentVisible)
14
- local picker = HSVColorPicker.new()
14
+ local picker = maid:Add(HSVColorPicker.new())
15
15
  picker.Gui.AnchorPoint = Vector2.new(0.5, 1)
16
16
  picker.Gui.Position = UDim2.new(0.5, 0, 1, 0)
17
17
  picker.Gui.Size = UDim2.new(0, 150, 1, -30);
18
18
  picker.Gui.ZIndex = 2;
19
- maid:GiveTask(picker)
20
19
 
21
20
  maid:GiveTask(picker:SyncValue(valueSync))
22
21
 
23
- local visible = Instance.new("BoolValue")
22
+ local visible = maid:Add(Instance.new("BoolValue"))
24
23
  visible.Value = false
25
- maid:GiveTask(visible)
26
24
 
27
25
  maid:GiveTask(visible.Changed:Connect(function()
28
26
  if visible.Value then
@@ -51,49 +49,47 @@ function ColorPickerStoryUtils.createPicker(maid, valueSync, labelText, currentV
51
49
  [Blend.OnEvent "Activated"] = function()
52
50
  visible.Value = not visible.Value
53
51
  end;
54
- [Blend.Children] = {
55
- picker.Gui;
56
- Blend.New "TextLabel" {
57
- BackgroundTransparency = 1;
58
- Text = labelText;
59
- Position = UDim2.new(0, 35, 0, 5);
60
- Size = UDim2.new(1, -40, 0, 20);
61
- Font = Enum.Font.FredokaOne;
62
- TextXAlignment = Enum.TextXAlignment.Left;
63
- TextScaled = true;
64
- TextColor3 = Color3.new(1, 1, 1);
65
- ZIndex = 0;
66
- };
67
52
 
68
- Blend.New "Frame" {
69
- BackgroundColor3 = valueSync;
70
- Size = UDim2.new(0, 20, 0, 20);
71
- Position = UDim2.new(0, 5, 0, 5);
72
- [Blend.Children] = {
73
- Blend.New "UICorner" {
74
- CornerRadius = UDim.new(0, 10);
75
- };
53
+ picker.Gui;
54
+ Blend.New "TextLabel" {
55
+ BackgroundTransparency = 1;
56
+ Text = labelText;
57
+ Position = UDim2.new(0, 35, 0, 5);
58
+ Size = UDim2.new(1, -40, 0, 20);
59
+ Font = Enum.Font.FredokaOne;
60
+ TextXAlignment = Enum.TextXAlignment.Left;
61
+ TextScaled = true;
62
+ TextColor3 = Color3.new(1, 1, 1);
63
+ ZIndex = 0;
64
+ };
65
+
66
+ Blend.New "Frame" {
67
+ BackgroundColor3 = valueSync;
68
+ Size = UDim2.new(0, 20, 0, 20);
69
+ Position = UDim2.new(0, 5, 0, 5);
70
+ [Blend.Children] = {
71
+ Blend.New "UICorner" {
72
+ CornerRadius = UDim.new(0, 10);
76
73
  };
77
74
  };
75
+ };
78
76
 
79
- Blend.New "UIPadding" {
80
- PaddingTop = UDim.new(0, 10);
81
- PaddingBottom = UDim.new(0, 10);
82
- PaddingLeft = UDim.new(0, 10);
83
- PaddingRight = UDim.new(0, 10);
84
- };
77
+ Blend.New "UIPadding" {
78
+ PaddingTop = UDim.new(0, 10);
79
+ PaddingBottom = UDim.new(0, 10);
80
+ PaddingLeft = UDim.new(0, 10);
81
+ PaddingRight = UDim.new(0, 10);
82
+ };
85
83
 
86
- Blend.New "UICorner" {
87
- CornerRadius = UDim.new(0, 10);
88
- };
84
+ Blend.New "UICorner" {
85
+ CornerRadius = UDim.new(0, 10);
89
86
  };
90
87
  }
91
88
 
92
89
  end
93
90
 
94
91
  function ColorPickerStoryUtils.create(maid, buildPickers)
95
- local currentVisible = ValueObject.new()
96
- maid:GiveTask(currentVisible)
92
+ local currentVisible = maid:Add(ValueObject.new())
97
93
 
98
94
  local built = {}
99
95
 
@@ -103,22 +99,21 @@ function ColorPickerStoryUtils.create(maid, buildPickers)
103
99
 
104
100
  local function pickerGroup(pickers)
105
101
  return Blend.New "Frame" {
106
- Size = UDim2.new(1, 0, 0, 0);
107
- AnchorPoint = Vector2.new(0.5, 0.5);
108
- Position = UDim2.fromScale(0.5, 0.5);
109
- BackgroundTransparency = 1;
110
- AutomaticSize = Enum.AutomaticSize.Y;
111
- [Blend.Children] = {
112
- Blend.New "UIListLayout" {
113
- Padding = UDim.new(0, 10);
114
- HorizontalAlignment = Enum.HorizontalAlignment.Left;
115
- VerticalAlignment = Enum.VerticalAlignment.Top;
116
- FillDirection = Enum.FillDirection.Horizontal;
117
- };
118
-
119
- pickers;
120
- };
102
+ Size = UDim2.new(1, 0, 0, 0);
103
+ AnchorPoint = Vector2.new(0.5, 0.5);
104
+ Position = UDim2.fromScale(0.5, 0.5);
105
+ BackgroundTransparency = 1;
106
+ AutomaticSize = Enum.AutomaticSize.Y;
107
+
108
+ Blend.New "UIListLayout" {
109
+ Padding = UDim.new(0, 10);
110
+ HorizontalAlignment = Enum.HorizontalAlignment.Left;
111
+ VerticalAlignment = Enum.VerticalAlignment.Top;
112
+ FillDirection = Enum.FillDirection.Horizontal;
121
113
  };
114
+
115
+ pickers;
116
+ };
122
117
  end
123
118
 
124
119
  local groups = {}
@@ -152,16 +147,14 @@ function ColorPickerStoryUtils.create(maid, buildPickers)
152
147
  end
153
148
  end;
154
149
 
155
- [Blend.Children] = {
156
- Blend.New "UIListLayout" {
157
- Padding = UDim.new(0, 10);
158
- HorizontalAlignment = Enum.HorizontalAlignment.Center;
159
- VerticalAlignment = Enum.VerticalAlignment.Top;
160
- FillDirection = Enum.FillDirection.Vertical;
161
- };
162
-
163
- groups;
150
+ Blend.New "UIListLayout" {
151
+ Padding = UDim.new(0, 10);
152
+ HorizontalAlignment = Enum.HorizontalAlignment.Center;
153
+ VerticalAlignment = Enum.VerticalAlignment.Top;
154
+ FillDirection = Enum.FillDirection.Vertical;
164
155
  };
156
+
157
+ groups;
165
158
  };
166
159
  end
167
160