Brush.Builder


public final class Brush.Builder


Builder for Brush.

For Java developers, use Brush.Builder to construct a Brush with default values, overriding only as needed. For example: Brush brush = Brush.builder().setFamily(family).setSize(size).setEpsilon(epsilon).build();

Summary

Public constructors

Public methods

final @NonNull Brush

Constructs a Brush from this Builder.

final @NonNull Brush.Builder
setColorIntArgb(@ColorInt int colorIntArgb)

Sets the color using a ColorInt, which is in the sRGB color space by definition.

final @NonNull Brush.Builder
setColorLong(@ColorLong long colorLong)

Sets the color using a ColorLong, which can encode several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

final @NonNull Brush.Builder
setEpsilon(
    @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float epsilon
)

Sets the epsilon of the brush, in stroke units.

final @NonNull Brush.Builder

Sets the BrushFamily for this brush.

final @NonNull Brush.Builder
setSize(
    @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float size
)

Sets the size of the brush, in stroke units.

Extension functions

final @NonNull Brush.Builder
@RequiresApi(value = 26)
BrushUtil.setAndroidColor(
    @NonNull Brush.Builder receiver,
    @NonNull Color color
)

Set the color on a Brush.Builder as an android.graphics.Color instance. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

Public constructors

Builder

Added in 1.0.0
public Builder()

Public methods

build

Added in 1.0.0
public final @NonNull Brush build()

Constructs a Brush from this Builder.

Throws
IllegalStateException

if family, size, and/or epsilon were never set

setColorIntArgb

Added in 1.0.0
public final @NonNull Brush.Builder setColorIntArgb(@ColorInt int colorIntArgb)

Sets the color using a ColorInt, which is in the sRGB color space by definition. Note that the ColorInt channel order puts alpha first (in the most significant byte).

Kotlin interprets integer literals greater than 0x7fffffff as Longs, so Kotlin callers that want to specify a literal ColorInt with alpha >= 0x80 must call Long.toInt on the literal.

setColorLong

Added in 1.0.0
public final @NonNull Brush.Builder setColorLong(@ColorLong long colorLong)

Sets the color using a ColorLong, which can encode several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

Some libraries (notably Jetpack UI Graphics) use ULong for ColorLongs, so the caller must call ULong.toLong on such a value before passing it to this method.

setEpsilon

Added in 1.0.0
public final @NonNull Brush.Builder setEpsilon(
    @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float epsilon
)

Sets the epsilon of the brush, in stroke units.

setFamily

Added in 1.0.0
public final @NonNull Brush.Builder setFamily(@NonNull BrushFamily family)

Sets the BrushFamily for this brush. See StockBrushes for available BrushFamily values.

setSize

Added in 1.0.0
public final @NonNull Brush.Builder setSize(
    @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float size
)

Sets the size of the brush, in stroke units.

Extension functions

BrushUtil.setAndroidColor

@RequiresApi(value = 26)
public final @NonNull Brush.Builder BrushUtil.setAndroidColor(
    @NonNull Brush.Builder receiver,
    @NonNull Color color
)

Set the color on a Brush.Builder as an android.graphics.Color instance. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.