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.foundation.text.modifiers
18 
19 import androidx.compose.foundation.text.TextAutoSize
20 import androidx.compose.ui.text.AnnotatedString
21 import androidx.compose.ui.text.TextLayoutResult
22 import androidx.compose.ui.unit.Constraints
23 import androidx.compose.ui.unit.Density
24 import androidx.compose.ui.unit.TextUnit
25 
26 /**
27  * An entity that allows performing text layout for auto sizing text.
28  *
29  * These methods are used by [TextAutoSize] in the [TextAutoSize.getFontSize] method, where
30  * developers can lay out text with different font sizes and do certain logic depending on whether
31  * or not the text overflows.
32  */
33 sealed interface TextAutoSizeLayoutScope : Density {
34     /**
35      * Lay out the text and return the result of the measurement
36      *
37      * @param constraints The constraints to lay the text out with
38      * @param text The text to lay out
39      * @param fontSize The font size to lay the text out with
40      * @return The result of the measurement
41      */
performLayoutnull42     fun performLayout(
43         constraints: Constraints,
44         text: AnnotatedString,
45         fontSize: TextUnit
46     ): TextLayoutResult
47 }
48 
49 /** Used only in tests */
50 internal abstract class SimpleTextAutoSizeLayoutScope : TextAutoSizeLayoutScope
51