Skip to content

Commit

Permalink
Update README.md (#1328)
Browse files Browse the repository at this point in the history
  • Loading branch information
igordmn authored Nov 1, 2021
1 parent b49c735 commit e632060
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion tutorials/Mouse_Events/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
```

0 comments on commit e632060

Please sign in to comment.