# LightPosition.Anchored

> A position measured from the composable that [state] is attached to with [lightAnchor].

## API Reference

> Source set: Common

```kotlin
public class Anchored(
        public val state: LightAnchorState,
        override val offset: DpOffset = DpOffset.Zero,
    ) : LightPosition()
```

A position measured from the composable that `state` is attached to with [lightAnchor](https://composables.com/jetpack-compose/androidx.compose.ui/ui/modifiers/lightAnchor/api.md). 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.

#### Parameters

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

## Functions

### equals

> Source set: Common

```kotlin
override fun equals(other: Any?): Boolean
```

### hashCode

> Source set: Common

```kotlin
override fun hashCode(): Int
```

### toString

> Source set: Common

```kotlin
override fun toString(): String
```

## Code Examples

### LightAnchorSample

```kotlin
@Sampled
@Composable
fun LightAnchorSample() {
    // 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,
                        ),
                )
        )
    }
}
```
