@quenty/uiobjectutils 3.3.0 → 3.4.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,23 @@
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
+ # [3.4.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/uiobjectutils@3.3.0...@quenty/uiobjectutils@3.4.0) (2023-05-26)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Better error message with radius ([c4952fb](https://github.com/Quenty/NevermoreEngine/commit/c4952fbe364847051f82173dca4631df0ff137c7))
12
+
13
+
14
+ ### Features
15
+
16
+ * Add UIAlignmentUtils.toNumber(alignment) and UIAlignmentUtils.toBias(alignment) ([8092aba](https://github.com/Quenty/NevermoreEngine/commit/8092aba1cc564daaf5c775cb23f3c2131005da80))
17
+ * Add UIAlignmentUtils.verticalAlignmentToBias(verticalAlignment) and UIAlignmentUtils.horizontalAlignmentToBias(horizontalAlignment) ([fb98622](https://github.com/Quenty/NevermoreEngine/commit/fb98622dad4ca05bf28ecf90b55521c6d48f9b38))
18
+
19
+
20
+
21
+
22
+
6
23
  # [3.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/uiobjectutils@3.2.0...@quenty/uiobjectutils@3.3.0) (2023-04-24)
7
24
 
8
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/uiobjectutils",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "UI object utils library for Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -27,5 +27,5 @@
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "a8a760988c8fd88c2581c5c496a8bad845de104c"
30
+ "gitHead": "11058e90e51ea83d3dad6ae9abe59cc19c36b94b"
31
31
  }
@@ -1,39 +1,132 @@
1
1
  --[=[
2
+ Utility methods for working with horizontal and vertical alignment
2
3
  @class UIAlignmentUtils
3
4
  ]=]
4
5
 
5
6
  local UIAlignmentUtils = {}
6
7
 
8
+ local HORIZONTAL_ALIGNMENT = {
9
+ [Enum.HorizontalAlignment.Left] = 0;
10
+ [Enum.HorizontalAlignment.Center] = 0.5;
11
+ [Enum.HorizontalAlignment.Right] = 1;
12
+ }
13
+
14
+ local HORIZONTAL_BIAS = {
15
+ [Enum.HorizontalAlignment.Left] = -1;
16
+ [Enum.HorizontalAlignment.Center] = 0;
17
+ [Enum.HorizontalAlignment.Right] = 1;
18
+ }
19
+
20
+ local VERTICAL_ALIGNMENT = {
21
+ [Enum.VerticalAlignment.Top] = 0;
22
+ [Enum.VerticalAlignment.Center] = 0.5;
23
+ [Enum.VerticalAlignment.Bottom] = 1;
24
+ }
25
+
26
+ local VERTICAL_BIAS = {
27
+ [Enum.VerticalAlignment.Top] = -1;
28
+ [Enum.VerticalAlignment.Center] = 0;
29
+ [Enum.VerticalAlignment.Bottom] = 1;
30
+ }
31
+
32
+ --[=[
33
+ Converts alignment to 0, 0.5 or 1
34
+
35
+ @param alignment HorizontalAlignment | VertialAlignment
36
+ @return number
37
+ ]=]
38
+ function UIAlignmentUtils.toNumber(alignment)
39
+ assert(alignment, "Bad alignment")
40
+
41
+ if HORIZONTAL_ALIGNMENT[alignment] then
42
+ return HORIZONTAL_ALIGNMENT[alignment]
43
+ elseif VERTICAL_ALIGNMENT[alignment] then
44
+ return VERTICAL_ALIGNMENT[alignment]
45
+ else
46
+ error(("[UIAlignmentUtils.toNumber] - Bad alignment %q"):format(tostring(alignment)))
47
+ end
48
+ end
49
+
50
+ --[=[
51
+ Converts alignment to bias, as -1, 0, or 1
52
+
53
+ @param alignment HorizontalAlignment | VertialAlignment
54
+ @return number
55
+ ]=]
56
+ function UIAlignmentUtils.toBias(alignment)
57
+ assert(alignment, "Bad alignment")
58
+
59
+ if HORIZONTAL_BIAS[alignment] then
60
+ return HORIZONTAL_BIAS[alignment]
61
+ elseif VERTICAL_BIAS[alignment] then
62
+ return VERTICAL_BIAS[alignment]
63
+ else
64
+ error(("[UIAlignmentUtils.toBias] - Bad alignment %q"):format(tostring(alignment)))
65
+ end
66
+ end
67
+
68
+ --[=[
69
+ Converts alignment to a number from 0 to 1
70
+
71
+ @param horizontalAlignment HorizontalAlignment
72
+ @return number
73
+ ]=]
7
74
  function UIAlignmentUtils.horizontalAlignmentToNumber(horizontalAlignment)
8
75
  assert(horizontalAlignment, "Bad horizontalAlignment")
9
76
 
10
- local x
11
- if horizontalAlignment == Enum.HorizontalAlignment.Left then
12
- x = 0
13
- elseif horizontalAlignment == Enum.HorizontalAlignment.Center then
14
- x = 0.5
15
- elseif horizontalAlignment == Enum.HorizontalAlignment.Right then
16
- x = 1
77
+ if HORIZONTAL_ALIGNMENT[horizontalAlignment] then
78
+ return HORIZONTAL_ALIGNMENT[horizontalAlignment]
17
79
  else
18
80
  error(("[UIAlignmentUtils] - Bad horizontalAlignment %q"):format(tostring(horizontalAlignment)))
19
81
  end
82
+ end
83
+
84
+ --[=[
85
+ Converts alignment to a number from -1 to 1
86
+
87
+ @param horizontalAlignment HorizontalAlignment
88
+ @return number
89
+ ]=]
90
+ function UIAlignmentUtils.horizontalAlignmentToBias(horizontalAlignment)
91
+ assert(horizontalAlignment, "Bad horizontalAlignment")
20
92
 
21
- return x
93
+ if HORIZONTAL_BIAS[horizontalAlignment] then
94
+ return HORIZONTAL_BIAS[horizontalAlignment]
95
+ else
96
+ error(("[UIAlignmentUtils] - Bad horizontalAlignment %q"):format(tostring(horizontalAlignment)))
97
+ end
22
98
  end
23
99
 
100
+ --[=[
101
+ Converts alignment to a number from 0 to 1
102
+
103
+ @param verticalAlignment VerticalAlignment
104
+ @return number
105
+ ]=]
24
106
  function UIAlignmentUtils.verticalAlignmentToNumber(verticalAlignment)
25
107
  assert(verticalAlignment, "Bad verticalAlignment")
26
- local y
27
- if verticalAlignment == Enum.VerticalAlignment.Top then
28
- y = 0
29
- elseif verticalAlignment == Enum.VerticalAlignment.Center then
30
- y = 0.5
31
- elseif verticalAlignment == Enum.VerticalAlignment.Bottom then
32
- y = 1
108
+
109
+ if VERTICAL_ALIGNMENT[verticalAlignment] then
110
+ return VERTICAL_ALIGNMENT[verticalAlignment]
111
+ else
112
+ error(("[UIAlignmentUtils] - Bad verticalAlignment %q"):format(tostring(verticalAlignment)))
113
+ end
114
+ end
115
+
116
+ --[=[
117
+ Converts alignment to a number from -1 to 1
118
+
119
+ @param verticalAlignment VerticalAlignment
120
+ @return number
121
+ ]=]
122
+ function UIAlignmentUtils.verticalAlignmentToBias(verticalAlignment)
123
+ assert(verticalAlignment, "Bad verticalAlignment")
124
+
125
+ if VERTICAL_BIAS[verticalAlignment] then
126
+ return VERTICAL_BIAS[verticalAlignment]
33
127
  else
34
128
  error(("[UIAlignmentUtils] - Bad verticalAlignment %q"):format(tostring(verticalAlignment)))
35
129
  end
36
- return y
37
130
  end
38
131
 
39
132
  return UIAlignmentUtils
@@ -33,7 +33,7 @@ end
33
33
  -- framePosition is top left corner
34
34
  -- returns position, relativePosition, normal
35
35
  function UICornerUtils.clampPositionToFrame(framePosition, frameSize, radius, point)
36
- assert(radius > 0, "Bad radius")
36
+ assert(radius >= 0, "Bad radius")
37
37
  assert(point, "Bad point")
38
38
 
39
39
  local px, py = point.x, point.y