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

Sean Proctor

03/27/2024, 1:57 PM
I'm having an issue with a font that is offset downward for no apparent reason. I'm trying to get it vertically centered and it is shifted down outside of the
Text
composable. The same font on Android is fine and all other fonts work as expected on desktop.
Screenshot from 2024-03-27 09-55-29.png
Copy code
Box(Modifier.fillMaxWidth()) {
    Text(
        text = value,
        color = textColor,
        fontFamily = remember { getFont(MR.fonts.digitalmono_regular) },
        style = MaterialTheme.typography.displaySmall,
        maxLines = 1,
        overflow = TextOverflow.Ellipsis,
        modifier = Modifier
            .padding(8.dp)
            .align(Alignment.CenterEnd)
            .background(Color.Red)
    )
}
g

Garret Yoder

03/27/2024, 5:42 PM
can you try setting lineHeight to the same as the text size?
s

Sean Proctor

03/27/2024, 7:12 PM
Yes, I tried that. I don't think it's necessary when using the theme typography though.
g

Garret Yoder

03/27/2024, 7:13 PM
I've had some really weird behavior on desktop specifically before that matching the two solved, not sure if it'd fix it for you too.
s

Sean Proctor

03/27/2024, 7:16 PM
No, setting the line height actually made it worse.
g

Garret Yoder

03/27/2024, 7:17 PM
Hm. Out of curiosity what happens if you set the lineheight to textsize*2? I wonder if something's not calculating correctly.
s

Sean Proctor

03/27/2024, 7:21 PM
that was a good idea. it's off the bottom of the box. setting the lineheight to 0 puts it where it should be.
g

Garret Yoder

03/27/2024, 7:24 PM
Yeah sounds like some math isn't mathing properly. At least you've got a workaround for now.
s

Sean Proctor

03/27/2024, 7:25 PM
My workaround is just to ditch this font.
z

Zoltan Demant

03/28/2024, 9:03 AM
Out of curiosity, which font was it? Which font works for you? Trying to figure out if my issue is the same, it does sound like it but all the font Ive tried fail in the exact same way 🤷🏽‍♂️
s

Sean Proctor

03/28/2024, 12:21 PM
It was this font: https://www.dafont.com/digital-7.font The default monospace font works fine.
🙏🏽 1
3 Views