From 8a49f24249b59b274ffb8dc63c0c3dc766404357 Mon Sep 17 00:00:00 2001 From: Username404 Date: Wed, 19 May 2021 12:46:11 +0200 Subject: [PATCH] Fix the behaviour of Type.CLICK --- .../fr/username404/snowygui/gui/feature/ButtonImpl.kt | 9 ++++++--- .../fr/username404/snowygui/gui/feature/ButtonInfo.kt | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt index 4634cbf..400a82c 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt @@ -59,8 +59,10 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { private fun lightDown() { opacity -= ButtonInfo.lightningFactor } override fun mouseClicked(d: Double, e: Double, i: Int): Boolean { wasWithinBounds = withinBounds(d, e).also { - if (it && (info.kind == Type.TOGGLE)) { - toggled = !toggled + if (it) { + if (info.kind == Type.TOGGLE) { + toggled = !toggled + } else if (info.kind == Type.CLICK) lightUp() } } return false @@ -68,7 +70,8 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { override fun mouseReleased(d: Double, e: Double, i: Int): Boolean { if (wasWithinBounds && (info.kind == Type.CLICK)) { - toggled = true + execAction() + lightDown() }; return false } override fun render(poseStack: PoseStack?) { diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt index a938e7b..e0bca79 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt @@ -17,7 +17,7 @@ annotation class ButtonInfo( internal var lightningFactor: Float = 0.33F enum class Type { TOGGLE, - CLICK // TODO Fix the CLICK behaviour + CLICK } } }; enum class Category(val translationKey: String, val categoryColor: Colors) {