Class
Common
class Bullet(
    val shape: Shape,
    val width: TextUnit,
    val height: TextUnit,
    val padding: TextUnit,
    val brush: Brush? = null,
    val alpha: Float = Float.NaN,
    val drawStyle: DrawStyle = Fill,
) : AnnotatedString.Annotation

Draws a bullet point next to a paragraph.

Bullets do not add indentation. The call site must provide sufficient leading space to accommodate the bullet and its padding, preventing overlap with the text.

There are several ways to achieve this leading space. One common approach is to use ParagraphStyle with textIndent within an AnnotatedString.

Parameters

shape the shape of the bullet to draw
width the width of the bullet
height the height of the bullet
padding the padding between the end of the bullet and the start of the paragraph
brush brush to draw a bullet with. If null is passed, the bullet will be drawn like the rest of the text
alpha opacity to be applied to brush drawing a bullet from 0.0f to 1.0f representing fully transparent to fully opaque respectively. When Float.NaN is passed, the alpha will not be changed and the one used for drawing rest of the text is used
drawStyle defines the draw style of the bullet, e.g. a fill or a stroke

Functions

fun copy(
        shape: Shape = this.shape,
        width: TextUnit = this.width,
        height: TextUnit = this.height,
        padding: TextUnit = this.padding,
        brush: Brush? = this.brush,
        alpha: Float = this.alpha,
        drawStyle: DrawStyle = this.drawStyle,
    ) = Bullet(shape, width, height, padding, brush, alpha, drawStyle)

Copies the existing Bullet replacing some of the fields as desired.

Companion Object

Properties

Common
val DefaultIndentation = 1.em

Indentation required to fit Default bullet.

Common
val DefaultSize = 0.25.em

Height and width for Default bullet.

Common
val DefaultPadding = 0.25.em

Padding between bullet and start of paragraph for Default bullet

Common
val Default = Bullet(CircleShape, DefaultSize, DefaultSize, DefaultPadding)

Default bullet used in AnnotatedString's bullet list

Code Examples

AnnotatedStringWithBulletListCustomBulletSample

@Composable
fun AnnotatedStringWithBulletListCustomBulletSample() {
    val bullet1 = Bullet.Default.copy(shape = RectangleShape)
    val bullet2 = bullet1.copy(drawStyle = Stroke(2f))
    val bullet3 = bullet1.copy(brush = SolidColor(Color.LightGray))
    BasicText(
        buildAnnotatedString {
            withBulletList(bullet = bullet1) {
                withBulletListItem { append("Item 1") }
                withBulletList(bullet = bullet2) {
                    withBulletListItem { append("Item 2") }
                    withBulletListItem { append("Item 3") }
                    withBulletList(bullet = bullet3) { withBulletListItem { append("Item 4") } }
                }
                withBulletListItem { append("Item 5") }
            }
        }
    )
}