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

android

Public functions

Brush

Constructs a Brush from this Builder.

android
Brush.Builder
setColorIntArgb(colorIntArgb: @ColorInt Int)

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

android
Brush.Builder

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.

android
Brush.Builder
setEpsilon(
    epsilon: @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) Float
)

Sets the epsilon of the brush, in stroke units.

android
Brush.Builder

Sets the BrushFamily for this brush.

android
Brush.Builder
setSize(
    size: @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) Float
)

Sets the size of the brush, in stroke units.

android

Extension functions

Brush.Builder

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

android
Brush.Builder

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.

android

Public constructors

Builder

Builder()

Public functions

build

fun build(): Brush

Constructs a Brush from this Builder.

Throws
IllegalStateException

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

setColorIntArgb

fun setColorIntArgb(colorIntArgb: @ColorInt Int): Brush.Builder

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

fun setColorLong(colorLong: @ColorLong Long): Brush.Builder

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

fun setEpsilon(
    epsilon: @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) Float
): Brush.Builder

Sets the epsilon of the brush, in stroke units.

setFamily

fun setFamily(family: BrushFamily): Brush.Builder

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

setSize

fun setSize(
    size: @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) Float
): Brush.Builder

Sets the size of the brush, in stroke units.

Extension functions

Brush.Builder.setComposeColor

fun Brush.Builder.setComposeColor(color: Color): Brush.Builder

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

Brush.Builder.setAndroidColor

@RequiresApi(value = 26)
fun Brush.Builder.setAndroidColor(color: Color): Brush.Builder

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.