mirror of
https://github.com/jlengrand/compose-multiplatform.git
synced 2026-03-10 08:11:20 +00:00
Update README.md (#1328)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user