Skip to content

Commit

Permalink
Getting things working for visionOS
Browse files Browse the repository at this point in the history
  • Loading branch information
aure committed Jan 28, 2024
1 parent 6861a93 commit e0240fd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -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: []),
Expand Down
12 changes: 10 additions & 2 deletions Sources/Controls/Implementations/SmallKnob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Controls/SingleTouchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SwiftUI

public typealias TouchCallback = (CGPoint?) -> Void

#if os(iOS)
#if !os(macOS)

import UIKit

Expand Down

0 comments on commit e0240fd

Please sign in to comment.