Package-level declarations

Types

Link copied to clipboard
sealed interface ContentDrawScope : DrawScope

The receiver scope of a draw node, which draws between other operations on the same surface. If drawContent is not called, what the node wraps is not drawn.

Link copied to clipboard
sealed interface DrawScope

The receiver scope for drawing operations inside org.jetbrains.compose.swing.foundation.Canvas, aligned with androidx's DrawScope.

Link copied to clipboard
annotation class DrawScopeMarker

Marks declarations that belong to the DrawScope drawing DSL, preventing nested scopes from calling into outer scope drawing operations without explicit qualification.

Link copied to clipboard
sealed interface DrawStyle

Defines how geometric shapes are rendered: whether filled or stroked.

Link copied to clipboard
sealed interface DrawTransform

Defines transformations that can be applied to the canvas coordinate system within a withTransform block.

Functions

Link copied to clipboard
inline fun DrawScope.clipPath(shape: Shape, block: DrawScope.() -> Unit)

Intersects the clip with shape for the duration of block.

Link copied to clipboard
inline fun DrawScope.clipRect(topLeft: Point2D, size: Dimension2D, block: DrawScope.() -> Unit)

Intersects the current clip with a rectangle defined by topLeft and size.

inline fun DrawScope.clipRect(x: Float = 0.0f, y: Float = 0.0f, width: Float = size.width.toFloat() - x, height: Float = size.height.toFloat() - y, block: DrawScope.() -> Unit)

Intersects the clip with a rectangle defined by x, y, width, height for the duration of block.

Link copied to clipboard
fun DrawScope.drawArc(paint: Paint, startAngle: Float, sweepAngle: Float, useCenter: Boolean, topLeft: Point2D, size: Dimension2D, style: DrawStyle = DrawStyle.Fill, @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f)

Draws an arc positioned within the bounding box defined by topLeft and size.

Link copied to clipboard
fun DrawScope.drawCircle(paint: Paint, radius: Float = minOf(size.width, size.height) / 2.0f, center: Point2D, style: DrawStyle = DrawStyle.Fill, @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f)

Draws a circle with radius centered at center.

Link copied to clipboard
fun DrawScope.drawImage(image: Image, topLeft: Point2D, size: Dimension2D? = null, @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f)

Draws an image positioned at topLeft, optionally scaled to size.

Link copied to clipboard
fun DrawScope.drawLine(paint: Paint, start: Point2D, end: Point2D, stroke: Stroke = DrawStyle.DefaultStroke.stroke, @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f)

Draws a line between start and end.

fun DrawScope.drawLine(paint: Paint, x1: Float, y1: Float, x2: Float, y2: Float, strokeWidth: Float, @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f)

Draws a straight line between (x1, y1) and (x2, y2) using a line of width strokeWidth.

Link copied to clipboard
fun DrawScope.drawOval(paint: Paint, topLeft: Point2D, size: Dimension2D, style: DrawStyle = DrawStyle.Fill, @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f)

Draws an oval within the bounding box defined by topLeft and size.

Link copied to clipboard
fun DrawScope.drawRect(paint: Paint, topLeft: Point2D, size: Dimension2D, style: DrawStyle = DrawStyle.Fill, @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f)

Draws a rectangle positioned at topLeft with size size.

Link copied to clipboard
fun DrawScope.drawRoundRect(paint: Paint, topLeft: Point2D, size: Dimension2D, cornerRadiusX: Float = 0.0f, cornerRadiusY: Float = cornerRadiusX, style: DrawStyle = DrawStyle.Fill, @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f)

Draws a rounded rectangle positioned at topLeft with size size.

Link copied to clipboard
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.

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.

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).

Link copied to clipboard
inline fun DrawScope.inset(inset: Float, block: DrawScope.() -> Unit)

Insets every side of the drawing area by inset for the duration of block; see the four-sided inset.

inline fun DrawScope.inset(horizontal: Float = 0.0f, vertical: Float = 0.0f, block: DrawScope.() -> Unit)

Insets the left and right of the drawing area by horizontal and its top and bottom by vertical for the duration of block; see the four-sided inset.

inline fun DrawScope.inset(left: Float, top: Float, right: Float, bottom: Float, block: DrawScope.() -> Unit)

Insets the drawing area by left, top, right and bottom for the duration of block: the origin moves to (left, top), and DrawScope.size shrinks by the insets, rounded down. Nothing is clipped.

Link copied to clipboard
fun DrawScope.measureText(text: String, font: Font? = null): TextLayout

Measures the layout of text under font (or the current font if null) using the canvas's font render context.

Link copied to clipboard
fun DrawScope.record(layer: ImageLayer, block: DrawScope.() -> Unit)

Records block into layer, the counterpart of androidx's GraphicsLayer.record inside a DrawScope: block draws in this scope's coordinates and size, onto a recording aligned to the device pixels this scope draws on, so a drawContent() inside it records the content where it would have painted. Draw it back with ImageLayer.draw on DrawScope.graphics. Where the clip leaves nothing to draw, block does not run and layer is left empty.

Link copied to clipboard
inline fun DrawScope.rotate(degrees: Float, pivotX: Float = size.width / 2f, pivotY: Float = size.height / 2f, block: DrawScope.() -> Unit)

Rotates the drawing space by degrees around pivot (pivotX, pivotY) for the duration of block.

Link copied to clipboard
inline fun DrawScope.scale(scaleX: Float, scaleY: Float = scaleX, pivotX: Float = size.width / 2f, pivotY: Float = size.height / 2f, block: DrawScope.() -> Unit)

Scales the drawing space by scaleX and scaleY around pivot (pivotX, pivotY) for the duration of block.

Link copied to clipboard
inline fun DrawScope.translate(dx: Float, dy: Float, block: DrawScope.() -> Unit)

Translates the drawing origin by dx and dy for the duration of block.

Link copied to clipboard
inline fun DrawScope.withTransform(transformBlock: DrawTransform.() -> Unit, drawBlock: DrawScope.() -> Unit)

Executes drawBlock with transformations applied in transformBlock, restoring the previous transform and clip state afterwards.