physicsBody

abstract fun Modifier.physicsBody(key: Any, config: PhysicsBodyConfig = PhysicsBodyConfig(), shape: PhysicsShape = PhysicsShape.Box, filter: CollisionFilter = CollisionFilter.Default, isDraggable: Boolean = true, dragConfig: DragConfig = DragConfig(), onCollision: (CollisionEvent) -> Unit? = null, onSleepChanged: (Boolean) -> Unit? = null, onDragStart: (DragEvent) -> Unit? = null, onDragEnd: (DragEvent) -> Unit? = null): Modifier

Registers the composable as a physics body and enables optional pointer-driven dragging.

Keys

key must be stable across recompositions (do not allocate new objects each frame) and unique within the same PhysicsBox container. Events use keys to map back to composables.

Dragging

If isDraggable is true, the engine may create a drag controller on pointer input. Drag behavior is defined by dragConfig. Drag callbacks (onDragStart, onDragEnd) are delivered with coordinates in container pixels (see DragEvent).

Collisions

If onCollision is provided, it will be invoked for contact events involving this body. Collision payload is described by CollisionEvent.

Performance notes

Event callbacks can be frequent. Keep handlers lightweight and avoid allocating per-event.

Parameters

key

Stable identifier used to bind the composable to a physics body and route events.

config

Physical properties (type, density, restitution, friction, etc.).

shape

Collision shape used by the engine.

filter

Collision filtering rules (category/mask/group or equivalent).

isDraggable

Enables pointer dragging for this body.

dragConfig

Drag tuning parameters (max force, spring frequency, damping, fling limits).

onCollision

Optional body-level collision callback.

onSleepChanged

Optional callback invoked when the body enters/leaves “sleep” state (engine-specific; typically means it stopped moving and is excluded from simulation work).

onDragStart

Optional callback invoked when a drag starts for this body.

onDragEnd

Optional callback invoked when a drag ends (including cancel).