|
|
|
@ -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,17 +22,20 @@ 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, |
|
|
|
|
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++}" |
|
|
|
@ -43,8 +47,9 @@ fun main() = Window(title = "Compose for Desktop", size = IntSize(400, 400)) {
|
|
|
|
|
text.value = "Long click! ${count.value++}" |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
.align(Alignment.Center) |
|
|
|
|
) |
|
|
|
|
Text(text = text.value, fontSize = 40.sp) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
|