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