1 /* 2 * Copyright 2021 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.glance.wear.tiles.curved 18 19 import androidx.compose.runtime.Immutable 20 import androidx.compose.ui.unit.TextUnit 21 import androidx.glance.text.FontStyle 22 import androidx.glance.text.FontWeight 23 import androidx.glance.unit.ColorProvider 24 25 /** 26 * The alignment of a [CurvedRow]'s elements, with respect to its anchor angle. This specifies how 27 * elements added to a [CurvedRow] should be laid out with respect to the [CurvedRow]'s anchor 28 * angle. 29 * 30 * As an example, assume that the following diagrams are wrapped to an arc, and each represents a 31 * [CurvedRow] element containing a single text element. The text element's anchor angle is "0" for 32 * all cases. 33 * 34 * ``` 35 * AnchorType.Start: 36 * -180 0 180 37 * Hello World! 38 * 39 * 40 * AnchorType.Center: 41 * -180 0 180 42 * Hello World! 43 * 44 * AnchorType.End: 45 * -180 0 180 46 * Hello World! 47 * ``` 48 */ 49 @JvmInline 50 public value class AnchorType private constructor(private val value: Int) { 51 public companion object { 52 /** 53 * Anchor at the start of the elements. This will cause elements added to a [CurvedRow] to 54 * begin at the given anchor angle, and sweep around to the right. 55 */ 56 public val Start: AnchorType = AnchorType(0) 57 58 /** 59 * Anchor at the center of the elements. This will cause the center of the whole set of 60 * elements added to a [CurvedRow] to be pinned at the given anchor angle. 61 */ 62 public val Center: AnchorType = AnchorType(1) 63 64 /** 65 * Anchor at the end of the elements. This will cause the set of elements inside the 66 * [CurvedRow] to end at the specified anchor angle, i.e. all elements should be to the left 67 * of anchor angle. 68 */ 69 public val End: AnchorType = AnchorType(2) 70 } 71 } 72 73 /** 74 * How to lay down components when they are thinner than the [CurvedRow]. Similar to vertical 75 * alignment in a Row. 76 */ 77 @JvmInline 78 public value class RadialAlignment private constructor(private val value: Int) { 79 companion object { 80 /** Put the child closest to the center of the [CurvedRow], within the available space */ 81 val Inner = RadialAlignment(0) 82 83 /** Put the child in the middle point of the available space. */ 84 val Center = RadialAlignment(1) 85 86 /** Put the child farthest from the center of the [CurvedRow], within the available space */ 87 val Outer = RadialAlignment(2) 88 } 89 } 90 91 /** Description of a text style for the [CurvedScope.curvedText] composable. */ 92 @Immutable 93 public class CurvedTextStyle( 94 public val color: ColorProvider? = null, 95 public val fontSize: TextUnit? = null, 96 public val fontWeight: FontWeight? = null, 97 public val fontStyle: FontStyle? = null 98 ) { equalsnull99 override fun equals(other: Any?): Boolean { 100 if (this === other) return true 101 if (other !is CurvedTextStyle) return false 102 103 if (color != other.color) return false 104 if (fontSize != other.fontSize) return false 105 if (fontWeight != other.fontWeight) return false 106 if (fontStyle != other.fontStyle) return false 107 108 return true 109 } 110 hashCodenull111 override fun hashCode(): Int { 112 var result = fontSize.hashCode() 113 result = 31 * result + fontWeight.hashCode() 114 result = 31 * result + fontStyle.hashCode() 115 return result 116 } 117 toStringnull118 override fun toString() = 119 "TextStyle(size=$fontSize, fontWeight=$fontWeight, fontStyle=$fontStyle)" 120 } 121