Skip to content

Instantly share code, notes, and snippets.

@cp-radhika-s
Created November 8, 2022 09:14
Show Gist options
  • Save cp-radhika-s/18d1b3cdd12fadc0d34d5d9fef924736 to your computer and use it in GitHub Desktop.
Save cp-radhika-s/18d1b3cdd12fadc0d34d5d9fef924736 to your computer and use it in GitHub Desktop.
@OptIn(ExperimentalTextApi::class)
@Composable
fun ExampleTextLayoutResult() {
val textMeasure = rememberTextMeasurer()
var textLayoutResult by remember { mutableStateOf<TextLayoutResult?>(null) }
Canvas(
modifier = Modifier
.fillMaxWidth()
.height(100.dp)
.layout { measurable, constraints ->
...
}
) {
drawRect(color = Color.Black)
textLayoutResult?.let {
drawText(
textLayoutResult = it,
alpha = 1f,
shadow = Shadow(color = Color.Red, offset = Offset(5f, 8f)),
textDecoration = TextDecoration.Underline
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment