-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathExampleJoystick.swift
50 lines (43 loc) · 1.52 KB
/
ExampleJoystick.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// ExampleJoystick.swift
// SwiftUIJoystick
//
// Created by Michael Ellis on 12/4/21.
//
import SwiftUI
import SwiftUIJoystick
// An example Joystick
// Copy this example and modify it
public struct Joystick: View {
/// The monitor object to observe the user input on the Joystick in XY or Polar coordinates
@ObservedObject public var joystickMonitor: JoystickMonitor
/// The width or diameter in which the Joystick will report values
/// For example: 100 will provide 0-100, with (50,50) being the origin
private let dragDiameter: CGFloat
/// Can be `.rect` or `.circle`
/// Rect will allow the user to access the four corners
/// Circle will limit Joystick it's radius determined by `dragDiameter / 2`
private let shape: JoystickShape
public init(monitor: JoystickMonitor, width: CGFloat, shape: JoystickShape = .rect) {
self.joystickMonitor = monitor
self.dragDiameter = width
self.shape = shape
}
public var body: some View {
VStack{
JoystickBuilder(
monitor: self.joystickMonitor,
width: self.dragDiameter,
shape: .rect,
background: {
// Example Background
RoundedRectangle(cornerRadius: 8).fill(Color.red.opacity(0.5))
},
foreground: {
// Example Thumb
Circle().fill(Color.black)
},
locksInPlace: false)
}
}
}