Google is committed to advancing racial equity for Black communities. See how.

TextUnit

@Immutable inline class TextUnit
kotlin.Any
   ↳ androidx.compose.ui.unit.TextUnit

The unit used for text related dimension value.

This unit can hold either scaled pixels (SP), relative font size (em) and special unit for indicating inheriting from other style.

Note that do not store this value in your persistent storage or send to another process since the internal representation may be changed in future.

Summary

Public constructors
<init>(packedValue: Long)

The unit used for text related dimension value.

Public methods
operator Int

Support comparing Dimensions with comparison operators.

operator TextUnit
div(other: Float)

Divide a TextUnit by a scalar.

operator TextUnit
div(other: Double)

Divide a TextUnit by a scalar.

operator TextUnit
div(other: Int)

Divide a TextUnit by a scalar.

operator Float
div(other: TextUnit)

Divide by another TextUnit to get a scalar.

operator TextUnit
minus(other: TextUnit)

Subtract a TextUnit from another one.

operator TextUnit
plus(other: TextUnit)

Add two TextUnits together.

operator TextUnit
times(other: Float)

Multiply a TextUnit by a scalar.

operator TextUnit
times(other: Double)

Multiply a TextUnit by a scalar.

operator TextUnit
times(other: Int)

Multiply a TextUnit by a scalar.

String

operator TextUnit

This is the same as multiplying the TextUnit by -1.

Companion functions
TextUnit
Em(value: Int)

Creates an EM unit TextUnit.

TextUnit
Em(value: Float)

Creates an EM unit TextUnit.

TextUnit
Em(value: Double)

Creates an EM unit TextUnit.

TextUnit
Sp(value: Int)

Creates a SP unit TextUnit.

TextUnit
Sp(value: Float)

Creates a SP unit TextUnit.

TextUnit
Sp(value: Double)

Creates a SP unit TextUnit.

Extension functions
From androidx.compose.ui.unit
TextUnit

Ensures that the value of TextUnit is not less than the specified minimumValue.

TextUnit

Ensures that the value of TextUnit is not greater than the specified maximumValue.

TextUnit
TextUnit.coerceIn(minimumValue: TextUnit, maximumValue: TextUnit)

Ensures that the value of TextUnit lies in the specified range minimumValue.

Properties
Boolean

True if this is a EM unit type.

Boolean

True if this is TextUnit.Inherit, otherwise false.

Boolean

True if this is a SP unit type.

Long

TextUnitType

A type information of this TextUnit.

Float

Returns the value

Companion properties
TextUnit

A special TextUnit instance for representing inheriting from parent value.

Public constructors

<init>

TextUnit(packedValue: Long)

The unit used for text related dimension value.

This unit can hold either scaled pixels (SP), relative font size (em) and special unit for indicating inheriting from other style.

Note that do not store this value in your persistent storage or send to another process since the internal representation may be changed in future.

Public methods

compareTo

inline operator fun compareTo(other: TextUnit): Int

Support comparing Dimensions with comparison operators.

div

inline operator fun div(other: Float): TextUnit

Divide a TextUnit by a scalar.

This operation works only if the left operand is not equal to TextUnit.Inherit. The result of this operation is the same unit type of the given one.

div

inline operator fun div(other: Double): TextUnit

Divide a TextUnit by a scalar.

This operation works only if the left operand is not equal to TextUnit.Inherit. The result of this operation is the same unit type of the given one.

div

inline operator fun div(other: Int): TextUnit

Divide a TextUnit by a scalar.

This operation works only if the left operand is not equal to TextUnit.Inherit. The result of this operation is the same unit type of the given one.

div

inline operator fun div(other: TextUnit): Float

Divide by another TextUnit to get a scalar.

This operation works only if all the operands are the same unit type and they are not equal to TextUnit.Inherit.

minus

inline operator fun minus(other: TextUnit): TextUnit

Subtract a TextUnit from another one.

This operation works only if all the operands are the same unit type and not they are not equal to TextUnit.Inherit. The result of this operation is the same unit type of the given one.

plus

inline operator fun plus(other: TextUnit): TextUnit

Add two TextUnits together.

This operation works only if all the operands are the same unit type and not they are not equal to TextUnit.Inherit. The result of this operation is the same unit type of the given one.

times

inline operator fun times(other: Float): TextUnit

Multiply a TextUnit by a scalar.

This operation works only if the left operand is not equal to TextUnit.Inherit. The result of this operation is the same unit type of the given one.

times

inline operator fun times(other: Double): TextUnit

Multiply a TextUnit by a scalar.

This operation works only if the left operand is not equal to TextUnit.Inherit. The result of this operation is the same unit type of the given one.

times

inline operator fun times(other: Int): TextUnit

Multiply a TextUnit by a scalar.

This operation works only if the left operand is not equal to TextUnit.Inherit. The result of this operation is the same unit type of the given one.

toString

fun toString(): String

unaryMinus

inline operator fun unaryMinus(): TextUnit

This is the same as multiplying the TextUnit by -1.0.

This operation works only if the operand is not equal to TextUnit.Inherit. The result of this operation is the same unit type of the given one.

Properties

isEm

val isEm: Boolean

True if this is a EM unit type.

isInherit

val isInherit: Boolean

True if this is TextUnit.Inherit, otherwise false.

isSp

val isSp: Boolean

True if this is a SP unit type.

packedValue

val packedValue: Long

type

val type: TextUnitType

A type information of this TextUnit.

Exceptions
RuntimeException if unknown unknown unit type is appeared.

value

val value: Float

Returns the value

Companion functions

Em

fun Em(value: Int): TextUnit

Creates an EM unit TextUnit.

Em

fun Em(value: Float): TextUnit

Creates an EM unit TextUnit.

Em

fun Em(value: Double): TextUnit

Creates an EM unit TextUnit.

Sp

fun Sp(value: Int): TextUnit

Creates a SP unit TextUnit.

Sp

fun Sp(value: Float): TextUnit

Creates a SP unit TextUnit.

Sp

fun Sp(value: Double): TextUnit

Creates a SP unit TextUnit.

Companion properties

Inherit

@Stable val Inherit: TextUnit

A special TextUnit instance for representing inheriting from parent value.