1 /*
2  * Copyright (C) 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.constraintlayout.compose
18 
19 import androidx.compose.foundation.layout.LayoutScopeMarker
20 import androidx.compose.runtime.Stable
21 import androidx.constraintlayout.core.parser.CLObject
22 
23 @LayoutScopeMarker
24 @Stable
25 class HorizontalChainScope internal constructor(internal val id: Any, containerObject: CLObject) {
26     /**
27      * Reference to the [ConstraintLayout] itself, which can be used to specify constraints between
28      * itself and its children.
29      */
30     val parent = ConstrainedLayoutReference("parent")
31 
32     /** The start anchor of the chain - can be constrained using [VerticalAnchorable.linkTo]. */
33     val start: VerticalAnchorable = ChainVerticalAnchorable(containerObject, -2)
34 
35     /** The left anchor of the chain - can be constrained using [VerticalAnchorable.linkTo]. */
36     val absoluteLeft: VerticalAnchorable = ChainVerticalAnchorable(containerObject, 0)
37 
38     /** The end anchor of the chain - can be constrained using [VerticalAnchorable.linkTo]. */
39     val end: VerticalAnchorable = ChainVerticalAnchorable(containerObject, -1)
40 
41     /** The right anchor of the chain - can be constrained using [VerticalAnchorable.linkTo]. */
42     val absoluteRight: VerticalAnchorable = ChainVerticalAnchorable(containerObject, 1)
43 }
44 
45 @LayoutScopeMarker
46 @Stable
47 class VerticalChainScope internal constructor(internal val id: Any, containerObject: CLObject) {
48     /**
49      * Reference to the [ConstraintLayout] itself, which can be used to specify constraints between
50      * itself and its children.
51      */
52     val parent = ConstrainedLayoutReference("parent")
53 
54     /** The top anchor of the chain - can be constrained using [HorizontalAnchorable.linkTo]. */
55     val top: HorizontalAnchorable = ChainHorizontalAnchorable(containerObject, 0)
56 
57     /** The bottom anchor of the chain - can be constrained using [HorizontalAnchorable.linkTo]. */
58     val bottom: HorizontalAnchorable = ChainHorizontalAnchorable(containerObject, 1)
59 }
60 
61 private class ChainVerticalAnchorable constructor(containerObject: CLObject, index: Int) :
62     BaseVerticalAnchorable(containerObject, index)
63 
64 private class ChainHorizontalAnchorable constructor(containerObject: CLObject, index: Int) :
65     BaseHorizontalAnchorable(containerObject, index)
66