DrawScope
interface DrawScope : Density
androidx.compose.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. DrawScope implementations are also provided sizing information and transformations are done relative to the local translation. That is 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.compose.foundation.Canvas import androidx.compose.foundation.layout.preferredSize import androidx.compose.ui.graphics.drawscope.inset import androidx.compose.ui.graphics.drawscope.rotate // 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 methods | |
---|---|
abstract Unit |
drawArc(brush: Brush, startAngle: Float, sweepAngle: Float, useCenter: Boolean, topLeft: Offset = Offset.Zero, size: Size = this.size.offsetSize(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. |
abstract Unit |
drawArc(color: Color, startAngle: Float, sweepAngle: Float, useCenter: Boolean, topLeft: Offset = Offset.Zero, size: Size = this.size.offsetSize(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. |
abstract 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. |
abstract 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. |
abstract Unit |
drawImage(image: ImageBitmap, 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 ImageBitmap into the canvas with its top-left corner at the given Offset. |
abstract Unit |
drawImage(image: ImageBitmap, srcOffset: IntOffset = IntOffset.Zero, srcSize: IntSize = IntSize(image.width, image.height), dstOffset: IntOffset = IntOffset.Zero, 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 |
abstract Unit |