Android 12 Developer Preview is here! Try it out, and give us your feedback!

DrawTransform

interface DrawTransform
androidx.compose.ui.graphics.drawscope.DrawTransform

Defines transformations that can be applied to a drawing environment

Summary

Public methods
abstract Unit
clipPath(path: Path, clipOp: ClipOp = ClipOp.Intersect)

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

abstract Unit
clipRect(left: Float = 0.0f, top: Float = 0.0f, right: Float = size.width, bottom: Float = size.height, clipOp: ClipOp = ClipOp.Intersect)

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.

abstract Unit
inset(left: Float, top: Float, right: Float, bottom: Float)

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

abstract Unit
rotate(degrees: Float, pivot: Offset = center)

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

abstract Unit
scale(scaleX: Float, scaleY: Float, pivot: Offset = center)

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.

abstract Unit
transform(matrix: Matrix)

Transform the drawing environment by the given matrix

abstract Unit
translate(left: Float = 0.0f, top: Float = 0.0f)

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

Extension functions
From androidx.compose.ui.graphics.drawscope
Unit
DrawTransform.inset(horizontal: Float = 0.0f, vertical: Float = 0.0f)

Convenience method modifies the DrawTransform bounds to inset both left and right bounds by horizontal as well as the top and bottom by vertical.

Unit

Convenience method modifies the DrawScope bounds to inset both left, top, right and bottom bounds by inset.

Unit
DrawTransform.rotateRad(radians: Float, pivot: Offset = center)

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

Unit
DrawTransform.scale(scale: Float, pivot: Offset = center)

Add an axis-aligned scale to the current transform, scaling uniformly in both directions by the provided scale factor at the pivot coordinate.

Properties
open Offset

Convenience method to obtain the current position of the current transformation

abstract Size

Get the current size of the CanvasTransform

Public methods

clipPath

abstract fun clipPath(
    path: Path,
    clipOp: ClipOp = ClipOp.Intersect
): Unit

Reduces the clip region to the intersection of the current clip and the given rounded rectangle. After this method is invoked, this clip is no longer applied

Parameters
path: Path Shape to clip drawing content within
clipOp: ClipOp = ClipOp.Intersect Clipping operation to conduct on the given bounds, defaults to ClipOp.Intersect

clipRect

abstract fun clipRect(
    left: Float = 0.0f,
    top: Float = 0.0f,