@quenty/uiobjectutils 6.15.0 → 6.15.1
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 +8 -0
- package/package.json +5 -5
- package/src/Client/GuiInteractionUtils.lua +11 -14
- package/src/Client/PlayerGuiUtils.lua +3 -4
- package/src/Client/RxClippedRectUtils.lua +43 -33
- package/src/Client/ScrollingDirectionUtils.lua +12 -3
- package/src/Client/UIAlignmentUtils.lua +43 -30
- package/src/Client/UICornerUtils.lua +26 -11
- package/src/Client/UIPaddingUtils.lua +21 -10
- package/src/Client/UIRotationUtils.lua +15 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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
|
+
## [6.15.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/uiobjectutils@6.15.0...@quenty/uiobjectutils@6.15.1) (2025-03-21)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/uiobjectutils
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [6.15.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/uiobjectutils@6.14.0...@quenty/uiobjectutils@6.15.0) (2025-02-18)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @quenty/uiobjectutils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/uiobjectutils",
|
|
3
|
-
"version": "6.15.
|
|
3
|
+
"version": "6.15.1",
|
|
4
4
|
"description": "UI object utils library for Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@quenty/brio": "^14.16.
|
|
31
|
+
"@quenty/brio": "^14.16.1",
|
|
32
32
|
"@quenty/enumutils": "^3.4.0",
|
|
33
|
-
"@quenty/instanceutils": "^13.16.
|
|
33
|
+
"@quenty/instanceutils": "^13.16.1",
|
|
34
34
|
"@quenty/loader": "^10.8.0",
|
|
35
|
-
"@quenty/rx": "^13.16.
|
|
35
|
+
"@quenty/rx": "^13.16.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "6b7c3e15e60cdb185986207b574e2b5591261e7a"
|
|
38
38
|
}
|
|
@@ -16,21 +16,19 @@ local GuiInteractionUtils = {}
|
|
|
16
16
|
@param gui GuiObject
|
|
17
17
|
@return Observable<boolean>
|
|
18
18
|
]=]
|
|
19
|
-
function GuiInteractionUtils.observeInteractionEnabled(gui)
|
|
19
|
+
function GuiInteractionUtils.observeInteractionEnabled(gui: GuiObject)
|
|
20
20
|
assert(typeof(gui) == "Instance" and gui:IsA("GuiObject"), "Bad gui")
|
|
21
21
|
|
|
22
22
|
return Rx.combineLatest({
|
|
23
|
-
visible = RxInstanceUtils.observeProperty(gui, "Visible")
|
|
24
|
-
guiState = RxInstanceUtils.observeProperty(gui, "GuiState")
|
|
25
|
-
dataModel = RxInstanceUtils.observeFirstAncestorBrio(gui, "DataModel")
|
|
23
|
+
visible = RxInstanceUtils.observeProperty(gui, "Visible"),
|
|
24
|
+
guiState = RxInstanceUtils.observeProperty(gui, "GuiState"),
|
|
25
|
+
dataModel = RxInstanceUtils.observeFirstAncestorBrio(gui, "DataModel"),
|
|
26
26
|
}):Pipe({
|
|
27
27
|
Rx.map(function(state)
|
|
28
|
-
return state.visible
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
end);
|
|
33
|
-
Rx.distinct();
|
|
28
|
+
return state.visible and state.guiState ~= Enum.GuiState.NonInteractable and state.dataModel and true
|
|
29
|
+
or false
|
|
30
|
+
end),
|
|
31
|
+
Rx.distinct(),
|
|
34
32
|
})
|
|
35
33
|
end
|
|
36
34
|
|
|
@@ -41,15 +39,14 @@ end
|
|
|
41
39
|
@param gui GuiObject
|
|
42
40
|
@return Observable<Brio>
|
|
43
41
|
]=]
|
|
44
|
-
function GuiInteractionUtils.observeInteractionEnabledBrio(gui)
|
|
42
|
+
function GuiInteractionUtils.observeInteractionEnabledBrio(gui: GuiObject)
|
|
45
43
|
assert(typeof(gui) == "Instance" and gui:IsA("GuiObject"), "Bad gui")
|
|
46
44
|
|
|
47
45
|
return GuiInteractionUtils.observeInteractionEnabled(gui):Pipe({
|
|
48
46
|
RxBrioUtils.switchToBrio(function(canInteract)
|
|
49
47
|
return canInteract
|
|
50
|
-
end)
|
|
48
|
+
end),
|
|
51
49
|
})
|
|
52
50
|
end
|
|
53
51
|
|
|
54
|
-
|
|
55
|
-
return GuiInteractionUtils
|
|
52
|
+
return GuiInteractionUtils
|
|
@@ -17,7 +17,7 @@ local PlayerGuiUtils = {}
|
|
|
17
17
|
|
|
18
18
|
@return PlayerGui
|
|
19
19
|
]=]
|
|
20
|
-
function PlayerGuiUtils.getPlayerGui()
|
|
20
|
+
function PlayerGuiUtils.getPlayerGui(): PlayerGui
|
|
21
21
|
local localPlayer = Players.LocalPlayer
|
|
22
22
|
if not localPlayer then
|
|
23
23
|
error("[PlayerGuiUtils.getPlayerGui] - No localPlayer")
|
|
@@ -36,7 +36,7 @@ end
|
|
|
36
36
|
|
|
37
37
|
@return PlayerGui | nil
|
|
38
38
|
]=]
|
|
39
|
-
function PlayerGuiUtils.findPlayerGui()
|
|
39
|
+
function PlayerGuiUtils.findPlayerGui(): PlayerGui?
|
|
40
40
|
local localPlayer = Players.LocalPlayer
|
|
41
41
|
if not localPlayer then
|
|
42
42
|
return nil
|
|
@@ -45,5 +45,4 @@ function PlayerGuiUtils.findPlayerGui()
|
|
|
45
45
|
return localPlayer:FindFirstChildOfClass("PlayerGui")
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
return PlayerGuiUtils
|
|
48
|
+
return PlayerGuiUtils
|
|
@@ -11,21 +11,20 @@ local RxInstanceUtils = require("RxInstanceUtils")
|
|
|
11
11
|
|
|
12
12
|
local RxClippedRectUtils = {}
|
|
13
13
|
|
|
14
|
-
|
|
15
14
|
--[=[
|
|
16
15
|
Observes the clipped rect for the given Gui
|
|
17
16
|
|
|
18
17
|
@param gui Gui
|
|
19
18
|
@return Observable<Rect>
|
|
20
19
|
]=]
|
|
21
|
-
function RxClippedRectUtils.observeClippedRect(gui)
|
|
20
|
+
function RxClippedRectUtils.observeClippedRect(gui: GuiObject)
|
|
22
21
|
assert(typeof(gui) == "Instance" and gui:IsA("GuiObject"), "Bad GuiBase2d")
|
|
23
22
|
|
|
24
23
|
-- At least use our object's size here...
|
|
25
24
|
return Rx.combineLatest({
|
|
26
|
-
absolutePosition = RxInstanceUtils.observeProperty(gui, "AbsolutePosition")
|
|
27
|
-
absoluteSize = RxInstanceUtils.observeProperty(gui, "AbsoluteSize")
|
|
28
|
-
parentRect = RxClippedRectUtils._observeParentClippedRect(gui)
|
|
25
|
+
absolutePosition = RxInstanceUtils.observeProperty(gui, "AbsolutePosition"),
|
|
26
|
+
absoluteSize = RxInstanceUtils.observeProperty(gui, "AbsoluteSize"),
|
|
27
|
+
parentRect = RxClippedRectUtils._observeParentClippedRect(gui),
|
|
29
28
|
}):Pipe({
|
|
30
29
|
Rx.map(function(state)
|
|
31
30
|
if state.parentRect then
|
|
@@ -33,22 +32,28 @@ function RxClippedRectUtils.observeClippedRect(gui)
|
|
|
33
32
|
else
|
|
34
33
|
return Rect.new(Vector2.zero, Vector2.zero)
|
|
35
34
|
end
|
|
36
|
-
end)
|
|
37
|
-
Rx.distinct()
|
|
35
|
+
end),
|
|
36
|
+
Rx.distinct(),
|
|
38
37
|
})
|
|
39
38
|
end
|
|
40
39
|
|
|
41
|
-
local function clampVector2(value)
|
|
42
|
-
return Vector2.new(math.clamp(value.
|
|
40
|
+
local function clampVector2(value: Vector2): Vector2
|
|
41
|
+
return Vector2.new(math.clamp(value.X, 0, 1), math.clamp(value.Y, 0, 1))
|
|
43
42
|
end
|
|
44
43
|
|
|
45
|
-
|
|
44
|
+
--[=[
|
|
45
|
+
Observes the clipped rect for the given Gui, but in scale coordinates
|
|
46
|
+
|
|
47
|
+
@param gui Gui
|
|
48
|
+
@return Observable<Rect>
|
|
49
|
+
]=]
|
|
50
|
+
function RxClippedRectUtils.observeClippedRectInScale(gui: GuiObject)
|
|
46
51
|
assert(typeof(gui) == "Instance" and gui:IsA("GuiObject"), "Bad GuiBase2d")
|
|
47
52
|
|
|
48
53
|
return Rx.combineLatest({
|
|
49
|
-
absolutePosition = RxInstanceUtils.observeProperty(gui, "AbsolutePosition")
|
|
50
|
-
absoluteSize = RxInstanceUtils.observeProperty(gui, "AbsoluteSize")
|
|
51
|
-
visibleRect = RxClippedRectUtils.observeClippedRect(gui)
|
|
54
|
+
absolutePosition = RxInstanceUtils.observeProperty(gui, "AbsolutePosition"),
|
|
55
|
+
absoluteSize = RxInstanceUtils.observeProperty(gui, "AbsoluteSize"),
|
|
56
|
+
visibleRect = RxClippedRectUtils.observeClippedRect(gui),
|
|
52
57
|
}):Pipe({
|
|
53
58
|
Rx.map(function(state)
|
|
54
59
|
if state.absoluteSize.x == 0 or state.absoluteSize.y == 0 then
|
|
@@ -61,16 +66,16 @@ function RxClippedRectUtils.observeClippedRectInScale(gui)
|
|
|
61
66
|
local visibleMin = state.visibleRect.Min
|
|
62
67
|
local visibleSize = state.visibleRect.Max - visibleMin
|
|
63
68
|
|
|
64
|
-
local topLeft = clampVector2((visibleMin - ourMin)/ourSize)
|
|
65
|
-
local size = clampVector2(visibleSize/ourSize)
|
|
69
|
+
local topLeft = clampVector2((visibleMin - ourMin) / ourSize)
|
|
70
|
+
local size = clampVector2(visibleSize / ourSize)
|
|
66
71
|
local bottomRight = topLeft + size
|
|
67
72
|
return Rect.new(topLeft, bottomRight)
|
|
68
|
-
end)
|
|
69
|
-
Rx.distinct()
|
|
73
|
+
end),
|
|
74
|
+
Rx.distinct(),
|
|
70
75
|
})
|
|
71
76
|
end
|
|
72
77
|
|
|
73
|
-
function RxClippedRectUtils._observeClippedRectImpl(gui)
|
|
78
|
+
function RxClippedRectUtils._observeClippedRectImpl(gui: GuiObject)
|
|
74
79
|
if gui:IsA("GuiObject") then
|
|
75
80
|
return RxInstanceUtils.observeProperty(gui, "ClipsDescendants"):Pipe({
|
|
76
81
|
Rx.switchMap(function(clipDescendants)
|
|
@@ -79,29 +84,34 @@ function RxClippedRectUtils._observeClippedRectImpl(gui)
|
|
|
79
84
|
end
|
|
80
85
|
|
|
81
86
|
return Rx.combineLatest({
|
|
82
|
-
absolutePosition = RxInstanceUtils.observeProperty(gui, "AbsolutePosition")
|
|
83
|
-
absoluteSize = RxInstanceUtils.observeProperty(gui, "AbsoluteSize")
|
|
84
|
-
parentRect = RxClippedRectUtils._observeParentClippedRect(gui)
|
|
87
|
+
absolutePosition = RxInstanceUtils.observeProperty(gui, "AbsolutePosition"),
|
|
88
|
+
absoluteSize = RxInstanceUtils.observeProperty(gui, "AbsoluteSize"),
|
|
89
|
+
parentRect = RxClippedRectUtils._observeParentClippedRect(gui),
|
|
85
90
|
}):Pipe({
|
|
86
91
|
Rx.map(function(state)
|
|
87
92
|
return RxClippedRectUtils._computeClippedRect(state)
|
|
88
|
-
end)
|
|
93
|
+
end),
|
|
89
94
|
})
|
|
90
|
-
end)
|
|
95
|
+
end),
|
|
91
96
|
})
|
|
92
97
|
else
|
|
93
98
|
if not gui:IsA("LayerCollector") then
|
|
94
|
-
warn(
|
|
99
|
+
warn(
|
|
100
|
+
string.format(
|
|
101
|
+
"[RxClippedRectUtils._observeClippedRectImpl] - Unknown gui instance type behind GuiBase2d of class %s - treating as layer collector. Please patch this method.",
|
|
102
|
+
tostring(gui.ClassName)
|
|
103
|
+
)
|
|
104
|
+
)
|
|
95
105
|
end
|
|
96
106
|
|
|
97
107
|
return Rx.combineLatest({
|
|
98
|
-
absolutePosition = RxInstanceUtils.observeProperty(gui, "AbsolutePosition")
|
|
99
|
-
absoluteSize = RxInstanceUtils.observeProperty(gui, "AbsoluteSize")
|
|
100
|
-
parentRect = RxClippedRectUtils._observeParentClippedRect(gui)
|
|
108
|
+
absolutePosition = RxInstanceUtils.observeProperty(gui, "AbsolutePosition"),
|
|
109
|
+
absoluteSize = RxInstanceUtils.observeProperty(gui, "AbsoluteSize"),
|
|
110
|
+
parentRect = RxClippedRectUtils._observeParentClippedRect(gui),
|
|
101
111
|
}):Pipe({
|
|
102
112
|
Rx.map(function(state)
|
|
103
113
|
return RxClippedRectUtils._computeClippedRect(state)
|
|
104
|
-
end)
|
|
114
|
+
end),
|
|
105
115
|
})
|
|
106
116
|
end
|
|
107
117
|
end
|
|
@@ -129,7 +139,7 @@ function RxClippedRectUtils._computeClippedRect(state)
|
|
|
129
139
|
return Rect.new(topLeftX, topLeftY, topLeftX + sizeX, topLeftY + sizeY)
|
|
130
140
|
end
|
|
131
141
|
|
|
132
|
-
function RxClippedRectUtils._observeParentClippedRect(gui)
|
|
142
|
+
function RxClippedRectUtils._observeParentClippedRect(gui: GuiBase2d)
|
|
133
143
|
assert(typeof(gui) == "Instance" and gui:IsA("GuiBase2d"), "Bad GuiBase2d")
|
|
134
144
|
|
|
135
145
|
return RxInstanceUtils.observeFirstAncestor(gui, "GuiObject"):Pipe({
|
|
@@ -137,10 +147,10 @@ function RxClippedRectUtils._observeParentClippedRect(gui)
|
|
|
137
147
|
if parent then
|
|
138
148
|
return RxClippedRectUtils._observeClippedRectImpl(parent)
|
|
139
149
|
else
|
|
140
|
-
return Rx.of(nil)
|
|
150
|
+
return Rx.of(nil)
|
|
141
151
|
end
|
|
142
|
-
end)
|
|
143
|
-
})
|
|
152
|
+
end),
|
|
153
|
+
})
|
|
144
154
|
end
|
|
145
155
|
|
|
146
|
-
return RxClippedRectUtils
|
|
156
|
+
return RxClippedRectUtils
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
3
|
+
Utility logic involving scrolling direction
|
|
4
|
+
|
|
2
5
|
@class ScrollingDirectionUtils
|
|
3
6
|
]=]
|
|
4
7
|
|
|
@@ -8,16 +11,22 @@ local EnumUtils = require("EnumUtils")
|
|
|
8
11
|
|
|
9
12
|
local ScrollingDirectionUtils = {}
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
--[=[
|
|
15
|
+
Determines if the scrolling direction can scroll horizontally
|
|
16
|
+
]=]
|
|
17
|
+
function ScrollingDirectionUtils.canScrollHorizontal(scrollingDirection: Enum.ScrollingDirection): boolean
|
|
12
18
|
assert(EnumUtils.isOfType(Enum.ScrollingDirection, scrollingDirection))
|
|
13
19
|
|
|
14
20
|
return scrollingDirection == Enum.ScrollingDirection.X or scrollingDirection == Enum.ScrollingDirection.XY
|
|
15
21
|
end
|
|
16
22
|
|
|
17
|
-
|
|
23
|
+
--[=[
|
|
24
|
+
Determines if the scrolling direction can scroll vertically
|
|
25
|
+
]=]
|
|
26
|
+
function ScrollingDirectionUtils.canScrollVertical(scrollingDirection: Enum.ScrollingDirection): boolean
|
|
18
27
|
assert(EnumUtils.isOfType(Enum.ScrollingDirection, scrollingDirection))
|
|
19
28
|
|
|
20
29
|
return scrollingDirection == Enum.ScrollingDirection.Y or scrollingDirection == Enum.ScrollingDirection.XY
|
|
21
30
|
end
|
|
22
31
|
|
|
23
|
-
return ScrollingDirectionUtils
|
|
32
|
+
return ScrollingDirectionUtils
|
|
@@ -6,39 +6,39 @@
|
|
|
6
6
|
local UIAlignmentUtils = {}
|
|
7
7
|
|
|
8
8
|
local HORIZONTAL_ALIGNMENT = {
|
|
9
|
-
[Enum.HorizontalAlignment.Left] = 0
|
|
10
|
-
[Enum.HorizontalAlignment.Center] = 0.5
|
|
11
|
-
[Enum.HorizontalAlignment.Right] = 1
|
|
9
|
+
[Enum.HorizontalAlignment.Left] = 0,
|
|
10
|
+
[Enum.HorizontalAlignment.Center] = 0.5,
|
|
11
|
+
[Enum.HorizontalAlignment.Right] = 1,
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
local HORIZONTAL_BIAS = {
|
|
15
|
-
[Enum.HorizontalAlignment.Left] = -1
|
|
16
|
-
[Enum.HorizontalAlignment.Center] = 0
|
|
17
|
-
[Enum.HorizontalAlignment.Right] = 1
|
|
15
|
+
[Enum.HorizontalAlignment.Left] = -1,
|
|
16
|
+
[Enum.HorizontalAlignment.Center] = 0,
|
|
17
|
+
[Enum.HorizontalAlignment.Right] = 1,
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
local VERTICAL_ALIGNMENT = {
|
|
21
|
-
[Enum.VerticalAlignment.Top] = 0
|
|
22
|
-
[Enum.VerticalAlignment.Center] = 0.5
|
|
23
|
-
[Enum.VerticalAlignment.Bottom] = 1
|
|
21
|
+
[Enum.VerticalAlignment.Top] = 0,
|
|
22
|
+
[Enum.VerticalAlignment.Center] = 0.5,
|
|
23
|
+
[Enum.VerticalAlignment.Bottom] = 1,
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
local VERTICAL_BIAS = {
|
|
27
|
-
[Enum.VerticalAlignment.Top] = -1
|
|
28
|
-
[Enum.VerticalAlignment.Center] = 0
|
|
29
|
-
[Enum.VerticalAlignment.Bottom] = 1
|
|
27
|
+
[Enum.VerticalAlignment.Top] = -1,
|
|
28
|
+
[Enum.VerticalAlignment.Center] = 0,
|
|
29
|
+
[Enum.VerticalAlignment.Bottom] = 1,
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
local VERTICAL_TO_HORIZONTAL = {
|
|
33
|
-
[Enum.VerticalAlignment.Top] = Enum.HorizontalAlignment.Left
|
|
34
|
-
[Enum.VerticalAlignment.Center] = Enum.HorizontalAlignment.Center
|
|
35
|
-
[Enum.VerticalAlignment.Bottom] = Enum.HorizontalAlignment.Right
|
|
33
|
+
[Enum.VerticalAlignment.Top] = Enum.HorizontalAlignment.Left,
|
|
34
|
+
[Enum.VerticalAlignment.Center] = Enum.HorizontalAlignment.Center,
|
|
35
|
+
[Enum.VerticalAlignment.Bottom] = Enum.HorizontalAlignment.Right,
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
local HORIZONTAL_TO_VERTICAL = {
|
|
39
|
-
[Enum.HorizontalAlignment.Left] = Enum.VerticalAlignment.Top
|
|
40
|
-
[Enum.HorizontalAlignment.Center] = Enum.VerticalAlignment.Center
|
|
41
|
-
[Enum.HorizontalAlignment.Right] = Enum.VerticalAlignment.Bottom
|
|
39
|
+
[Enum.HorizontalAlignment.Left] = Enum.VerticalAlignment.Top,
|
|
40
|
+
[Enum.HorizontalAlignment.Center] = Enum.VerticalAlignment.Center,
|
|
41
|
+
[Enum.HorizontalAlignment.Right] = Enum.VerticalAlignment.Bottom,
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
--[=[
|
|
@@ -47,7 +47,7 @@ local HORIZONTAL_TO_VERTICAL = {
|
|
|
47
47
|
@param alignment HorizontalAlignment | VertialAlignment
|
|
48
48
|
@return number
|
|
49
49
|
]=]
|
|
50
|
-
function UIAlignmentUtils.toNumber(alignment)
|
|
50
|
+
function UIAlignmentUtils.toNumber(alignment: Enum.HorizontalAlignment | Enum.VerticalAlignment): number
|
|
51
51
|
assert(alignment, "Bad alignment")
|
|
52
52
|
|
|
53
53
|
if HORIZONTAL_ALIGNMENT[alignment] then
|
|
@@ -64,12 +64,19 @@ end
|
|
|
64
64
|
@param verticalAlignment HorizontalAlignment
|
|
65
65
|
@return HorizontalAlignment
|
|
66
66
|
]=]
|
|
67
|
-
function UIAlignmentUtils.verticalToHorizontalAlignment(
|
|
67
|
+
function UIAlignmentUtils.verticalToHorizontalAlignment(
|
|
68
|
+
verticalAlignment: Enum.VerticalAlignment
|
|
69
|
+
): Enum.HorizontalAlignment
|
|
68
70
|
assert(verticalAlignment, "Bad verticalAlignment")
|
|
69
71
|
|
|
70
72
|
local found = VERTICAL_TO_HORIZONTAL[verticalAlignment]
|
|
71
73
|
if not found then
|
|
72
|
-
error(
|
|
74
|
+
error(
|
|
75
|
+
string.format(
|
|
76
|
+
"[UIAlignmentUtils.verticalToHorizontalAlignment] - Bad verticalAlignment %q",
|
|
77
|
+
tostring(verticalAlignment)
|
|
78
|
+
)
|
|
79
|
+
)
|
|
73
80
|
end
|
|
74
81
|
return found
|
|
75
82
|
end
|
|
@@ -79,24 +86,30 @@ end
|
|
|
79
86
|
@param horizontalAlignment HorizontalAlignment
|
|
80
87
|
@return VertialAlignment
|
|
81
88
|
]=]
|
|
82
|
-
function UIAlignmentUtils.horizontalToVerticalAlignment(
|
|
89
|
+
function UIAlignmentUtils.horizontalToVerticalAlignment(
|
|
90
|
+
horizontalAlignment: Enum.HorizontalAlignment
|
|
91
|
+
): Enum.VerticalAlignment
|
|
83
92
|
assert(horizontalAlignment, "Bad horizontalAlignment")
|
|
84
93
|
|
|
85
94
|
local found = HORIZONTAL_TO_VERTICAL[horizontalAlignment]
|
|
86
95
|
if not found then
|
|
87
|
-
error(
|
|
96
|
+
error(
|
|
97
|
+
string.format(
|
|
98
|
+
"[UIAlignmentUtils.horizontalToVerticalAlignment] - Bad horizontalAlignment %q",
|
|
99
|
+
tostring(horizontalAlignment)
|
|
100
|
+
)
|
|
101
|
+
)
|
|
88
102
|
end
|
|
89
103
|
return found
|
|
90
104
|
end
|
|
91
105
|
|
|
92
|
-
|
|
93
106
|
--[=[
|
|
94
107
|
Converts alignment to bias, as -1, 0, or 1
|
|
95
108
|
|
|
96
109
|
@param alignment HorizontalAlignment | VertialAlignment
|
|
97
110
|
@return number
|
|
98
111
|
]=]
|
|
99
|
-
function UIAlignmentUtils.toBias(alignment)
|
|
112
|
+
function UIAlignmentUtils.toBias(alignment: Enum.HorizontalAlignment | Enum.VerticalAlignment): number
|
|
100
113
|
assert(alignment, "Bad alignment")
|
|
101
114
|
|
|
102
115
|
if HORIZONTAL_BIAS[alignment] then
|
|
@@ -114,7 +127,7 @@ end
|
|
|
114
127
|
@param horizontalAlignment HorizontalAlignment
|
|
115
128
|
@return number
|
|
116
129
|
]=]
|
|
117
|
-
function UIAlignmentUtils.horizontalAlignmentToNumber(horizontalAlignment)
|
|
130
|
+
function UIAlignmentUtils.horizontalAlignmentToNumber(horizontalAlignment: Enum.HorizontalAlignment): number
|
|
118
131
|
assert(horizontalAlignment, "Bad horizontalAlignment")
|
|
119
132
|
|
|
120
133
|
if HORIZONTAL_ALIGNMENT[horizontalAlignment] then
|
|
@@ -130,7 +143,7 @@ end
|
|
|
130
143
|
@param horizontalAlignment HorizontalAlignment
|
|
131
144
|
@return number
|
|
132
145
|
]=]
|
|
133
|
-
function UIAlignmentUtils.horizontalAlignmentToBias(horizontalAlignment)
|
|
146
|
+
function UIAlignmentUtils.horizontalAlignmentToBias(horizontalAlignment: Enum.HorizontalAlignment): number
|
|
134
147
|
assert(horizontalAlignment, "Bad horizontalAlignment")
|
|
135
148
|
|
|
136
149
|
if HORIZONTAL_BIAS[horizontalAlignment] then
|
|
@@ -146,7 +159,7 @@ end
|
|
|
146
159
|
@param verticalAlignment VerticalAlignment
|
|
147
160
|
@return number
|
|
148
161
|
]=]
|
|
149
|
-
function UIAlignmentUtils.verticalAlignmentToNumber(verticalAlignment)
|
|
162
|
+
function UIAlignmentUtils.verticalAlignmentToNumber(verticalAlignment: Enum.VerticalAlignment): number
|
|
150
163
|
assert(verticalAlignment, "Bad verticalAlignment")
|
|
151
164
|
|
|
152
165
|
if VERTICAL_ALIGNMENT[verticalAlignment] then
|
|
@@ -162,7 +175,7 @@ end
|
|
|
162
175
|
@param verticalAlignment VerticalAlignment
|
|
163
176
|
@return number
|
|
164
177
|
]=]
|
|
165
|
-
function UIAlignmentUtils.verticalAlignmentToBias(verticalAlignment)
|
|
178
|
+
function UIAlignmentUtils.verticalAlignmentToBias(verticalAlignment: Enum.VerticalAlignment): number
|
|
166
179
|
assert(verticalAlignment, "Bad verticalAlignment")
|
|
167
180
|
|
|
168
181
|
if VERTICAL_BIAS[verticalAlignment] then
|
|
@@ -172,4 +185,4 @@ function UIAlignmentUtils.verticalAlignmentToBias(verticalAlignment)
|
|
|
172
185
|
end
|
|
173
186
|
end
|
|
174
187
|
|
|
175
|
-
return UIAlignmentUtils
|
|
188
|
+
return UIAlignmentUtils
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
@class UICornerUtils
|
|
3
4
|
]=]
|
|
@@ -10,7 +11,7 @@ local UICornerUtils = {}
|
|
|
10
11
|
@param parent Instance
|
|
11
12
|
@return UICorner
|
|
12
13
|
]=]
|
|
13
|
-
function UICornerUtils.fromScale(scale, parent)
|
|
14
|
+
function UICornerUtils.fromScale(scale: number, parent: Instance?): UICorner
|
|
14
15
|
local uiCorner = Instance.new("UICorner")
|
|
15
16
|
uiCorner.CornerRadius = UDim.new(scale, 0)
|
|
16
17
|
uiCorner.Parent = parent
|
|
@@ -23,7 +24,7 @@ end
|
|
|
23
24
|
@param parent Instance
|
|
24
25
|
@return UICorner
|
|
25
26
|
]=]
|
|
26
|
-
function UICornerUtils.fromOffset(offset, parent)
|
|
27
|
+
function UICornerUtils.fromOffset(offset: number, parent: Instance?): UICorner
|
|
27
28
|
local uiCorner = Instance.new("UICorner")
|
|
28
29
|
uiCorner.CornerRadius = UDim.new(0, offset)
|
|
29
30
|
uiCorner.Parent = parent
|
|
@@ -31,15 +32,29 @@ function UICornerUtils.fromOffset(offset, parent)
|
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
-- framePosition is top left corner
|
|
34
|
-
--
|
|
35
|
-
|
|
35
|
+
--[=[
|
|
36
|
+
Clamps a position to a frame with a rounded corner
|
|
37
|
+
|
|
38
|
+
@param framePosition Vector2 -- From top left corner
|
|
39
|
+
@param frameSize Vector2
|
|
40
|
+
@param radius number
|
|
41
|
+
@param point Vector2
|
|
42
|
+
@return Vector2? -- Position
|
|
43
|
+
@return Vector2? -- Normal
|
|
44
|
+
]=]
|
|
45
|
+
function UICornerUtils.clampPositionToFrame(
|
|
46
|
+
framePosition: Vector2,
|
|
47
|
+
frameSize: Vector2,
|
|
48
|
+
radius: number,
|
|
49
|
+
point: Vector2
|
|
50
|
+
): (Vector2?, Vector2?)
|
|
36
51
|
assert(radius >= 0, "Bad radius")
|
|
37
52
|
assert(point, "Bad point")
|
|
38
53
|
|
|
39
|
-
local px, py = point.
|
|
54
|
+
local px, py = point.X, point.Y
|
|
40
55
|
|
|
41
|
-
local fpx, fpy = framePosition.
|
|
42
|
-
local fsx, fsy = frameSize.
|
|
56
|
+
local fpx, fpy = framePosition.X, framePosition.Y
|
|
57
|
+
local fsx, fsy = frameSize.X, frameSize.Y
|
|
43
58
|
|
|
44
59
|
local minx = fpx + radius
|
|
45
60
|
local maxx = fpx + fsx - radius
|
|
@@ -66,14 +81,14 @@ function UICornerUtils.clampPositionToFrame(framePosition, frameSize, radius, po
|
|
|
66
81
|
|
|
67
82
|
-- project in direction of offset
|
|
68
83
|
local direction = point - position
|
|
69
|
-
if direction.
|
|
84
|
+
if direction.Magnitude == 0 then
|
|
70
85
|
-- Shouldn't happen!
|
|
71
86
|
return nil, nil
|
|
72
87
|
end
|
|
73
88
|
|
|
74
|
-
local normal = direction.
|
|
75
|
-
local outsidePosition = position + normal*radius
|
|
89
|
+
local normal = direction.Unit
|
|
90
|
+
local outsidePosition = position + normal * radius
|
|
76
91
|
return outsidePosition, normal
|
|
77
92
|
end
|
|
78
93
|
|
|
79
|
-
return UICornerUtils
|
|
94
|
+
return UICornerUtils
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Utility functions for UI padding
|
|
3
4
|
@class UIPaddingUtils
|
|
@@ -5,7 +6,10 @@
|
|
|
5
6
|
|
|
6
7
|
local UIPaddingUtils = {}
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
--[=[
|
|
10
|
+
Constructs a new UIPadding from a UDim
|
|
11
|
+
]=]
|
|
12
|
+
function UIPaddingUtils.fromUDim(udim: UDim): UIPadding
|
|
9
13
|
local uiPadding = Instance.new("UIPadding")
|
|
10
14
|
uiPadding.PaddingBottom = udim
|
|
11
15
|
uiPadding.PaddingTop = udim
|
|
@@ -15,22 +19,29 @@ function UIPaddingUtils.fromUDim(udim)
|
|
|
15
19
|
return uiPadding
|
|
16
20
|
end
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
--[=[
|
|
23
|
+
Compute the total padding for the UIPadding
|
|
24
|
+
]=]
|
|
25
|
+
function UIPaddingUtils.getTotalPadding(uiPadding: UIPadding): UDim2
|
|
26
|
+
return UDim2.new(uiPadding.PaddingLeft + uiPadding.PaddingRight, uiPadding.PaddingBottom + uiPadding.PaddingTop)
|
|
21
27
|
end
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
--[=[
|
|
30
|
+
Computes the total absolute padding for a UIPadding
|
|
31
|
+
]=]
|
|
32
|
+
function UIPaddingUtils.getTotalAbsolutePadding(uiPadding: UIPadding, absoluteSize: Vector2): Vector2
|
|
24
33
|
local padding = UIPaddingUtils.getTotalPadding(uiPadding)
|
|
25
34
|
return Vector2.new(
|
|
26
|
-
padding.X.Offset + padding.X.Scale*absoluteSize.
|
|
27
|
-
padding.Y.Offset + padding.Y.Scale*absoluteSize.Y
|
|
35
|
+
padding.X.Offset + padding.X.Scale * absoluteSize.X,
|
|
36
|
+
padding.Y.Offset + padding.Y.Scale * absoluteSize.Y
|
|
28
37
|
)
|
|
29
38
|
end
|
|
30
39
|
|
|
31
|
-
|
|
40
|
+
--[=[
|
|
41
|
+
Compute the horizontal Padding
|
|
42
|
+
]=]
|
|
43
|
+
function UIPaddingUtils.getHorizontalPadding(uiPadding: UIPadding): UDim
|
|
32
44
|
return uiPadding.PaddingLeft + uiPadding.PaddingRight
|
|
33
45
|
end
|
|
34
46
|
|
|
35
|
-
|
|
36
|
-
return UIPaddingUtils
|
|
47
|
+
return UIPaddingUtils
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
@class UIRotationUtils
|
|
3
4
|
]=]
|
|
@@ -6,13 +7,19 @@ local require = require(script.Parent.loader).load(script)
|
|
|
6
7
|
|
|
7
8
|
local UIRotationUtils = {}
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
--[=[
|
|
11
|
+
Converts a rotation to the unit circle
|
|
12
|
+
]=]
|
|
13
|
+
function UIRotationUtils.toUnitCircle(rotationDegrees: number): number
|
|
10
14
|
assert(type(rotationDegrees) == "number", "Bad rotationDegrees")
|
|
11
15
|
|
|
12
16
|
return -rotationDegrees + 90
|
|
13
17
|
end
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
--[=[
|
|
20
|
+
Converts a rotation to the unit circle direction
|
|
21
|
+
]=]
|
|
22
|
+
function UIRotationUtils.toUnitCircleDirection(rotationDegrees: number): Vector2
|
|
16
23
|
assert(type(rotationDegrees) == "number", "Bad rotationDegrees")
|
|
17
24
|
|
|
18
25
|
local angle = math.rad(UIRotationUtils.toUnitCircle(rotationDegrees))
|
|
@@ -23,11 +30,13 @@ function UIRotationUtils.toUnitCircleDirection(rotationDegrees)
|
|
|
23
30
|
return Vector2.new(x, y)
|
|
24
31
|
end
|
|
25
32
|
|
|
26
|
-
|
|
33
|
+
--[=[
|
|
34
|
+
Converts a rotation to the gui rotation vector
|
|
35
|
+
]=]
|
|
36
|
+
function UIRotationUtils.toGuiDirection(unitCircleDirection: Vector2): Vector2
|
|
27
37
|
assert(typeof(unitCircleDirection) == "Vector2", "Bad rotationAnchorPoint")
|
|
28
38
|
|
|
29
|
-
return unitCircleDirection*Vector2.new(1, -1)
|
|
39
|
+
return unitCircleDirection * Vector2.new(1, -1)
|
|
30
40
|
end
|
|
31
41
|
|
|
32
|
-
|
|
33
|
-
return UIRotationUtils
|
|
42
|
+
return UIRotationUtils
|