TextStyle
class TextStyle
internal constructor(
internal val spanStyle: SpanStyle,
internal val paragraphStyle: ParagraphStyle,
val platformStyle: PlatformTextStyle? = null,
)
Styling configuration for a Text
.
Parameters
platformStyle | Platform specific TextStyle parameters. |
Secondary Constructors
internal constructor(
spanStyle: SpanStyle,
paragraphStyle: ParagraphStyle,
) : this(
spanStyle = spanStyle,
paragraphStyle = paragraphStyle,
platformStyle =
createPlatformTextStyleInternal(spanStyle.platformStyle, paragraphStyle.platformStyle),
)
constructor(
color: Color = Color.Unspecified,
fontSize: TextUnit = TextUnit.Unspecified,
fontWeight: FontWeight? = null,
fontStyle: FontStyle? = null,
fontSynthesis: FontSynthesis? = null,
fontFamily: FontFamily? = null,
fontFeatureSettings: String? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
baselineShift: BaselineShift? = null,
textGeometricTransform: TextGeometricTransform? = null,
localeList: LocaleList? = null,
background: Color = Color.Unspecified,
textDecoration: TextDecoration? = null,
shadow: Shadow? = null,
textAlign: TextAlign? = null,
textDirection: TextDirection? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
textIndent: TextIndent? = null,
) : this(
SpanStyle(
color = color,
fontSize = fontSize,
fontWeight = fontWeight,
fontStyle = fontStyle,
fontSynthesis = fontSynthesis,
fontFamily = fontFamily,
fontFeatureSettings = fontFeatureSettings,
letterSpacing = letterSpacing,
baselineShift = baselineShift,
textGeometricTransform = textGeometricTransform,
localeList = localeList,
background = background,
textDecoration = textDecoration,
shadow = shadow,
platformStyle = null,
drawStyle = null,
),
ParagraphStyle(
textAlign = textAlign ?: TextAlign.Unspecified,
textDirection = textDirection ?: TextDirection.Unspecified,
lineHeight = lineHeight,
textIndent = textIndent,
platformStyle = null,
lineHeightStyle = null,
lineBreak = LineBreak.Unspecified,
hyphens = Hyphens.Unspecified,
textMotion = null,
),
platformStyle = null,
)
constructor(
color: Color = Color.Unspecified,
fontSize: TextUnit = TextUnit.Unspecified,
fontWeight: FontWeight? = null,
fontStyle: FontStyle? = null,
fontSynthesis: FontSynthesis? = null,
fontFamily: FontFamily? = null,
fontFeatureSettings: String? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
baselineShift: BaselineShift? = null,
textGeometricTransform: TextGeometricTransform? = null,
localeList: LocaleList? = null,
background: Color = Color.Unspecified,
textDecoration: TextDecoration? = null,
shadow: Shadow? = null,
textAlign: TextAlign? = null,
textDirection: TextDirection? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
textIndent: TextIndent? = null,
platformStyle: PlatformTextStyle? = null,
lineHeightStyle: LineHeightStyle? = null,
) : this(
SpanStyle(
color = color,
fontSize = fontSize,
fontWeight = fontWeight,
fontStyle = fontStyle,
fontSynthesis = fontSynthesis,
fontFamily = fontFamily,
fontFeatureSettings = fontFeatureSettings,
letterSpacing = letterSpacing,
baselineShift = baselineShift,
textGeometricTransform = textGeometricTransform,
localeList = localeList,
background = background,
textDecoration = textDecoration,
shadow = shadow,
platformStyle = platformStyle?.spanStyle,
drawStyle = null,
),
ParagraphStyle(
textAlign = textAlign ?: TextAlign.Unspecified,
textDirection = textDirection ?: TextDirection.Unspecified,
lineHeight = lineHeight,
textIndent = textIndent,
platformStyle = platformStyle?.paragraphStyle,
lineHeightStyle = lineHeightStyle,
lineBreak = LineBreak.Unspecified,
hyphens = Hyphens.Unspecified,
textMotion = null,
),
platformStyle = platformStyle,
)
constructor(
color: Color = Color.Unspecified,
fontSize: TextUnit = TextUnit.Unspecified,
fontWeight: FontWeight? = null,
fontStyle: FontStyle? = null,
fontSynthesis: FontSynthesis? = null,
fontFamily: FontFamily? = null,
fontFeatureSettings: String? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
baselineShift: BaselineShift? = null,
textGeometricTransform: TextGeometricTransform? = null,
localeList: LocaleList? = null,
background: Color = Color.Unspecified,
textDecoration: TextDecoration? = null,
shadow: Shadow? = null,
textAlign: TextAlign? = null,
textDirection: TextDirection? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
textIndent: TextIndent? = null,
platformStyle: PlatformTextStyle? = null,
lineHeightStyle: LineHeightStyle? = null,
lineBreak: LineBreak? = null,
hyphens: Hyphens? = null,
) : this(
SpanStyle(
color = color,
fontSize = fontSize,
fontWeight = fontWeight,
fontStyle = fontStyle,
fontSynthesis = fontSynthesis,
fontFamily = fontFamily,
fontFeatureSettings = fontFeatureSettings,
letterSpacing = letterSpacing,
baselineShift = baselineShift,
textGeometricTransform = textGeometricTransform,
localeList = localeList,
background = background,
textDecoration = textDecoration,
shadow = shadow,
platformStyle = platformStyle?.spanStyle,
),
ParagraphStyle(
textAlign = textAlign ?: TextAlign.Unspecified,
textDirection = textDirection ?: TextDirection.Unspecified,
lineHeight = lineHeight,
textIndent = textIndent,
platformStyle = platformStyle?.paragraphStyle,
lineHeightStyle = lineHeightStyle,
lineBreak = lineBreak ?: LineBreak.Unspecified,
hyphens = hyphens ?: Hyphens.Unspecified,
),
platformStyle = platformStyle,
)
Styling configuration for a Text
.
Parameters
color | The text color. |
fontSize | The size of glyphs to use when painting the text. This may be TextUnit.Unspecified for inheriting from another TextStyle . |
fontWeight | The typeface thickness to use when painting the text (e.g., bold). |
fontStyle | The typeface variant to use when drawing the letters (e.g., italic). |
fontSynthesis | Whether to synthesize font weight and/or style when the requested weight or style cannot be found in the provided font family. |
fontFamily | The font family to be used when rendering the text. |
fontFeatureSettings | The advanced typography settings provided by font. The format is the same as the CSS font-feature-settings attribute: https://www.w3.org/TR/css-fonts-3/#font-feature-settings-prop |
letterSpacing | The amount of space to add between each letter. |
baselineShift | The amount by which the text is shifted up from the current baseline. |
textGeometricTransform | The geometric transformation applied the text. |
localeList | The locale list used to select region-specific glyphs. |
background | The background color for the text. |
textDecoration | The decorations to paint on the text (e.g., an underline). |
shadow | The shadow effect applied on the text. |
textAlign | The alignment of the text within the lines of the paragraph. |
textDirection | The algorithm to be used to resolve the final text and paragraph direction: Left To Right or Right To Left. If no value is provided the system will use the LayoutDirection as the primary signal. |
lineHeight | Line height for the Paragraph in TextUnit unit, e.g. SP or EM. |
textIndent | The indentation of the paragraph. |
platformStyle | Platform specific TextStyle parameters. |
lineHeightStyle | the configuration for line height such as vertical alignment of the line, whether to apply additional space as a result of line height to top of first line top and bottom of last line. The configuration is applied only when a lineHeight is defined. When null, LineHeightStyle.Default is used. |
lineBreak | The line breaking configuration for the text. |
hyphens | The configuration of hyphenation. |
constructor(
color: Color = Color.Unspecified,
fontSize: TextUnit = TextUnit.Unspecified,
fontWeight: FontWeight? = null,
fontStyle: FontStyle? = null,
fontSynthesis: FontSynthesis? = null,
fontFamily: FontFamily? = null,
fontFeatureSettings: String? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
baselineShift: BaselineShift? = null,
textGeometricTransform: TextGeometricTransform? = null,
localeList: LocaleList? = null,
background: Color = Color.Unspecified,
textDecoration: TextDecoration? = null,
shadow: Shadow? = null,
drawStyle: DrawStyle? = null,
textAlign: TextAlign? = null,
textDirection: TextDirection? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
textIndent: TextIndent? = null,
platformStyle: PlatformTextStyle? = null,
lineHeightStyle: LineHeightStyle? = null,
lineBreak: LineBreak? = null,
hyphens: Hyphens? = null,
textMotion: TextMotion? = null,
) : this(
SpanStyle(
color = color,
fontSize = fontSize,
fontWeight = fontWeight,
fontStyle = fontStyle,
fontSynthesis = fontSynthesis,
fontFamily = fontFamily,
fontFeatureSettings = fontFeatureSettings,
letterSpacing = letterSpacing,
baselineShift = baselineShift,
textGeometricTransform = textGeometricTransform,
localeList = localeList,
background = background,
textDecoration = textDecoration,
shadow = shadow,
platformStyle = platformStyle?.spanStyle,
drawStyle = drawStyle,
),
ParagraphStyle(
textAlign = textAlign ?: TextAlign.Unspecified,
textDirection = textDirection ?: TextDirection.Unspecified,
lineHeight = lineHeight,
textIndent = textIndent,
platformStyle = platformStyle?.paragraphStyle,
lineHeightStyle = lineHeightStyle,
lineBreak = lineBreak ?: LineBreak.Unspecified,
hyphens = hyphens ?: Hyphens.Unspecified,
textMotion = textMotion,
),
platformStyle = platformStyle,
)
constructor(
color: Color = Color.Unspecified,
fontSize: TextUnit = TextUnit.Unspecified,
fontWeight: FontWeight? = null,
fontStyle: FontStyle? = null,
fontSynthesis: FontSynthesis? = null,
fontFamily: FontFamily? = null,
fontFeatureSettings: String? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
baselineShift: BaselineShift? = null,
textGeometricTransform: TextGeometricTransform? = null,
localeList: LocaleList? = null,
background: Color = Color.Unspecified,
textDecoration: TextDecoration? = null,
shadow: Shadow? = null,
drawStyle: DrawStyle? = null,
textAlign: TextAlign = TextAlign.Unspecified,
textDirection: TextDirection = TextDirection.Unspecified,
lineHeight: TextUnit = TextUnit.Unspecified,
textIndent: TextIndent? = null,
platformStyle: PlatformTextStyle? = null,
lineHeightStyle: LineHeightStyle? = null,
lineBreak: LineBreak = LineBreak.Unspecified,
hyphens: Hyphens = Hyphens.Unspecified,
textMotion: TextMotion? = null,
) : this(
SpanStyle(
color = color,
fontSize = fontSize,
fontWeight = fontWeight,
fontStyle = fontStyle,
fontSynthesis = fontSynthesis,
fontFamily = fontFamily,
fontFeatureSettings = fontFeatureSettings,
letterSpacing = letterSpacing,
baselineShift = baselineShift,
textGeometricTransform = textGeometricTransform,
localeList = localeList,
background = background,
textDecoration = textDecoration,
shadow = shadow,
platformStyle = platformStyle?.spanStyle,
drawStyle = drawStyle,
),
ParagraphStyle(
textAlign = textAlign,
textDirection = textDirection,
lineHeight = lineHeight,
textIndent = textIndent,
platformStyle = platformStyle?.paragraphStyle,
lineHeightStyle = lineHeightStyle,
lineBreak = lineBreak,
hyphens = hyphens,
textMotion = textMotion,
),
platformStyle = platformStyle,
)
Styling configuration for a Text
.
Parameters
color | The text color. |
fontSize | The size of glyphs to use when painting the text. This may be TextUnit.Unspecified for inheriting from another TextStyle . |
fontWeight | The typeface thickness to use when painting the text (e.g., bold). |
fontStyle | The typeface variant to use when drawing the letters (e.g., italic). |
fontSynthesis | Whether to synthesize font weight and/or style when the requested weight or style cannot be found in the provided font family. |
fontFamily | The font family to be used when rendering the text. |
fontFeatureSettings | The advanced typography settings provided by font. The format is the same as the CSS font-feature-settings attribute: https://www.w3.org/TR/css-fonts-3/#font-feature-settings-prop |
letterSpacing | The amount of space to add between each letter. |
baselineShift | The amount by which the text is shifted up from the current baseline. |
textGeometricTransform | The geometric transformation applied the text. |
localeList | The locale list used to select region-specific glyphs. |
background | The background color for the text. |
textDecoration | The decorations to paint on the text (e.g., an underline). |
shadow | The shadow effect applied on the text. |
drawStyle | Drawing style of text, whether fill in the text while drawing or stroke around the edges. |
textAlign | The alignment of the text within the lines of the paragraph. |
textDirection | The algorithm to be used to resolve the final text and paragraph direction: Left To Right or Right To Left. If no value is provided the system will use the LayoutDirection as the primary signal. |
lineHeight | Line height for the Paragraph in TextUnit unit, e.g. SP or EM. |
textIndent | The indentation of the paragraph. |
platformStyle | Platform specific TextStyle parameters. |
lineHeightStyle | the configuration for line height such as vertical alignment of the line, whether to apply additional space as a result of line height to top of first line top and bottom of last line. The configuration is applied only when a lineHeight is defined. When null, LineHeightStyle.Default is used. |
lineBreak | The line breaking configuration for the text. |
hyphens | The configuration of hyphenation. |
textMotion | Text character placement, whether to optimize for animated or static text. |
constructor(
brush: Brush?,
alpha: Float = Float.NaN,
fontSize: TextUnit = TextUnit.Unspecified,
fontWeight: FontWeight? = null,
fontStyle: FontStyle? = null,
fontSynthesis: FontSynthesis? = null,
fontFamily: FontFamily? = null,
fontFeatureSettings: String? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
baselineShift: BaselineShift? = null,
textGeometricTransform: TextGeometricTransform? = null,
localeList: LocaleList? = null,
background: Color = Color.Unspecified,
textDecoration: TextDecoration? = null,
shadow: Shadow? = null,
drawStyle: DrawStyle? = null,
textAlign: TextAlign = TextAlign.Unspecified,
textDirection: TextDirection = TextDirection.Unspecified,
lineHeight: TextUnit = TextUnit.Unspecified,
textIndent: TextIndent? = null,
platformStyle: PlatformTextStyle? = null,
lineHeightStyle: LineHeightStyle? = null,
lineBreak: LineBreak = LineBreak.Unspecified,
hyphens: Hyphens = Hyphens.Unspecified,
textMotion: TextMotion? = null,
) : this(
SpanStyle(
brush = brush,
alpha = alpha,
fontSize = fontSize,
fontWeight = fontWeight,
fontStyle = fontStyle,
fontSynthesis = fontSynthesis,
fontFamily = fontFamily,
fontFeatureSettings = fontFeatureSettings,
letterSpacing = letterSpacing,
baselineShift = baselineShift,
textGeometricTransform = textGeometricTransform,
localeList = localeList,
background = background,
textDecoration = textDecoration,
shadow = shadow,
platformStyle = platformStyle?.spanStyle,
drawStyle = drawStyle,
),
ParagraphStyle(
textAlign = textAlign,
textDirection = textDirection,
lineHeight = lineHeight,
textIndent = textIndent,
platformStyle = platformStyle?.paragraphStyle,
lineHeightStyle = lineHeightStyle,
lineBreak = lineBreak,
hyphens = hyphens,
textMotion = textMotion,
),
platformStyle = platformStyle,
)
Styling configuration for a Text
.
Parameters
brush | The brush to use when painting the text. If brush is given as null, it will be treated as unspecified. It is equivalent to calling the alternative color constructor with Color.Unspecified |
alpha | Opacity to be applied to brush from 0.0f to 1.0f representing fully transparent to fully opaque respectively. |
fontSize | The size of glyphs to use when painting the text. This may be TextUnit.Unspecified for inheriting from another TextStyle . |
fontWeight | The typeface thickness to use when painting the text (e.g., bold). |
fontStyle | The typeface variant to use when drawing the letters (e.g., italic). |
fontSynthesis | Whether to synthesize font weight and/or style when the requested weight or style cannot be found in the provided font family. |
fontFamily | The font family to be used when rendering the text. |
fontFeatureSettings | The advanced typography settings provided by font. The format is the same as the CSS font-feature-settings attribute: https://www.w3.org/TR/css-fonts-3/#font-feature-settings-prop |
letterSpacing | The amount of space to add between each letter. |
baselineShift | The amount by which the text is shifted up from the current baseline. |
textGeometricTransform | The geometric transformation applied the text. |
localeList | The locale list used to select region-specific glyphs. |
background | The background color for the text. |
textDecoration | The decorations to paint on the text (e.g., an underline). |
shadow | The shadow effect applied on the text. |
drawStyle | Drawing style of text, whether fill in the text while drawing or stroke around the edges. |
textAlign | The alignment of the text within the lines of the paragraph. |
textDirection | The algorithm to be used to resolve the final text and paragraph direction: Left To Right or Right To Left. If no value is provided the system will use the LayoutDirection as the primary signal. |
lineHeight | Line height for the Paragraph in TextUnit unit, e.g. SP or EM. |
textIndent | The indentation of the paragraph. |
platformStyle | Platform specific TextStyle parameters. |
lineHeightStyle | the configuration for line height such as vertical alignment of the line, whether to apply additional space as a result of line height to top of first line top and bottom of last line. The configuration is applied only when a lineHeight is defined. |
lineBreak | The line breaking configuration for the text. |
hyphens | The configuration of hyphenation. |
textMotion | Text character placement, whether to optimize for animated or static text. |
constructor(
brush: Brush?,
alpha: Float = Float.NaN,
fontSize: TextUnit = TextUnit.Unspecified,
fontWeight: FontWeight? = null,
fontStyle: FontStyle? = null,
fontSynthesis: FontSynthesis? = null,
fontFamily: FontFamily? = null,
fontFeatureSettings: String? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
baselineShift: BaselineShift? = null,
textGeometricTransform: TextGeometricTransform? = null,
localeList: LocaleList? = null,
background: Color = Color.Unspecified,
textDecoration: TextDecoration? = null,
shadow: Shadow? = null,
drawStyle: DrawStyle? = null,
textAlign: TextAlign? = null,
textDirection: TextDirection? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
textIndent: TextIndent? = null,
platformStyle: PlatformTextStyle? = null,
lineHeightStyle: LineHeightStyle? = null,
lineBreak: LineBreak? = null,
hyphens: Hyphens? = null,
textMotion: TextMotion? = null,
) : this(
SpanStyle(
brush = brush,
alpha = alpha,
fontSize = fontSize,
fontWeight = fontWeight,
fontStyle = fontStyle,
fontSynthesis = fontSynthesis,
fontFamily = fontFamily,
fontFeatureSettings = fontFeatureSettings,
letterSpacing = letterSpacing,
baselineShift = baselineShift,
textGeometricTransform = textGeometricTransform,
localeList = localeList,
background = background,
textDecoration = textDecoration,
shadow = shadow,
platformStyle = platformStyle?.spanStyle,
drawStyle = drawStyle,
),
ParagraphStyle(
textAlign = textAlign ?: TextAlign.Unspecified,
textDirection = textDirection ?: TextDirection.Unspecified,
lineHeight = lineHeight,
textIndent = textIndent,
platformStyle = platformStyle?.paragraphStyle,
lineHeightStyle = lineHeightStyle,
lineBreak = lineBreak ?: LineBreak.Unspecified,
hyphens = hyphens ?: Hyphens.Unspecified,
textMotion = textMotion,
),
platformStyle = platformStyle,
)
Properties
val brush: Brush?
The brush to use when drawing text. If not null, overrides color
.
val color: Color
The text color.
val alpha: Float
Opacity of text. This value is either provided along side Brush, or via alpha channel in color.
val fontSize: TextUnit
The size of glyphs to use when painting the text. This may be TextUnit.Unspecified
for
inheriting from another TextStyle
.
val fontWeight: FontWeight?
The typeface thickness to use when painting the text (e.g., bold).
val fontStyle: FontStyle?
The typeface variant to use when drawing the letters (e.g., italic).
val fontSynthesis: FontSynthesis?
Whether to synthesize font weight and/or style when the requested weight or style cannot be found in the provided font family.
val fontFamily: FontFamily?
The font family to be used when rendering the text.
val fontFeatureSettings: String?
The advanced typography settings provided by font. The format is the same as the CSS font-feature-settings attribute: https://www.w3.org/TR/css-fonts-3/#font-feature-settings-prop
val letterSpacing: TextUnit
The amount of space to add between each letter.
val baselineShift: BaselineShift?
The amount by which the text is shifted up from the current baseline.
val textGeometricTransform: TextGeometricTransform?
The geometric transformation applied the text.
val localeList: LocaleList?
The locale list used to select region-specific glyphs.
val background: Color
The background color for the text.
val textDecoration: TextDecoration?
The decorations to paint on the text (e.g., an underline).
val shadow: Shadow?
The shadow effect applied on the text.
val drawStyle: DrawStyle?
Drawing style of text, whether fill in the text while drawing or stroke around the edges.
val textAlign: TextAlign
The alignment of the text within the lines of the paragraph.
Deprecated Kept for backwards compatibility.
val deprecated_boxing_textAlign: TextAlign?
val textDirection: TextDirection
The algorithm to be used to resolve the final text and paragraph direction: Left To Right or
Right To Left. If no value is provided the system will use the LayoutDirection
as the
primary signal.
Deprecated Kept for backwards compatibility.
val deprecated_boxing_textDirection: TextDirection?
val lineHeight: TextUnit
Line height for the Paragraph
in TextUnit
unit, e.g. SP or EM.
val textIndent: TextIndent?
The indentation of the paragraph.
val lineHeightStyle: LineHeightStyle?
The configuration for line height such as vertical alignment of the line, whether to apply additional space as a result of line height to top of first line top and bottom of last line.
The configuration is applied only when a lineHeight
is defined.
When null, LineHeightStyle.Default
is used.
val hyphens: Hyphens
The hyphens configuration of the paragraph.
Deprecated Kept for backwards compatibility.
val deprecated_boxing_hyphens: Hyphens?
val lineBreak: LineBreak
The line breaking configuration of the paragraph.
Deprecated Kept for backwards compatibility.
val deprecated_boxing_lineBreak: LineBreak?
val textMotion: TextMotion?
Text character placement configuration, whether to optimize for animated or static text.
Functions
fun toSpanStyle(): SpanStyle
fun toParagraphStyle(): ParagraphStyle
fun merge(other: TextStyle? = null): TextStyle
Returns a new text style that is a combination of this style and the given other
style.
other
text style's null or inherit properties are replaced with the non-null properties of
this text style. Another way to think of it is that the "missing" properties of the other
style are filled by the properties of this style.
If the given text style is null, returns this text style.
fun merge(
color: Color = Color.Unspecified,
fontSize: TextUnit = TextUnit.Unspecified,
fontWeight: FontWeight? = null,
fontStyle: FontStyle? = null,
fontSynthesis: FontSynthesis? = null,
fontFamily: FontFamily? = null,
fontFeatureSettings: String? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
baselineShift: BaselineShift? = null,
textGeometricTransform: TextGeometricTransform? = null,
localeList: LocaleList? = null,
background: Color = Color.Unspecified,
textDecoration: TextDecoration? = null,
shadow: Shadow? = null,
drawStyle: DrawStyle? = null,
textAlign: TextAlign = TextAlign.Unspecified,
textDirection: TextDirection = TextDirection.Unspecified,
lineHeight: TextUnit = TextUnit.Unspecified,
textIndent: TextIndent? = null,
lineHeightStyle: LineHeightStyle? = null,
lineBreak: LineBreak = LineBreak.Unspecified,
hyphens: Hyphens = Hyphens.Unspecified,
platformStyle: PlatformTextStyle? = null,
textMotion: TextMotion? = null,
): TextStyle
Fast merge non-default values and parameters.
This is the same algorithm as merge
but does not require allocating it's parameter and may
return this instead of allocating a result when all values are default.
This is a similar algorithm to copy
but when either this or a parameter are set to a
default value, the other value will take precedent.
To explain better, consider the following examples:
Example 1:
- this.color =
Color.Unspecified
color
=Color.Red
- result =>
Color.Red
Example 2:
- this.color =
Color.Red
color
=Color.Unspecified
- result =>
Color.Red
Example 3:
- this.color =
Color.Red
color
=Color.Blue
- result =>
Color.Blue
You should always use this method over the merge
(TextStyle
) overload when you do not
already have a TextStyle allocated. You should chose this over copy
when building a theming
system and applying styling information to a specific usage.
Returns
this or a new TextLayoutResult with all parameters chosen to the non-default option provided. |
fun merge(
color: Color = Color.Unspecified,
fontSize: TextUnit = TextUnit.Unspecified,
fontWeight: FontWeight? = null,
fontStyle: FontStyle? = null,
fontSynthesis: FontSynthesis? = null,
fontFamily: FontFamily? = null,
fontFeatureSettings: String? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
baselineShift: BaselineShift? = null,
textGeometricTransform: TextGeometricTransform? = null,
localeList: LocaleList? = null,
background: Color = Color.Unspecified,
textDecoration: TextDecoration? = null,
shadow: Shadow? = null,
drawStyle: DrawStyle? = null,
textAlign: TextAlign? = null,
textDirection: TextDirection? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
textIndent: TextIndent? = null,
lineHeightStyle: LineHeightStyle? = null,
lineBreak: LineBreak? = null,
hyphens: Hyphens? = null,
platformStyle: PlatformTextStyle? = null,
textMotion: TextMotion? = null,
): TextStyle
fun merge(other: SpanStyle): TextStyle
Returns a new text style that is a combination of this style and the given other
style.
fun merge(other: ParagraphStyle): TextStyle
Returns a new text style that is a combination of this style and the given other
style.
operator fun plus(other: TextStyle): TextStyle
Plus operator overload that applies a merge
.
operator fun plus(other: ParagraphStyle): TextStyle
Plus operator overload that applies a merge
.
operator fun plus(other: SpanStyle): TextStyle
Plus operator overload that applies a merge
.
fun copy(
color: Color = this.spanStyle.color,
fontSize: TextUnit = this.spanStyle.fontSize,
fontWeight: FontWeight? = this.spanStyle.fontWeight,
fontStyle: FontStyle? = this.spanStyle.fontStyle,
fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
fontFamily: FontFamily? = this.spanStyle.fontFamily,
fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
letterSpacing: TextUnit = this.spanStyle.letterSpacing,
baselineShift: BaselineShift? = this.spanStyle.baselineShift,
textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
localeList: LocaleList? = this.spanStyle.localeList,
background: Color = this.spanStyle.background,
textDecoration: TextDecoration? = this.spanStyle.textDecoration,
shadow: Shadow? = this.spanStyle.shadow,
textAlign: TextAlign? = this.paragraphStyle.textAlign,
textDirection: TextDirection? = this.paragraphStyle.textDirection,
lineHeight: TextUnit = this.paragraphStyle.lineHeight,
textIndent: TextIndent? = this.paragraphStyle.textIndent,
): TextStyle
fun copy(
color: Color = this.spanStyle.color,
fontSize: TextUnit = this.spanStyle.fontSize,
fontWeight: FontWeight? = this.spanStyle.fontWeight,
fontStyle: FontStyle? = this.spanStyle.fontStyle,
fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
fontFamily: FontFamily? = this.spanStyle.fontFamily,
fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
letterSpacing: TextUnit = this.spanStyle.letterSpacing,
baselineShift: BaselineShift? = this.spanStyle.baselineShift,
textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
localeList: LocaleList? = this.spanStyle.localeList,
background: Color = this.spanStyle.background,
textDecoration: TextDecoration? = this.spanStyle.textDecoration,
shadow: Shadow? = this.spanStyle.shadow,
textAlign: TextAlign? = this.paragraphStyle.textAlign,
textDirection: TextDirection? = this.paragraphStyle.textDirection,
lineHeight: TextUnit = this.paragraphStyle.lineHeight,
textIndent: TextIndent? = this.paragraphStyle.textIndent,
platformStyle: PlatformTextStyle? = this.platformStyle,
lineHeightStyle: LineHeightStyle? = this.paragraphStyle.lineHeightStyle,
): TextStyle
fun copy(
color: Color = this.spanStyle.color,
fontSize: TextUnit = this.spanStyle.fontSize,
fontWeight: FontWeight? = this.spanStyle.fontWeight,
fontStyle: FontStyle? = this.spanStyle.fontStyle,
fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
fontFamily: FontFamily? = this.spanStyle.fontFamily,
fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
letterSpacing: TextUnit = this.spanStyle.letterSpacing,
baselineShift: BaselineShift? = this.spanStyle.baselineShift,
textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
localeList: LocaleList? = this.spanStyle.localeList,
background: Color = this.spanStyle.background,
textDecoration: TextDecoration? = this.spanStyle.textDecoration,
shadow: Shadow? = this.spanStyle.shadow,
textAlign: TextAlign? = this.paragraphStyle.textAlign,
textDirection: TextDirection? = this.paragraphStyle.textDirection,
lineHeight: TextUnit = this.paragraphStyle.lineHeight,
textIndent: TextIndent? = this.paragraphStyle.textIndent,
platformStyle: PlatformTextStyle? = this.platformStyle,
lineHeightStyle: LineHeightStyle? = this.paragraphStyle.lineHeightStyle,
lineBreak: LineBreak? = this.paragraphStyle.lineBreak,
hyphens: Hyphens? = this.paragraphStyle.hyphens,
): TextStyle
fun copy(
color: Color = this.spanStyle.color,
fontSize: TextUnit = this.spanStyle.fontSize,
fontWeight: FontWeight? = this.spanStyle.fontWeight,
fontStyle: FontStyle? = this.spanStyle.fontStyle,
fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
fontFamily: FontFamily? = this.spanStyle.fontFamily,
fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
letterSpacing: TextUnit = this.spanStyle.letterSpacing,
baselineShift: BaselineShift? = this.spanStyle.baselineShift,
textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
localeList: LocaleList? = this.spanStyle.localeList,
background: Color = this.spanStyle.background,
textDecoration: TextDecoration? = this.spanStyle.textDecoration,
shadow: Shadow? = this.spanStyle.shadow,
drawStyle: DrawStyle? = this.spanStyle.drawStyle,
textAlign: TextAlign? = this.paragraphStyle.textAlign,
textDirection: TextDirection? = this.paragraphStyle.textDirection,
lineHeight: TextUnit = this.paragraphStyle.lineHeight,
textIndent: TextIndent? = this.paragraphStyle.textIndent,
platformStyle: PlatformTextStyle? = this.platformStyle,
lineHeightStyle: LineHeightStyle? = this.paragraphStyle.lineHeightStyle,
lineBreak: LineBreak? = this.paragraphStyle.lineBreak,
hyphens: Hyphens? = this.paragraphStyle.hyphens,
textMotion: TextMotion? = this.paragraphStyle.textMotion,
): TextStyle
fun copy(
color: Color = this.spanStyle.color,
fontSize: TextUnit = this.spanStyle.fontSize,
fontWeight: FontWeight? = this.spanStyle.fontWeight,
fontStyle: FontStyle? = this.spanStyle.fontStyle,
fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
fontFamily: FontFamily? = this.spanStyle.fontFamily,
fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
letterSpacing: TextUnit = this.spanStyle.letterSpacing,
baselineShift: BaselineShift? = this.spanStyle.baselineShift,
textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
localeList: LocaleList? = this.spanStyle.localeList,
background: Color = this.spanStyle.background,
textDecoration: TextDecoration? = this.spanStyle.textDecoration,
shadow: Shadow? = this.spanStyle.shadow,
drawStyle: DrawStyle? = this.spanStyle.drawStyle,
textAlign: TextAlign = this.paragraphStyle.textAlign,
textDirection: TextDirection = this.paragraphStyle.textDirection,
lineHeight: TextUnit = this.paragraphStyle.lineHeight,
textIndent: TextIndent? = this.paragraphStyle.textIndent,
platformStyle: PlatformTextStyle? = this.platformStyle,
lineHeightStyle: LineHeightStyle? = this.paragraphStyle.lineHeightStyle,
lineBreak: LineBreak = this.paragraphStyle.lineBreak,
hyphens: Hyphens = this.paragraphStyle.hyphens,
textMotion: TextMotion? = this.paragraphStyle.textMotion,
): TextStyle
fun copy(
brush: Brush?,
alpha: Float = this.spanStyle.alpha,
fontSize: TextUnit = this.spanStyle.fontSize,
fontWeight: FontWeight? = this.spanStyle.fontWeight,
fontStyle: FontStyle? = this.spanStyle.fontStyle,
fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
fontFamily: FontFamily? = this.spanStyle.fontFamily,
fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
letterSpacing: TextUnit = this.spanStyle.letterSpacing,
baselineShift: BaselineShift? = this.spanStyle.baselineShift,
textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
localeList: LocaleList? = this.spanStyle.localeList,
background: Color = this.spanStyle.background,
textDecoration: TextDecoration? = this.spanStyle.textDecoration,
shadow: Shadow? = this.spanStyle.shadow,
drawStyle: DrawStyle? = this.spanStyle.drawStyle,
textAlign: TextAlign? = this.paragraphStyle.textAlign,
textDirection: TextDirection? = this.paragraphStyle.textDirection,
lineHeight: TextUnit = this.paragraphStyle.lineHeight,
textIndent: TextIndent? = this.paragraphStyle.textIndent,
platformStyle: PlatformTextStyle? = this.platformStyle,
lineHeightStyle: LineHeightStyle? = this.paragraphStyle.lineHeightStyle,
lineBreak: LineBreak? = this.paragraphStyle.lineBreak,
hyphens: Hyphens? = this.paragraphStyle.hyphens,
textMotion: TextMotion? = this.paragraphStyle.textMotion,
): TextStyle
fun copy(
brush: Brush?,
alpha: Float = this.spanStyle.alpha,
fontSize: TextUnit = this.spanStyle.fontSize,
fontWeight: FontWeight? = this.spanStyle.fontWeight,
fontStyle: FontStyle? = this.spanStyle.fontStyle,
fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
fontFamily: FontFamily? = this.spanStyle.fontFamily,
fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
letterSpacing: TextUnit = this.spanStyle.letterSpacing,
baselineShift: BaselineShift? = this.spanStyle.baselineShift,
textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
localeList: LocaleList? = this.spanStyle.localeList,
background: Color = this.spanStyle.background,
textDecoration: TextDecoration? = this.spanStyle.textDecoration,
shadow: Shadow? = this.spanStyle.shadow,
drawStyle: DrawStyle? = this.spanStyle.drawStyle,
textAlign: TextAlign = this.paragraphStyle.textAlign,
textDirection: TextDirection = this.paragraphStyle.textDirection,
lineHeight: TextUnit = this.paragraphStyle.lineHeight,
textIndent: TextIndent? = this.paragraphStyle.textIndent,
platformStyle: PlatformTextStyle? = this.platformStyle,
lineHeightStyle: LineHeightStyle? = this.paragraphStyle.lineHeightStyle,
lineBreak: LineBreak = this.paragraphStyle.lineBreak,
hyphens: Hyphens = this.paragraphStyle.hyphens,
textMotion: TextMotion? = this.paragraphStyle.textMotion,
): TextStyle
fun hasSameLayoutAffectingAttributes(other: TextStyle): Boolean
Returns true if text layout affecting attributes between this TextStyle and other are the same.
The attributes that do not require a layout change are color, textDecoration and shadow.
Majority of attributes change text layout, and examples are line height, font properties, font size, locale etc.
This function can be used to identify if a new text layout is required for a given TextStyle.
Parameters
other | The TextStyle to compare to. |
fun hasSameDrawAffectingAttributes(other: TextStyle): Boolean
Companion Object
Properties
val Default = TextStyle()
Constant for default text style.