Text¶
Text is the fundamental typography component in CortenaUI used to render strings and sentences on the screen. It is hardwired directly into the standard typography theme of the Cortena operating system, eliminating the need for developers to depend on the Material Theme.
Concept¶
Every text automatically resolves its style based on a semantic role (TextRole). This ensures that the appearance of all fonts, text weights, line heights, and colors is uniform and consistent across the operating system without needing to be configured manually on every call.
- Default Color: Automatically resolves against
LocalContentColor.currentorLocalColors.current.onBackground. - Default Role: Defaults to
TextRole.BodyMedium(14sp) for regular body sentences. - Typography Scaling: Automatically resolves font sizes, weights, and line heights in SP based on the chosen semantic role.
- Weight Override: An optional
TextWeightparameter lets a single role render in a heavier weight without switching to a separate role tier. Useful for buttons, tabs, and metadata where the role's size is right but emphasis is required. - Font Family: Automatically uses
LocalFontFamily.current, which is provided byThemeorContentView. If no custom font is set, the system default font is used. Can be overridden per-instance via thestyleparameter.
API Reference¶
@Composable
fun Text(
text: String,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
style: TextStyle? = null,
role: TextRole? = null,
weight: TextWeight? = null,
maxLines: Int = Int.MAX_VALUE,
overflow: TextOverflow = TextOverflow.Clip,
)
Parameters¶
| Name | Data Type | Description |
|---|---|---|
text |
String |
The sentence / text you want to render. |
modifier |
Modifier |
Standard Compose modifier. |
color |
Color |
Text color. Defaults to Color.Unspecified, resolving dynamically against LocalContentColor or theme's onBackground color. |
style |
TextStyle? |
Custom TextStyle to be merged on top of the resolved role style (e.g., custom letter spacing, text decoration). Default: null. |
role |
TextRole? |
Semantic typography role. null falls back to LocalTextRole.current (set by sized parents like Button), then to BodyMedium. |
weight |
TextWeight? |
Optional weight override. null falls back to LocalTextWeight.current, then to TextWeight.Default (use the role's weight). |
maxLines |
Int |
Maximum number of lines for the text to span before being truncated. Default: Int.MAX_VALUE. |
overflow |
TextOverflow |
How visual text overflow should be handled (e.g., TextOverflow.Ellipsis, TextOverflow.Clip). Default: TextOverflow.Clip. |
TextRole Reference¶
The TextRole enum defines 12 distinct semantic scales across 4 categories:
- Display:
DisplayLarge,DisplayMedium,DisplaySmall(For massive, prominent titles) - Headline:
HeadlineLarge,HeadlineMedium,HeadlineSmall(For main layout headings) - Title:
TitleLarge,TitleMedium,TitleSmall(For section headers and sub-elements) - Body:
BodyLarge,BodyMedium,BodySmall(For standard readable paragraphs and caption notes)
There is no separate "Label" tier. For buttons, tabs, menu items, and other interactive labels, pick the size from the role above and pass weight = TextWeight.Medium.
TextWeight Reference¶
| Weight | Value | Use case |
|---|---|---|
TextWeight.Default |
— | Inherit the role's natural weight. The default for body copy. |
TextWeight.Medium |
500 | Interactive labels (buttons, tabs, menu items), inline emphasis. |
TextWeight.Bold |
700 | Strong emphasis. Use sparingly. |
Examples¶
Using Default Style and Role¶
Using Semantic Roles and Custom Colors¶
Text(
text = "Large Dashboard Header",
role = TextRole.DisplayMedium,
color = Color(LocalColors.current.primary)
)
Replacing the Old Label Roles¶
// Old: TextRole.LabelLarge
Text(text = "Save", role = TextRole.BodyMedium, weight = TextWeight.Medium)
// Old: TextRole.LabelSmall
Text(text = "Caption", role = TextRole.BodySmall, weight = TextWeight.Medium)
Advanced Customizations (Style Merging & Ellipsis Truncation)¶
Text(
text = "This is a very long heading that will automatically be truncated with an ellipsis if it exceeds a single line in length.",
role = TextRole.TitleMedium,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = TextStyle(
textDecoration = TextDecoration.Underline,
letterSpacing = 1.5.sp
)
)