commonMain.androidx.compose.foundation.text.modifiers.SelectableTextAnnotatedStringElement.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of foundation-desktop Show documentation
Show all versions of foundation-desktop Show documentation
Higher level abstractions of the Compose UI primitives. This library is design system agnostic, providing the high-level building blocks for both application and design-system developers
The newest version!
/*
* 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.compose.foundation.text.modifiers
import androidx.compose.foundation.text.AutoSize
import androidx.compose.foundation.text.DefaultMinLines
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.ColorProducer
import androidx.compose.ui.node.ModifierNodeElement
import androidx.compose.ui.platform.InspectorInfo
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.Placeholder
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.style.TextOverflow
/** Element for any text that is in a selection container. */
internal data class SelectableTextAnnotatedStringElement(
private val text: AnnotatedString,
private val style: TextStyle,
private val fontFamilyResolver: FontFamily.Resolver,
private val onTextLayout: ((TextLayoutResult) -> Unit)? = null,
private val overflow: TextOverflow = TextOverflow.Clip,
private val softWrap: Boolean = true,
private val maxLines: Int = Int.MAX_VALUE,
private val minLines: Int = DefaultMinLines,
private val placeholders: List>? = null,
private val onPlaceholderLayout: ((List) -> Unit)? = null,
private val selectionController: SelectionController? = null,
private val color: ColorProducer? = null,
private val autoSize: AutoSize? = null
) : ModifierNodeElement() {
override fun create(): SelectableTextAnnotatedStringNode =
SelectableTextAnnotatedStringNode(
text,
style,
fontFamilyResolver,
onTextLayout,
overflow,
softWrap,
maxLines,
minLines,
placeholders,
onPlaceholderLayout,
selectionController,
color,
autoSize
)
override fun update(node: SelectableTextAnnotatedStringNode) {
node.update(
text = text,
style = style,
placeholders = placeholders,
minLines = minLines,
maxLines = maxLines,
softWrap = softWrap,
fontFamilyResolver = fontFamilyResolver,
overflow = overflow,
onTextLayout = onTextLayout,
onPlaceholderLayout = onPlaceholderLayout,
selectionController = selectionController,
color = color,
autoSize = autoSize
)
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is SelectableTextAnnotatedStringElement) return false
// these three are most likely to actually change
if (color != other.color) return false
if (text != other.text) return false
if (style != other.style) return false
if (placeholders != other.placeholders) return false
// these are equally unlikely to change
if (fontFamilyResolver != other.fontFamilyResolver) return false
if (autoSize != other.autoSize) return false
if (onTextLayout !== other.onTextLayout) return false
if (overflow != other.overflow) return false
if (softWrap != other.softWrap) return false
if (maxLines != other.maxLines) return false
if (minLines != other.minLines) return false
// these never change, but check anyway for correctness
if (onPlaceholderLayout !== other.onPlaceholderLayout) return false
if (selectionController != other.selectionController) return false
return true
}
override fun hashCode(): Int {
var result = text.hashCode()
result = 31 * result + style.hashCode()
result = 31 * result + fontFamilyResolver.hashCode()
result = 31 * result + (onTextLayout?.hashCode() ?: 0)
result = 31 * result + overflow.hashCode()
result = 31 * result + softWrap.hashCode()
result = 31 * result + maxLines
result = 31 * result + minLines
result = 31 * result + (placeholders?.hashCode() ?: 0)
result = 31 * result + (onPlaceholderLayout?.hashCode() ?: 0)
result = 31 * result + (selectionController?.hashCode() ?: 0)
result = 31 * result + (autoSize?.hashCode() ?: 0)
result = 31 * result + (color?.hashCode() ?: 0)
return result
}
override fun InspectorInfo.inspectableProperties() {
// Show nothing in the inspector.
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy