DistanceText

fun DistanceText(distance: Distance, modifier: Modifier = Modifier, format: DistanceFormat = DistanceFormat.Short, locale: Locale = Locale.current, unit: DistanceUnit = distance.unitForLocale(locale), style: TextStyle = TextStyle.Default)

Displays a formatted distance as text, adapting to the specified locale, unit system, and format style.

This composable renders a textual representation of a given distance value, with options for different units, formats, locales, and text styles. It automatically adjusts the level of accuracy based on the specified format, showing a user-friendly, concise distance.

Parameters

distance

The Distance value to be displayed.

modifier

Modifier to be applied to the underlying Text element.

format

Defines the format style for the distance text.

  • DistanceFormat.Long: Displays in a detailed format (e.g., "10 miles", "5 feet", "6 meters").

  • DistanceFormat.Short: Displays in a concise format (e.g., "10 mi", "5 ft", "6 m"). This setting determines the highest level of accuracy, e.g., converting "2500 cm" to "2.5 m".

locale

The Locale to use for determining language and unit system (imperial or metric). Defaults to the current locale.

unit

The DistanceUnit for the distance representation. By default, it is auto-selected based on the specified or current locale.

style

Text style applied to the Text element displaying the distance.


fun DistanceText(distance: Distance, unit: DistanceUnit, language: String, modifier: Modifier = Modifier, format: DistanceFormat = DistanceFormat.Short, style: TextStyle = TextStyle.Default)

Displays a formatted distance as text, adapting to the specified language, unit system, and format style.

This composable renders a textual representation of a given distance value, with options for different units, formats, locales, and text styles. It automatically adjusts the level of accuracy based on the specified format, showing a user-friendly, concise distance.

Parameters

distance

The Distance value to be displayed.

unit

The DistanceUnit for the distance representation.

language

The ISO 639 compliant language code to use for determining unit system.

modifier

Modifier to be applied to the underlying Text element.

format

Defines the format style for the distance text.

  • DistanceFormat.Long: Displays in a detailed format (e.g., "10 miles", "5 feet", "6 meters").

  • DistanceFormat.Short: Displays in a concise format (e.g., "10 mi", "5 ft", "6 m"). This setting determines the highest level of accuracy, e.g., converting "2500 cm" to "2.5 m".

style

Text style applied to the Text element displaying the distance.