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.runtime.Immutable
20 
21 /** [ConstraintSet] implementation used in the kotlin DSL. */
22 @Immutable
23 internal class DslConstraintSet
24 constructor(val description: ConstraintSetScope.() -> Unit, extendFrom: ConstraintSet? = null) :
25     DerivedConstraintSet {
26     internal val scope: ConstraintSetScope =
27         ConstraintSetScope(extendFrom = (extendFrom as? DslConstraintSet)?.scope?.containerObject)
28             .apply(description)
29 
30     override val extendFrom: ConstraintSet? = null // Not needed
31 
applyToStatenull32     override fun applyToState(state: State) {
33         scope.applyTo(state)
34     }
35 
overridenull36     override fun override(name: String, value: Float): ConstraintSet {
37         // nothing yet
38         return this
39     }
40 
equalsnull41     override fun equals(other: Any?): Boolean {
42         if (other is DslConstraintSet) {
43             return scope == other.scope
44         }
45         return false
46     }
47 
hashCodenull48     override fun hashCode(): Int {
49         return scope.hashCode()
50     }
51 }
52