Skip to content

Commit

Permalink
Fix pan deceleration (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
buh authored Apr 6, 2023
1 parent 6d48782 commit c490711
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Sources/Flow/Views/WorkspaceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ extension WorkspaceView.Coordinator: UIGestureRecognizerDelegate {
#else

class PanView: NSView {
private static let defaultPanSpeed = 5.0

@Binding var pan: CGSize
@Binding var zoom: Double
@Binding var mousePosition: CGPoint

var trackingArea: NSTrackingArea!
private var panSpeed = PanView.defaultPanSpeed

init(pan: Binding<CGSize>, zoom: Binding<Double>, mousePosition: Binding<CGPoint>) {
_pan = pan
Expand Down Expand Up @@ -149,7 +152,12 @@ class PanView: NSView {
zoom(at: p, scale: scale)

} else {
let panSpeed = 5.0
if event.momentumPhase == .changed {
panSpeed *= 0.95
} else {
panSpeed = PanView.defaultPanSpeed
}

pan.width += panSpeed * event.deltaX / zoom
pan.height += panSpeed * event.deltaY / zoom
}
Expand Down

0 comments on commit c490711

Please sign in to comment.