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
18 
19 import androidx.annotation.RestrictTo
20 import androidx.glance.layout.Alignment
21 import androidx.glance.text.TextStyle
22 
23 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
24 interface Emittable {
25     var modifier: GlanceModifier
26 
copynull27     fun copy(): Emittable
28 }
29 
30 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
31 abstract class EmittableWithChildren(
32     internal var maxDepth: Int = Int.MAX_VALUE,
33     internal val resetsDepthForChildren: Boolean = false
34 ) : Emittable {
35     val children: MutableList<Emittable> = mutableListOf<Emittable>()
36 
37     protected fun childrenToString(): String = children.joinToString(",\n").prependIndent("  ")
38 }
39 
40 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
EmittableWithChildrennull41 fun EmittableWithChildren.addChild(e: Emittable) {
42     this.children += e
43 }
44 
45 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
EmittableWithChildrennull46 fun EmittableWithChildren.addChildIfNotNull(e: Emittable?) {
47     if (e != null) this.children += e
48 }
49 
50 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
51 abstract class EmittableLazyItemWithChildren : EmittableWithChildren() {
52     var alignment: Alignment = Alignment.CenterStart
53 }
54 
55 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
56 abstract class EmittableWithText : Emittable {
57     var text: String = ""
58     var style: TextStyle? = null
59     var maxLines: Int = Int.MAX_VALUE
60 }
61 
62 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
63 abstract class EmittableCheckable : EmittableWithText() {
64     var checked: Boolean = false
65 }
66