Brush
-
android
class Brush
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 |
|---|
class Brush.BuilderBuilder for |
object Brush.Companion |
Public companion functions |
||
|---|---|---|
Brush.Builder |
builder()Returns a new |
android
|
Brush |
createWithColorIntArgb(Returns a new |
android
|
Brush |
createWithColorLong(Returns a new |
android
|
Public constructors |
|
|---|---|
Brush(The default color of a |
android
|
Public functions |
||
|---|---|---|
Brush |
copy(Creates a copy of |
android
|
Brush |
copyWithColorIntArgb(Creates a copy of |
android
|
Brush |
copyWithColorLong(Creates a copy of |
android
|
open operator Boolean |
android
|
|
open Int |
hashCode() |
android
|
Brush.Builder |
Returns a |
android
|
open String |
toString() |
android
|
Public properties |
||
|---|---|---|
Int |
The brush color as a |
android
|
Long |
The brush color as a |
android
|
Float |
The smallest distance for which two points should be considered visually distinct for stroke generation geometry purposes. |
android
|
BrushFamily |
The |
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 |
Brush.copyWithComposeColor(Creates a copy of |
android
|
Brush |
@RequiresApi(value = 26)Creates a copy of |
android
|
Color |
@RequiresApi(value = 26)The brush color as an |
android
|
Extension properties |
||
|---|---|---|
Color |
The brush color as an |
android
|
Public companion functions
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: @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) Float,
epsilon: @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) 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: @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) Float = this.size,
epsilon: @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) 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: @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) Float = this.size,
epsilon: @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) 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: @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) Float = this.size,
epsilon: @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) 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.
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.
Public properties
colorIntArgb
val colorIntArgb: Int
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 colorLong: 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.
epsilon
val epsilon: Float
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 family: BrushFamily
The BrushFamily for this brush. See StockBrushes for available BrushFamily values.
Extension functions
copyWithComposeColor
fun Brush.copyWithComposeColor(
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 androidx.compose.ui.graphics.Color value, 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.
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.
Extension properties
composeColor
val Brush.composeColor: Color
The brush color as an androidx.compose.ui.graphics.Color value, 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.