1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.compose.ui.text.style 18 19 import androidx.compose.runtime.Stable 20 21 /** How overflowing text should be handled. */ 22 @kotlin.jvm.JvmInline 23 value class TextOverflow internal constructor(internal val value: Int) { 24 toStringnull25 override fun toString(): String { 26 return when (this) { 27 Clip -> "Clip" 28 Ellipsis -> "Ellipsis" 29 MiddleEllipsis -> "MiddleEllipsis" 30 Visible -> "Visible" 31 StartEllipsis -> "StartEllipsis" 32 else -> "Invalid" 33 } 34 } 35 36 companion object { 37 /** 38 * Clip the overflowing text to fix its container. 39 * 40 * @sample androidx.compose.ui.text.samples.TextOverflowClipSample 41 */ 42 @Stable val Clip = TextOverflow(1) 43 44 /** 45 * Use an ellipsis at the end of the string to indicate that the text has overflowed. 46 * 47 * For example, [This is a ...]. 48 * 49 * @sample androidx.compose.ui.text.samples.TextOverflowEllipsisSample 50 */ 51 @Stable val Ellipsis = TextOverflow(2) 52 53 /** 54 * Display all text, even if there is not enough space in the specified bounds. When 55 * overflow is visible, text may be rendered outside the bounds of the composable displaying 56 * the text. This ensures that all text is displayed to the user, and is typically the right 57 * choice for most text display. It does mean that the text may visually occupy a region 58 * larger than the bounds of it's composable. This can lead to situations where text 59 * displays outside the bounds of the background and clickable on a Text composable with a 60 * fixed height and width. 61 * 62 * @sample androidx.compose.ui.text.samples.TextOverflowVisibleFixedSizeSample 63 * 64 * To make the background and click region expand to match the size of the text, allow it to 65 * expand vertically/horizontally using `Modifier.heightIn`/`Modifier.widthIn` or similar. 66 * 67 * @sample androidx.compose.ui.text.samples.TextOverflowVisibleMinHeightSample 68 * 69 * Note: text that expands past its bounds using `Visible` may be clipped by other modifiers 70 * such as `Modifier.clipToBounds`. 71 */ 72 @Stable val Visible = TextOverflow(3) 73 74 /** 75 * Use an ellipsis at the start of the string to indicate that the text has overflowed. 76 * 77 * For example, [... is a text]. 78 * 79 * Note that not all platforms support the ellipsis at the start. For example, on Android 80 * the start ellipsis is only available for a single line text (i.e. when either a soft wrap 81 * is disabled or a maximum number of lines maxLines set to 1). In case of multiline text it 82 * will fallback to [Clip]. 83 */ 84 @Stable val StartEllipsis = TextOverflow(4) 85 86 /** 87 * Use an ellipsis in the middle of the string to indicate that the text has overflowed. 88 * 89 * For example, [This ... text]. 90 * 91 * Note that not all platforms support the ellipsis in the middle. For example, on Android 92 * the middle ellipsis is only available for a single line text (i.e. when either a soft 93 * wrap is disabled or a maximum number of lines maxLines set to 1). In case of multiline 94 * text it will fallback to [Clip]. 95 */ 96 @Stable val MiddleEllipsis = TextOverflow(5) 97 } 98 } 99