BaselineShift

Class

Common
value class BaselineShift(val multiplier: Float)

The amount by which the text is shifted up or down from current the baseline.

Parameters

multipliershift the baseline by multiplier * (baseline - ascent)

Companion Object

Properties

Common
val Superscript = BaselineShift(0.5f)

Default baseline shift for superscript.

Common
val Subscript = BaselineShift(-0.5f)

Default baseline shift for subscript

Common
val None = BaselineShift(0.0f)

Constant for no baseline shift.

Code Examples

BaselineShiftAnnotatedStringSample

@Composable
fun BaselineShiftAnnotatedStringSample() {
    val annotatedString = buildAnnotatedString {
        append("Text ")
        withStyle(SpanStyle(baselineShift = BaselineShift.Superscript)) { append("Demo") }
    }
    Text(text = annotatedString)
}

BaselineShiftSample

@Composable
fun BaselineShiftSample() {
    Text(
        fontSize = 20.sp,
        text =
            buildAnnotatedString {
                append(text = "Hello")
                withStyle(SpanStyle(baselineShift = BaselineShift.Superscript, fontSize = 16.sp)) {
                    append("superscript")
                    withStyle(SpanStyle(baselineShift = BaselineShift.Subscript)) {
                        append("subscript")
                    }
                }
            },
    )
}