Is this the correct way of using text on a canvas ...
# compose
n
Is this the correct way of using text on a canvas in Compose? 🧵
Copy code
Canvas(modifier = Modifier
            .fillMaxWidth()
            .height(400.dp)
            .clipToBounds(),
            onDraw = {
                drawRect(Color.Blue)
                val paint = Paint()
                wordsAndColors.forEach { (word, color) ->
                    paint.textAlign = Paint.Align.CENTER
                    paint.textSize = 64f
                    paint.color = color.toArgb()
                    drawContext.canvas.nativeCanvas.drawText(
                        word,
                        center.x, center.y, paint
                    )
                }
            }
        )
And if so, how can I avoid words overlapping each other in the center of the canvas?
d
afaik, there's no public API for rendering text on canvas, but you can try
TextDelegate
(search this channel)
n
Ooh thanks will check this out! 🙂
@Denis Works perfectly, thanks!
👍 1