# withDrawAnnotation

> Associates [drawAnnotation] with the text appended while running [block].

## API Reference

### withDrawAnnotation

> Source set: Common

```kotlin
public inline fun <R : Any> Builder.withDrawAnnotation(
    drawAnnotation: DrawAnnotation,
    block: Builder.() -> R,
): R
```

Associates `drawAnnotation` with the text appended while running `block`.

#### Parameters

| | |
| --- | --- |
| drawAnnotation | annotation that draws behind or over the appended text range |
| block | function to run while [drawAnnotation](https://composables.com/jetpack-compose/androidx.compose.ui/ui-text/functions/DrawAnnotation/api.md) is active |

#### Return

result of `block`

## Code Examples

### DrawAnnotationSample

```kotlin
@Sampled
@Composable
fun DrawAnnotationSample() {
    val cachedPath = remember { Path() }
    val highlight = remember {
        DrawAnnotation(
            drawBehind = {
                textLayoutResult.fillPathForRange(
                    start = start,
                    end = end,
                    target = cachedPath,
                    cornerRadius = CornerRadius(4.dp.toPx()),
                )
                drawPath(cachedPath, color = Color.Yellow.copy(alpha = 0.4f))
            }
        )
    }
    BasicText(
        buildAnnotatedString {
            append("Compose ")
            withDrawAnnotation(highlight) { append("custom draw annotation") }
        }
    )
}
```
