Allow zoom using scroll wheel

This commit is contained in:
Ahnaf Mahmud 2024-08-13 20:30:21 +01:00 committed by GitHub
parent 304a4c8e7e
commit ea5a5354fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -81,6 +81,15 @@ struct UnderlyingImageView: View {
scale = min(widthScale, heightScale)
}
private func setupScrollMonitor() {
#if os(macOS)
NSEvent.addLocalMonitorForEvents(matching: .scrollWheel) {event in
scale = scale + event.scrollingDeltaY/1000
return event
}
#endif
}
var imageView: Image {
#if os(macOS)
Image(nsImage: image)
@ -94,6 +103,9 @@ struct UnderlyingImageView: View {
.gesture(dragGesture)
.gesture(magnificationgesture)
.gesture(rotationGesture)
.onAppear {
setupScrollMonitor()
}
}
var dragGesture: some Gesture {