dimsuz
03/12/2023, 11:11 PMText
displaying a multiline String. What would be the nicest way (or any way) to find out which line of this Text is under the mouse cursor?
I see that Text
has onTextLayout
, so I guess I can use it to calculate stuff, so then the question boils down to:
How do I get coordinates of the mouse cursor relative to the currently rendered Composable underneath it?ephemient
03/12/2023, 11:16 PMephemient
03/12/2023, 11:33 PMvar layoutResult: TextLayoutResult? by remember { mutableStateOf(null) }
Text(
...,
modifier = Modifier
.pointerInput(Unit) {
awaitPointerEventScope {
while (true) {
val event = awaitPointerEvent()
layoutResult?.getLineForVerticalPosition(event.changes[0].position.y)
}
}
},
onTextLayout = {
layoutResult = it
},
...
)
might be what you're looking fordimsuz
03/13/2023, 11:26 AM