Bullet
-
Cmn
class Bullet : 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.
import androidx.compose.foundation.text.BasicText import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.graphics.drawscope.Stroke import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.Bullet import androidx.compose.ui.text.buildAnnotatedString 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") } } } )
Summary
Public companion properties |
||
|---|---|---|
Bullet |
Default bullet used in AnnotatedString's bullet list |
Cmn
|
TextUnit |
Indentation required to fit |
Cmn
|
TextUnit |
Padding between bullet and start of paragraph for |
Cmn
|
TextUnit |
Height and width for |
Cmn
|
Public constructors |
|
|---|---|
|
Cmn
|
Public functions |
||
|---|---|---|
Bullet |
copy(Copies the existing |
Cmn
|
open operator Boolean |
Cmn
|
|
open Int |
hashCode() |
Cmn
|
open String |
toString() |
Cmn
|
Public properties |
||
|---|---|---|
Float |
opacity to be applied to |
Cmn
|
Brush? |
brush to draw a bullet with. |
Cmn
|
DrawStyle |
defines the draw style of the bullet, e.g. a fill or a stroke |
Cmn
|
TextUnit |
the height of the bullet |
Cmn
|
TextUnit |
the padding between the end of the bullet and the start of the paragraph |
Cmn
|
Shape |
the shape of the bullet to draw |
Cmn
|
TextUnit |
the width of the bullet |
Cmn
|
Public companion properties
DefaultPadding
val DefaultPadding: TextUnit
Padding between bullet and start of paragraph for Default bullet
Public constructors
Bullet
Bullet(
shape: Shape,
width: TextUnit,
height: TextUnit,
padding: TextUnit,
brush: Brush? = null,
alpha: Float = Float.NaN,
drawStyle: DrawStyle = Fill
)
| Parameters | |
|---|---|
shape: Shape |
the shape of the bullet to draw |
width: TextUnit |
the width of the bullet |
height: TextUnit |
the height of the bullet |
padding: TextUnit |
the padding between the end of the bullet and the start of the paragraph |
brush: Brush? = null |
brush to draw a bullet with. If |
alpha: Float = Float.NaN |
opacity to be applied to |
drawStyle: DrawStyle = Fill |
defines the draw style of the bullet, e.g. a fill or a stroke |
Public functions
copy
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
Copies the existing Bullet replacing some of the fields as desired.
Public properties
alpha
val alpha: Float
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
brush
val brush: Brush?
brush to draw a bullet with. If null is passed, the bullet will be drawn like the rest of the text