I have weird behaviours when calculating the size ...
# doodle
c
I have weird behaviours when calculating the size of a text using
TextMetrics
. More inđź§µ
When i try to calculate the size of a text with a custom font. At the widest possible, no room to properly render:
At medium width, all good
But all good with the default font, no matter the screen size:
Screenshot 2023-06-06 at 11.11.19 AM.png,Screenshot 2023-06-06 at 11.11.29 AM.png
n
can you share the code that calls the
TextMetrics
?
c
Sure
Copy code
val maxWidth = parent.width
val size = textMetrics.size(
    text = styledText,
    width = maxWidth,
    lineSpacing = lineHeight ?: 1f,
    textSpacing = TextSpacing(letterSpacing = letterSpacing ?: 0.0)
)
n
looks like you’re not passing in the font. you’ll need to do that to get an accurate measure for the custom font.
c
Okay. I thought since passing in the
StyledText
instead of the string will cover for font
n
ah, sorry i missed that you were using the
StyledText
API.
sounds like a bug if the
StyledText
has the right font.
c
Apologies, My font was null the whole time i was trying to calculate the size. it works well now, my bad.