Hi! I have a `Text` displaying a multiline String...
# compose-desktop
d
Hi! I have a
Text
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?
oh I guess that was added in 1.4 which isn't MPP yet
I suppose something like
Copy code
var 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 for
d
This is perfect, thank you! I'll wait for 1.4 to arrive and until then will try the latter solution.