OudsCodeText

fun OudsCodeText(text: String, modifier: Modifier = Modifier, color: Color = OudsCodeTextDefaults.Color, textAlign: TextAlign? = null, lineHeight: TextUnit = TextUnit.Unspecified, overflow: TextOverflow = TextOverflow.Clip, softWrap: Boolean = true, maxLines: Int = Int.MAX_VALUE, minLines: Int = 1, onTextLayout: (TextLayoutResult) -> Unit? = null)

Code style is dedicated to technical content such as code snippets, commands, system values, and identifiers. It uses a monospace typeface to preserve character alignment and improve readability of structured content. Available in a single size, it provides a consistent presentation of technical information throughout the product. Its use should be limited to content that requires an accurate code-like representation.

An overload accepting annotated string is available for rich text formatting.

Design

NameCode
Version1.0.0

Parameters

text

Text to be displayed.

modifier

Modifier applied to the code text.

color

Color of the code text.

textAlign

Alignment of the text within the lines of the paragraph. See TextStyle.textAlign.

lineHeight

Line height for the Paragraph in TextUnit unit, e.g. SP or EM. See TextStyle.lineHeight.

overflow

How visual overflow should be handled.

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.

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. It is required that 1 <= minLines<= maxLines.

minLines

The minimum height in terms of minimum number of visible lines. It is required that 1 <= minLines<= maxLines.

onTextLayout

Callback that is executed when a new text layout is calculated. A TextLayoutResult object that callback provides contains paragraph information, size of the text, baselines and other details. The callback can be used to add additional decoration or functionality to the text. For example, to draw selection around the text.

Samples

OudsCodeText(
    modifier = Modifier.padding(OudsTheme.spaces.fixed.small),
    text = "Code",
)

fun OudsCodeText(text: AnnotatedString, modifier: Modifier = Modifier, color: Color = OudsCodeTextDefaults.Color, textAlign: TextAlign? = null, lineHeight: TextUnit = TextUnit.Unspecified, overflow: TextOverflow = TextOverflow.Clip, softWrap: Boolean = true, maxLines: Int = Int.MAX_VALUE, minLines: Int = 1, onTextLayout: (TextLayoutResult) -> Unit = {})

Code style is dedicated to technical content such as code snippets, commands, system values, and identifiers. It uses a monospace typeface to preserve character alignment and improve readability of structured content. Available in a single size, it provides a consistent presentation of technical information throughout the product. Its use should be limited to content that requires an accurate code-like representation.

An overload accepting plain text is available for simple text without formatting.

Design

NameCode
Version1.0.0

Parameters

text

Text to be displayed. Note: Use rich text in compliance with guidelines and accessibility criteria.

modifier

Modifier applied to the code text.

color

Color of the code text.

textAlign

Alignment of the text within the lines of the paragraph. See TextStyle.textAlign.

lineHeight

Line height for the Paragraph in TextUnit unit, e.g. SP or EM. See TextStyle.lineHeight.

overflow

How visual overflow should be handled.

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.

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. It is required that 1 <= minLines<= maxLines.

minLines

The minimum height in terms of minimum number of visible lines. It is required that 1 <= minLines<= maxLines.

onTextLayout

Callback that is executed when a new text layout is calculated. A TextLayoutResult object that callback provides contains paragraph information, size of the text, baselines and other details. The callback can be used to add additional decoration or functionality to the text. For example, to draw selection around the text.

Samples

OudsCodeText(
    modifier = Modifier.padding(OudsTheme.spaces.fixed.small),
    text = buildAnnotatedString {
        append("Code with ")
        withStyle(SpanStyle(color = OudsTheme.colorScheme.content.brandPrimary)) { append("colored text") }
        append(" and ")
        withStyle(SpanStyle(fontWeight = FontWeight.Bold)) { append("bold text") }
    }
)