# TextUnit

Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/TextUnit.kt+class:androidx.compose.ui.unit.TextUnit) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/AllAndroid/JVM
- Cmn

  ```
  value class TextUnit
  ```

*** ** * ** ***

The unit used for text related dimension value.

This unit can hold either scaled pixels (SP), relative font size (EM) and special unit Unspecified for indicating inheriting from other style or using the default value. It can be created with `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/package-summary#(kotlin.Float).sp()` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/package-summary#(kotlin.Float).em()`. (e.g. 15.sp or 18.em) which can be applied to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html`, `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html`, and `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html`.

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 companion properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()` A special `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` instance for representing inheriting from parent value. | Cmn |

| ### Public functions |
|---|---|---|
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#compareTo(androidx.compose.ui.unit.TextUnit)(other: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit)` Support comparing Dimensions with comparison operators. | Cmn |
| `inline operator https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#div(kotlin.Double)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html)` Divide a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` by a scalar. | Cmn |
| `inline operator https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#div(kotlin.Float)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Divide a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` by a scalar. | Cmn |
| `inline operator https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#div(kotlin.Int)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Divide a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` by a scalar. | Cmn |
| `inline operator https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#times(kotlin.Double)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html)` Multiply a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` by a scalar. | Cmn |
| `inline operator https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#times(kotlin.Float)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Multiply a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` by a scalar. | Cmn |
| `inline operator https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#times(kotlin.Int)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Multiply a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` by a scalar. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#toString()()` | Cmn |
| `inline operator https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#unaryMinus()()` This is the same as multiplying the `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` by -1.0. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#isEm()` True if this is a EM unit type. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#isSp()` True if this is a SP unit type. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnitType` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#type()` A type information of this TextUnit. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#value()` Returns the value of this `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit`. | Cmn |

| ### Extension functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/remote/creation/compose/state/RemoteFloat` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#(androidx.compose.ui.unit.TextUnit).toPx(androidx.compose.remote.creation.compose.capture.RemoteDensity)(density: https://developer.android.com/reference/kotlin/androidx/compose/remote/creation/compose/capture/RemoteDensity)` Converts a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` to pixels using the provided `https://developer.android.com/reference/kotlin/androidx/compose/remote/creation/compose/capture/RemoteDensity`. | android |
| `https://developer.android.com/reference/kotlin/androidx/compose/remote/creation/compose/state/RemoteTextUnit` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#(androidx.compose.ui.unit.TextUnit).asRemoteTextUnit()()` Extension function to convert a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` to a `https://developer.android.com/reference/kotlin/androidx/compose/remote/creation/compose/state/RemoteTextUnit`. | android |
| `inline https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#(androidx.compose.ui.unit.TextUnit).takeOrElse(kotlin.Function0)(block: () -> https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit)` If this `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/package-summary#(androidx.compose.ui.geometry.Offset).isSpecified()` then this is returned, otherwise `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/package-summary#(androidx.compose.ui.unit.TextUnit).takeOrElse(kotlin.Function0)` is executed and its result is returned. | Cmn |

| ### Extension properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#(androidx.compose.ui.unit.TextUnit).isSpecified()` `false` when this is `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#(androidx.compose.ui.unit.TextUnit).isUnspecified()` `true` when this is `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`. | Cmn |

## Public companion properties

### Unspecified

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val Unspecified: TextUnit
```

A special `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` instance for representing inheriting from parent value.

Notice that performing arithmetic operations on `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()` may result in an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`.

## Public functions

### compareTo

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
inline operator fun compareTo(other: TextUnit): Int
```

Support comparing Dimensions with comparison operators.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | 0 if this `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` equals to the `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#compareTo(androidx.compose.ui.unit.TextUnit)`, a negative number if it's less than the `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#compareTo(androidx.compose.ui.unit.TextUnit)`, or a positive number if it's greater than the `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#compareTo(androidx.compose.ui.unit.TextUnit)`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if this `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` and the `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#compareTo(androidx.compose.ui.unit.TextUnit)` has different `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnitType`s or either of the two has the `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnitType` equals to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnitType#Unspecified()`. |

### div

Cmn Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.1.0)

```
inline operator fun div(other: Double): TextUnit
```

Divide a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` by a scalar.

This operation works only if the left operand is not equal to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`. The result of this operation is the same unit type of the given one.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if this `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit`'s type is `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnitType#Unspecified()`. |

### div

Cmn Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.1.0)

