Skip to content

Commit

Permalink
Trying again to fix macOS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranb662 committed May 2, 2020
1 parent 3769774 commit 9109f6b
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions Sources/Sliders/RadialSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,11 @@ public struct RSlider: View {

private func calculateDirection(_ pt1: CGPoint, _ pt2: CGPoint) -> Double {
let a = pt2.x - pt1.x
#if os(macOS)
let b = -pt2.y - pt1.y
#else
let b = pt2.y - pt1.y

#endif
return Double(atanP(x: a, y: b)/(2 * .pi))
}
private var configuration: RSliderConfiguration {
Expand All @@ -233,19 +236,7 @@ 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 @@ -257,7 +248,6 @@ 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 9109f6b

Please sign in to comment.