{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

Painter

public abstract class Painter

Known direct subclasses
BitmapPainter

Painter implementation used to draw an ImageBitmap into the provided canvas This implementation can handle applying alpha and ColorFilter to it's drawn result

BrushPainter

Painter implementation used to fill the provided bounds with the specified Brush.

ColorPainter

Painter implementation used to fill the provided bounds with the specified color

VectorPainter

Painter implementation that abstracts the drawing of a Vector graphic.


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

Public methods

final void
draw(
    @NonNull DrawScope receiver,
    @NonNull Size size,
    float alpha,
    ColorFilter colorFilter
)
abstract @NonNull Size

Return the intrinsic size of the Painter.

Protected methods

boolean
applyAlpha(float alpha)

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

boolean

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

boolean

Apply the appropriate internal configuration to positioning content with the given LayoutDirection

abstract void

Implementation of drawing logic for instances of Painter.

Public constructors

Painter

public Painter()

Public methods

draw

public final void draw(
    @NonNull DrawScope receiver,
    @NonNull Size size,
    float alpha,
    ColorFilter colorFilter
)

getIntrinsicSize

public abstract @NonNull Size getIntrinsicSize()

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

Protected methods

applyAlpha

protected boolean applyAlpha(float alpha)

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

applyColorFilter

protected boolean applyColorFilter(ColorFilter colorFilter)

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

applyLayoutDirection

protected boolean applyLayoutDirection(@NonNull LayoutDirection layoutDirection)

Apply the appropriate internal configuration to positioning content with the given LayoutDirection

onDraw

protected abstract void onDraw(@NonNull DrawScope receiver)

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