@quenty/uiobjectutils 6.16.0 → 6.16.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
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
|
+
## [6.16.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/uiobjectutils@6.16.0...@quenty/uiobjectutils@6.16.1) (2025-04-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Add types to packages ([2374fb2](https://github.com/Quenty/NevermoreEngine/commit/2374fb2b043cfbe0e9b507b3316eec46a4e353a0))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [6.16.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/uiobjectutils@6.15.2...@quenty/uiobjectutils@6.16.0) (2025-04-02)
|
|
7
18
|
|
|
8
19
|
**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.16.
|
|
3
|
+
"version": "6.16.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.17.
|
|
32
|
-
"@quenty/enumutils": "^3.4.
|
|
33
|
-
"@quenty/instanceutils": "^13.17.
|
|
34
|
-
"@quenty/loader": "^10.8.
|
|
35
|
-
"@quenty/rx": "^13.17.
|
|
31
|
+
"@quenty/brio": "^14.17.1",
|
|
32
|
+
"@quenty/enumutils": "^3.4.1",
|
|
33
|
+
"@quenty/instanceutils": "^13.17.1",
|
|
34
|
+
"@quenty/loader": "^10.8.1",
|
|
35
|
+
"@quenty/rx": "^13.17.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "78c3ac0ab08dd18085b6e6e6e4f745e76ed99f68"
|
|
38
38
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
@class GuiInteractionUtils
|
|
3
4
|
]=]
|
|
@@ -7,6 +8,8 @@ local require = require(script.Parent.loader).load(script)
|
|
|
7
8
|
local RxInstanceUtils = require("RxInstanceUtils")
|
|
8
9
|
local Rx = require("Rx")
|
|
9
10
|
local RxBrioUtils = require("RxBrioUtils")
|
|
11
|
+
local _Observable = require("Observable")
|
|
12
|
+
local _Brio = require("Brio")
|
|
10
13
|
|
|
11
14
|
local GuiInteractionUtils = {}
|
|
12
15
|
|
|
@@ -16,7 +19,7 @@ local GuiInteractionUtils = {}
|
|
|
16
19
|
@param gui GuiObject
|
|
17
20
|
@return Observable<boolean>
|
|
18
21
|
]=]
|
|
19
|
-
function GuiInteractionUtils.observeInteractionEnabled(gui: GuiObject)
|
|
22
|
+
function GuiInteractionUtils.observeInteractionEnabled(gui: GuiObject): _Observable.Observable<boolean>
|
|
20
23
|
assert(typeof(gui) == "Instance" and gui:IsA("GuiObject"), "Bad gui")
|
|
21
24
|
|
|
22
25
|
return Rx.combineLatest({
|
|
@@ -27,9 +30,9 @@ function GuiInteractionUtils.observeInteractionEnabled(gui: GuiObject)
|
|
|
27
30
|
Rx.map(function(state)
|
|
28
31
|
return state.visible and state.guiState ~= Enum.GuiState.NonInteractable and state.dataModel and true
|
|
29
32
|
or false
|
|
30
|
-
end),
|
|
31
|
-
Rx.distinct(),
|
|
32
|
-
})
|
|
33
|
+
end) :: any,
|
|
34
|
+
Rx.distinct() :: any,
|
|
35
|
+
}) :: any
|
|
33
36
|
end
|
|
34
37
|
|
|
35
38
|
--[=[
|
|
@@ -37,16 +40,16 @@ end
|
|
|
37
40
|
interaction.
|
|
38
41
|
|
|
39
42
|
@param gui GuiObject
|
|
40
|
-
@return Observable<Brio
|
|
43
|
+
@return Observable<Brio<true>>
|
|
41
44
|
]=]
|
|
42
|
-
function GuiInteractionUtils.observeInteractionEnabledBrio(gui: GuiObject)
|
|
45
|
+
function GuiInteractionUtils.observeInteractionEnabledBrio(gui: GuiObject): _Observable.Observable<_Brio.Brio<true>>
|
|
43
46
|
assert(typeof(gui) == "Instance" and gui:IsA("GuiObject"), "Bad gui")
|
|
44
47
|
|
|
45
48
|
return GuiInteractionUtils.observeInteractionEnabled(gui):Pipe({
|
|
46
49
|
RxBrioUtils.switchToBrio(function(canInteract)
|
|
47
50
|
return canInteract
|
|
48
|
-
end),
|
|
49
|
-
})
|
|
51
|
+
end) :: any,
|
|
52
|
+
}) :: any
|
|
50
53
|
end
|
|
51
54
|
|
|
52
55
|
return GuiInteractionUtils
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Helper functions to observe parts of a Gui that are clipped or not
|
|
3
4
|
|
|
@@ -8,16 +9,23 @@ local require = require(script.Parent.loader).load(script)
|
|
|
8
9
|
|
|
9
10
|
local Rx = require("Rx")
|
|
10
11
|
local RxInstanceUtils = require("RxInstanceUtils")
|
|
12
|
+
local _Observable = require("Observable")
|
|
11
13
|
|
|
12
14
|
local RxClippedRectUtils = {}
|
|
13
15
|
|
|
16
|
+
type State = {
|
|
17
|
+
absolutePosition: Vector2,
|
|
18
|
+
absoluteSize: Vector2,
|
|
19
|
+
parentRect: Rect?,
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
--[=[
|
|
15
23
|
Observes the clipped rect for the given Gui
|
|
16
24
|
|
|
17
25
|
@param gui Gui
|
|
18
26
|
@return Observable<Rect>
|
|
19
27
|
]=]
|
|
20
|
-
function RxClippedRectUtils.observeClippedRect(gui: GuiObject)
|
|
28
|
+
function RxClippedRectUtils.observeClippedRect(gui: GuiObject): _Observable.Observable<Rect>
|
|
21
29
|
assert(typeof(gui) == "Instance" and gui:IsA("GuiObject"), "Bad GuiBase2d")
|
|
22
30
|
|
|
23
31
|
-- At least use our object's size here...
|
|
@@ -26,28 +34,34 @@ function RxClippedRectUtils.observeClippedRect(gui: GuiObject)
|
|
|
26
34
|
absoluteSize = RxInstanceUtils.observeProperty(gui, "AbsoluteSize"),
|
|
27
35
|
parentRect = RxClippedRectUtils._observeParentClippedRect(gui),
|
|
28
36
|
}):Pipe({
|
|
29
|
-
Rx.map(function(state)
|
|
37
|
+
Rx.map(function(state: State)
|
|
30
38
|
if state.parentRect then
|
|
31
39
|
return RxClippedRectUtils._computeClippedRect(state)
|
|
32
40
|
else
|
|
33
41
|
return Rect.new(Vector2.zero, Vector2.zero)
|
|
34
42
|
end
|
|
35
|
-
end),
|
|
36
|
-
Rx.distinct(),
|
|
37
|
-
})
|
|
43
|
+
end) :: any,
|
|
44
|
+
Rx.distinct() :: any,
|
|
45
|
+
}) :: any
|
|
38
46
|
end
|
|
39
47
|
|
|
40
48
|
local function clampVector2(value: Vector2): Vector2
|
|
41
49
|
return Vector2.new(math.clamp(value.X, 0, 1), math.clamp(value.Y, 0, 1))
|
|
42
50
|
end
|
|
43
51
|
|
|
52
|
+
type ClippedRectState = {
|
|
53
|
+
visibleRect: Rect,
|
|
54
|
+
absolutePosition: Vector2,
|
|
55
|
+
absoluteSize: Vector2,
|
|
56
|
+
}
|
|
57
|
+
|
|
44
58
|
--[=[
|
|
45
59
|
Observes the clipped rect for the given Gui, but in scale coordinates
|
|
46
60
|
|
|
47
61
|
@param gui Gui
|
|
48
62
|
@return Observable<Rect>
|
|
49
63
|
]=]
|
|
50
|
-
function RxClippedRectUtils.observeClippedRectInScale(gui: GuiObject)
|
|
64
|
+
function RxClippedRectUtils.observeClippedRectInScale(gui: GuiObject): _Observable.Observable<Rect>
|
|
51
65
|
assert(typeof(gui) == "Instance" and gui:IsA("GuiObject"), "Bad GuiBase2d")
|
|
52
66
|
|
|
53
67
|
return Rx.combineLatest({
|
|
@@ -55,8 +69,8 @@ function RxClippedRectUtils.observeClippedRectInScale(gui: GuiObject)
|
|
|
55
69
|
absoluteSize = RxInstanceUtils.observeProperty(gui, "AbsoluteSize"),
|
|
56
70
|
visibleRect = RxClippedRectUtils.observeClippedRect(gui),
|
|
57
71
|
}):Pipe({
|
|
58
|
-
Rx.map(function(state)
|
|
59
|
-
if state.absoluteSize.
|
|
72
|
+
Rx.map(function(state: ClippedRectState): Rect
|
|
73
|
+
if state.absoluteSize.X == 0 or state.absoluteSize.Y == 0 then
|
|
60
74
|
return Rect.new(Vector2.zero, Vector2.zero)
|
|
61
75
|
end
|
|
62
76
|
|
|
@@ -70,12 +84,12 @@ function RxClippedRectUtils.observeClippedRectInScale(gui: GuiObject)
|
|
|
70
84
|
local size = clampVector2(visibleSize / ourSize)
|
|
71
85
|
local bottomRight = topLeft + size
|
|
72
86
|
return Rect.new(topLeft, bottomRight)
|
|
73
|
-
end),
|
|
74
|
-
Rx.distinct(),
|
|
75
|
-
})
|
|
87
|
+
end) :: any,
|
|
88
|
+
Rx.distinct() :: any,
|
|
89
|
+
}) :: any
|
|
76
90
|
end
|
|
77
91
|
|
|
78
|
-
function RxClippedRectUtils._observeClippedRectImpl(gui: GuiObject)
|
|
92
|
+
function RxClippedRectUtils._observeClippedRectImpl(gui: GuiObject): _Observable.Observable<Rect>
|
|
79
93
|
if gui:IsA("GuiObject") then
|
|
80
94
|
return RxInstanceUtils.observeProperty(gui, "ClipsDescendants"):Pipe({
|
|
81
95
|
Rx.switchMap(function(clipDescendants)
|
|
@@ -90,10 +104,10 @@ function RxClippedRectUtils._observeClippedRectImpl(gui: GuiObject)
|
|
|
90
104
|
}):Pipe({
|
|
91
105
|
Rx.map(function(state)
|
|
92
106
|
return RxClippedRectUtils._computeClippedRect(state)
|
|
93
|
-
end),
|
|
94
|
-
})
|
|
95
|
-
end),
|
|
96
|
-
})
|
|
107
|
+
end) :: any,
|
|
108
|
+
}) :: any
|
|
109
|
+
end) :: any,
|
|
110
|
+
}) :: any
|
|
97
111
|
else
|
|
98
112
|
if not gui:IsA("LayerCollector") then
|
|
99
113
|
warn(
|
|
@@ -111,12 +125,12 @@ function RxClippedRectUtils._observeClippedRectImpl(gui: GuiObject)
|
|
|
111
125
|
}):Pipe({
|
|
112
126
|
Rx.map(function(state)
|
|
113
127
|
return RxClippedRectUtils._computeClippedRect(state)
|
|
114
|
-
end),
|
|
115
|
-
})
|
|
128
|
+
end) :: any,
|
|
129
|
+
}) :: any
|
|
116
130
|
end
|
|
117
131
|
end
|
|
118
132
|
|
|
119
|
-
function RxClippedRectUtils._computeClippedRect(state)
|
|
133
|
+
function RxClippedRectUtils._computeClippedRect(state: State): Rect
|
|
120
134
|
if not state.parentRect then
|
|
121
135
|
return Rect.new(state.absolutePosition, state.absolutePosition + state.absoluteSize)
|
|
122
136
|
end
|
|
@@ -126,11 +140,11 @@ function RxClippedRectUtils._computeClippedRect(state)
|
|
|
126
140
|
|
|
127
141
|
local parentMin = state.parentRect.Min
|
|
128
142
|
local parentMax = state.parentRect.Max
|
|
129
|
-
local topLeftX = math.max(topLeft.
|
|
130
|
-
local topLeftY = math.max(topLeft.
|
|
143
|
+
local topLeftX = math.max(topLeft.X, parentMin.X)
|
|
144
|
+
local topLeftY = math.max(topLeft.Y, parentMin.Y)
|
|
131
145
|
|
|
132
|
-
local bottomRightX = math.min(bottomRight.
|
|
133
|
-
local bottomRightY = math.min(bottomRight.
|
|
146
|
+
local bottomRightX = math.min(bottomRight.X, parentMax.X)
|
|
147
|
+
local bottomRightY = math.min(bottomRight.Y, parentMax.Y)
|
|
134
148
|
|
|
135
149
|
-- negative sizes not allowed...
|
|
136
150
|
local sizeX = math.max(0, bottomRightX - topLeftX)
|
|
@@ -139,18 +153,18 @@ function RxClippedRectUtils._computeClippedRect(state)
|
|
|
139
153
|
return Rect.new(topLeftX, topLeftY, topLeftX + sizeX, topLeftY + sizeY)
|
|
140
154
|
end
|
|
141
155
|
|
|
142
|
-
function RxClippedRectUtils._observeParentClippedRect(gui: GuiBase2d)
|
|
156
|
+
function RxClippedRectUtils._observeParentClippedRect(gui: GuiBase2d): _Observable.Observable<Rect?>
|
|
143
157
|
assert(typeof(gui) == "Instance" and gui:IsA("GuiBase2d"), "Bad GuiBase2d")
|
|
144
158
|
|
|
145
159
|
return RxInstanceUtils.observeFirstAncestor(gui, "GuiObject"):Pipe({
|
|
146
|
-
Rx.switchMap(function(parent)
|
|
160
|
+
Rx.switchMap(function(parent: GuiObject): any
|
|
147
161
|
if parent then
|
|
148
162
|
return RxClippedRectUtils._observeClippedRectImpl(parent)
|
|
149
163
|
else
|
|
150
164
|
return Rx.of(nil)
|
|
151
165
|
end
|
|
152
|
-
end),
|
|
153
|
-
})
|
|
166
|
+
end) :: any,
|
|
167
|
+
}) :: any
|
|
154
168
|
end
|
|
155
169
|
|
|
156
170
|
return RxClippedRectUtils
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Utility methods for working with horizontal and vertical alignment
|
|
3
4
|
@class UIAlignmentUtils
|
|
@@ -5,37 +6,37 @@
|
|
|
5
6
|
|
|
6
7
|
local UIAlignmentUtils = {}
|
|
7
8
|
|
|
8
|
-
local HORIZONTAL_ALIGNMENT = {
|
|
9
|
+
local HORIZONTAL_ALIGNMENT: { [Enum.HorizontalAlignment]: number } = {
|
|
9
10
|
[Enum.HorizontalAlignment.Left] = 0,
|
|
10
11
|
[Enum.HorizontalAlignment.Center] = 0.5,
|
|
11
12
|
[Enum.HorizontalAlignment.Right] = 1,
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
local HORIZONTAL_BIAS = {
|
|
15
|
+
local HORIZONTAL_BIAS: { [Enum.HorizontalAlignment]: number } = {
|
|
15
16
|
[Enum.HorizontalAlignment.Left] = -1,
|
|
16
17
|
[Enum.HorizontalAlignment.Center] = 0,
|
|
17
18
|
[Enum.HorizontalAlignment.Right] = 1,
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
local VERTICAL_ALIGNMENT = {
|
|
21
|
+
local VERTICAL_ALIGNMENT: { [Enum.VerticalAlignment]: number } = {
|
|
21
22
|
[Enum.VerticalAlignment.Top] = 0,
|
|
22
23
|
[Enum.VerticalAlignment.Center] = 0.5,
|
|
23
24
|
[Enum.VerticalAlignment.Bottom] = 1,
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
local VERTICAL_BIAS = {
|
|
27
|
+
local VERTICAL_BIAS: { [Enum.VerticalAlignment]: number } = {
|
|
27
28
|
[Enum.VerticalAlignment.Top] = -1,
|
|
28
29
|
[Enum.VerticalAlignment.Center] = 0,
|
|
29
30
|
[Enum.VerticalAlignment.Bottom] = 1,
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
local VERTICAL_TO_HORIZONTAL = {
|
|
33
|
+
local VERTICAL_TO_HORIZONTAL: { [Enum.VerticalAlignment]: Enum.HorizontalAlignment } = {
|
|
33
34
|
[Enum.VerticalAlignment.Top] = Enum.HorizontalAlignment.Left,
|
|
34
35
|
[Enum.VerticalAlignment.Center] = Enum.HorizontalAlignment.Center,
|
|
35
36
|
[Enum.VerticalAlignment.Bottom] = Enum.HorizontalAlignment.Right,
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
local HORIZONTAL_TO_VERTICAL = {
|
|
39
|
+
local HORIZONTAL_TO_VERTICAL: { [Enum.HorizontalAlignment]: Enum.VerticalAlignment } = {
|
|
39
40
|
[Enum.HorizontalAlignment.Left] = Enum.VerticalAlignment.Top,
|
|
40
41
|
[Enum.HorizontalAlignment.Center] = Enum.VerticalAlignment.Center,
|
|
41
42
|
[Enum.HorizontalAlignment.Right] = Enum.VerticalAlignment.Bottom,
|
|
@@ -50,10 +51,10 @@ local HORIZONTAL_TO_VERTICAL = {
|
|
|
50
51
|
function UIAlignmentUtils.toNumber(alignment: Enum.HorizontalAlignment | Enum.VerticalAlignment): number
|
|
51
52
|
assert(alignment, "Bad alignment")
|
|
52
53
|
|
|
53
|
-
if HORIZONTAL_ALIGNMENT[alignment] then
|
|
54
|
-
return HORIZONTAL_ALIGNMENT[alignment]
|
|
55
|
-
elseif VERTICAL_ALIGNMENT[alignment] then
|
|
56
|
-
return VERTICAL_ALIGNMENT[alignment]
|
|
54
|
+
if HORIZONTAL_ALIGNMENT[alignment :: any] then
|
|
55
|
+
return HORIZONTAL_ALIGNMENT[alignment :: any]
|
|
56
|
+
elseif VERTICAL_ALIGNMENT[alignment :: any] then
|
|
57
|
+
return VERTICAL_ALIGNMENT[alignment :: any]
|
|
57
58
|
else
|
|
58
59
|
error(string.format("[UIAlignmentUtils.toNumber] - Bad alignment %q", tostring(alignment)))
|
|
59
60
|
end
|
|
@@ -112,10 +113,10 @@ end
|
|
|
112
113
|
function UIAlignmentUtils.toBias(alignment: Enum.HorizontalAlignment | Enum.VerticalAlignment): number
|
|
113
114
|
assert(alignment, "Bad alignment")
|
|
114
115
|
|
|
115
|
-
if HORIZONTAL_BIAS[alignment] then
|
|
116
|
-
return HORIZONTAL_BIAS[alignment]
|
|
117
|
-
elseif VERTICAL_BIAS[alignment] then
|
|
118
|
-
return VERTICAL_BIAS[alignment]
|
|
116
|
+
if HORIZONTAL_BIAS[alignment :: any] then
|
|
117
|
+
return HORIZONTAL_BIAS[alignment :: any]
|
|
118
|
+
elseif VERTICAL_BIAS[alignment :: any] then
|
|
119
|
+
return VERTICAL_BIAS[alignment :: any]
|
|
119
120
|
else
|
|
120
121
|
error(string.format("[UIAlignmentUtils.toBias] - Bad alignment %q", tostring(alignment)))
|
|
121
122
|
end
|