diff --git a/Package.swift b/Package.swift index a6c8489..8af0cd4 100644 --- a/Package.swift +++ b/Package.swift @@ -1,10 +1,10 @@ -// swift-tools-version: 5.5 +// swift-tools-version: 5.9 import PackageDescription let package = Package( name: "Controls", - platforms: [.macOS(.v12), .iOS(.v15)], + platforms: [.macOS(.v12), .iOS(.v15), .visionOS(.v1)], products: [.library(name: "Controls", targets: ["Controls"])], targets: [ .target(name: "Controls", dependencies: []), diff --git a/Sources/Controls/Implementations/SmallKnob.swift b/Sources/Controls/Implementations/SmallKnob.swift index 23b4530..83ebb39 100644 --- a/Sources/Controls/Implementations/SmallKnob.swift +++ b/Sources/Controls/Implementations/SmallKnob.swift @@ -21,6 +21,15 @@ public struct SmallKnob: View { Double((value - range.lowerBound) / (range.upperBound - range.lowerBound)) } + var offsetX: CGFloat { + -sin(normalizedValue * 1.6 * .pi + 0.2 * .pi) / 2.0 * 0.75 + } + + var offsetY: CGFloat { + cos(normalizedValue * 1.6 * .pi + 0.2 * .pi) / 2.0 * 0.75 + } + + public var body: some View { Control(value: $value, in: range, geometry: .twoDimensionalDrag(xSensitivity: 1, ySensitivity: 1)) { geo in @@ -29,8 +38,7 @@ public struct SmallKnob: View { Rectangle().foregroundColor(foregroundColor) .frame(width: geo.size.width / 20, height: geo.size.height / 4) .rotationEffect(Angle(radians: normalizedValue * 1.6 * .pi + 0.2 * .pi)) - .offset(x: -sin(normalizedValue * 1.6 * .pi + 0.2 * .pi) * geo.size.width / 2.0 * 0.75, - y: cos(normalizedValue * 1.6 * .pi + 0.2 * .pi) * geo.size.height / 2.0 * 0.75) + .offset(x: offsetX * Double(geo.size.width), y: offsetY * Double(geo.size.height)) }.drawingGroup() // Drawing groups improve antialiasing of rotated indicator } .aspectRatio(CGSize(width: 1, height: 1), contentMode: .fit) diff --git a/Sources/Controls/SingleTouchView.swift b/Sources/Controls/SingleTouchView.swift index 5d31ecc..0c2481a 100644 --- a/Sources/Controls/SingleTouchView.swift +++ b/Sources/Controls/SingleTouchView.swift @@ -2,7 +2,7 @@ import SwiftUI public typealias TouchCallback = (CGPoint?) -> Void -#if os(iOS) +#if !os(macOS) import UIKit