Browse Source

Update click tutorial.

pull/215/head
Nikolay Igotti 4 years ago
parent
commit
872b9e05cc
  1. 15
      tutorials/Mouse_Events/README.md
  2. BIN
      tutorials/Mouse_Events/mouse_click.gif

15
tutorials/Mouse_Events/README.md

@ -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,17 +22,20 @@ 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)
.fillMaxWidth(0.7f)
.fillMaxHeight(0.2f)
.clickable( .clickable(
onClick = { onClick = {
text.value = "Click! ${count.value++}" 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++}" text.value = "Long click! ${count.value++}"
} }
) )
.align(Alignment.Center)
) )
Text(text = text.value, fontSize = 40.sp)
}
} }
} }
``` ```

BIN
tutorials/Mouse_Events/mouse_click.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

Loading…
Cancel
Save