LineBreak
-
Cmn
value class LineBreak
When soft wrap is enabled and the width of the text exceeds the width of its container, line breaks are inserted in the text to split it over multiple lines.
There are a number of parameters that affect how the line breaks are inserted. For example, the breaking algorithm can be changed to one with improved readability at the cost of speed. Another example is the strictness, which in some languages determines which symbols can appear at the start of a line.
LineBreak represents a configuration for line breaking, offering several presets for different use cases: Simple, Heading, Paragraph.
import androidx.compose.material.Text import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.LineBreak import androidx.compose.ui.unit.sp Text( text = "Title of an article", style = TextStyle(fontSize = 20.sp, lineBreak = LineBreak.Heading), ) Text( text = "A long paragraph in an article", style = TextStyle(lineBreak = LineBreak.Paragraph), )
For further customization, each platform has its own parameters. An example on Android:
import androidx.compose.material.Text import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.LineBreak import androidx.compose.ui.unit.sp val customTitleLineBreak = LineBreak( strategy = LineBreak.Strategy.Simple, strictness = LineBreak.Strictness.Loose, wordBreak = LineBreak.WordBreak.Default, ) Text( text = "Title of an article", style = TextStyle(fontSize = 20.sp, lineBreak = customTitleLineBreak), ) val defaultStrictnessParagraphLineBreak = LineBreak.Paragraph.copy(strictness = LineBreak.Strictness.Default) Text( text = "A long paragraph in an article", style = TextStyle(lineBreak = defaultStrictnessParagraphLineBreak), )
Summary
Nested types |
|---|
value class LineBreak.StrategyThe strategy used for line breaking. |
value class LineBreak.StrictnessDescribes the strictness of line breaking, determining before which characters line breaks can be inserted. |
value class LineBreak.WordBreakDescribes how line breaks should be inserted within words. |
Public companion properties |
||
|---|---|---|
LineBreak |
Looser breaking rules, suitable for short text such as titles or narrow newspaper columns. |
Cmn
android
|
LineBreak |
Slower, higher quality line breaking for improved readability. |
Cmn
android
|
LineBreak |
Basic, fast line breaking. |
Cmn
android
|
LineBreak |
This represents an unset value, a usual replacement for "null" when a primitive value is desired. |
Cmn
android
|
Public constructors |
|
|---|---|
LineBreak(This represents a configuration for line breaking on Android, describing |
android
|
Public functions |
||
|---|---|---|
LineBreak |
copy( |
android
|
open String |
toString() |
android
|
Public properties |
||
|---|---|---|
LineBreak.Strategy |
android
|
|
LineBreak.Strictness |
android
|
|
LineBreak.WordBreak |
android
|
Extension properties |
||
|---|---|---|
Boolean |
Returns |
Cmn
|
Public companion properties
Heading
val Heading: LineBreak
Looser breaking rules, suitable for short text such as titles or narrow newspaper columns. For longer lines of text, use Paragraph for improved readability.
Paragraph
val Paragraph: LineBreak
Slower, higher quality line breaking for improved readability. Suitable for larger amounts of text.
Simple
val Simple: LineBreak
Basic, fast line breaking. Ideal for text input fields, as it will cause minimal text reflow when editing.
Unspecified
val Unspecified: LineBreak
This represents an unset value, a usual replacement for "null" when a primitive value is desired.
Public constructors
LineBreak
LineBreak(
strategy: LineBreak.Strategy,
strictness: LineBreak.Strictness,
wordBreak: LineBreak.WordBreak
)
This represents a configuration for line breaking on Android, describing Strategy, Strictness, and WordBreak.
| Parameters | |
|---|---|
strategy: LineBreak.Strategy |
defines the algorithm that inserts line breaks |
strictness: LineBreak.Strictness |
defines the line breaking rules |
wordBreak: LineBreak.WordBreak |
defines how words are broken |
Public functions
copy
fun copy(
strategy: LineBreak.Strategy = this.strategy,
strictness: LineBreak.Strictness = this.strictness,
wordBreak: LineBreak.WordBreak = this.wordBreak
): LineBreak
Public properties
Extension properties
isSpecified
val LineBreak.isSpecified: Boolean
Returns true if it is not LineBreak.Unspecified.
| See also | |
|---|---|
Unspecified |