Skip to content

Commit

Permalink
Add DevicesGamePadSettingsView
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Oct 24, 2023
1 parent 19cd65d commit b6fb903
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 82 deletions.
115 changes: 115 additions & 0 deletions src/apps/SettingsWindow/src/View/DevicesGamePadSettingsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import SwiftUI

struct DevicesGamePadSettingsView: View {
@Binding var connectedDeviceSetting: LibKrbn.ConnectedDeviceSetting
@Binding var showing: Bool

var body: some View {
ZStack(alignment: .topLeading) {
VStack(alignment: .leading, spacing: 12.0) {
Text(
"\(connectedDeviceSetting.connectedDevice.productName) (\(connectedDeviceSetting.connectedDevice.manufacturerName))"
)
.padding(.leading, 40)
.padding(.top, 20)

GroupBox(label: Text("Deadzone")) {
VStack(alignment: .leading) {
HStack {
Toggle(isOn: $connectedDeviceSetting.gamePadOverwriteXYStickDeadzone) {
Text("Overwrite XY stick deadzone: ")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)
.frame(width: 250.0)

HStack(alignment: .center, spacing: 0) {
Text("Deadzone:")

DoubleTextField(
value: $connectedDeviceSetting.gamePadXYStickDeadzone,
range: 0.05...1,
step: 0.01,
width: 40)

Text("(Default: 0.1)")
}
.padding(.leading, 20)
.disabled(!connectedDeviceSetting.gamePadOverwriteXYStickDeadzone)

Spacer()
}

HStack {
Toggle(isOn: $connectedDeviceSetting.gamePadOverwriteWheelsStickDeadzone) {
Text("Overwrite Wheels stick deadzone: ")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)
.frame(width: 250.0)

HStack(alignment: .center, spacing: 0) {
Text("Deadzone:")

DoubleTextField(
value: $connectedDeviceSetting.gamePadWheelsStickDeadzone,
range: 0.05...1,
step: 0.01,
width: 40)

Text("(Default: 0.1)")
}
.padding(.leading, 20)
.disabled(!connectedDeviceSetting.gamePadOverwriteWheelsStickDeadzone)
}
}.padding()
}

VStack(alignment: .leading, spacing: 2.0) {
Toggle(isOn: $connectedDeviceSetting.gamePadSwapSticks) {
Text("Swap gamepad XY and wheels sticks")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)
}
.frame(width: 240.0)

Spacer()
}

SheetCloseButton {
showing = false
}
}
.padding()
.frame(width: 1000, height: 600)
}
}

struct DevicesGamePadSettingsView_Previews: PreviewProvider {
@State static var connectedDeviceSetting = LibKrbn.ConnectedDeviceSetting(
LibKrbn.ConnectedDevice(
index: 0,
manufacturerName: "",
productName: "",
transport: "",
vendorId: 0,
productId: 0,
deviceAddress: nil,
isKeyboard: false,
isPointingDevice: false,
isGamePad: true,
isBuiltInKeyboard: false,
isBuiltInTrackpad: false,
isBuiltInTouchBar: false,
isAppleDevice: false
)
)
@State static var showing = true

static var previews: some View {
DevicesGamePadSettingsView(
connectedDeviceSetting: $connectedDeviceSetting,
showing: $showing)
}
}
94 changes: 12 additions & 82 deletions src/apps/SettingsWindow/src/View/DevicesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,89 +250,19 @@ struct DevicesView: View {

var body: some View {
if connectedDeviceSetting.connectedDevice.isGamePad {
if !showing {
Button(
action: {
showing = true
},
label: {
Label("Show game pad settings", systemImage: "gamecontroller")
.buttonLabelStyle()
}
)

} else {
VStack(alignment: .leading, spacing: 2.0) {
HStack {
Toggle(isOn: $connectedDeviceSetting.gamePadOverwriteXYStickDeadzone) {
Text("Overwrite XY stick deadzone: ")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)
.frame(width: 240.0)

if connectedDeviceSetting.gamePadOverwriteXYStickDeadzone {
HStack(alignment: .center, spacing: 0) {
Text(
"Deadzone: \(connectedDeviceSetting.gamePadXYStickDeadzone, specifier: "%.2f")")

Stepper(
value: $connectedDeviceSetting.gamePadXYStickDeadzone,
in: 0.05...1,
step: 0.01
) {
Text("")
}
.frame(width: 20)

Text("(Default: 0.1)")

Spacer().frame(maxWidth: .infinity)
}
.padding(.leading, 20)
}
}

HStack {
Toggle(isOn: $connectedDeviceSetting.gamePadOverwriteWheelsStickDeadzone) {
Text("Overwrite Wheels stick deadzone: ")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)
.frame(width: 240.0)

if connectedDeviceSetting.gamePadOverwriteWheelsStickDeadzone {
HStack(alignment: .center, spacing: 0) {
Text(
"Deadzone: \(connectedDeviceSetting.gamePadWheelsStickDeadzone, specifier: "%.2f")"
)

Stepper(
value: $connectedDeviceSetting.gamePadWheelsStickDeadzone,
in: 0.05...1,
step: 0.01
) {
Text("")
}
.frame(width: 20)

Text("(Default: 0.1)")

Spacer().frame(maxWidth: .infinity)
}
.padding(.leading, 20)
}
}

VStack(alignment: .leading, spacing: 2.0) {
Toggle(isOn: $connectedDeviceSetting.gamePadSwapSticks) {
Text("Swap gamepad XY and wheels sticks")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)
}
.frame(width: 240.0)
Button(
action: {
showing = true
},
label: {
Label("Open game pad settings", systemImage: "gamecontroller")
.buttonLabelStyle()
}
)
.sheet(isPresented: $showing) {
DevicesGamePadSettingsView(
connectedDeviceSetting: $connectedDeviceSetting, showing: $showing
)
}
}
}
Expand Down

0 comments on commit b6fb903

Please sign in to comment.