@quenty/buttonhighlightmodel 14.11.1 → 14.12.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,18 @@
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
+ # [14.12.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/buttonhighlightmodel@14.11.1...@quenty/buttonhighlightmodel@14.12.0) (2024-11-06)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Include dependency ([2a0752d](https://github.com/Quenty/NevermoreEngine/commit/2a0752d3c9abb23d2c2fcefef1502bbb5906dc25))
12
+ * Mouse scrolling scrolling check ([2742ac4](https://github.com/Quenty/NevermoreEngine/commit/2742ac4a10cf1e852d381231e72153c941e03f88))
13
+
14
+
15
+
16
+
17
+
6
18
  ## [14.11.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/buttonhighlightmodel@14.11.0...@quenty/buttonhighlightmodel@14.11.1) (2024-11-04)
7
19
 
8
20
  **Note:** Version bump only for package @quenty/buttonhighlightmodel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/buttonhighlightmodel",
3
- "version": "14.11.1",
3
+ "version": "14.12.0",
4
4
  "description": "Contains model information for the current button",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -28,15 +28,16 @@
28
28
  "dependencies": {
29
29
  "@quenty/acceltween": "^2.5.0",
30
30
  "@quenty/baseobject": "^10.7.1",
31
- "@quenty/blend": "^12.11.1",
31
+ "@quenty/blend": "^12.12.0",
32
32
  "@quenty/loader": "^10.7.1",
33
33
  "@quenty/maid": "^3.4.0",
34
- "@quenty/rx": "^13.11.1",
34
+ "@quenty/rectutils": "^1.1.0",
35
+ "@quenty/rx": "^13.12.0",
35
36
  "@quenty/steputils": "^3.5.2",
36
- "@quenty/valueobject": "^13.11.1"
37
+ "@quenty/valueobject": "^13.12.0"
37
38
  },
38
39
  "publishConfig": {
39
40
  "access": "public"
40
41
  },
41
- "gitHead": "01c43a0ddd3c5e0cb2d9027313dbfa9852eedef1"
42
+ "gitHead": "00e6f71716216dd6ecbc8505ad898a1ab7f72756"
42
43
  }
@@ -42,6 +42,8 @@ local Maid = require("Maid")
42
42
  local Rx = require("Rx")
43
43
  local StepUtils = require("StepUtils")
44
44
  local ValueObject = require("ValueObject")
45
+ local RectUtils = require("RectUtils")
46
+ local RxInstanceUtils = require("RxInstanceUtils")
45
47
 
46
48
  local ButtonHighlightModel = setmetatable({}, BaseObject)
47
49
  ButtonHighlightModel.ClassName = "ButtonHighlightModel"
@@ -68,6 +70,11 @@ function ButtonHighlightModel.new(button, onUpdate)
68
70
  self._isKeyDown = self._maid:Add(ValueObject.new(false, "boolean"))
69
71
  self._isHighlighted = self._maid:Add(ValueObject.new(false, "boolean"))
70
72
 
73
+ -- Mouse state
74
+ self._isMouseOverBasedUponMouseMovement = self._maid:Add(ValueObject.new(false, "boolean"))
75
+ self._isMouseOverScrollingCheck = self._maid:Add(ValueObject.new(false, "boolean"))
76
+ self._lastMousePositionForScrollingCheck = self._maid:Add(ValueObject.new(nil))
77
+
71
78
  --[=[
72
79
  @prop InteractionEnabledChanged Signal<boolean>
73
80
  @readonly
@@ -153,7 +160,8 @@ function ButtonHighlightModel:SetButton(button: Instance)
153
160
  if button then
154
161
  maid:GiveTask(button.InputEnded:Connect(function(inputObject)
155
162
  if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
156
- self._isMouseOver.Value = false
163
+ self._lastMousePositionForScrollingCheck.Value = inputObject.Position
164
+ self._isMouseOverBasedUponMouseMovement.Value = false
157
165
  end
158
166
 
159
167
  if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
@@ -175,7 +183,9 @@ function ButtonHighlightModel:SetButton(button: Instance)
175
183
 
176
184
  maid:GiveTask(button.InputBegan:Connect(function(inputObject)
177
185
  if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
178
- self._isMouseOver.Value = true
186
+ self._isMouseOverBasedUponMouseMovement.Value = true
187
+ self._isMouseOverScrollingCheck.Value = true
188
+ self._lastMousePositionForScrollingCheck.Value = inputObject.Position
179
189
  end
180
190
 
181
191
  if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
@@ -186,6 +196,25 @@ function ButtonHighlightModel:SetButton(button: Instance)
186
196
  self:_trackTouch(inputObject)
187
197
  end
188
198
  end))
199
+
200
+ -- Track until something indicates removal
201
+ maid:GiveTask(self._isMouseOverBasedUponMouseMovement:ObserveBrio(function(mouseOver)
202
+ return mouseOver
203
+ end):Subscribe(function(brio)
204
+ if brio:IsDead() then
205
+ return
206
+ end
207
+
208
+ self:_trackIfButtonMovedOutFromMouse(brio:ToMaid(), button)
209
+ end))
210
+
211
+ -- We have to track as long as the mouse hasn't moved
212
+ maid:GiveTask(Rx.combineLatest({
213
+ isMouseOverFromInput = self._isMouseOverBasedUponMouseMovement:Observe();
214
+ isMouseOverScrollingCheck = self._isMouseOverScrollingCheck:Observe();
215
+ }):Subscribe(function(state)
216
+ self._isMouseOver.Value = state.isMouseOverFromInput and state.isMouseOverScrollingCheck
217
+ end))
189
218
  end
190
219
 
191
220
  self._maid._buttonMaid = maid
@@ -197,6 +226,44 @@ function ButtonHighlightModel:SetButton(button: Instance)
197
226
  end
198
227
  end
199
228
 
229
+ function ButtonHighlightModel:_trackIfButtonMovedOutFromMouse(maid, button)
230
+ maid:GiveTask(button.InputChanged:Connect(function(inputObject)
231
+ if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
232
+ self._lastMousePositionForScrollingCheck.Value = inputObject.Position
233
+ end
234
+ end))
235
+
236
+ maid:GiveTask(Rx.combineLatest({
237
+ mousePosition = self._lastMousePositionForScrollingCheck:Observe();
238
+ absolutePosition = RxInstanceUtils.observeProperty(button, "AbsolutePosition");
239
+ absoluteSize = RxInstanceUtils.observeProperty(button, "AbsoluteSize");
240
+ }):Pipe({
241
+ Rx.map(function(state)
242
+ if not state.mousePosition then
243
+ return true
244
+ end
245
+
246
+ local area = Rect.new(state.absolutePosition, state.absolutePosition + state.absoluteSize)
247
+
248
+ if RectUtils.contains(area, Vector2.new(state.mousePosition.x, state.mousePosition.y)) then
249
+ return true
250
+ end
251
+
252
+ -- TODO: check rounded corners and rotated guis
253
+
254
+ return false
255
+ end)
256
+ }):Subscribe(function(state)
257
+ self._isMouseOverScrollingCheck.Value = state
258
+ end))
259
+
260
+ maid:GiveTask(function()
261
+ self._isMouseOverScrollingCheck.Value = false
262
+ self._lastMousePositionForScrollingCheck.Value = nil
263
+ end)
264
+
265
+ end
266
+
200
267
  --[=[
201
268
  Gets if the button is pressed
202
269
  @return boolean