public interface TextAutoSize
Interface used by Text composables to override text size to automatically grow or shrink text to fill the layout bounds.
Functions
getFontSize
public 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.
Return
The derived optimal font size
equals
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.
Return
true if both AutoSize instances are identical.
hashCode
override fun hashCode(): Int
This type is used in performance-sensitive paths and requires providing identity guarantees.
Return
a unique hashcode for this AutoSize instance.
Members
Companion
public companion object
Functions
StepBased
public fun StepBased(
minFontSize: TextUnit = TextAutoSizeDefaults.MinFontSize,
maxFontSize: TextUnit = TextAutoSizeDefaults.MaxFontSize,
stepSize: TextUnit = 0.25.sp,
): TextAutoSize
Automatically size the text with the biggest font size that fits the available space.
When text auto size is performed with TextOverflow.Ellipsis, TextOverflow.StartEllipsis or TextOverflow.MiddleEllipsis (e.g. by specifying textOverflow on BasicText), this implementation will consider the text to be fitting the available space if it is not ellipsized.
Parameters
| minFontSize | The smallest potential font size of the text. Default = 12.sp. This must be smaller than maxFontSize; an IllegalArgumentException will be thrown otherwise. |
| maxFontSize | The largest potential font size of the text. Default = 112.sp. This must be larger than minFontSize; an IllegalArgumentException will be thrown otherwise. |
| stepSize | The smallest difference between potential font sizes. Specifically, every font size, when subtracted by minFontSize, is divisible by stepSize. Default = 0.25.sp. This must not be less than 0.0001f.sp; an IllegalArgumentException will be thrown otherwise. If stepSize is greater than the difference between minFontSize and maxFontSize, minFontSize will be used for the layout. |
Return
AutoSize instance with the step-based configuration. Using this in a compatible composable will cause its text to be sized as above.