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.xr.compose.subspace.node
18 
19 import androidx.annotation.RestrictTo
20 import androidx.compose.ui.semantics.SemanticsConfiguration
21 import androidx.xr.compose.unit.IntVolumeSize
22 import androidx.xr.runtime.math.Pose
23 import androidx.xr.scenecore.Component
24 import androidx.xr.scenecore.Entity
25 
26 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
27 public interface SubspaceSemanticsInfo {
28 
29     /** The unique ID of this semantics node. */
30     public val semanticsId: Int
31 
32     /** The size of the bounding box for this node. */
33     public val size: IntVolumeSize
34 
35     /** The pose of this node relative to its parent layout node in the Compose hierarchy. */
36     public val pose: Pose
37 
38     /** The position of this node relative to the root of this Compose hierarchy, in pixels. */
39     public val poseInRoot: Pose
40 
41     /**
42      * The semantics configuration of this node.
43      *
44      * This includes all properties attached as modifiers to the current layout node.
45      */
46     public val config: SemanticsConfiguration
47 
48     /**
49      * The children of this node in the semantics tree.
50      *
51      * The children are ordered in inverse hit test order (i.e., paint order).
52      */
53     public val semanticsChildren: List<SubspaceSemanticsInfo>
54 
55     /** The parent of this node in the semantics tree. */
56     public val semanticsParent: SubspaceSemanticsInfo?
57 
58     /** Whether this node is the root of a semantics tree. */
59     public val isRoot: Boolean
60         get() = semanticsParent == null
61 
62     /** The [Entity] associated with this node. */
63     public val semanticsEntity: Entity?
64 
65     /** The scale factor of this node relative to its parent. */
66     public val scale: Float
67         get() = semanticsEntity?.getScale() ?: 1f
68 
69     /** The components attached to this node by SubspaceLayoutNode update. */
70     public val components: List<Component>?
71         @Suppress("NullableCollection") get() = semanticsEntity?.getComponents()
72 }
73