https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
a

adte

03/13/2023, 2:13 AM
Hey guys, I'm using the
drawBehind
modifier, which doesn't provide a Composable scope. However I need a composable scope in order to use
rememberTextMeasurer
in
drawText
. How can I do that?
l

Loney Chou

03/13/2023, 3:31 AM
remember
it in a composable, then use it in
drawBehind
. If you don't have one, wrap it with
Modifier.composed
.
a

adte

03/13/2023, 4:53 AM
@Loney Chou Ah, I see thank you. It's annoying to have to pass text measurer instance into all my drawing functions, though 😕
e

efemoney

03/13/2023, 8:19 AM
That is what
Modifier.composed
is for
e

ephemient

03/13/2023, 8:42 AM
or use
drawWithCache
e.g. this will effectively "remember" the
TextMeasurer
across draw calls:
Copy code
val fontFamilyResolver = LocalFontFamilyResolver.current
Modifier
    .drawWithCache {
        val textMeasurer = TextMeasurer(fontFamilyResolver, this, layoutDirection)
        onDrawBehind {
            drawText(textMeasurer, "Hello, world!")
        }
    }
I suppose it doesn't really have a benefit over
rememberTextMeasurer()
outside, though
z

Zach Klippenstein (he/him) [MOD]

03/13/2023, 4:05 PM
@Halil Ozercan Maybe we need a sibling to
rememberTextMeasurer
that can be used from
Modifier.Node
?
h

Halil Ozercan

03/13/2023, 4:13 PM
This was discussed the first time around we were designing the TextMeasurer. The best approach is to be able to instantiate a TextMeasurer solely from drawWithCache scope. Now that we have the ability to read locals (LocalFontFamilyResolver) in Modifier.Node, there should be nothing stopping us from doing that.
z

Zach Klippenstein (he/him) [MOD]

03/13/2023, 4:40 PM
What if it’s also needed from a layout modifier, like for the BTF2 use case?
e

efemoney

03/19/2023, 10:16 AM
@Halil Ozercan reading Locals from node is not implemented in any released version right? Is there an open PR or something I can look at to see more details
e

efemoney

03/19/2023, 1:15 PM
Amazing! Is this making it into 1.4? (pls say yes black 😅)
h

Halil Ozercan

03/19/2023, 2:50 PM
@Andrew Bailey This was merged right after API freeze was lifted so I'm gonna assume it's part of 1.5 track?
a

Andrew Bailey

03/19/2023, 2:52 PM
Yes. It's going in as part of 1.5
20 Views