BoundariesConfig

@Immutable
data class BoundariesConfig(val enabled: Boolean = true, val restitution: Float = 0.2f, val friction: Float = 0.3f, val thicknessPx: Float = 64.0f)

Optional static boundaries around the dev.zinchenko.physicsbox.layout.PhysicsBox container.

When enabled, the engine creates four static “walls” (left / top / right / bottom) that surround the container. These walls prevent dynamic bodies from leaving the visible area and allow you to tune how objects bounce and slide when they hit the edges.

Coordinate space and sizing

  • The container uses Compose coordinates: X to the right, Y down.

  • Boundary geometry is generated from the current container size (in px) as observed by PhysicsBoxLayout.

  • thicknessPx defines the wall thickness in pixels. A thicker wall reduces the chance that fast bodies “tunnel” through edges (though true CCD depends on body settings like isBullet).

Contact behavior

  • restitution controls how “bouncy” the container edges are:

  • 0.0 → no bounce (perfectly inelastic)

  • 1.0 → highly elastic bounce Values above 1.0 are allowed by the underlying physics engines in many cases, but can inject energy and destabilize simulation; keep it in [0..1] for typical UI use.

  • friction controls sliding against the walls:

  • 0.0 → no friction (objects slide freely)

  • higher values → stronger resistance to sliding

Lifecycle

  • Walls are (re)generated whenever the container size changes.

  • Disabling boundaries removes the walls from the physics world.

Recommended starting values

  • restitution = 0.2f and friction = 0.3f give a subtle bounce with controlled sliding.

  • thicknessPx = 32f..96f is usually enough for UI scenes depending on element sizes and speeds.

Constructors

Link copied to clipboard
constructor(enabled: Boolean = true, restitution: Float = 0.2f, friction: Float = 0.3f, thicknessPx: Float = 64.0f)

Properties

Link copied to clipboard

Whether the boundary walls should exist around the container.

Link copied to clipboard

Sliding friction against the walls. Must be >= 0.

Link copied to clipboard

Bounciness of the walls. Must be >= 0.

Link copied to clipboard

Wall thickness in pixels. Must be > 0.