Fix Button#isEnabled ?

This commit is contained in:
Loof 2025-09-18 17:57:55 +02:00
parent d51ef24c20
commit 09ab647a79

View File

@ -55,6 +55,7 @@ private class RestorableTextButtonStyle(
//todo ButtonStyle *does* have a `disabled` Drawable, and Button ignores touches in disabled state anyway - all this is a wrong approach
/** Disable a [Button] by setting its [touchable][Button.touchable] and [style][Button.style] properties. */
fun Button.disable() {
touchable = Touchable.disabled
/** We want disabled buttons to "swallow" the click so that things behind aren't activated, so we don't change touchable
The action won't be activated due to [ActorAttachments.activate] checking the isDisabled property */
isDisabled = true
@ -65,6 +66,7 @@ fun Button.disable() {
}
/** Enable a [Button] by setting its [touchable][Button.touchable] and [style][Button.style] properties. */
fun Button.enable() {
touchable = Touchable.enabled
val oldStyle = style
if (oldStyle is RestorableTextButtonStyle) {
style = oldStyle.restoreStyle
@ -78,7 +80,12 @@ fun Button.enable() {
* which is more appropriate to toggle On/Off buttons, while this one is good for 'click-to-do-something' buttons.
*/
var Button.isEnabled: Boolean
get() = touchable == Touchable.enabled
get() = when (touchable) {
Touchable.enabled -> true
Touchable.disabled -> false
// idk what to do here
Touchable.childrenOnly -> throw IllegalStateException()
}
set(value) = if (value) enable() else disable()
fun colorFromHex(hexColor: Int): Color {