Defines how stroke inputs are interpreted to create the visual representation of a stroke.

The type completely describes how inputs are used to create stroke meshes, and how those meshes should be drawn by stroke renderers. In an analogous way to "font" and "font family", a Brush can be considered an instance of a BrushFamily with a particular color, size, and an extra parameter controlling visual fidelity, called epsilon.

Summary

Nested types

Builder for Brush.

Public companion functions

Brush.Builder

Returns a new Brush.Builder.

android
Brush
createWithColorIntArgb(
    family: BrushFamily,
    colorIntArgb: @ColorInt Int,
    size: Float,
    epsilon: Float
)

Returns a new Brush with the color specified by a ColorInt, which is in the sRGB color space by definition.

android
Brush
createWithColorLong(
    family: BrushFamily,
    colorLong: @ColorLong Long,
    size: Float,
    epsilon: Float
)

Returns a new Brush with the color specified by 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

Public constructors

Brush(family: BrushFamily, size: Float, epsilon: Float)

The default color of a Brush is pure black.

android

Public functions

Brush
copy(family: BrushFamily, size: Float, epsilon: Float)

Creates a copy of this and allows named properties to be altered while keeping the rest unchanged.

android
Brush
copyWithColorIntArgb(
    colorIntArgb: @ColorInt Int,
    family: BrushFamily,
    size: Float,
    epsilon: Float
)

Creates a copy of this and allows named properties to be altered while keeping the rest unchanged.

android
Brush
copyWithColorLong(
    colorLong: @ColorLong Long,
    family: BrushFamily,
    size: Float,
    epsilon: Float
)

Creates a copy of this and allows named properties to be altered while keeping the rest unchanged.

android
open operator Boolean
equals(other: Any?)
android
open Int
android
Brush.Builder

Returns a Builder with values set equivalent to this.

android
open String
android

Protected functions

Unit

Delete native Brush memory.

android

Public properties

Int

The brush color as a ColorInt, which can only express colors in the sRGB color space.

android
Long

The brush color as a ColorLong, which can express colors in several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

android
Float

The smallest distance for which two points should be considered visually distinct for stroke generation geometry purposes.

android
BrushFamily

The BrushFamily for this brush.

android
Float

The overall thickness of strokes created with a given brush, in the same units as the stroke coordinate system.

android

Extension functions

Brush
@RequiresApi(value = 26)
Brush.copyWithAndroidColor(
    color: Color,
    family: BrushFamily,
    size: Float,
    epsilon: Float
)

Creates a copy of this Brush and allows named properties to be altered while keeping the rest unchanged.

android
Color

The brush color as an android.graphics.Color instance, which can express colors in 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

Returns a Brush.Builder with values set equivalent to the Brush and the color specified by an android.graphics.Color instance, 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

Public companion functions

builder

fun builder(): Brush.Builder

Returns a new Brush.Builder.

createWithColorIntArgb

fun createWithColorIntArgb(
    family: BrushFamily,
    colorIntArgb: @ColorInt Int,
    size: Float,
    epsilon: Float
): Brush

Returns a new Brush with the color specified by 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 callers that want to specify a literal ColorInt with alpha >= 0x80 must call Long.toInt on the literal.

createWithColorLong

fun createWithColorLong(
    family: BrushFamily,
    colorLong: @ColorLong Long,
    size: Float,
    epsilon: Float
): Brush

Returns a new Brush with the color specified by 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.

Public constructors

Brush

Brush(family: BrushFamily, size: Float, epsilon: Float)

The default color of a Brush is pure black. To set a custom color, use createWithColorLong or createWithColorIntArgb.

Public functions

copy

fun copy(
    family: BrushFamily = this.family,
    size: Float = this.size,
    epsilon: Float = this.epsilon
): Brush

Creates a copy of this and allows named properties to be altered while keeping the rest unchanged. To change the color, use copyWithColorLong or copyWithColorIntArgb.

copyWithColorIntArgb

fun copyWithColorIntArgb(
    colorIntArgb: @ColorInt Int,
    family: BrushFamily = this.family,
    size: Float = this.size,
    epsilon: Float = this.epsilon
): Brush

Creates a copy of this and allows named properties to be altered while keeping the rest unchanged. The color is specified as 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 callers that want to specify a literal ColorInt with alpha >= 0x80 must call Long.toInt on the literal.

copyWithColorLong

fun copyWithColorLong(
    colorLong: @ColorLong Long,
    family: BrushFamily = this.family,
    size: Float = this.size,
    epsilon: Float = this.epsilon
): Brush

Creates a copy of this and allows named properties to be altered while keeping the rest unchanged. The color is specified as 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.

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

toBuilder

fun toBuilder(): Brush.Builder

Returns a Builder with values set equivalent to this. Java developers, use the returned builder to build a copy of a Brush. Kotlin developers, see copy method.

toString

open fun toString(): String

Protected functions

finalize

protected fun finalize(): Unit

Delete native Brush memory.

Public properties

colorIntArgb

val colorIntArgbInt

The brush color as a ColorInt, which can only express colors in the sRGB color space. For clients that want to support wide-gamut colors, use colorLong.

colorLong

val colorLongLong

The brush color as a ColorLong, which can express colors in several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

epsilon

val epsilonFloat

The smallest distance for which two points should be considered visually distinct for stroke generation geometry purposes. Effectively, it is the visual fidelity of strokes created with this brush, where any (lack of) visual fidelity can be observed by a user the further zoomed in they are on the stroke. Lower values of epsilon result in higher fidelity strokes at the cost of somewhat higher memory usage. This value, like size, is in the same units as the stroke coordinate system. A size of 0.1 physical pixels at the default zoom level is a good starting point that can tolerate a reasonable amount of zooming in with high quality visual results.

family

val familyBrushFamily

The BrushFamily for this brush. See StockBrushes for available BrushFamily values.

size

val sizeFloat

The overall thickness of strokes created with a given brush, in the same units as the stroke coordinate system. This must be at least as big as epsilon.

Extension functions

copyWithAndroidColor

@RequiresApi(value = 26)
fun Brush.copyWithAndroidColor(
    color: Color,
    family: BrushFamily = this.family,
    size: Float = this.size,
    epsilon: Float = this.epsilon
): Brush

Creates a copy of this Brush and allows named properties to be altered while keeping the rest unchanged. The color is specified as an android.graphics.Color instance, 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.

createAndroidColor

@RequiresApi(value = 26)
fun Brush.createAndroidColor(): Color

The brush color as an android.graphics.Color instance, which can express colors in several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

Unless an instance of android.graphics.Color is actually needed, prefer to use Brush.colorLong to get the color without causing an allocation, especially in performance-sensitive code. Brush.colorLong is fully compatible with the Long representation of android.graphics.Color.

toBuilderWithAndroidColor

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

Returns a Brush.Builder with values set equivalent to the Brush and the color specified by an android.graphics.Color instance, 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. Java developers, use the returned builder to build a copy of a Brush. Kotlin developers, see copyWithAndroidColor method.

In Kotlin, calling this is equivalent to calling Brush.toBuilder followed by Brush.Builder.setAndroidColor. For Java callers, this function allows more fluent call chaining.