Implement the behaviour of Type.TOGGLE in ClickButton.kt

This commit is contained in:
Username404-59 2021-05-01 17:38:57 +02:00
parent f85ed7e605
commit b3c7fb1325
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 10 additions and 2 deletions

View File

@ -37,12 +37,20 @@ class ClickButton(
private fun lightUp() { opacity += lightningFactor } private fun lightUp() { opacity += lightningFactor }
private fun lightDown() { opacity -= lightningFactor } private fun lightDown() { opacity -= lightningFactor }
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean { override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
wasWithinBounds = withinBounds(d, e).also { if (it) lightUp() } wasWithinBounds = withinBounds(d, e).also {
if (it) {
if (!toggled) lightUp() else lightDown()
if ((kind == Type.TOGGLE)) {
if (toggled) execAction()
toggled = !toggled
}
}
}
return false return false
} }
override fun mouseReleased(d: Double, e: Double, i: Int): Boolean { override fun mouseReleased(d: Double, e: Double, i: Int): Boolean {
if (wasWithinBounds) { if (wasWithinBounds && (kind != Type.TOGGLE)) {
lightDown() lightDown()
execAction() execAction()
}; return false }; return false