TextAutoSize
Interface
Common
interface TextAutoSize
Interface used by Text composables to override text size to automatically grow or shrink text to fill the layout bounds.
Functions
fun TextAutoSizeLayoutScope.getFontSize(
constraints: Constraints,
text: AnnotatedString,
): TextUnit
Calculates font size and provides access to TextAutoSizeLayoutScope
, which offers
TextAutoSizeLayoutScope.performLayout
to lay out the text and use the measured size.
Returns
The derived optimal font size |
override fun equals(other: Any?): Boolean
This type is used in performance-sensitive paths and requires providing equality guarantees.
Using a data class is sufficient. Singletons may implement this function with referential
equality (this === other
). Instances with no properties may implement this function by
checking the type of the other object.
Returns
true if both AutoSize instances are identical. |
override fun hashCode(): Int
This type is used in performance-sensitive paths and requires providing identity guarantees.
Returns
a unique hashcode for this AutoSize instance. |
Code Examples
TextAutoSizeBasicTextSample
/** Sample of using [TextAutoSize.StepBased] to auto-size text. */
@Composable
fun TextAutoSizeBasicTextSample() {
Box(modifier = Modifier.size(200.dp)) {
// The text will find the biggest available font size that fits in the box.
BasicText(text = "Hello World", autoSize = TextAutoSize.StepBased())
}
}