CanvasScope

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
val center: Point

The center of the current bounds of the drawing scope (group, layer or whole canvas)

Link copied to clipboard
val size: Size

The size of the current drawing scope (group, layer or whole canvas)

Functions

Link copied to clipboard
inline fun createModel(size: Size, canvasState: CanvasState, block: CanvasScope.() -> Unit): CanvasModel
Link copied to clipboard
inline fun draw(canvas: Canvas, size: Size, canvasState: CanvasState, block: CanvasScope.() -> Unit)

Draws into the provided Canvas with the commands specified in the lambda with this CanvasScope as a receiver.

Link copied to clipboard
inline fun drawIntoCanvas(noinline block: (Canvas) -> Unit)

Provides access to draw directly with the underlying Canvas. This is helpful for situations to re-use the existing Canvas drawing logic.

Link copied to clipboard
inline fun fill(shape: Shape, shading: Shading, blendingMode: BlendingMode = DEFAULT_BLENDING_MODE, shadow: Shadow? = null)

Fills the given Shape.

Link copied to clipboard
inline fun group(transform: Transform = Transform.IDENTITY, size: Size? = null, clip: Path? = null, clipToBounds: Boolean = false, block: CanvasScope.() -> Unit)

Creates a group. Groups can be used to treat multiple drawing commands as a single one and applying transforms or clips to all of them at the same time. For a group, first the transform is applied, then the content is drawn inside the transformed coordinates and then the clip is applied to the drawn content.

Link copied to clipboard
inline fun layer(transform: Transform = Transform.IDENTITY, size: Size? = null, clip: Path? = null, @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f, blendingMode: BlendingMode = DEFAULT_BLENDING_MODE, block: CanvasScope.() -> Unit)

Creates a layer which allocates and redirects drawing to an offscreen buffer. It may be useful in cases like applying transparency or blending modes to multiple drawing commands at once. Layers should be as small as possible and should be used only when necessary because they may cause performance issues if used incorrectly.

Link copied to clipboard
inline fun stroke(shape: Shape, shading: Shading, blendingMode: BlendingMode = DEFAULT_BLENDING_MODE, shadow: Shadow? = null, lineWidth: Float = CanvasStroke.DEFAULT_LINE_WIDTH, lineCap: LineCap = DEFAULT_LINE_CAP, lineJoin: LineJoin = DEFAULT_LINE_JOIN, miterLimit: Float = CanvasStroke.DEFAULT_MITER_LIMIT, dashLengths: FloatArray? = null, dashPhase: Float = 0.0f)

Strokes the given Shape.