🌈 Create new beautiful Compose Gradients with our new wesite ->
Class

ParagraphStyle

Paragraph styling configuration.

ParagraphStyleSample

@Sampled
@Composable
fun ParagraphStyleSample() {
    val textStyle =
        TextStyle(
            textAlign = TextAlign.Justify,
            lineHeight = 20.sp,
            textIndent = TextIndent(firstLine = 14.sp, restLine = 3.sp),
        )
    Text(
        text =
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor " +
                "incididunt ut labore et dolore magna aliqua.\nUt enim ad minim veniam, quis " +
                "nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
        style = textStyle,
    )
}

ParagraphStyleAnnotatedStringsSample

@Sampled
@Composable
fun ParagraphStyleAnnotatedStringsSample() {
    val text =
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor " +
            "incididunt ut labore et dolore magna aliqua.\nUt enim ad minim veniam, quis " +
            "nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."

    val paragraphStyle1 = ParagraphStyle(textIndent = TextIndent(firstLine = 14.sp))
    val paragraphStyle2 = ParagraphStyle(lineHeight = 30.sp)

    Text(
        text =
            buildAnnotatedString {
                append(text)
                addStyle(paragraphStyle1, 0, text.indexOf('\n') + 1)
                addStyle(paragraphStyle2, text.indexOf('\n') + 1, text.length)
            }
    )
}

AnnotatedStringBuilderPushParagraphStyleSample

@Sampled
fun AnnotatedStringBuilderPushParagraphStyleSample() {
    with(AnnotatedString.Builder()) {
        // push a ParagraphStyle to be applied to any appended text after this point.
        pushStyle(ParagraphStyle(lineHeight = 18.sp))
        // append a paragraph which will have lineHeight 18.sp
        append("Paragraph One\n")
        // pop the ParagraphStyle
        pop()
        // append new paragraph, this paragraph will not have the line height defined.
        append("Paragraph Two\n")

        toAnnotatedString()
    }
}