|
|
|
@ -14,6 +14,7 @@ so code like this will work on both platforms:
|
|
|
|
|
|
|
|
|
|
```kotlin |
|
|
|
|
import androidx.compose.desktop.Window |
|
|
|
|
import androidx.compose.foundation.background |
|
|
|
|
import androidx.compose.foundation.clickable |
|
|
|
|
import androidx.compose.foundation.layout.* |
|
|
|
|
import androidx.compose.material.Text |
|
|
|
@ -21,30 +22,34 @@ import androidx.compose.runtime.mutableStateOf
|
|
|
|
|
import androidx.compose.runtime.remember |
|
|
|
|
import androidx.compose.ui.Alignment |
|
|
|
|
import androidx.compose.ui.Modifier |
|
|
|
|
import androidx.compose.ui.graphics.Color |
|
|
|
|
import androidx.compose.ui.unit.IntSize |
|
|
|
|
import androidx.compose.ui.unit.sp |
|
|
|
|
|
|
|
|
|
fun main() = Window(title = "Compose for Desktop", size = IntSize(400, 400)) { |
|
|
|
|
var count = remember { mutableStateOf(0) } |
|
|
|
|
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxWidth()) { |
|
|
|
|
var text = remember { mutableStateOf("Click me!") } |
|
|
|
|
Text( |
|
|
|
|
text = text.value, |
|
|
|
|
fontSize = 50.sp, |
|
|
|
|
modifier = Modifier |
|
|
|
|
.clickable( |
|
|
|
|
onClick = { |
|
|
|
|
text.value = "Click! ${count.value++}" |
|
|
|
|
}, |
|
|
|
|
onDoubleClick = { |
|
|
|
|
text.value = "Double click! ${count.value++}" |
|
|
|
|
}, |
|
|
|
|
onLongClick = { |
|
|
|
|
text.value = "Long click! ${count.value++}" |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
.align(Alignment.Center) |
|
|
|
|
) |
|
|
|
|
var text = remember { mutableStateOf("Click magenta box!") } |
|
|
|
|
Column { |
|
|
|
|
Box( |
|
|
|
|
modifier = Modifier |
|
|
|
|
.background(Color.Magenta) |
|
|
|
|
.fillMaxWidth(0.7f) |
|
|
|
|
.fillMaxHeight(0.2f) |
|
|
|
|
.clickable( |
|
|
|
|
onClick = { |
|
|
|
|
text.value = "Click! ${count.value++}" |
|
|
|
|
}, |
|
|
|
|
onDoubleClick = { |
|
|
|
|
text.value = "Double click! ${count.value++}" |
|
|
|
|
}, |
|
|
|
|
onLongClick = { |
|
|
|
|
text.value = "Long click! ${count.value++}" |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
Text(text = text.value, fontSize = 40.sp) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
|