mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-20 02:59:19 +01:00
Don't spam drag events if asked nicely
This commit is contained in:
parent
b17efa3aa2
commit
c9f8f4a123
@ -23,6 +23,11 @@ trait MouseHandler extends Widget {
|
|||||||
|
|
||||||
protected def receiveDragEvents: Boolean = false
|
protected def receiveDragEvents: Boolean = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If `true`, drag events, once they start, will be sent on every update cycle when if the mouse does not move.
|
||||||
|
*/
|
||||||
|
protected def spamDragEvents: Boolean = true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If `true`, a [[ClickEvent]] will be registered even if the mouse button is released
|
* If `true`, a [[ClickEvent]] will be registered even if the mouse button is released
|
||||||
* outside the tolerance threshold, as long as it stays within the widget's bounds.
|
* outside the tolerance threshold, as long as it stays within the widget's bounds.
|
||||||
@ -89,7 +94,7 @@ trait MouseHandler extends Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dragButtons.foreach(button => {
|
for (button <- dragButtons if spamDragEvents || prevPositions(button) != mousePos) {
|
||||||
handleEvent(
|
handleEvent(
|
||||||
DragEvent(
|
DragEvent(
|
||||||
DragEvent.State.Drag,
|
DragEvent.State.Drag,
|
||||||
@ -99,9 +104,9 @@ trait MouseHandler extends Widget {
|
|||||||
mousePos - prevPositions(button),
|
mousePos - prevPositions(button),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
prevPositions(button) = mousePos
|
prevPositions(button) = mousePos
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -103,8 +103,9 @@ class TextInput(val initialText: String = "") extends Widget with MouseHandler w
|
|||||||
override def maximumSize: Size2D = Size2D(Float.PositiveInfinity, 24)
|
override def maximumSize: Size2D = Size2D(Float.PositiveInfinity, 24)
|
||||||
|
|
||||||
override def receiveAllMouseEvents = true
|
override def receiveAllMouseEvents = true
|
||||||
override def receiveDragEvents: Boolean = true
|
override protected def receiveDragEvents: Boolean = true
|
||||||
override def receiveClickEvents: Boolean = true
|
override protected def receiveClickEvents: Boolean = true
|
||||||
|
override protected def spamDragEvents: Boolean = false
|
||||||
|
|
||||||
private def mouseInBounds: Boolean = clippedBounds.contains(UiHandler.mousePosition)
|
private def mouseInBounds: Boolean = clippedBounds.contains(UiHandler.mousePosition)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user