@@ -29,6 +29,9 @@ import androidx.xr.scenecore.MovableComponent
29
29
import androidx.xr.scenecore.PlaneSemantic
30
30
import androidx.xr.scenecore.PlaneType
31
31
import androidx.xr.scenecore.ResizableComponent
32
+ import androidx.xr.scenecore.ResizeListener
33
+ import androidx.xr.scenecore.SurfaceEntity
34
+ import java.util.concurrent.Executor
32
35
import java.util.concurrent.Executors
33
36
34
37
private fun setPoseExample (entity : Entity ) {
@@ -73,11 +76,26 @@ private fun moveableComponentExample(session: Session, entity: Entity) {
73
76
// [END androidxr_scenecore_moveableComponentExample]
74
77
}
75
78
76
- private fun resizableComponentExample (session : Session , entity : Entity ) {
79
+ private fun resizableComponentExample (session : Session , entity : Entity , executor : Executor ) {
77
80
// [START androidxr_scenecore_resizableComponentExample]
78
81
val resizableComponent = ResizableComponent .create(session)
79
82
resizableComponent.minimumSize = Dimensions (177f , 100f , 1f )
80
83
resizableComponent.fixedAspectRatio = 16f / 9f // Specify a 16:9 aspect ratio
84
+
85
+ resizableComponent.addResizeListener(
86
+ executor,
87
+ object : ResizeListener {
88
+ override fun onResizeEnd (entity : Entity , finalSize : Dimensions ) {
89
+
90
+ // update the size in the component
91
+ resizableComponent.size = finalSize
92
+
93
+ // update the Entity to reflect the new size
94
+ (entity as SurfaceEntity ).canvasShape = SurfaceEntity .CanvasShape .Quad (finalSize.width, finalSize.height)
95
+ }
96
+ },
97
+ )
98
+
81
99
entity.addComponent(resizableComponent)
82
100
// [END androidxr_scenecore_resizableComponentExample]
83
101
}
0 commit comments