Q: How can I draw text on a `Canvas` ? Can anyone ...
# compose-desktop
t
Q: How can I draw text on a
Canvas
? Can anyone show me some sample code?
j
IIRC, unfortunately, drawing text on Canvas is not yet supported but is on the todo list. cc @Nader Jawad @Siyamed
👍 1
t
Noted. Thanks for responding 👍
n
Depending on the use case it migjt be easier to use a text composable with Modifier.drawBehind to allow you to issue drawing commands behind the text itself
t
that wudn't cover my usecase @Nader Jawad, but thanks for the info. didn't know that method.
n
You can also access the android.graphics.Canvas object in a DrawScope using
drawIntoCanvas { canvas -> canvas.nativeCanvas.drawText}
if you need to
n
Compose's DrawScope API leverages a compose Canvas interface which is a wrapper around android.graphics.Canvas on Android. With each of the APIs that interact with the system we provide interop APIs of the form native<X> or asAndroid<X> and can jump back into the compose world by using toCompose<X>
While we don't provide a direct primitive to draw text with composed graphics APIs directly outside of the Text composable you can always jump back into the Android APIs as a workaround
j
Or in this case, that would be back to the native desktop skia APIs.
t
Yeah, this looks useful.
s
you can also use Paragraph() construct or Text() composable directly.
we have a ticket for that ticket number: 159949181
t
@Siyamed Can you give me the full url ?
j
t
Alright thanks )