Hello all, looking for some help drawing text alon...
# compose
b
Hello all, looking for some help drawing text along an arc drawn in Canvas. Code in replies.
Drawing and arc on a canvas
Copy code
Canvas(modifier = Modifier.fillMaxSize()) {
   drawArc(
      Color.Green,
      30f,
      90f,
      topLeft = Offset(0f, 0f),
      useCenter = true,
      size = Size(sizeInPx, sizeInPx)
   )
}
I would like to draw text along the inside of that arc. Looks like I can use drawIntoCanvas and get ahold of the native canvas:
Copy code
Canvas(modifier = Modifier.fillMaxSize()) {
   drawIntoCanvas {
      it.nativeCanvas.drawText(
         sector.text,
         0f,
         0f,
         Paint().apply {
            setColor(android.graphics.Color.BLACK)
            textSize = textSizeInPx
         }
      )
   }
}
However that is not drawing along the arc path. From some searching looks like maybe there used to be a compose drawText method, but I don’t see that anymore. Looks like I might be able to use nativeCanvas.drawTextOnPath(), which requires another calculation of the arc. Am I going down the correct path?
s
pretty sure there is a
drawText
method. We just used one inside a
Canvas()
we used it inside of a
drawContext.canvas.nativeCanvas.apply { }
b
Right so there is a drawText on nativeCanvas, but not on the compose Canvas?
s
I think you’re right.
t
drawText
in compose canvas has been added to compose in 1.3.0-alpha02 you can give it a try