Returns the change in the centroid location between the previous and the current pointers that are down.
CalculatePan
@Composable
fun CalculatePan() {
val offsetX = remember { mutableStateOf(0f) }
val offsetY = remember { mutableStateOf(0f) }
Box(
Modifier.offset { IntOffset(offsetX.value.roundToInt(), offsetY.value.roundToInt()) }
.graphicsLayer()
.background(Color.Blue)
.pointerInput(Unit) {
awaitEachGesture {
awaitFirstDown()
do {
val event = awaitPointerEvent()
val offset = event.calculatePan()
offsetX.value += offset.x
offsetY.value += offset.y
} while (event.changes.any { it.pressed })
}
}
.fillMaxSize()
)
}