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 package androidx.compose.ui.text.style 17 18 /** 19 * Defines how to align text horizontally. `TextAlign` controls how text aligns in the space it 20 * appears. 21 */ 22 @kotlin.jvm.JvmInline 23 value class TextAlign internal constructor(internal val value: Int) { 24 toStringnull25 override fun toString(): String { 26 return when (this) { 27 Left -> "Left" 28 Right -> "Right" 29 Center -> "Center" 30 Justify -> "Justify" 31 Start -> "Start" 32 End -> "End" 33 Unspecified -> "Unspecified" 34 else -> "Invalid" 35 } 36 } 37 38 companion object { 39 /** Align the text on the left edge of the container. */ 40 val Left = TextAlign(1) 41 42 /** Align the text on the right edge of the container. */ 43 val Right = TextAlign(2) 44 45 /** Align the text in the center of the container. */ 46 val Center = TextAlign(3) 47 48 /** 49 * Stretch lines of text that end with a soft line break to fill the width of the container. 50 * 51 * Lines that end with hard line breaks are aligned towards the [Start] edge. 52 */ 53 val Justify = TextAlign(4) 54 55 /** 56 * Align the text on the leading edge of the container. 57 * 58 * For Left to Right text ([ResolvedTextDirection.Ltr]), this is the left edge. 59 * 60 * For Right to Left text ([ResolvedTextDirection.Rtl]), like Arabic, this is the right 61 * edge. 62 */ 63 val Start = TextAlign(5) 64 65 /** 66 * Align the text on the trailing edge of the container. 67 * 68 * For Left to Right text ([ResolvedTextDirection.Ltr]), this is the right edge. 69 * 70 * For Right to Left text ([ResolvedTextDirection.Rtl]), like Arabic, this is the left edge. 71 */ 72 val End = TextAlign(6) 73 74 /** Return a list containing all possible values of TextAlign. */ valuesnull75 fun values(): List<TextAlign> = listOf(Left, Right, Center, Justify, Start, End) 76 77 /** 78 * This represents an unset value, a usual replacement for "null" when a primitive value is 79 * desired. 80 */ 81 val Unspecified = TextAlign(Int.MIN_VALUE) 82 } 83 } 84