AutoSizeText

fun AutoSizeText(text: String, modifier: Modifier = Modifier, suggestedFontSizes: ImmutableWrapper<List<TextUnit>> = emptyList<TextUnit>().toImmutableWrapper(), minTextSize: TextUnit = TextUnit.Unspecified, maxTextSize: TextUnit = TextUnit.Unspecified, stepGranularityTextSize: TextUnit = TextUnit.Unspecified, alignment: Alignment = Alignment.TopStart, color: Color = Color.Unspecified, fontStyle: FontStyle? = null, fontWeight: FontWeight? = null, fontFamily: FontFamily? = null, letterSpacing: TextUnit = TextUnit.Unspecified, textDecoration: TextDecoration? = null, lineSpacingRatio: Float = 0.1f, maxLines: Int = Int.MAX_VALUE, onTextLayout: (TextLayoutResult) -> Unit = {}, style: TextStyle = LocalTextStyle.current)

Composable function that automatically adjusts the text size to fit within given constraints, considering the ratio of line spacing to text size.

Features:

  1. Best performance: Utilizes a dichotomous binary search algorithm for swift and optimal text size determination without unnecessary iterations.

  2. Alignment support: Supports six possible alignment values via the Alignment interface.

  3. Material Design 3 support.

  4. Font scaling support: User-initiated font scaling doesn't affect the visual rendering output.

  5. Multiline Support with maxLines Parameter.

Limitations:

  1. MinLine is set to 1 under the hood and cannot be changed.

Author

Reda El Madini - For support, contact gladiatorkilo@gmail.com or shatz.dan@gmail.com

Parameters

text

The text to be displayed.

modifier

The modifier for the text composable.

suggestedFontSizes

The suggested font sizes to choose from.

minTextSize

The minimum text size allowed.

maxTextSize

The maximum text size allowed.

stepGranularityTextSize

The step size for adjusting the text size.

alignment

The alignment of the text within its container.

color

The color of the text.

fontStyle

The font style of the text.

fontWeight

The font weight of the text.

fontFamily

The font family of the text.

letterSpacing

The letter spacing of the text.

textDecoration

The text decoration style.

lineSpacingRatio

The ratio of line spacing to text size.

maxLines

The maximum number of lines for the text.

onTextLayout

Callback invoked when the text layout is available.

style

The base style to apply to the text.


fun AutoSizeText(text: AnnotatedString, modifier: Modifier = Modifier, suggestedFontSizes: ImmutableWrapper<List<TextUnit>> = emptyList<TextUnit>().toImmutableWrapper(), minTextSize: TextUnit = TextUnit.Unspecified, maxTextSize: TextUnit = TextUnit.Unspecified, stepGranularityTextSize: TextUnit = TextUnit.Unspecified, alignment: Alignment = Alignment.TopStart, color: Color = Color.Unspecified, fontStyle: FontStyle? = null, fontWeight: FontWeight? = null, fontFamily: FontFamily? = null, letterSpacing: TextUnit = TextUnit.Unspecified, textDecoration: TextDecoration? = null, lineSpacingRatio: Float = 0.1f, maxLines: Int = Int.MAX_VALUE, inlineContent: ImmutableWrapper<Map<String, InlineTextContent>> = mapOf<String, InlineTextContent>().toImmutableWrapper(), onTextLayout: (TextLayoutResult) -> Unit = {}, style: TextStyle = LocalTextStyle.current)

Composable function that automatically adjusts the text size to fit within given constraints using AnnotatedString, considering the ratio of line spacing to text size.

Features: Similar to AutoSizeText(String), with support for AnnotatedString.

See also