public sealed interface TextStyleScope
Configures layout- and draw-affecting text attributes for BasicText.
Use this scope in the styleProvider lambda parameter of BasicText. State reads performed within this scope are observed during the layout phase, skipping recomposition when invalidated and re-evaluating during measurement (recalculating text layout only when layout-affecting attributes change).
Functions
setTextStyle
public fun setTextStyle(style: TextStyle)
Sets all text attributes from style.
Overwrites all attributes in this scope with the values from style, resetting attributes that are unspecified or null in style. Call individual setter methods after setTextStyle to override specific attributes.
Parameters
| style | text style to copy attributes from |
setColor
public fun setColor(color: Color)
Sets the color to apply to the text.
If color is specified (color.isSpecified), this clears any brush and alpha previously set via setBrush, setAlpha, or setTextStyle. If color is Color.Unspecified, any existing brush and alpha are preserved.
setBrush
public fun setBrush(brush: Brush)
Sets the Brush for painting the text, clearing any color previously set via setColor or setTextStyle (resetting it to Color.Unspecified).
setAlpha
public fun setAlpha(alpha: Float)
Sets the opacity of the text (0.0 to 1.0) applied when a brush is configured (via setBrush or setTextStyle). Cleared when a specified color is set via setColor or when setTextStyle sets a style without a brush.
setFontSize
public fun setFontSize(fontSize: TextUnit)
Sets the size of glyphs to use when painting the text (e.g., 16.sp).
setFontWeight
public fun setFontWeight(fontWeight: FontWeight)
Sets the typeface thickness to use when painting the text (e.g., FontWeight.Bold).
setFontStyle
public fun setFontStyle(fontStyle: FontStyle)
Sets the typeface variant to use when drawing letters (e.g., FontStyle.Italic).
setFontSynthesis
public fun setFontSynthesis(fontSynthesis: FontSynthesis)
Sets the font synthesis rules determining if and how bold/italic styles are synthesized when the font family does not natively support them.
setFontFamily
public fun setFontFamily(fontFamily: FontFamily)
Sets the font family used when rendering text.
setFontFeatureSettings
public fun setFontFeatureSettings(fontFeatureSettings: String)
Sets advanced typography settings in CSS format (e.g., "smcp" for small caps).
setLetterSpacing
public fun setLetterSpacing(letterSpacing: TextUnit)
Sets the amount of space to add between letters (in SP or EM).
setBaselineShift
public fun setBaselineShift(baselineShift: BaselineShift)
Sets the vertical shift amount from the baseline (e.g., BaselineShift.Superscript). If BaselineShift.Unspecified, inherits from parent or default style.
setTextGeometricTransform
public fun setTextGeometricTransform(textGeometricTransform: TextGeometricTransform)
Sets the geometric transformation to apply to the text.
setLocaleList
public fun setLocaleList(localeList: LocaleList)
Sets the locale list used to select region-specific glyphs.
setBackground
public fun setBackground(background: Color)
Sets the background color covering the entire line height from start to end.
setTextDecoration
public fun setTextDecoration(textDecoration: TextDecoration)
Sets the decorations to paint on the text (e.g., TextDecoration.Underline).
setShadow
public fun setShadow(shadow: Shadow)
Sets the shadow effect applied to the text.
setDrawStyle
public fun setDrawStyle(drawStyle: DrawStyle)
Sets the drawing style of the text (fill or stroke).
setTextAlign
public fun setTextAlign(textAlign: TextAlign)
Sets the alignment of the text within lines of the paragraph.
setTextDirection
public fun setTextDirection(textDirection: TextDirection)
Sets the algorithm used to resolve text direction.
setLineHeight
public fun setLineHeight(lineHeight: TextUnit)
Sets the line height for the paragraph (e.g., 24.sp).
setTextIndent
public fun setTextIndent(textIndent: TextIndent)
Sets the paragraph indentation.
setPlatformStyle
public fun setPlatformStyle(platformStyle: PlatformTextStyle)
Sets platform-specific text styling parameters.
setLineHeightStyle
public fun setLineHeightStyle(lineHeightStyle: LineHeightStyle)
Sets the line height distribution configuration.
setLineBreak
public fun setLineBreak(lineBreak: LineBreak)
Sets the line breaking configuration of the paragraph.
setHyphens
public fun setHyphens(hyphens: Hyphens)
Sets the hyphenation configuration of the paragraph.
setTextMotion
public fun setTextMotion(textMotion: TextMotion)
Sets the text character placement optimization for animated or static text.