Created
March 4, 2023 19:46
-
-
Save fvilarino/f892b181e2d6b7195547596e48c3f324 to your computer and use it in GitHub Desktop.
Ticker - Text Properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Text( | |
text = letter.toString(), | |
color = textColor, | |
fontFamily = FontFamily.Monospace, | |
fontSize = fontSize, | |
modifier = modifier | |
.background(backgroundColor) | |
.drawBehind { | |
drawLine( | |
Color.Red, | |
Offset(x = 0f, y = center.y), | |
Offset( | |
x = size.width, | |
y = center.y | |
), | |
strokeWidth = density, | |
) | |
}, | |
onTextLayout = { textLayoutResult -> | |
// 1 | |
val layoutInput = textLayoutResult.layoutInput | |
// 2 | |
val fontSizePx = with(layoutInput.density) { layoutInput.style.fontSize.toPx() } | |
// 3 | |
val baseline = textLayoutResult.firstBaseline | |
// 4 | |
val top = textLayoutResult.getLineTop(0) | |
// 5 | |
val bottom = textLayoutResult.getLineBottom(0) | |
// 6 | |
val ascent = bottom - fontSizePx | |
// 7 | |
val descent = bottom - (baseline - fontSizePx - top) | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment