# InlineTextContent

Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/InlineTextContent.kt+class:androidx.compose.foundation.text.InlineTextContent) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.0.0) Common/AllAndroid/JVM
- Cmn

  ```
  class InlineTextContent
  ```

*** ** * ** ***

A data class that stores a composable to be inserted into the text layout.

Different from a regular composable, a `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/Placeholder` is also needed for text layout to reserve space. In this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/InlineTextContent#placeholder()`, the size of the content and how it will be aligned within the text line is defined. When the children composable is measured, its size given in `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/Placeholder#width()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/Placeholder#height()` will be converted into `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Constraints` and passed through `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Layout.composable#Layout(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.layout.MeasurePolicy)`.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.text.BasicText
import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.appendInlineContent
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.Placeholder
import androidx.compose.ui.text.PlaceholderVerticalAlign
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.unit.em

val myId = "inlineContent"
val text = buildAnnotatedString {
    append("Hello")
    // Append a placeholder string "[myBox]" and attach an annotation "inlineContent" on it.
    appendInlineContent(myId, "[myBox]")
}

val inlineContent =
    mapOf(
        Pair(
            // This tells the [BasicText] to replace the placeholder string "[myBox]" by
            // the composable given in the [InlineTextContent] object.
            myId,
            InlineTextContent(
                // Placeholder tells text layout the expected size and vertical alignment of
                // children composable.
                Placeholder(
                    width = 0.5.em,
                    height = 0.5.em,
                    placeholderVerticalAlign = PlaceholderVerticalAlign.AboveBaseline,
                )
            ) {
                // This [Box] will fill maximum size, which is specified by the [Placeholder]
                // above. Notice the width and height in [Placeholder] are specified in
                // TextUnit,
                // and are converted into pixel by text layout.
                Box(modifier = Modifier.fillMaxSize().background(color = Color.Red))
            },
        )
    )

BasicText(text = text, inlineContent = inlineContent)
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/BasicText.composable#BasicText(kotlin.String,androidx.compose.ui.Modifier,androidx.compose.ui.text.TextStyle,kotlin.Function1,androidx.compose.ui.text.style.TextOverflow,kotlin.Boolean,kotlin.Int,kotlin.Int,androidx.compose.ui.graphics.ColorProducer,androidx.compose.foundation.text.TextAutoSize)` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/Placeholder` |   |

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/InlineTextContent#InlineTextContent(androidx.compose.ui.text.Placeholder,kotlin.Function1)( placeholder: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/Placeholder, children: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` | Cmn |

| ### Public properties |
|---|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/InlineTextContent#children()` The composable to be inserted into the text layout. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/Placeholder` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/InlineTextContent#placeholder()` The setting object that defines the size and vertical alignment of this composable in the text line. | Cmn |

## Public constructors

### InlineTextContent

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.0.0)

```
InlineTextContent(
    placeholder: Placeholder,
    children: @Composable (String) -> Unit
)
```

## Public properties

### children

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.0.0)

```
val children: @Composable (String) -> Unit
```

The composable to be inserted into the text layout. The string parameter passed to it will the alternateText given to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/package-summary#(androidx.compose.ui.text.AnnotatedString.Builder).appendInlineContent(kotlin.String,kotlin.String)`.

### placeholder

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.0.0)

```
val placeholder: Placeholder
```

The setting object that defines the size and vertical alignment of this composable in the text line. This is different from the measure of Layout

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/Placeholder` |   |