![JAR search and dependency download from the Maven repository](/logo.png)
net.peanuuutz.fork.ui.foundation.input.Clickable.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fork-ui Show documentation
Show all versions of fork-ui Show documentation
Comprehensive API designed for Minecraft modders
The newest version!
package net.peanuuutz.fork.ui.foundation.input
import androidx.compose.runtime.Stable
import androidx.compose.runtime.remember
import kotlinx.coroutines.CoroutineScope
import net.peanuuutz.fork.ui.foundation.input.interaction.MutableInteractionSource
import net.peanuuutz.fork.ui.ui.modifier.Modifier
import net.peanuuutz.fork.ui.ui.modifier.composed
import net.peanuuutz.fork.ui.ui.modifier.conditional
@Stable
fun Modifier.clickable(
label: Any? = null,
isEnabled: Boolean = true,
onClick: CoroutineScope.() -> Unit
): Modifier {
if (!isEnabled) {
return this
}
return composed {
clickable(
interactionSource = remember { MutableInteractionSource() },
label = label,
indication = LocalVisualIndication.current,
onClick = onClick
)
}
}
@Stable
fun Modifier.clickable(
interactionSource: MutableInteractionSource? = null,
label: Any? = null,
indication: VisualIndication? = null,
isEnabled: Boolean = true,
onClick: CoroutineScope.() -> Unit
): Modifier {
if (!isEnabled) {
return this
}
return this
.pressable(
interactionSource = interactionSource,
label = label,
onRelease = onClick
)
.conditional(interactionSource != null) {
interactionSource!!
this
.hoverable(
interactionSource = interactionSource,
label = label
)
.focusable(
interactionSource = interactionSource,
label = label
)
.visualIndication(
interactionSource = interactionSource,
indication = indication,
label = label
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy