drawText

fun DrawScope.drawText(text: String, x: Float = 0.0f, y: Float = 0.0f, paint: Paint? = null, font: Font? = null, @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f)

Draws text with its top-left corner positioned at (x, y).

Unlike raw java.awt.Graphics2D.drawString which places the font baseline at y, this follows AndroidX's convention where (x, y) is the top-left corner of the rendered text block.

Parameters

text

the text to render.

x

horizontal offset of the top-left corner.

y

vertical offset of the top-left corner.

paint

the Paint to draw with, or null to keep the graphics context's current paint.

font

the Font to render with, or null to keep the graphics context's current font.

alpha

the opacity to render with.


fun DrawScope.drawText(text: String, topLeft: Point2D, paint: Paint? = null, font: Font? = null, @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f)

Draws text with its top-left corner positioned at topLeft.

Parameters

text

the text to render.

topLeft

coordinates of the top-left corner.

paint

the Paint to draw with, or null to keep the graphics context's current paint.

font

the Font to render with, or null to keep the graphics context's current font.

alpha

the opacity to render with.


fun DrawScope.drawText(textLayout: TextLayout, topLeft: Point2D, paint: Paint? = null, @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f)

Draws textLayout with its top-left corner positioned at topLeft.

Parameters

textLayout

the pre-computed text layout to render.

topLeft

coordinates of the top-left corner.

paint

the Paint to draw with, or null to keep the graphics context's current paint.

alpha

the opacity to render with.