Skip to content

Instantly share code, notes, and snippets.

@fvilarino
Created March 4, 2023 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fvilarino/f892b181e2d6b7195547596e48c3f324 to your computer and use it in GitHub Desktop.
Save fvilarino/f892b181e2d6b7195547596e48c3f324 to your computer and use it in GitHub Desktop.
Ticker - Text Properties
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