> Documentation index: https://developer.android.com/reference/llms.txt

# LightPosition.Anchored

Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui.md.txt) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/lighting/Light.kt+class:androidx.compose.ui.lighting.LightPosition.Anchored) Added in [1.14.0-alpha01](https://developer.android.com/jetpack/androidx/releases/compose-ui.md.txt#1.14.0-alpha01) Common/All
- Cmn

  ```
  class LightPosition.Anchored : LightPosition
  ```

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.compose.ui.lighting.LightPosition](https://developer.android.com/reference/kotlin/androidx/compose/ui/lighting/LightPosition.md.txt) ||
|   | ↳ | [androidx.compose.ui.lighting.LightPosition.Anchored](https://developer.android.com/reference/kotlin/androidx/compose/ui/lighting/LightPosition.Anchored.md.txt) |

*** ** * ** ***

A position measured from the composable that `state` is attached to with `lightAnchor`. The anchor must be in the same composition hierarchy as the lit composable. An anchor in a different Popup, Dialog or ComposeView contributes no light.

The light follows that composable wherever it is laid out, without either composable needing to know about the other. Until the anchored composable has been placed the position cannot be resolved and the light contributes nothing.

```kotlin
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.lighting.LightAnchorState
import androidx.compose.ui.lighting.LightPosition
import androidx.compose.ui.lighting.PointLight
import androidx.compose.ui.lighting.SurfaceGeometrySpec
import androidx.compose.ui.lighting.SurfaceMaterial
import androidx.compose.ui.lighting.illuminate
import androidx.compose.ui.lighting.lightAnchor
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp

// A single anchor, shared by the composable that defines the light's position and by the
// light itself.
val anchor = remember { LightAnchorState() }

var moved by remember { mutableStateOf(false) }
val lightX by animateDpAsState(if (moved) 200.dp else 24.dp, label = "lightX")

// Since our light color is white, we set a darker background so that its visible.
val surfaceColor = remember { Color.Black }
val surfaceShape = remember { RoundedCornerShape(24.dp) }

Box(Modifier.size(240.dp).clickable { moved = !moved }) {
    // The light using this anchor will now follow this composable
    Box(
        Modifier.offset { IntOffset(x = lightX.roundToPx(), y = 24.dp.roundToPx()) }
            .size(16.dp)
            .lightAnchor(anchor)
    )

    Box(
        Modifier.align(Alignment.Center)
            .size(160.dp)
            .background(surfaceColor)
            .illuminate(
                lights =
                    listOf(
                        PointLight(
                            color = Color.White,
                            position = LightPosition.Anchored(anchor),
                            elevation = 48.dp,
                            falloffRadius = 320.dp,
                            intensity = 1f,
                        )
                    ),
                surfaceMaterial =
                    SurfaceMaterial.diffuse(Color.White).specular(Color.White, shininess = 32f),
                surfaceGeometrySpec =
                    SurfaceGeometrySpec.convex(
                        shape = surfaceShape,
                        thickness = 1.dp,
                        bevelWidth = 12.dp,
                    ),
            )
    )
}
```

## Summary

| ### Public constructors |
|---|---|
| `Anchored(state: LightAnchorState, offset: DpOffset)` | Cmn |

| ### Public functions |
|---|---|---|
| `open operator Boolean` | `equals(other: Any?)` | Cmn |
| `open Int` | `hashCode()` | Cmn |
| `open String` | `toString()` | Cmn |

| ### Public properties |
|---|---|---|
| `open DpOffset` | `offset` position of the light relative to the anchored composable's top-left corner. | Cmn |
| `LightAnchorState` | `state` the anchor to position against. | Cmn |

## Public constructors

### Anchored

Cmn Added in [1.14.0-alpha01](https://developer.android.com/jetpack/androidx/releases/compose-ui.md.txt#1.14.0-alpha01)

```
Anchored(state: LightAnchorState, offset: DpOffset = DpOffset.Zero)
```

| Parameters |
|---|---|
| `state: LightAnchorState` | the anchor to position against. Two anchored positions are equal only when they share the same state instance. |
| `offset: DpOffset = DpOffset.Zero` | position of the light relative to the anchored composable's top-left corner. |

## Public functions

### equals

Cmn

```
open operator fun equals(other: Any?): Boolean
```

### hashCode

Cmn

```
open fun hashCode(): Int
```

### toString

Cmn

```
open fun toString(): String
```

## Public properties

### offset

Cmn

```
open val offset: DpOffset
```

position of the light relative to the anchored composable's top-left corner.

### state

Cmn Added in [1.14.0-alpha01](https://developer.android.com/jetpack/androidx/releases/compose-ui.md.txt#1.14.0-alpha01)

```
val state: LightAnchorState
```

the anchor to position against. Two anchored positions are equal only when they share the same state instance.