Skip to content

Commit

Permalink
Fix for Y direction issue of RSlider on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranb662 committed May 2, 2020
1 parent 6e6a357 commit 3769774
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Sources/Sliders/RadialSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ public struct RSlider: View {
private func makeThumb(_ proxy: GeometryProxy) -> some View {
let radius = min(proxy.size.height, proxy.size.width)/2
let middle = CGPoint(x: proxy.frame(in: .global).midX, y: proxy.frame(in: .global).midY)
#if os(macOS)
let gesture = DragGesture(minimumDistance: 0)
.onChanged { (value) in
let direction = self.calculateDirection(middle, value.location)
self.value = direction*(self.range.upperBound-self.range.lowerBound) + self.range.lowerBound
self.isActive = true
}
.onEnded { (value) in
let direction = self.calculateDirection(middle, value.location)
self.value = direction*(self.range.upperBound-self.range.lowerBound) + self.range.lowerBound
self.isActive = false
}
#else
let gesture = DragGesture(minimumDistance: 0, coordinateSpace: .global)
.onChanged { (value) in
let direction = self.calculateDirection(middle, value.location)
Expand All @@ -244,6 +257,7 @@ public struct RSlider: View {
self.value = direction*(self.range.upperBound-self.range.lowerBound) + self.range.lowerBound
self.isActive = false
}
#endif
let pct = (value-range.lowerBound)/(range.upperBound-range.lowerBound)
let pX = radius*CGFloat(cos(pct*2 * .pi ))
let pY = radius*CGFloat(sin(pct*2 * .pi ))
Expand Down

0 comments on commit 3769774

Please sign in to comment.