Fix the behaviour of Type.CLICK

This commit is contained in:
Username404 2021-05-19 12:46:11 +02:00
parent 69625d3aef
commit 8a49f24249
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
2 changed files with 7 additions and 4 deletions

View File

@ -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)) {
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?) {

View File

@ -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) {