CurvedTextStyle
class CurvedTextStyle
Styling configuration for a curved text.
import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.text.BasicText import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.TextStyle import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.wear.compose.foundation.CurvedLayout import androidx.wear.compose.foundation.CurvedModifier import androidx.wear.compose.foundation.CurvedTextStyle import androidx.wear.compose.foundation.background import androidx.wear.compose.foundation.basicCurvedText import androidx.wear.compose.foundation.curvedComposable import androidx.wear.compose.foundation.padding import androidx.wear.compose.foundation.size import androidx.wear.compose.material.Text CurvedLayout(modifier = Modifier.fillMaxSize()) { basicCurvedText( "Curved Text", CurvedModifier.padding(10.dp), style = { CurvedTextStyle(fontSize = 16.sp, color = Color.Black, background = Color.White) }, ) curvedComposable { Box(modifier = Modifier.size(20.dp).background(Color.Gray)) } curvedComposable { BasicText( "Normal Text", Modifier.padding(5.dp), TextStyle(fontSize = 16.sp, color = Color.Black, background = Color.White), ) } }
Sample using different letter spacings for top & bottom text:
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.TextStyle import androidx.compose.ui.unit.sp import androidx.wear.compose.foundation.CurvedDirection import androidx.wear.compose.foundation.CurvedLayout import androidx.wear.compose.foundation.CurvedTextStyle import androidx.wear.compose.foundation.basicCurvedText import androidx.wear.compose.material.Text val style = CurvedTextStyle( letterSpacing = 0.6.sp, letterSpacingCounterClockwise = 1.4.sp, color = Color.White, ) Box { CurvedLayout(modifier = Modifier.fillMaxSize()) { basicCurvedText("Clockwise", style = style) } CurvedLayout( modifier = Modifier.fillMaxSize(), angularDirection = CurvedDirection.Angular.CounterClockwise, anchor = 90f, ) { basicCurvedText("Counter Clockwise", style = style) } }
Sample using different warping:
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.TextStyle import androidx.compose.ui.unit.sp import androidx.wear.compose.foundation.CurvedDirection import androidx.wear.compose.foundation.CurvedLayout import androidx.wear.compose.foundation.CurvedTextStyle import androidx.wear.compose.foundation.basicCurvedText import androidx.wear.compose.material.Text val style = CurvedTextStyle( letterSpacing = 0.6.sp, letterSpacingCounterClockwise = 1.4.sp, color = Color.White, ) Box { CurvedLayout(modifier = Modifier.fillMaxSize()) { basicCurvedText( "No Warping", style = style.copy(warpOffset = CurvedTextStyle.WarpOffset.None), ) } CurvedLayout( modifier = Modifier.fillMaxSize(), angularDirection = CurvedDirection.Angular.CounterClockwise, anchor = 90f, ) { basicCurvedText( "Standard Warping", style.copy(warpOffset = CurvedTextStyle.WarpOffset.HalfOpticalHeight), ) } }
Summary
Nested types |
|---|
value class CurvedTextStyle.WarpOffsetUsed to specify if we want to warp the text, and if so, the offset for warping. |
Public constructors |
|---|
CurvedTextStyle(style: TextStyle)Create a curved text style from the given text style. |
CurvedTextStyle( |
Public functions |
|
|---|---|
CurvedTextStyle |
copy( |
open operator Boolean |
|
open Int |
hashCode() |
CurvedTextStyle |
merge(other: CurvedTextStyle?)Returns a new curved text style that is a combination of this style and the given |
operator CurvedTextStyle |
plus(other: CurvedTextStyle)Plus operator overload that applies a |
open String |
toString() |
Public properties |
|
|---|---|
Color |
The background color for the text. |
Color |
The text color. |
FontFamily? |
The font family to be used when rendering the text. |
TextUnit |
The size of glyphs (in logical pixels) to use when painting the text. |
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. |
FontWeight? |
The thickness of the glyphs, in a range of 1, 1000. see |
TextUnit |
The amount of space (in em or sp) to add between each letter, when text is going clockwise. |
TextUnit |
The amount of space (in em or sp) to add between each letter, when text is going counterClockwise. |
TextUnit |
Line height for the text in |
CurvedTextStyle.WarpOffset |
specifies if we want to warp the text, and if so, the offset for warping. |
Public constructors
CurvedTextStyle
CurvedTextStyle(style: TextStyle)
Create a curved text style from the given text style.
Note that not all parameters in the text style will be used, only TextStyle.color, TextStyle.fontSize, TextStyle.background, TextStyle.fontFamily, TextStyle.fontWeight, TextStyle.fontStyle, TextStyle.fontSynthesis, TextStyle.letterSpacing, TextStyle.lineHeight.
CurvedTextStyle
CurvedTextStyle(
background: Color = Color.Unspecified,
color: Color = Color.Unspecified,
fontSize: TextUnit = TextUnit.Unspecified,
fontFamily: FontFamily? = null,
fontWeight: FontWeight? = null,
fontStyle: FontStyle? = null,
fontSynthesis: FontSynthesis? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
letterSpacingCounterClockwise: TextUnit = TextUnit.Unspecified,
lineHeight: TextUnit = TextUnit.Unspecified,
warpOffset: CurvedTextStyle.WarpOffset = WarpOffset.Unspecified
)
| Parameters | |
|---|---|
background: Color = Color.Unspecified |
The background color for the text. |
color: Color = Color.Unspecified |
The text color. |
fontSize: TextUnit = TextUnit.Unspecified |
The size of glyphs (in logical pixels) to use when painting the text. This may be |
fontFamily: FontFamily? = null |
The font family to be used when rendering the text. |
fontWeight: FontWeight? = null |
The thickness of the glyphs, in a range of 1, 1000. see |
fontStyle: FontStyle? = null |
The typeface variant to use when drawing the letters (e.g. italic). |
fontSynthesis: FontSynthesis? = null |
Whether to synthesize font weight and/or style when the requested weight or style cannot be found in the provided font family. |
letterSpacing: TextUnit = TextUnit.Unspecified |
The amount of space (in em or sp) to add between each letter, when text is going clockwise. |
letterSpacingCounterClockwise: TextUnit = TextUnit.Unspecified |
The amount of space (in em or sp) to add between each letter, when text is going counterClockwise. Note that this usually needs to be bigger than |
lineHeight: TextUnit = TextUnit.Unspecified |
Line height for the text in |
warpOffset: CurvedTextStyle.WarpOffset = WarpOffset.Unspecified |
specifies if we want to warp the text, and if so, the offset for warping. Warping the text will cause each character to be modified in shape so that it is thinner when it is closer to the center of the center of the screen and wider when it's further away. This also makes adjacent characters share a line, so this is particularly useful for cursive fonts. When warping is active, this parameter specifies which horizontal line of the text will keep its width. |
Public functions
copy
fun copy(
background: Color = this.background,
color: Color = this.color,
fontSize: TextUnit = this.fontSize,
fontFamily: FontFamily? = this.fontFamily,
fontWeight: FontWeight? = this.fontWeight,
fontStyle: FontStyle? = this.fontStyle,
fontSynthesis: FontSynthesis? = this.fontSynthesis,
letterSpacing: TextUnit = this.letterSpacing,
letterSpacingCounterClockwise: TextUnit = this.letterSpacingCounterClockwise,
lineHeight: TextUnit = this.lineHeight,
warpOffset: CurvedTextStyle.WarpOffset = this.warpOffset
): CurvedTextStyle
merge
fun merge(other: CurvedTextStyle? = null): CurvedTextStyle
Returns a new curved text style that is a combination of this style and the given other style.
other curved text style's null or inherit properties are replaced with the non-null properties of this curved 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 curved text style is null, returns this curved text style.
plus
operator fun plus(other: CurvedTextStyle): CurvedTextStyle
Plus operator overload that applies a merge.
Public properties
fontFamily
val fontFamily: FontFamily?
The font family to be used when rendering the text.
fontSize
val fontSize: TextUnit
The size of glyphs (in logical pixels) to use when painting the text. This may be TextUnit.Unspecified for inheriting from another CurvedTextStyle.
fontStyle
val fontStyle: FontStyle?
The typeface variant to use when drawing the letters (e.g. italic).
fontSynthesis
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.
fontWeight
val fontWeight: FontWeight?
The thickness of the glyphs, in a range of 1, 1000. see FontWeight
letterSpacing
val letterSpacing: TextUnit
The amount of space (in em or sp) to add between each letter, when text is going clockwise.
letterSpacingCounterClockwise
val letterSpacingCounterClockwise: TextUnit
The amount of space (in em or sp) to add between each letter, when text is going counterClockwise. Note that this usually needs to be bigger than letterSpacing to account for the fact that going clockwise, text fans out from the baseline while going counter clockwise text fans in. If not specified, the value for letterSpacing will be used.
lineHeight
val lineHeight: TextUnit
Line height for the text in TextUnit unit, e.g. SP or EM. Note that since curved text only has one line, this used the equivalent of a lineHeightStyle: alignment = Center, trim = None, mode = Fixed
warpOffset
val warpOffset: CurvedTextStyle.WarpOffset
specifies if we want to warp the text, and if so, the offset for warping. Warping the text will cause each character to be modified in shape so that it is thinner when it is closer to the center of the center of the screen and wider when it's further away. This also makes adjacent characters share a line, so this is particularly useful for cursive fonts. When warping is active, this parameter specifies which horizontal line of the text will keep its width.