Browse Source

Update README.md (#1328)

1.0-documentation v1.0.0-beta6-dev446
Igor Demin 3 years ago committed by GitHub
parent
commit
e632060753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 37
      tutorials/Mouse_Events/README.md

37
tutorials/Mouse_Events/README.md

@ -208,4 +208,39 @@ fun main() = singleWindowApplication {
```
<img alt="Application running" src="mouse_event.gif" height="500" />
If you need more information about events there is an available raw AWT mouse event object in `mouseEvent` property of `PointerEvent`
### Swing interoperability
Compose for Desktop uses Swing underneath and allows to access raw AWT events:
```kotlin
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.*
import androidx.compose.ui.window.singleWindowApplication
fun main() = singleWindowApplication {
var text by remember { mutableStateOf("") }
Box(
Modifier.fillMaxSize().pointerInput(Unit) {
while (true) {
val event = awaitPointerEventScope { awaitPointerEvent() }
val awtEvent = event.mouseEvent
if (event.type == PointerEventType.Press) {
text = awtEvent?.locationOnScreen?.toString().orEmpty()
}
}
},
contentAlignment = Alignment.Center
) {
Text(text)
}
}
```

Loading…
Cancel
Save