From b3c7fb1325ec1a08e4741d391684d2d433cae54c Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Sat, 1 May 2021 17:38:57 +0200 Subject: [PATCH] Implement the behaviour of Type.TOGGLE in ClickButton.kt --- .../username404/snowygui/gui/elements/ClickButton.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickButton.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickButton.kt index 2017e38..2034238 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickButton.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickButton.kt @@ -37,12 +37,20 @@ class ClickButton( private fun lightUp() { opacity += lightningFactor } private fun lightDown() { opacity -= lightningFactor } 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 } override fun mouseReleased(d: Double, e: Double, i: Int): Boolean { - if (wasWithinBounds) { + if (wasWithinBounds && (kind != Type.TOGGLE)) { lightDown() execAction() }; return false