// // ValuePickerKeyboard.swift // WorkoutsPlus // // Created by Felix Förtsch on 24.09.24. // // TODO: Value keyboard binds to a metric (value + unit). You type in the $value and select the unit [m, s, kg] on the wheel. // Example: Push-up (value: reps, unit: nil), Push-up (value: additional weight, unit: kg), Run (value: distance/time, unit: m/s) // This means to use the valuekeyboard you would need to know which unit is allowed and then style the value depending on the unit import SwiftUI struct KeyboardButtonStyle: ButtonStyle { var width: CGFloat = 100 var height: CGFloat = 50 var color: Color = Color(.systemGray6) var font: Font = .system(size: 24, weight: .bold, design: .rounded) func makeBody(configuration: Configuration) -> some View { configuration.label .frame(width: width, height: height) .background(color) .cornerRadius(8) .shadow(color: .gray, radius: 1, x: 0, y: 1) .scaleEffect(configuration.isPressed ? 0.95 : 1.0) .font(font) } } protocol ValueKeyboardProtocol { var value: String { get set } var availableUnits: [String] { get set } } struct ValueKeyboard: View { @Binding var isPresented: Bool @Binding var value: String @Binding var unit: [String] var body: some View { VStack { ZStack { RoundedRectangle(cornerRadius: 8) .fill(Color(.systemGray5)) .frame(height: 80) HStack { TextField("0", text: $value) .font(.system(size: 32, weight: .bold, design: .rounded)) .padding() Picker("Unit", selection: $unit) { ForEach(unit, id: \.self) { unit in Text(unit.description).tag(unit) } } .pickerStyle(WheelPickerStyle()) .frame(width: 125, height: 125) } .padding() .mask(RoundedRectangle(cornerRadius: 8).frame(height: 80)) } .padding() .frame(height: 100) VStack(spacing: 20) { HStack(spacing: 20) { Button(action: { handleButtonTap("1") }) { Text("1") } Button(action: { handleButtonTap("2") }) { Text("2") } Button(action: { handleButtonTap("3") }) { Text("3") } } HStack(spacing: 20) { Button(action: { handleButtonTap("4") }) { Text("4") } Button(action: { handleButtonTap("5") }) { Text("5") } Button(action: { handleButtonTap("6") }) { Text("6") } } HStack(spacing: 20) { Button(action: { handleButtonTap("7") }) { Text("7") } Button(action: { handleButtonTap("8") }) { Text("8") } Button(action: { handleButtonTap("9") }) { Text("9") } } HStack(spacing: 20) { Button(action: { handleButtonTap("⌫") }) { Text("⌫") } Button(action: { handleButtonTap("0") }) { Text("0") } Button(action: { handleButtonTap("→") }) { Text("→") } .buttonStyle(KeyboardButtonStyle(color: .blue)) .foregroundStyle(.white) } } .buttonStyle(KeyboardButtonStyle()) } } private func handleButtonTap(_ button: String) { // switch button { // case "⌫": // if !value.value.isEmpty { // value.value.removeLast() // } // case "→": // isPresented.toggle() // default: // value.value.append(button) // } // } } } #Preview("ExerciseValue") { @Previewable @State var isPresented: Bool = true let value = 0 let unit = ExerciseMetric.allCases VStack { // ValueKeyboard(isPresented: $isPresented, value: value, unit: unit) } }