1 /* 2 * Copyright 2024 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 18 19 import androidx.compose.runtime.Immutable 20 21 /** 22 * Represents the styles of the links in the [AnnotatedString] in different states 23 * 24 * These style objects will be applied to every [LinkAnnotation] annotation present in the 25 * [AnnotatedString], overriding any styling that might be already present in the [AnnotatedString] 26 * at the [LinkAnnotation]'s position. 27 * 28 * If null is passed to the style argument, it means that a [LinkAnnotation] representing a link 29 * will not get a specific link styling for this state. Instead it will be styled according to the 30 * rest of the [AnnotatedString]. 31 * 32 * The resulting style of the link is always a combination of all styles merged into one in the 33 * order `style.merge(focusedStyle).merge(hoveredStyle).merge(pressedStyle)`. 34 * 35 * @param style style configuration for a link that is always applied 36 * @param focusedStyle style configuration for a link applied on top of the [style] when the link is 37 * focused 38 * @param hoveredStyle style configuration for a link applied on top of the [style] when the link is 39 * hovered 40 * @param pressedStyle style configuration for a link applied on top of the [style] when the link is 41 * pressed 42 */ 43 @Immutable 44 class TextLinkStyles( 45 val style: SpanStyle? = null, 46 val focusedStyle: SpanStyle? = null, 47 val hoveredStyle: SpanStyle? = null, 48 val pressedStyle: SpanStyle? = null 49 ) { equalsnull50 override fun equals(other: Any?): Boolean { 51 if (this === other) return true 52 if (other == null || other !is TextLinkStyles) return false 53 54 if (style != other.style) return false 55 if (focusedStyle != other.focusedStyle) return false 56 if (hoveredStyle != other.hoveredStyle) return false 57 if (pressedStyle != other.pressedStyle) return false 58 59 return true 60 } 61 hashCodenull62 override fun hashCode(): Int { 63 var result = style?.hashCode() ?: 0 64 result = 31 * result + (focusedStyle?.hashCode() ?: 0) 65 result = 31 * result + (hoveredStyle?.hashCode() ?: 0) 66 result = 31 * result + (pressedStyle?.hashCode() ?: 0) 67 return result 68 } 69 } 70