DrawScope

abstract class DrawScope : Density
kotlin.Any
   ↳ androidx.ui.graphics.drawscope.DrawScope

Creates a scoped drawing environment with the provided Canvas. This provides a declarative, stateless API to draw shapes and paths without requiring consumers to maintain underlying Canvas state information. The bounds for drawing within DrawScope are provided by the call to DrawScope.draw and are always bound to the local translation. That is the left and top coordinates are always the origin and the right and bottom coordinates are always the specified width and height respectively. Drawing content is not clipped, so it is possible to draw outside of the specified bounds.

import androidx.ui.foundation.Canvas
import androidx.ui.graphics.drawscope.inset
import androidx.ui.graphics.drawscope.rotate
import androidx.ui.layout.preferredSize

// Sample showing how to use the DrawScope receiver scope to issue
// drawing commands
Canvas(Modifier.preferredSize(120.dp)) {
    drawRect(color = Color.Gray) // Draw grey background
    // Inset content by 10 pixels on the left/right sides and 12 by the
    // top/bottom
    inset(10.0f, 12.0f) {
        val quadrantSize = size / 2.0f

        // Draw a rectangle within the inset bounds
        drawRect(
            size = quadrantSize,
            color = Color.Red
        )

        rotate(45.0f) {
            drawRect(size = quadrantSize, color = Color.Blue)
        }
    }
}

Summary

Public constructors

Creates a scoped drawing environment with the provided Canvas.

