Builder

class Builder(capacity: Int = 16) : Appendable

Builder class for AnnotatedString. Enables construction of an AnnotatedString using methods such as append and addStyle.

This class implements Appendable and can be used with other APIs that don't know about AnnotatedStrings:

Parameters

capacity

initial capacity for the internal char buffer

Constructors

Link copied to clipboard
constructor(text: String)

Create an Builder instance using the given String.

constructor(text: AnnotatedString)

Create an Builder instance using the given AnnotatedString.

constructor(capacity: Int = 16)

Properties

Link copied to clipboard
val length: Int

Returns the length of the String.

Functions

Link copied to clipboard
fun addStyle(style: SpanStyle, start: Int, end: Int)

Set a SpanStyle for the given range between start (inclusive) and end (exclusive) to this Builder.

Link copied to clipboard

Appends the given AnnotatedString to this Builder.

open override fun append(char: Char): AnnotatedString.Builder

open override fun append(text: CharSequence?): AnnotatedString.Builder

Appends text to this Builder if non-null, and returns this Builder.

fun append(text: String)

Appends the given String to this Builder.

fun append(text: AnnotatedString, start: Int, end: Int)

Appends the range of text between start (inclusive) and end (exclusive) to this Builder. All spans and annotations from text between start and end will be copied over as well.

open override fun append(text: CharSequence?, start: Int, end: Int): AnnotatedString.Builder

Appends the range of text between start (inclusive) and end (exclusive) to this Builder if non-null, and returns this Builder.

Link copied to clipboard
fun pop()

Ends the style or annotation that was added via a push operation before.

fun pop(index: Int)

Ends the styles or annotation up to and including the pushStyle that returned the given index.

Link copied to clipboard
fun pushStyle(style: SpanStyle): Int

Applies the given SpanStyle to any appended text until a corresponding pop is called.

Link copied to clipboard

Constructs an AnnotatedString based on the configurations applied to the Builder.

Link copied to clipboard

Pushes style to the AnnotatedString.Builder, executes block and then pops the style.