aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThunderblade73 <85900443+Thunderblade73@users.noreply.github.com>2024-06-12 16:29:37 +0200
committerGitHub <noreply@github.com>2024-06-12 16:29:37 +0200
commit191709f74379465286aa47142b8962849c67aa7f (patch)
tree84f6322766bc172b00e5f98e51faee1f867a5749 /src
parent637fd3bc9fe05ade7a2bb609a429b20b1e0dd1e9 (diff)
downloadskyhanni-191709f74379465286aa47142b8962849c67aa7f.tar.gz
skyhanni-191709f74379465286aa47142b8962849c67aa7f.tar.bz2
skyhanni-191709f74379465286aa47142b8962849c67aa7f.zip
Fix: Scrollables infinitly scrolling (#2053)
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/ScrollInput.kt23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/ScrollInput.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/ScrollInput.kt
index e47cca31c..b255859ec 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/ScrollInput.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/ScrollInput.kt
@@ -8,7 +8,7 @@ abstract class ScrollInput(
protected val maxValue: Int,
protected val velocity: Double,
protected val dragScrollMouseButton: Int?,
- startValue: Double?
+ startValue: Double?,
) {
init {
@@ -22,8 +22,6 @@ abstract class ScrollInput(
}
get() = scrollValue.getValue()
- private var mouseEventTime = 0L
-
fun asInt() = scroll.toInt()
fun asDouble() = scroll
@@ -34,12 +32,7 @@ abstract class ScrollInput(
scroll = scroll.coerceIn(minValue.toDouble(), maxValue.toDouble())
}
- protected fun isMouseEventValid(): Boolean {
- val mouseEvent = Mouse.getEventNanoseconds()
- val mouseEventsValid = mouseEvent - mouseEventTime > 20L
- mouseEventTime = mouseEvent
- return mouseEventsValid
- }
+ protected fun isMouseEventValid(): Boolean = scrollValue.isMouseEventValid()
abstract fun update(isValid: Boolean)
@@ -51,7 +44,7 @@ abstract class ScrollInput(
maxHeight: Int,
velocity: Double,
dragScrollMouseButton: Int?,
- startValue: Double? = null
+ startValue: Double? = null,
) : ScrollInput(scrollValue, minHeight, maxHeight, velocity, dragScrollMouseButton, startValue) {
override fun update(isValid: Boolean) {
if (maxValue < minValue) return
@@ -70,6 +63,9 @@ abstract class ScrollInput(
class ScrollValue {
var field: Double? = null
+
+ private var mouseEventTime = 0L
+
fun getValue(): Double =
field ?: throw IllegalStateException("ScrollValue should be initialized before get.")
@@ -82,4 +78,11 @@ class ScrollValue {
field = value
}
+ fun isMouseEventValid(): Boolean {
+ val mouseEvent = Mouse.getEventNanoseconds()
+ val mouseEventsValid = mouseEvent - mouseEventTime > 20L
+ mouseEventTime = mouseEvent
+ return mouseEventsValid
+ }
+
}