Public methods
Unit
drawArc(brush: Brush, startAngle: Float, sweepAngle: Float, useCenter: Boolean, topLeft: Offset = Offset.Zero, size: Size = this.size - topLeft, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draw an arc scaled to fit inside the given rectangle.

Unit
drawArc(color: Color, startAngle: Float, sweepAngle: Float, useCenter: Boolean, topLeft: Offset = Offset.Zero, size: Size = this.size - topLeft, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draw an arc scaled to fit inside the given rectangle.

Unit
drawCircle(brush: Brush, radius: Float = size.minDimension / 2.0f, center: Offset = this.center, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws a circle at the provided center coordinate and radius.

Unit
drawCircle(color: Color, radius: Float = size.minDimension / 2.0f, center: Offset = this.center, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws a circle at the provided center coordinate and radius.

Unit
drawImage(image: ImageAsset, topLeft: Offset = Offset.Zero, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws the given ImageAsset into the canvas with its top-left corner at the given Offset.

Unit
drawImage(image: ImageAsset, srcOffset: IntOffset = IntOffset.Origin, srcSize: IntSize = IntSize(image.width, image.height), dstOffset: IntOffset = IntOffset.Origin, dstSize: IntSize = srcSize, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws the subset of the given image described by the src argument into the canvas in the axis-aligned rectangle given by the dst argument.

Unit
drawLine(brush: Brush, start: Offset, end: Offset, strokeWidth: Float = Stroke.HairlineWidth, cap: StrokeCap = Stroke.DefaultCap, pathEffect: NativePathEffect? = null, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws a line between the given points using the given paint.

Unit
drawLine(color: Color, start: Offset, end: Offset, strokeWidth: Float = Stroke.HairlineWidth, cap: StrokeCap = Stroke.DefaultCap, pathEffect: NativePathEffect? = null, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws a line between the given points using the given paint.

Unit
drawOval(brush: Brush, topLeft: Offset = Offset.Zero, size: Size = this.size - topLeft, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws an oval with the given offset and size.

Unit
drawOval(color: Color, topLeft: Offset = Offset.Zero, size: Size = this.size - topLeft, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws an oval with the given offset and size.

Unit
drawPath(path: Path, color: Color, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws the given Path with the given Color.

Unit
drawPath(path: Path, brush: Brush, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws the given Path with the given Color.

Unit
drawPoints(points: List<Offset>, pointMode: PointMode, color: Color, strokeWidth: Float = Stroke.HairlineWidth, cap: StrokeCap = StrokeCap.butt, pathEffect: NativePathEffect? = null, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws a sequence of points according to the given PointMode.

Unit
drawPoints(points: List<Offset>, pointMode: PointMode, brush: Brush, strokeWidth: Float = Stroke.HairlineWidth, cap: StrokeCap = StrokeCap.butt, pathEffect: NativePathEffect? = null, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws a sequence of points according to the given PointMode.

Unit
drawRect(brush: Brush, topLeft: Offset = Offset.Zero, size: Size = this.size - topLeft, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws a rectangle with the given offset and size.

Unit
drawRect(color: Color, topLeft: Offset = Offset.Zero, size: Size = this.size - topLeft, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws a rectangle with the given offset and size.

Unit
drawRoundRect(brush: Brush, topLeft: Offset = Offset.Zero, size: Size = this.size - topLeft, radius: Radius = Radius.Zero, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws a rounded rectangle with the provided size, offset and radii for the x and y axis respectively.

Unit
drawRoundRect(color: Color, topLeft: Offset = Offset.Zero, size: Size = this.size - topLeft, radius: Radius = Radius.Zero, style: DrawStyle = Fill, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, colorFilter: ColorFilter? = null, blendMode: BlendMode = DefaultBlendMode)

Draws a rounded rectangle with the given Paint.

Protected methods
Unit
draw(canvas: Canvas, size: Size, block: DrawScope.() -> Unit)

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

Inherited functions
Extension functions
From androidx.ui.graphics.drawscope
Unit
DrawScope.clipPath(path: Path, clipOp: ClipOp = ClipOp.intersect, block: DrawScope.() -> Unit)

Reduces the clip region to the intersection of the current clip and the given rounded rectangle.

Unit
DrawScope.clipRect(left: Float = 0.0f, top: Float = 0.0f, right: Float = size.width, bottom: Float = size.height, clipOp: ClipOp = ClipOp.intersect, block: DrawScope.() -> Unit)

Reduces the clip region to the intersection of the current clip and the given rectangle indicated by the given left, top, right and bottom bounds.

Unit
DrawScope.drawCanvas(block: (Canvas, Size) -> Unit)

Provides access to draw directly with the underlying Canvas along with the current size of the DrawScope.

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

Simultaneously translate the DrawScope coordinate space by left and top as well as modify the dimensions of the current painting area.

Unit
DrawScope.inset(dx: Float = 0.0f, dy: Float = 0.0f, block: DrawScope.() -> Unit)

Convenience method modifies the DrawScope bounds to inset both left and right bounds by dx as well as the top and bottom by dy.

Unit
DrawScope.rotate(degrees: Float, pivotX: Float = center.x, pivotY: Float = center.y, block: DrawScope.() -> Unit)

Add a rotation (in degrees clockwise) to the current transform at the given pivot point.

Unit
DrawScope.rotateRad(radians: Float, pivotX: Float = center.x, pivotY: Float = center.y, block: DrawScope.() -> Unit)

Add a rotation (in radians clockwise) to the current transform at the given pivot point.

Unit
DrawScope.scale(scaleX: Float, scaleY: Float = scaleX, pivotX: Float = center.x, pivotY: Float = center.y, block: DrawScope.() -> Unit)

Add an axis-aligned scale to the current transform, scaling by the first argument in the horizontal direction and the second in the vertical direction at the given pivot coordinate.

Unit
DrawScope.translate(left: Float = 0.0f, top: Float = 0.0f, block: DrawScope.() -> Unit)

Translate the coordinate space by the given delta in pixels in both the x and y coordinates respectively

Unit
DrawScope.withTransform(transformBlock: DrawTransform.() -> Unit, drawBlock: DrawScope.() -> Unit)

Perform 1 or more transformations and execute drawing commands with the specified transformations applied.

From androidx.ui.graphics
Unit
DrawScope.drawOutline(outline: Outline, color: Color, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DrawScope.DefaultBlendMode)

Draws the Outline on a DrawScope.

Unit
DrawScope.drawOutline(outline: Outline, brush: Brush, @FloatRange(0.0, 1.0) alpha: Float = 1.0f, style: DrawStyle = Fill, colorFilter: ColorFilter? = null, blendMode: BlendMode = DrawScope.DefaultBlendMode)

Draws the Outline on a DrawScope.

Inherited extension functions
From androidx.ui.layout
Constraints

Creates the Constraints corresponding to the current DpConstraints.

DpConstraints

Creates the DpConstraints corresponding to the current Constraints.

Properties
Offset

Center of the current bounds of the drawing environment

abstract LayoutDirection

The layout direction of the layout being drawn in.

Size

Provides the dimensions of the current drawing environment

Companion properties
BlendMode

Default blending mode used for each drawing operation.

Inherited properties

Public constructors

<init>

DrawScope()

Creates a scoped drawing environment with the provided Canvas. This provides a declarative, stateless API to draw shapes and paths without requiring consumers to maintain underlying Canvas state information. The bounds for drawing within DrawScope are provided by the call to DrawScope.draw and are always bound to the local translation. That is the left and top coordinates are always the origin and the right and bottom coordinates are always the specified width and height respectively. Drawing content is not clipped, so it is possible to draw outside of the specified bounds.

import androidx.ui.foundation.Canvas
import androidx.ui.graphics.drawscope.inset
import androidx.ui.graphics.drawscope.rotate
import androidx.ui.layout.preferredSize

// Sample showing how to use the DrawScope receiver scope to issue
// drawing commands
Canvas(Modifier.preferredSize(120.dp)) {
    drawRect(color = Color.Gray) // Draw grey background
    // Inset content by 10 pixels on the left/right sides and 12 by the
    // top/bottom
    inset(10.0f, 12.0f) {
        val quadrantSize = size / 2.0f

        // Draw a rectangle within the inset bounds
        drawRect(
            size = quadrantSize,
            color = Color.Red
        )

        rotate(45.0f) {
            drawRect(size = quadrantSize, color = Color.Blue)
        }
    }
}

Public methods

drawArc

fun drawArc(
    brush: Brush,
    startAngle: Float,
    sweepAngle: Float,
    useCenter: Boolean,
    topLeft: Offset = Offset.Zero,
    size: Size = this.size - topLeft,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draw an arc scaled to fit inside the given rectangle. It starts from startAngle degrees around the oval up to startAngle + sweepAngle degrees around the oval, with zero degrees being the point on the right hand side of the oval that crosses the horizontal line that intersects the center of the rectangle and with positive angles going clockwise around the oval. If useCenter is true, the arc is closed back to the center, forming a circle sector. Otherwise, the arc is not closed, forming a circle segment.

Parameters
brush: Brush Color or fill to be applied to the arc
topLeft: Offset = Offset.Zero Offset from the local origin of 0, 0 relative to the current translation
size: Size = this.size - topLeft Dimensions of the arc to draw
startAngle: Float Starting angle in degrees. 0 represents 3 o'clock
sweepAngle: Float Size of the arc in degrees that is drawn clockwise relative to startAngle
useCenter: Boolean Flag indicating if the arc is to close the center of the bounds
alpha: Float = 1.0f Opacity to be applied to the arc from 0.0f to 1.0f representing fully transparent to fully opaque respectively
style: DrawStyle = Fill Whether or not the arc is stroked or filled in
colorFilter: ColorFilter? = null ColorFilter to apply to the brush when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to be applied to the arc when it is drawn

drawArc

fun drawArc(
    color: Color,
    startAngle: Float,
    sweepAngle: Float,
    useCenter: Boolean,
    topLeft: Offset = Offset.Zero,
    size: Size = this.size - topLeft,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draw an arc scaled to fit inside the given rectangle. It starts from startAngle degrees around the oval up to startAngle + sweepAngle degrees around the oval, with zero degrees being the point on the right hand side of the oval that crosses the horizontal line that intersects the center of the rectangle and with positive angles going clockwise around the oval. If useCenter is true, the arc is closed back to the center, forming a circle sector. Otherwise, the arc is not closed, forming a circle segment.

Parameters
color: Color Color to be applied to the arc
topLeft: Offset = Offset.Zero Offset from the local origin of 0, 0 relative to the current translation
size: Size = this.size - topLeft Dimensions of the arc to draw
startAngle: Float Starting angle in degrees. 0 represents 3 o'clock
sweepAngle: Float Size of the arc in degrees that is drawn clockwise relative to startAngle
useCenter: Boolean Flag indicating if the arc is to close the center of the bounds
alpha: Float = 1.0f Opacity to be applied to the arc from 0.0f to 1.0f representing fully transparent to fully opaque respectively
style: DrawStyle = Fill Whether or not the arc is stroked or filled in
colorFilter: ColorFilter? = null ColorFilter to apply to the color when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to be applied to the arc when it is drawn

drawCircle

fun drawCircle(
    brush: Brush,
    radius: Float = size.minDimension / 2.0f,
    center: Offset = this.center,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws a circle at the provided center coordinate and radius. If no center point is provided the center of the bounds is used.

Parameters
brush: Brush The color or fill to be applied to the circle
radius: Float = size.minDimension / 2.0f The radius of the circle
center: Offset = this.center The center coordinate where the circle is to be drawn
alpha: Float = 1.0f Opacity to be applied to the circle from 0.0f to 1.0f representing fully transparent to fully opaque respectively
style: DrawStyle = Fill Whether or not the circle is stroked or filled in
colorFilter: ColorFilter? = null ColorFilter to apply to the brush when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to be applied to the brush

drawCircle

fun drawCircle(
    color: Color,
    radius: Float = size.minDimension / 2.0f,
    center: Offset = this.center,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws a circle at the provided center coordinate and radius. If no center point is provided the center of the bounds is used.

Parameters
color: Color The color or fill to be applied to the circle
radius: Float = size.minDimension / 2.0f The radius of the circle
center: Offset = this.center The center coordinate where the circle is to be drawn
alpha: Float = 1.0f Opacity to be applied to the circle from 0.0f to 1.0f representing fully transparent to fully opaque respectively
style: DrawStyle = Fill Whether or not the circle is stroked or filled in
colorFilter: ColorFilter? = null ColorFilter to apply to the color when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to be applied to the brush

drawImage

fun drawImage(
    image: ImageAsset,
    topLeft: Offset = Offset.Zero,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws the given ImageAsset into the canvas with its top-left corner at the given Offset. The image is composited into the canvas using the given Paint.

Parameters
image: ImageAsset The ImageAsset to draw
topLeft: Offset = Offset.Zero Offset from the local origin of 0, 0 relative to the current translation
alpha: Float = 1.0f Opacity to be applied to image from 0.0f to 1.0f representing fully transparent to fully opaque respectively
style: DrawStyle = Fill Specifies whether the image is to be drawn filled in or as a rectangular stroke
colorFilter: ColorFilter? = null ColorFilter to apply to the image when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to apply to destination

drawImage

fun drawImage(
    image: ImageAsset,
    srcOffset: IntOffset = IntOffset.Origin,
    srcSize: IntSize = IntSize(image.width, image.height),
    dstOffset: IntOffset = IntOffset.Origin,
    dstSize: IntSize = srcSize,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws the subset of the given image described by the src argument into the canvas in the axis-aligned rectangle given by the dst argument.

If no src rect is provided, the entire image is scaled into the corresponding destination bounds

Parameters
image: ImageAsset The source image to draw
srcOffset: IntOffset = IntOffset.Origin Optional offset representing the top left offset of the source image to draw, this defaults to the origin of image
srcSize: IntSize = IntSize(image.width, image.height) Optional dimensions of the source image to draw relative to srcOffset, this defaults the width and height of image
dstOffset: IntOffset = IntOffset.Origin Optional offset representing the top left offset of the destination to draw the given image, this defaults to the origin of the current translation tarting top left offset in the destination to draw the image
dstSize: IntSize = srcSize Optional dimensions of the destination to draw, this defaults to srcSize
alpha: Float = 1.0f Opacity to be applied to image from 0.0f to 1.0f representing fully transparent to fully opaque respectively
style: DrawStyle = Fill Specifies whether the image is to be drawn filled in or as a rectangular stroke
colorFilter: ColorFilter? = null ColorFilter to apply to the image when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to apply to destination

drawLine

fun drawLine(
    brush: Brush,
    start: Offset,
    end: Offset,
    strokeWidth: Float = Stroke.HairlineWidth,
    cap: StrokeCap = Stroke.DefaultCap,
    pathEffect: NativePathEffect? = null,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws a line between the given points using the given paint. The line is stroked.

Parameters
brush: Brush the color or fill to be applied to the line
start: Offset first point of the line to be drawn
end: Offset second point of the line to be drawn
strokeWidth: Float = Stroke.HairlineWidth stroke width to apply to the line
cap: StrokeCap = Stroke.DefaultCap treatment applied to the ends of the line segment
pathEffect: NativePathEffect? = null optional effect or pattern to apply to the line
alpha: Float = 1.0f opacity to be applied to the brush from 0.0f to 1.0f representing fully transparent to fully opaque respectively
colorFilter: ColorFilter? = null ColorFilter to apply to the brush when drawn into the destination
blendMode: BlendMode = DefaultBlendMode the blending algorithm to apply to the brush

drawLine

fun drawLine(
    color: Color,
    start: Offset,
    end: Offset,
    strokeWidth: Float = Stroke.HairlineWidth,
    cap: StrokeCap = Stroke.DefaultCap,
    pathEffect: NativePathEffect? = null,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws a line between the given points using the given paint. The line is stroked.

Parameters
color: Color the color to be applied to the line
start: Offset first point of the line to be drawn
end: Offset second point of the line to be drawn
strokeWidth: Float = Stroke.HairlineWidth The stroke width to apply to the line
cap: StrokeCap = Stroke.DefaultCap treatment applied to the ends of the line segment
pathEffect: NativePathEffect? = null optional effect or pattern to apply to the line
alpha: Float = 1.0f opacity to be applied to the color from 0.0f to 1.0f representing fully transparent to fully opaque respectively
colorFilter: ColorFilter? = null ColorFilter to apply to the color when drawn into the destination
blendMode: BlendMode = DefaultBlendMode the blending algorithm to apply to the color

drawOval

fun drawOval(
    brush: Brush,
    topLeft: Offset = Offset.Zero,
    size: Size = this.size - topLeft,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws an oval with the given offset and size. If no offset from the top left is provided, it is drawn starting from the origin of the current translation. If no size is provided, the size of the current environment is used.

Parameters
brush: Brush Color or fill to be applied to the oval
topLeft: Offset = Offset.Zero Offset from the local origin of 0, 0 relative to the current translation
size: Size = this.size - topLeft Dimensions of the rectangle to draw
alpha: Float = 1.0f Opacity to be applied to the oval from 0.0f to 1.0f representing fully transparent to fully opaque respectively
style: DrawStyle = Fill Whether or not the oval is stroked or filled in
colorFilter: ColorFilter? = null ColorFilter to apply to the brush when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to be applied to the brush

drawOval

fun drawOval(
    color: Color,
    topLeft: Offset = Offset.Zero,
    size: Size = this.size - topLeft,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws an oval with the given offset and size. If no offset from the top left is provided, it is drawn starting from the origin of the current translation. If no size is provided, the size of the current environment is used.

Parameters
color: Color Color to be applied to the oval
topLeft: Offset = Offset.Zero Offset from the local origin of 0, 0 relative to the current translation
size: Size = this.size - topLeft Dimensions of the rectangle to draw
alpha: Float = 1.0f Opacity to be applied to the oval from 0.0f to 1.0f representing fully transparent to fully opaque respectively
style: DrawStyle = Fill Whether or not the oval is stroked or filled in
colorFilter: ColorFilter? = null ColorFilter to apply to the color when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to be applied to the brush

drawPath

fun drawPath(
    path: Path,
    color: Color,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws the given Path with the given Color. Whether this shape is filled or stroked (or both) is controlled by DrawStyle. If the path is filled, then subpaths within it are implicitly closed (see Path.close).

Parameters
path: Path Path to draw
color: Color Color to be applied to the path
alpha: Float = 1.0f Opacity to be applied to the path from 0.0f to 1.0f representing fully transparent to fully opaque respectively
style: DrawStyle = Fill Whether or not the path is stroked or filled in
colorFilter: ColorFilter? = null ColorFilter to apply to the color when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to be applied to the path when it is drawn

drawPath

fun drawPath(
    path: Path,
    brush: Brush,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws the given Path with the given Color. Whether this shape is filled or stroked (or both) is controlled by DrawStyle. If the path is filled, then subpaths within it are implicitly closed (see Path.close).

Parameters
path: Path Path to draw
brush: Brush Brush to be applied to the path
alpha: Float = 1.0f Opacity to be applied to the path from 0.0f to 1.0f representing fully transparent to fully opaque respectively
style: DrawStyle = Fill Whether or not the path is stroked or filled in
colorFilter: ColorFilter? = null ColorFilter to apply to the brush when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to be applied to the path when it is drawn

drawPoints

fun drawPoints(
    points: List<Offset>,
    pointMode: PointMode,
    color: Color,
    strokeWidth: Float = Stroke.HairlineWidth,
    cap: StrokeCap = StrokeCap.butt,
    pathEffect: NativePathEffect? = null,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws a sequence of points according to the given PointMode.

The points argument is interpreted as offsets from the origin.

Parameters
points: List<Offset> List of points to draw with the specified PointMode
pointMode: PointMode PointMode used to indicate how the points are to be drawn
color: Color Color to be applied to the points
alpha: Float = 1.0f Opacity to be applied to the path from 0.0f to 1.0f representing fully transparent to fully opaque respectively
strokeWidth: Float = Stroke.HairlineWidth The stroke width to apply to the line
cap: StrokeCap = StrokeCap.butt Treatment applied to the ends of the line segment
pathEffect: NativePathEffect? = null optional effect or pattern to apply to the point
colorFilter: ColorFilter? = null ColorFilter to apply to the color when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to be applied to the path when it is drawn

drawPoints

fun drawPoints(
    points: List<Offset>,
    pointMode: PointMode,
    brush: Brush,
    strokeWidth: Float = Stroke.HairlineWidth,
    cap: StrokeCap = StrokeCap.butt,
    pathEffect: NativePathEffect? = null,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws a sequence of points according to the given PointMode.

The points argument is interpreted as offsets from the origin.

Parameters
points: List<Offset> List of points to draw with the specified PointMode
pointMode: PointMode PointMode used to indicate how the points are to be drawn
brush: Brush Brush to be applied to the points
strokeWidth: Float = Stroke.HairlineWidth The stroke width to apply to the line
cap: StrokeCap = StrokeCap.butt Treatment applied to the ends of the line segment
pathEffect: NativePathEffect? = null optional effect or pattern to apply to the points
alpha: Float = 1.0f Opacity to be applied to the path from 0.0f to 1.0f representing fully transparent to fully opaque respectively
colorFilter: ColorFilter? = null ColorFilter to apply to the brush when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to be applied to the path when it is drawn

drawRect

fun drawRect(
    brush: Brush,
    topLeft: Offset = Offset.Zero,
    size: Size = this.size - topLeft,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws a rectangle with the given offset and size. If no offset from the top left is provided, it is drawn starting from the origin of the current translation. If no size is provided, the size of the current environment is used.

Parameters
brush: Brush The color or fill to be applied to the rectangle
topLeft: Offset = Offset.Zero Offset from the local origin of 0, 0 relative to the current translation
size: Size = this.size - topLeft Dimensions of the rectangle to draw
alpha: Float = 1.0f Opacity to be applied to the brush from 0.0f to 1.0f representing fully transparent to fully opaque respectively
style: DrawStyle = Fill Whether or not the rectangle is stroked or filled in
colorFilter: ColorFilter? = null ColorFilter to apply to the brush when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to apply to destination

drawRect

fun drawRect(
    color: Color,
    topLeft: Offset = Offset.Zero,
    size: Size = this.size - topLeft,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws a rectangle with the given offset and size. If no offset from the top left is provided, it is drawn starting from the origin of the current translation. If no size is provided, the size of the current environment is used.

Parameters
color: Color The color to be applied to the rectangle
topLeft: Offset = Offset.Zero Offset from the local origin of 0, 0 relative to the current translation
size: Size = this.size - topLeft Dimensions of the rectangle to draw
alpha: Float = 1.0f Opacity to be applied to the color from 0.0f to 1.0f representing fully transparent to fully opaque respectively
style: DrawStyle = Fill Whether or not the rectangle is stroked or filled in
colorFilter: ColorFilter? = null ColorFilter to apply to the color source pixels
blendMode: BlendMode = DefaultBlendMode Blending algorithm to apply to destination

drawRoundRect

fun drawRoundRect(
    brush: Brush,
    topLeft: Offset = Offset.Zero,
    size: Size = this.size - topLeft,
    radius: Radius = Radius.Zero,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws a rounded rectangle with the provided size, offset and radii for the x and y axis respectively. This rectangle is drawn with the provided Brush parameter and is filled or stroked based on the given DrawStyle

Parameters
brush: Brush The color or fill to be applied to the rounded rectangle
topLeft: Offset = Offset.Zero Offset from the local origin of 0, 0 relative to the current translation
size: Size = this.size - topLeft Dimensions of the rectangle to draw
radius: Radius = Radius.Zero Corner radius of the rounded rectangle
alpha: Float = 1.0f Opacity to be applied to rounded rectangle from 0.0f to 1.0f representing fully transparent to fully opaque respectively
style: DrawStyle = Fill Specifies whether the rounded rectangle is stroked or filled in
colorFilter: ColorFilter? = null ColorFilter to apply to the brush when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to be applied to the brush

drawRoundRect

fun drawRoundRect(
    color: Color,
    topLeft: Offset = Offset.Zero,
    size: Size = this.size - topLeft,
    radius: Radius = Radius.Zero,
    style: DrawStyle = Fill,
    @FloatRange(0.0, 1.0) alpha: Float = 1.0f,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
): Unit

Draws a rounded rectangle with the given Paint. Whether the rectangle is filled or stroked (or both) is controlled by Paint.style.

Parameters
color: Color The color to be applied to the rounded rectangle
topLeft: Offset = Offset.Zero Offset from the local origin of 0, 0 relative to the current translation
size: Size = this.size - topLeft Dimensions of the rectangle to draw
radius: Radius = Radius.Zero Corner radius of the rounded rectangle
alpha: Float = 1.0f Opacity to be applied to rounded rectangle from 0.0f to 1.0f representing fully transparent to fully opaque respectively
style: DrawStyle = Fill Specifies whether the rounded rectangle is stroked or filled in
colorFilter: ColorFilter? = null ColorFilter to apply to the color when drawn into the destination
blendMode: BlendMode = DefaultBlendMode Blending algorithm to be applied to the color

Protected methods

draw

protected fun draw(
    canvas: Canvas,
    size: Size,
    block: DrawScope.() -> Unit
): Unit

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

Parameters
canvas: Canvas target canvas to render into
size: Size bounds relative to the current canvas translation in which the DrawScope should draw within
block: DrawScope.() -> Unit lambda that is called to issue drawing commands on this DrawScope

Properties

center

val center: Offset

Center of the current bounds of the drawing environment

layoutDirection

abstract val layoutDirection: LayoutDirection

The layout direction of the layout being drawn in.

size

var size: Size

Provides the dimensions of the current drawing environment

Companion properties

DefaultBlendMode

val DefaultBlendMode: BlendMode

Default blending mode used for each drawing operation. This ensures that content is drawn on top of the pixels in the destination