Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Fix image panning bug ( closes #33 )
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhasDissa committed Aug 28, 2023
1 parent 5c41b09 commit 32ab9a1
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,18 @@ fun PhotoView(
awaitFirstDown()
do {
val event = awaitPointerEvent()
scale *= event.calculateZoom()
scale = max(scale, 1f)
val offset = event.calculatePan()

val w = size.width * (scale - 1f) / 2
offsetX = (offsetX + offset.x).coerceIn(-w, w)
val h = size.height * (scale - 1f) / 2
offsetY = (offsetY + offset.y).coerceIn(-h, h)
if (event.changes.size >= 2) {
scale *= event.calculateZoom()
scale = max(scale, 1f)
val offset = event.calculatePan()
val w = size.width * (scale - 1f) / 2
offsetX = (offsetX + offset.x).coerceIn(-w, w)
val h = size.height * (scale - 1f) / 2
offsetY = (offsetY + offset.y).coerceIn(-h, h)
event.changes.forEach {
it.consume()
}
}
} while (event.changes.any { it.pressed })
}
},
Expand Down

0 comments on commit 32ab9a1

Please sign in to comment.