The second Android 11 Developer Preview is now available, test it out and share your feedback.

VectorAssetBuilder

class VectorAssetBuilder
kotlin.Any
   ↳ androidx.ui.graphics.vector.VectorAssetBuilder

Builder used to construct a Vector graphic tree. This is useful for caching the result of expensive operations used to construct a vector graphic for compose. For example, the vector graphic could be serialized and downloaded from a server and represented internally in a VectorAsset before it is composed through DrawVector The generated VectorAsset is recommended to be memoized across composition calls to avoid doing redundant work

Summary

Public constructors

<init>(name: String = DefaultGroupName, defaultWidth: Dp, defaultHeight: Dp, viewportWidth: Float, viewportHeight: Float)

Builder used to construct a Vector graphic tree.

Public methods

VectorAssetBuilder
addPath(pathData: List<PathNode>, name: String = DefaultPathName, fill: Brush? = null, fillAlpha: Float = DefaultAlpha, stroke: Brush? = null, strokeAlpha: Float = DefaultAlpha, strokeLineWidth: Float = DefaultStrokeLineWidth, strokeLineCap: StrokeCap = DefaultStrokeLineCap, strokeLineJoin: StrokeJoin = DefaultStrokeLineJoin, strokeLineMiter: Float = DefaultStrokeLineMiter)

Add a path to the VectorAsset graphic.

VectorAsset

Construct a VectorAsset.

VectorAssetBuilder

Pops the topmost VectorGroup from this VectorAssetBuilder.

VectorAssetBuilder
pushGroup(name: String = DefaultGroupName, rotate: Float = DefaultRotation, pivotX: Float = DefaultPivotX, pivotY: Float = DefaultPivotY, scaleX: Float = DefaultScaleX, scaleY: Float = DefaultScaleY, translationX: Float = DefaultTranslationX, translationY: Float = DefaultTranslationY, clipPathData: List<PathNode> = EmptyPath)

Create a new group and push it to the front of the stack of VectorAsset nodes

Extension functions

From androidx.ui.graphics.vector
VectorAssetBuilder
VectorAssetBuilder.group(name: String = DefaultGroupName, rotate: Float = DefaultRotation, pivotX: Float = DefaultPivotX, pivotY: Float = DefaultPivotY, scaleX: Float = DefaultScaleX, scaleY: Float = DefaultScaleY, translationX: Float = DefaultTranslationX, translationY: Float = DefaultTranslationY, clipPathData: List<PathNode> = EmptyPath, block: VectorAssetBuilder.() -> Unit)

DSL extension for adding a VectorGroup to this.

VectorAssetBuilder
VectorAssetBuilder.path(name: String = DefaultPathName, fill: Brush? = null, fillAlpha: Float = DefaultAlpha, stroke: Brush? = null, strokeAlpha: Float = DefaultAlpha, strokeLineWidth: Float = DefaultStrokeLineWidth, strokeLineCap: StrokeCap = DefaultStrokeLineCap, strokeLineJoin: StrokeJoin = DefaultStrokeLineJoin, strokeLineMiter: Float = DefaultStrokeLineMiter, pathBuilder: PathBuilder.() -> Unit)

DSL extension for adding a VectorPath to this.

From androidx.ui.material.icons
VectorAssetBuilder
VectorAssetBuilder.materialPath(fillAlpha: Float = 1f, strokeAlpha: Float = 1f, pathBuilder: PathBuilder.() -> Unit)

Adds a vector path to this icon with sane Material defaults.

Properties

Dp

Intrinsic height of the Vector in Dp

Dp

Intrinsic width of the Vector in Dp

String

Name of the vector asset

Float

Used to define the height of the viewport space.

Float

Used to define the width of the viewport space.

Public constructors

<init>

VectorAssetBuilder(
    name: String = DefaultGroupName,
    defaultWidth: Dp,
    defaultHeight: Dp,
    viewportWidth: Float,
    viewportHeight: Float)

Builder used to construct a Vector graphic tree. This is useful for caching the result of expensive operations used to construct a vector graphic for compose. For example, the vector graphic could be serialized and downloaded from a server and represented internally in a VectorAsset before it is composed through DrawVector The generated VectorAsset is recommended to be memoized across composition calls to avoid doing redundant work

