The second Android 11 Developer Preview is now available, test it out and share your feedback.

Painter

abstract class Painter
kotlin.Any
   ↳ androidx.ui.graphics.painter.Painter

Abstraction for something that can be drawn. In addition to providing the ability to draw into a specified bounded area, Painter provides a few high level mechanisms that consumers can use to configure how the content is drawn. These include alpha, ColorFilter, and RTL

Implementations should provide a meaningful equals method that compares values of different Painter subclasses and not rely on just referential equality

Summary

Public constructors

Abstraction for something that can be drawn.

Public methods

Unit
draw(canvas: Canvas, bounds: PxSize, alpha: Float = DefaultAlpha, colorFilter: ColorFilter? = null, rtl: Boolean = false)

Protected methods

open Boolean
applyAlpha(alpha: Float)

Apply the provided alpha value returning true if it was applied successfully, or false if it could not be applied

open Boolean

Apply the provided color filter returning true if it was applied successfully, or false if it could not be applied

open Boolean

Apply the appropriate internal configuration to positioning content for locales with right-to-left languages

abstract Unit
onDraw(canvas: Canvas, bounds: PxSize)

Implementation of drawing logic for instances of Painter.

Extension functions

From androidx.ui.core
DrawModifier
Painter.asModifier(sizeToIntrinsics: Boolean = true, alignment: Alignment = Alignment.Center, scaleFit: ScaleFit = ScaleFit.Fit, alpha: Float = DefaultAlpha, colorFilter: ColorFilter? = null, rtl: Boolean = false)

Create a DrawModifier from this Painter.

Properties

abstract PxSize

Return the intrinsic size of the Painter.

Public constructors

<init>

Painter()

Abstraction for something that can be drawn. In addition to providing the ability to draw into a specified bounded area, Painter provides a few high level mechanisms that consumers can use to configure how the content is drawn. These include alpha, ColorFilter, and RTL

Implementations should provide a meaningful equals method that compares values of different Painter subclasses and not rely on just referential equality

Public methods

draw

fun draw(
    canvas: Canvas,
    bounds: PxSize,
    alpha: Float = DefaultAlpha,
    colorFilter: ColorFilter? = null,
    rtl: Boolean = false
): Unit

Protected methods

applyAlpha

protected open fun applyAlpha(alpha: Float): Boolean

Apply the provided alpha value returning true if it was applied successfully, or false if it could not be applied

applyColorFilter

protected open fun applyColorFilter(colorFilter: ColorFilter?): Boolean

Apply the provided color filter returning true if it was applied successfully, or false if it could not be applied

applyRtl

protected open fun applyRtl(rtl: Boolean): Boolean

Apply the appropriate internal configuration to positioning content for locales with right-to-left languages

onDraw

protected abstract fun onDraw(
    canvas: Canvas,
    bounds: PxSize
): Unit

Implementation of drawing logic for instances of Painter. This is invoked internally within draw after the positioning and configuring the Painter

Properties

intrinsicSize

abstract val intrinsicSize: PxSize

Return the intrinsic size of the Painter. If the there is no intrinsic size (i.e. filling bounds with an arbitrary color) return PxSize.UnspecifiedSize. If there is no intrinsic size in a single dimension, return PxSize with Px.Infinity in the desired dimension. If a Painter does not have an intrinsic size, it will always draw within the full bounds of the destination