| /* |
| * Copyright 2023 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package androidx.wear.compose.materialcore |
| |
| import androidx.annotation.RestrictTo |
| import androidx.compose.foundation.text.BasicText |
| import androidx.compose.foundation.text.InlineTextContent |
| import androidx.compose.runtime.Composable |
| import androidx.compose.ui.Modifier |
| import androidx.compose.ui.graphics.Color |
| import androidx.compose.ui.text.AnnotatedString |
| import androidx.compose.ui.text.Paragraph |
| import androidx.compose.ui.text.TextLayoutResult |
| import androidx.compose.ui.text.TextStyle |
| import androidx.compose.ui.text.font.FontFamily |
| import androidx.compose.ui.text.font.FontStyle |
| import androidx.compose.ui.text.font.FontWeight |
| import androidx.compose.ui.text.style.TextAlign |
| import androidx.compose.ui.text.style.TextDecoration |
| import androidx.compose.ui.text.style.TextOverflow |
| import androidx.compose.ui.unit.TextUnit |
| |
| /** |
| * High level element that displays text and provides semantics / accessibility information. |
| * |
| * For ease of use, commonly used parameters from [TextStyle] are also present here. The order of |
| * precedence is as follows: |
| * - If a parameter is explicitly set here (i.e, it is _not_ `null` or [TextUnit.Unspecified]), |
| * then this parameter will always be used. |
| * - If a parameter is _not_ set, (`null` or [TextUnit.Unspecified]), then the corresponding value |
| * from [style] will be used instead. |
| * |
| * @param text The text to be displayed, where [AnnotatedString] allows multiple styles to be used. |
| * @param modifier [Modifier] to apply to this layout node. |
| * @param color [Color] to apply to the text. |
| * @param fontSize The size of glyphs to use when painting the text. See [TextStyle.fontSize]. |
| * @param fontStyle The typeface variant to use when drawing the letters (e.g., italic). |
| * See [TextStyle.fontStyle]. |
| * @param fontWeight The typeface thickness to use when painting the text (e.g., [FontWeight.Bold]). |
| * @param fontFamily The font family to be used when rendering the text. See [TextStyle.fontFamily]. |
| * @param letterSpacing The amount of space to add between each letter. |
| * See [TextStyle.letterSpacing]. |
| * @param textDecoration The decorations to paint on the text (e.g., an underline). |
| * See [TextStyle.textDecoration]. |
| * @param textAlign The alignment of the text within the lines of the paragraph. |
| * See [TextStyle.textAlign]. |
| * @param lineHeight Line height for the [Paragraph] in [TextUnit] unit, e.g. SP or EM. |
| * See [TextStyle.lineHeight]. |
| * @param overflow How visual overflow should be handled. |
| * @param softWrap Whether the text should break at soft line breaks. If false, the glyphs in the |
| * text will be positioned as if there was unlimited horizontal space. If [softWrap] is false, |
| * [overflow] and TextAlign may have unexpected effects. |
| * @param maxLines An optional maximum number of lines for the text to span, wrapping if |
| * necessary. If the text exceeds the given number of lines, it will be truncated according to |
| * [overflow] and [softWrap]. If it is not null, then it must be greater than zero. |
| * @param minLines The minimum height in terms of minimum number of visible lines. It is required |
| * that 1 <= [minLines] <= [maxLines]. |
| * @param inlineContent A map store composables that replaces certain ranges of the text. It's |
| * used to insert composables into text layout. Check [InlineTextContent] for more information. |
| * @param onTextLayout Callback that is executed when a new text layout is calculated. A |
| * [TextLayoutResult] object that callback provides contains paragraph information, size of the |
| * text, baselines and other details. The callback can be used to add additional decoration or |
| * functionality to the text. For example, to draw selection around the text. |
| * @param style Style configuration for the text such as color, font, line height etc. |
| */ |
| @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) |
| @Composable |
| public fun Text( |
| text: AnnotatedString, |
| modifier: Modifier, |
| color: Color, |
| fontSize: TextUnit, |
| fontStyle: FontStyle?, |
| fontWeight: FontWeight?, |
| fontFamily: FontFamily?, |
| letterSpacing: TextUnit, |
| textDecoration: TextDecoration?, |
| textAlign: TextAlign?, |
| lineHeight: TextUnit, |
| overflow: TextOverflow, |
| softWrap: Boolean, |
| maxLines: Int, |
| minLines: Int, |
| inlineContent: Map<String, InlineTextContent>, |
| onTextLayout: (TextLayoutResult) -> Unit, |
| style: TextStyle |
| ) { |
| BasicText( |
| text = text, |
| modifier = modifier, |
| style = style.merge( |
| color = color, |
| fontSize = fontSize, |
| fontWeight = fontWeight, |
| textAlign = textAlign ?: TextAlign.Unspecified, |
| lineHeight = lineHeight, |
| fontFamily = fontFamily, |
| textDecoration = textDecoration, |
| fontStyle = fontStyle, |
| letterSpacing = letterSpacing |
| ), |
| onTextLayout = onTextLayout, |
| overflow = overflow, |
| softWrap = softWrap, |
| maxLines = maxLines, |
| minLines = minLines, |
| inlineContent = inlineContent |
| ) |
| } |