```
inline operator fun div(other: Float): TextUnit
```

Divide a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` by a scalar.

This operation works only if the left operand is not equal to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`. The result of this operation is the same unit type of the given one.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if this `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit`'s type is `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnitType#Unspecified()`. |

### div

Cmn Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.1.0)

```
inline operator fun div(other: Int): TextUnit
```

Divide a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` by a scalar.

This operation works only if the left operand is not equal to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`. The result of this operation is the same unit type of the given one.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if this `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit`'s type is `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnitType#Unspecified()`. |

### times

Cmn Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.1.0)

```
inline operator fun times(other: Double): TextUnit
```

Multiply a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` by a scalar.

This operation works only if the left operand is not equal to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`. The result of this operation is the same unit type of the given one.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if this `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit`'s type is `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnitType#Unspecified()`. |

### times

Cmn Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.1.0)

```
inline operator fun times(other: Float): TextUnit
```

Multiply a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` by a scalar.

This operation works only if the left operand is not equal to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`. The result of this operation is the same unit type of the given one.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if this `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit`'s type is `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnitType#Unspecified()`. |

### times

Cmn Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.1.0)

```
inline operator fun times(other: Int): TextUnit
```

Multiply a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` by a scalar.

This operation works only if the left operand is not equal to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`. The result of this operation is the same unit type of the given one.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if this `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit`'s type is `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnitType#Unspecified()`. |

### toString

Cmn

```
open fun toString(): String
```

### unaryMinus

Cmn Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.1.0)

```
inline operator fun unaryMinus(): TextUnit
```

This is the same as multiplying the `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` by -1.0.

This operation works only if the operand is not equal to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`. The result of this operation is the same unit type of the given one.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if this `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit`'s type is `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnitType#Unspecified()`. |

## Public properties

### isEm

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val isEm: Boolean
```

True if this is a EM unit type.

### isSp

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val isSp: Boolean
```

True if this is a SP unit type.

### type

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val type: TextUnitType
```

A type information of this TextUnit.

### value

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val value: Float
```

Returns the value of this `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit`.

For example, the value of 3.sp equals to 3, and value of 5.em equals to 5. The value of `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit`s whose `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnitType` is `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnitType#Unspecified()` is undefined.

## Extension functions

### TextUnit.toPx

android Artifact: [androidx.compose.remote:remote-creation-compose](https://developer.android.com/jetpack/androidx/releases/compose-remote) [View Source](https://cs.android.com/search?q=file:androidx/compose/remote/creation/compose/capture/RemoteDensityCompose.kt+function:toPx)

```
fun TextUnit.toPx(density: RemoteDensity): RemoteFloat
```

Converts a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` to pixels using the provided `https://developer.android.com/reference/kotlin/androidx/compose/remote/creation/compose/capture/RemoteDensity`.

| Parameters |
|---|---|
| `density: https://developer.android.com/reference/kotlin/androidx/compose/remote/creation/compose/capture/RemoteDensity` | The `https://developer.android.com/reference/kotlin/androidx/compose/remote/creation/compose/capture/RemoteDensity` used to convert this `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` to pixels. |

### TextUnit.asRemoteTextUnit

android Artifact: [androidx.compose.remote:remote-creation-compose](https://developer.android.com/jetpack/androidx/releases/compose-remote) [View Source](https://cs.android.com/search?q=file:androidx/compose/remote/creation/compose/state/RemoteTextUnit.kt+function:asRemoteTextUnit)

```
fun TextUnit.asRemoteTextUnit(): RemoteTextUnit
```

Extension function to convert a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` to a `https://developer.android.com/reference/kotlin/androidx/compose/remote/creation/compose/state/RemoteTextUnit`.

### TextUnit.takeOrElse

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/TextUnit.kt+function:takeOrElse)

```
inline fun TextUnit.takeOrElse(block: () -> TextUnit): TextUnit
```

If this `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/package-summary#(androidx.compose.ui.geometry.Offset).isSpecified()` then this is returned, otherwise `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/package-summary#(androidx.compose.ui.unit.TextUnit).takeOrElse(kotlin.Function0)` is executed and its result is returned.

## Extension properties

### TextUnit.isSpecified

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/TextUnit.kt+symbol:isSpecified)

```
val TextUnit.isSpecified: Boolean
```

`false` when this is `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`.

### TextUnit.isUnspecified

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/TextUnit.kt+symbol:isUnspecified)

```
val TextUnit.isUnspecified: Boolean
```

`true` when this is `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`.