# SceneCoreEntitySizeAdapter

Artifact: [androidx.xr.compose:compose](https://developer.android.com/jetpack/androidx/releases/xr-compose) [View Source](https://cs.android.com/search?q=file:androidx/xr/compose/subspace/SceneCoreEntity.kt+class:androidx.xr.compose.subspace.SceneCoreEntitySizeAdapter) Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-compose#1.0.0-beta02)


```
interface SceneCoreEntitySizeAdapter<T : Entity>
```

<br />

*** ** * ** ***

The sizing strategy used by `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SceneCoreEntity.composable#SceneCoreEntity(kotlin.Function0,androidx.xr.compose.subspace.layout.SubspaceModifier,kotlin.Function1,androidx.xr.compose.subspace.SceneCoreEntitySizeAdapter,kotlin.Function0)` to control and read the size of an entity.

The developer should use `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SceneCoreEntitySizeAdapter#onLayoutSizeChanged(androidx.xr.scenecore.Entity,androidx.xr.compose.unit.IntVolumeSize)` to apply compose layout size changes to the entity. Compose will not inherently affect the size of the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`.

If the developer uses `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SceneCoreEntitySizeAdapter#onLayoutSizeChanged(androidx.xr.scenecore.Entity,androidx.xr.compose.unit.IntVolumeSize)` to change the size of the entity, but `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SceneCoreEntitySizeAdapter#currentSize(androidx.xr.scenecore.Entity)` is not provided, then the intrinsic size of the entity will be ignored and the layout size as determined solely by compose will be used to size the entity. If the `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SceneCoreEntity.composable#SceneCoreEntity(kotlin.Function0,androidx.xr.compose.subspace.layout.SubspaceModifier,kotlin.Function1,androidx.xr.compose.subspace.SceneCoreEntitySizeAdapter,kotlin.Function0)` has no children or size modifiers then compose doesn't know how to size this node and it will be size 0, causing it not to render at all. In such a case, please do one of the following: (1) provide `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SceneCoreEntitySizeAdapter#currentSize(androidx.xr.scenecore.Entity)` so compose can infer the size from the entity, (2) add a sizing modifier to control the size of the entity, or (3) remove the adapter from the `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SceneCoreEntity.composable#SceneCoreEntity(kotlin.Function0,androidx.xr.compose.subspace.layout.SubspaceModifier,kotlin.Function1,androidx.xr.compose.subspace.SceneCoreEntitySizeAdapter,kotlin.Function0)` as without an adapter compose will not try to control the size of this entity.

Note that many SceneCore entities accept sizes in meter units instead of pixels. `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Scene#virtualPixelDensity()` can be used to convert between pixels and meters.

```kotlin
import androidx.xr.compose.subspace.SceneCoreEntitySizeAdapter
import androidx.xr.compose.unit.IntVolumeSize
import androidx.xr.runtime.math.IntSize2d
import androidx.xr.scenecore.PanelEntity

val panelSizeAdapter =
    object : SceneCoreEntitySizeAdapter<PanelEntity> {
        override fun onLayoutSizeChanged(entity: PanelEntity, size: IntVolumeSize) {
            entity.sizeInPixels = IntSize2d(size.width, size.height)
        }

        override fun currentSize(entity: PanelEntity): IntVolumeSize {
            return IntVolumeSize(
                width = entity.sizeInPixels.width,
                height = entity.sizeInPixels.height,
                depth = 0,
            )
        }
    }
```

## Summary

| ### Public functions |
|---|---|
| `open https://developer.android.com/reference/kotlin/androidx/xr/compose/unit/IntVolumeSize?` | `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SceneCoreEntitySizeAdapter#currentSize(androidx.xr.scenecore.Entity)(entity: T)` A getter method that returns the current `https://developer.android.com/reference/kotlin/androidx/xr/compose/unit/IntVolumeSize` in pixels of the entity. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SceneCoreEntitySizeAdapter#onLayoutSizeChanged(androidx.xr.scenecore.Entity,androidx.xr.compose.unit.IntVolumeSize)(entity: T, size: https://developer.android.com/reference/kotlin/androidx/xr/compose/unit/IntVolumeSize)` A callback that is invoked with the final layout size of the composable in pixels. |

## Public functions

### currentSize

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-compose#1.0.0-beta02)

```
open fun currentSize(entity: T): IntVolumeSize?
```

A getter method that returns the current `https://developer.android.com/reference/kotlin/androidx/xr/compose/unit/IntVolumeSize` in pixels of the entity. This isn't as critical for compose as `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SceneCoreEntitySizeAdapter#onLayoutSizeChanged(androidx.xr.scenecore.Entity,androidx.xr.compose.unit.IntVolumeSize)`; however, this can help to inform compose of the intrinsic size of the entity.

### onLayoutSizeChanged

Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-compose#1.0.0-beta02)

```
fun onLayoutSizeChanged(entity: T, size: IntVolumeSize): Unit
```

A callback that is invoked with the final layout size of the composable in pixels.