State of Compose 2023 results are in! Click here to learn more

← Back to Foundation

CoreText

Component
in
Foundation
. Since 1.0.0-alpha08

Overview

Code Examples

CoreText is a low level element that displays text with multiple different styles. The text to display is described using a AnnotatedString. Typically you will instead want to use androidx.compose.foundation.Text, which is a higher level Text element that contains semantics and consumes style information from a theme.

@param text AnnotatedString encoding a styled text. @param modifier Modifier to apply to this layout node. @param style Style configuration for the text such as color, font, line height etc. @param softWrap Whether the text should break at soft line breaks. If false, the glyphs in the text will be positioned as if there was unlimited horizontal space. If softWrap is false, overflow and TextAlign may have unexpected effects. @param overflow How visual overflow should be handled. @param maxLines An optional maximum number of lines for the text to span, wrapping if necessary. If the text exceeds the given number of lines, it will be truncated according to overflow and softWrap. If it is not null, then it must be greater than zero. @param inlineContent A map store composables that replaces certain ranges of the text. It's used to insert composables into text layout. Check InlineTextContent for more information. @param onTextLayout Callback that is executed when a new text layout is calculated.

Overloads

CoreText

@Composable
@InternalTextApi
@OptIn(ExperimentalTextApi::class)
fun CoreText(
    text: AnnotatedString,
    modifier: Modifier = Modifier,
    style: TextStyle,
    softWrap: Boolean,
    overflow: TextOverflow,
    maxLines: Int,
    inlineContent: Map<String, InlineTextContent>,
    onTextLayout: (TextLayoutResult) -> Unit
)

Parameters

NameDescription
textAnnotatedString encoding a styled text.
modifierModifier to apply to this layout node.
styleStyle configuration for the text such as color, font, line height etc.
softWrapWhether the text should break at soft line breaks. If false, the glyphs in the text will be positioned as if there was unlimited horizontal space. If softWrap is false, overflow and TextAlign may have unexpected effects.
overflowHow visual overflow should be handled.
maxLinesAn optional maximum number of lines for the text to span, wrapping if necessary. If the text exceeds the given number of lines, it will be truncated according to overflow and softWrap. If it is not null, then it must be greater than zero.
inlineContentA map store composables that replaces certain ranges of the text. It's used to insert composables into text layout. Check InlineTextContent for more information.
onTextLayoutCallback that is executed when a new text layout is calculated