Public methods

addPath

fun addPath(
    pathData: List<PathNode>,
    name: String = DefaultPathName,
    fill: Brush? = null,
    fillAlpha: Float = DefaultAlpha,
    stroke: Brush? = null,
    strokeAlpha: Float = DefaultAlpha,
    strokeLineWidth: Float = DefaultStrokeLineWidth,
    strokeLineCap: StrokeCap = DefaultStrokeLineCap,
    strokeLineJoin: StrokeJoin = DefaultStrokeLineJoin,
    strokeLineMiter: Float = DefaultStrokeLineMiter
): VectorAssetBuilder

Add a path to the VectorAsset graphic. This represents a leaf node in the VectorAsset graphics tree structure

Parameters
pathData: List<PathNode> path information to render the shape of the path
name: String = DefaultPathName the name of the path
fill: Brush? = null specifies the Brush used to fill the path
fillAlpha: Float = DefaultAlpha the alpha to fill the path
stroke: Brush? = null specifies the Brush used to fill the stroke
strokeAlpha: Float = DefaultAlpha the alpha to stroke the path
strokeLineWidth: Float = DefaultStrokeLineWidth the width of the line to stroke the path
strokeLineCap: StrokeCap = DefaultStrokeLineCap specifies the linecap for a stroked path
strokeLineJoin: StrokeJoin = DefaultStrokeLineJoin specifies the linejoin for a stroked path
strokeLineMiter: Float = DefaultStrokeLineMiter specifies the miter limit for a stroked path
Return
This VectorAssetBuilder instance as a convenience for chaining calls

build

fun build(): VectorAsset

Construct a VectorAsset. This concludes the creation process of a VectorAsset graphic This builder cannot be re-used to create additional VectorAsset instances

Return
The newly created VectorAsset instance

popGroup

fun popGroup(): VectorAssetBuilder

Pops the topmost VectorGroup from this VectorAssetBuilder. This is used to indicate that no additional VectorAsset nodes will be added to the current VectorGroup

Return
This VectorAssetBuilder instance as a convenience for chaining calls

pushGroup

fun pushGroup(
    name: String = DefaultGroupName,
    rotate: Float = DefaultRotation,
    pivotX: Float = DefaultPivotX,
    pivotY: Float = DefaultPivotY,
    scaleX: Float = DefaultScaleX,
    scaleY: Float = DefaultScaleY,
    translationX: Float = DefaultTranslationX,
    translationY: Float = DefaultTranslationY,
    clipPathData: List<PathNode> = EmptyPath
): VectorAssetBuilder

Create a new group and push it to the front of the stack of VectorAsset nodes

Parameters
name: String = DefaultGroupName the name of the group
rotate: Float = DefaultRotation the rotation of the group in degrees
pivotX: Float = DefaultPivotX the x coordinate of the pivot point to rotate or scale the group
pivotY: Float = DefaultPivotY the y coordinate of the pivot point to rotate or scale the group
scaleX: Float = DefaultScaleX the scale factor in the X-axis to apply to the group
scaleY: Float = DefaultScaleY the scale factor in the Y-axis to apply to the group
translationX: Float = DefaultTranslationX the translation in virtual pixels to apply along the x-axis
translationY: Float = DefaultTranslationY the translation in virtual pixels to apply along the y-axis
clipPathData: List<PathNode> = EmptyPath the path information used to clip the content within the group
Return
This VectorAssetBuilder instance as a convenience for chaining calls

Properties

defaultHeight

val defaultHeight: Dp

Intrinsic height of the Vector in Dp

defaultWidth

val defaultWidth: Dp

Intrinsic width of the Vector in Dp

name

val name: String

Name of the vector asset

viewportHeight

val viewportHeight: Float

Used to define the height of the viewport space. Viewport is basically the virtual canvas where the paths are drawn on.

viewportWidth

val viewportWidth: Float

Used to define the width of the viewport space. Viewport is basically the virtual canvas where the paths are drawn on.