Skip to content

Commit cd2e0c1

Browse files
authored
Updates to ResizableComponent (#516)
* Adding snippet for MV-HEVC video playback * updating the resizable snippet to include ResizeListener
1 parent 9d62789 commit cd2e0c1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

xr/src/main/java/com/example/xr/scenecore/Entities.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import androidx.xr.scenecore.MovableComponent
2929
import androidx.xr.scenecore.PlaneSemantic
3030
import androidx.xr.scenecore.PlaneType
3131
import androidx.xr.scenecore.ResizableComponent
32+
import androidx.xr.scenecore.ResizeListener
33+
import androidx.xr.scenecore.SurfaceEntity
34+
import java.util.concurrent.Executor
3235
import java.util.concurrent.Executors
3336

3437
private fun setPoseExample(entity: Entity) {
@@ -73,11 +76,26 @@ private fun moveableComponentExample(session: Session, entity: Entity) {
7376
// [END androidxr_scenecore_moveableComponentExample]
7477
}
7578

76-
private fun resizableComponentExample(session: Session, entity: Entity) {
79+
private fun resizableComponentExample(session: Session, entity: Entity, executor: Executor) {
7780
// [START androidxr_scenecore_resizableComponentExample]
7881
val resizableComponent = ResizableComponent.create(session)
7982
resizableComponent.minimumSize = Dimensions(177f, 100f, 1f)
8083
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+
8199
entity.addComponent(resizableComponent)
82100
// [END androidxr_scenecore_resizableComponentExample]
83101
}

0 commit comments

Comments
 (0)