I feel that the decision to implement tooltips via...
# compose-desktop
a
I feel that the decision to implement tooltips via composition is not the best idea. It interferes with the layout by forcing a Box where I didn’t want one.
For example I have a Row with two Texts and I want both to have the same tooltip. I can’t just wrap them both in one TooltipArea.
c
What would the alternative be? I think in your case, you should wrap your Row in TooltipArea, not put the TooltipArea inside the Row. The
TooltipArea
allows you to customize the placement of the tooltip, with the default being
CursorPoint
. From a quick glance as its source,
CursorPoint
doesn’t really care about the bounds of the parent Box and just places the popup at the cursor’s location. But you could use
ComponentRect
to place it relative to the TooltipArea’s Box, or you could write your own implementation to place the tooltip anywhere on the screen you’d like
a
Would it not be possible to do it via a modifier?
I would still need to specify it on both Texts, so it doesn’t completely solve it. But still better.
c
Looking at the source,
TooltipArea
is essentially 2 things: A Modifier that watches for the cursor position to determine when to show the popup, and then a
Popup
Composable to actually display your content. Modifiers don’t create new UI elements, which is why it needs that separate
Popup
to display the content. But you might be able to hack something together with
Modifier.drawWithContent { }
and the other modifiers taken from the TooltipArea’s original source (it’s pretty minimal, shouldn’t be too difficult to copy it all over to your project). But note that the default Canvas doesn’t have any way to draw text, but I think you can drop down to the native Skiko canvas to add text to the
Modifier.drawWithContent
canvas
107 Views