Interface

DrawScope

Creates a scoped drawing environment with the provided Canvas.

DrawScopeSample

/**
 * Sample showing how to use CanvasScope to issue drawing commands into a given canvas as well as
 * providing transformations to the drawing environment
 */
@Sampled
@Composable
fun DrawScopeSample() {
    // Sample showing how to use the DrawScope receiver scope to issue
    // drawing commands
    Canvas(Modifier.size(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) }
        }
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: