DrawContext

DrawContext is an extension of MeasureContext that stores a Canvas and other properties. It also defines helpful drawing functions.

Inheritors

Properties

Link copied to clipboard
abstract val canvas: Canvas

The canvas to draw the chart on.

Link copied to clipboard

The elevation overlay color, applied to ShapeComponents that cast shadows.

Functions

Link copied to clipboard

Overlays the given color with DrawContext.elevationOverlayColor, changing the opacity of DrawContext.elevationOverlayColor depending on the value of elevationDp.

Link copied to clipboard
open fun clipRect(rectF: RectF)

Clips the Canvas to the specified rectF.

open fun clipRect(left: Float, top: Float, right: Float, bottom: Float)

Clips the Canvas to the specified rectangle.

Link copied to clipboard
open fun restoreCanvas()

Restores the Canvas state.

Link copied to clipboard
open fun restoreCanvasToCount(count: Int)

Restores the Canvas state to the given save level.

Link copied to clipboard
open fun saveCanvas(): Int

Saves the Canvas state.

Link copied to clipboard
open fun saveLayer(left: Float = 0.0f, top: Float = 0.0f, right: Float = canvas.width.toFloat(), bottom: Float = canvas.height.toFloat()): Int

A convenience function for Canvas.saveLayer.

Link copied to clipboard
inline fun DrawContext.withCanvas(block: Canvas.() -> Unit)

Calls the specified function block with DrawContext.canvas as its receiver.

Link copied to clipboard
abstract fun withOtherCanvas(canvas: Canvas, block: (DrawContext) -> Unit)

Temporarily swaps the Canvas and yields DrawContext as the block’s receiver.