TreatmentMenuView.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import SwiftUI
  2. struct TreatmentMenuView: View {
  3. @Environment(\.dismiss) var dismiss
  4. @Binding var selectedTreatment: TreatmentOption?
  5. let treatments = TreatmentOption.allCases
  6. private var is40mm: Bool {
  7. let size = WKInterfaceDevice.current().screenBounds.size
  8. return size.height < 225 && size.width < 185
  9. }
  10. private var iconSize: CGFloat {
  11. is40mm ? 18 : 22
  12. }
  13. var body: some View {
  14. NavigationView {
  15. List {
  16. ForEach(treatments) { treatment in
  17. Button(action: {
  18. selectedTreatment = treatment
  19. dismiss() // Close after selecting
  20. }) {
  21. HStack(spacing: 10) {
  22. switch treatment {
  23. case .meal:
  24. mealIcon
  25. Text(treatment.displayName)
  26. case .bolus:
  27. bolusIcon
  28. Text(treatment.displayName)
  29. case .mealBolusCombo:
  30. mealIcon
  31. bolusIcon
  32. }
  33. }
  34. .foregroundColor(.white)
  35. .frame(maxWidth: .infinity)
  36. }
  37. .buttonStyle(PressableIconButtonStyle())
  38. }
  39. }.navigationTitle("Pick Treatment")
  40. }
  41. }
  42. var mealIcon: some View {
  43. Image(systemName: "fork.knife")
  44. .resizable()
  45. .aspectRatio(contentMode: .fit)
  46. .frame(width: iconSize, height: iconSize)
  47. .padding(is40mm ? 6 : 10)
  48. .background(Color.orange)
  49. .clipShape(Circle())
  50. }
  51. var bolusIcon: some View {
  52. Image(systemName: "syringe.fill")
  53. .resizable()
  54. .aspectRatio(contentMode: .fit)
  55. .frame(width: iconSize, height: iconSize)
  56. .padding(is40mm ? 6 : 10)
  57. .background(Color.blue)
  58. .clipShape(Circle())
  59. }
  60. }
  61. enum TreatmentOption: String, CaseIterable, Identifiable {
  62. var id: String { rawValue }
  63. case mealBolusCombo
  64. case meal
  65. case bolus
  66. var displayName: String {
  67. switch self {
  68. case .mealBolusCombo: return "Meal & Bolus"
  69. case .meal: return "Meal"
  70. case .bolus: return "Bolus"
  71. }
  72. }
  73. }
  74. struct PressableIconButtonStyle: ButtonStyle {
  75. func makeBody(configuration: Configuration) -> some View {
  76. configuration.label
  77. .background(Color.clear)
  78. .opacity(configuration.isPressed ? 0.3 : 1.0) // Change opacity when pressed
  79. .animation(.easeInOut(duration: 0.25), value: configuration.isPressed) // Smooth transition
  80. }
  81. }