TextStyleScope

Known direct subclasses
ReusableTextStyleScope

Mutable TextStyleScope implementation reused across layout and draw passes to avoid allocations.


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).

Summary

Public functions

Unit
setAlpha(alpha: Float)

Sets the opacity of the text (0.0 to 1.0) applied when a brush is configured (via setBrush or setTextStyle).

Cmn
Unit
setBackground(background: Color)

Sets the background color covering the entire line height from start to end.

Cmn
Unit

Sets the vertical shift amount from the baseline (e.g., BaselineShift.Superscript).

Cmn
Unit
setBrush(brush: Brush)

Sets the Brush for painting the text, clearing any color previously set via setColor or setTextStyle (resetting it to Color.Unspecified).

Cmn
Unit
setColor(color: Color)

Sets the color to apply to the text.

Cmn
Unit
setDrawStyle(drawStyle: DrawStyle)

Sets the drawing style of the text (fill or stroke).

Cmn
Unit

Sets the font family used when rendering text.

Cmn
Unit
setFontFeatureSettings(fontFeatureSettings: String)

Sets advanced typography settings in CSS format (e.g., "smcp" for small caps).

Cmn
Unit
setFontSize(fontSize: TextUnit)

Sets the size of glyphs to use when painting the text (e.g., 16.sp).

Cmn
Unit
setFontStyle(fontStyle: FontStyle)

Sets the typeface variant to use when drawing letters (e.g., FontStyle.Italic).

Cmn
Unit

Sets the font synthesis rules determining if and how bold/italic styles are synthesized when the font family does not natively support them.

Cmn
Unit

Sets the typeface thickness to use when painting the text (e.g., FontWeight.Bold).

Cmn
Unit
setHyphens(hyphens: Hyphens)

Sets the hyphenation configuration of the paragraph.

Cmn
Unit
setLetterSpacing(letterSpacing: TextUnit)

Sets the amount of space to add between letters (in SP or EM).

Cmn
Unit
setLineBreak(lineBreak: LineBreak)

Sets the line breaking configuration of the paragraph.

Cmn
Unit
setLineHeight(lineHeight: TextUnit)

Sets the line height for the paragraph (e.g., 24.sp).

Cmn
Unit

Sets the line height distribution configuration.

Cmn
Unit

Sets the locale list used to select region-specific glyphs.

Cmn
Unit

Sets platform-specific text styling parameters.

Cmn
Unit
setShadow(shadow: Shadow)

Sets the shadow effect applied to the text.

Cmn
Unit
setTextAlign(textAlign: TextAlign)

Sets the alignment of the text within lines of the paragraph.

Cmn
Unit

Sets the decorations to paint on the text (e.g., TextDecoration.Underline).

Cmn
Unit

Sets the algorithm used to resolve text direction.

Cmn
Unit
setTextGeometricTransform(
    textGeometricTransform: TextGeometricTransform
)

Sets the geometric transformation to apply to the text.

Cmn
Unit

Sets the paragraph indentation.

Cmn
Unit

Sets the text character placement optimization for animated or static text.

Cmn
Unit

Sets all text attributes from style.

Cmn

Public functions

setAlpha

fun setAlpha(alpha: Float): Unit

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.

setBackground

fun setBackground(background: Color): Unit

Sets the background color covering the entire line height from start to end.

setBaselineShift

fun setBaselineShift(baselineShift: BaselineShift): Unit

Sets the vertical shift amount from the baseline (e.g., BaselineShift.Superscript). If BaselineShift.Unspecified, inherits from parent or default style.

setBrush

fun setBrush(brush: Brush): Unit

Sets the Brush for painting the text, clearing any color previously set via setColor or setTextStyle (resetting it to Color.Unspecified).

setColor

fun setColor(color: Color): Unit

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.

setDrawStyle

fun setDrawStyle(drawStyle: DrawStyle): Unit

Sets the drawing style of the text (fill or stroke).

setFontFamily

fun setFontFamily(fontFamily: FontFamily): Unit

Sets the font family used when rendering text.

setFontFeatureSettings

fun setFontFeatureSettings(fontFeatureSettings: String): Unit

Sets advanced typography settings in CSS format (e.g., "smcp" for small caps).

setFontSize

fun setFontSize(fontSize: TextUnit): Unit

Sets the size of glyphs to use when painting the text (e.g., 16.sp).

setFontStyle

fun setFontStyle(fontStyle: FontStyle): Unit

Sets the typeface variant to use when drawing letters (e.g., FontStyle.Italic).

setFontSynthesis

fun setFontSynthesis(fontSynthesis: FontSynthesis): Unit

Sets the font synthesis rules determining if and how bold/italic styles are synthesized when the font family does not natively support them.

setFontWeight

fun setFontWeight(fontWeight: FontWeight): Unit

Sets the typeface thickness to use when painting the text (e.g., FontWeight.Bold).

setHyphens

fun setHyphens(hyphens: Hyphens): Unit

Sets the hyphenation configuration of the paragraph.

setLetterSpacing

fun setLetterSpacing(letterSpacing: TextUnit): Unit

Sets the amount of space to add between letters (in SP or EM).

setLineBreak

fun setLineBreak(lineBreak: LineBreak): Unit

Sets the line breaking configuration of the paragraph.

setLineHeight

fun setLineHeight(lineHeight: TextUnit): Unit

Sets the line height for the paragraph (e.g., 24.sp).

setLineHeightStyle

fun setLineHeightStyle(lineHeightStyle: LineHeightStyle): Unit

Sets the line height distribution configuration.

setLocaleList

fun setLocaleList(localeList: LocaleList): Unit

Sets the locale list used to select region-specific glyphs.

setPlatformStyle

fun setPlatformStyle(platformStyle: PlatformTextStyle): Unit

Sets platform-specific text styling parameters.

setShadow

fun setShadow(shadow: Shadow): Unit

Sets the shadow effect applied to the text.

setTextAlign

fun setTextAlign(textAlign: TextAlign): Unit

Sets the alignment of the text within lines of the paragraph.

setTextDecoration

fun setTextDecoration(textDecoration: TextDecoration): Unit

Sets the decorations to paint on the text (e.g., TextDecoration.Underline).

setTextDirection

fun setTextDirection(textDirection: TextDirection): Unit

Sets the algorithm used to resolve text direction.

setTextGeometricTransform

fun setTextGeometricTransform(
    textGeometricTransform: TextGeometricTransform
): Unit

Sets the geometric transformation to apply to the text.

setTextIndent

fun setTextIndent(textIndent: TextIndent): Unit

Sets the paragraph indentation.

setTextMotion

fun setTextMotion(textMotion: TextMotion): Unit

Sets the text character placement optimization for animated or static text.

setTextStyle

fun setTextStyle(style: TextStyle): Unit

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: TextStyle

text style to copy attributes from