Thread
#compose
    Nat Strangerweather

    Nat Strangerweather

    1 year ago
    Is this the correct way of using text on a canvas in Compose? :thread-please:
    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

    Denis

    1 year ago
    afaik, there's no public API for rendering text on canvas, but you can try
    TextDelegate
    (search this channel)
    Nat Strangerweather

    Nat Strangerweather

    1 year ago
    Ooh thanks will check this out! 🙂
    @Denis Works perfectly, thanks!