TreatmentMenuView.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import SwiftUI
  2. struct TreatmentMenuView: View {
  3. @Environment(\.presentationMode) var presentationMode
  4. let treatments = TreatmentOptions.allCases
  5. @State private var selectedOption: TreatmentOptions? = nil
  6. var body: some View {
  7. ScrollView {
  8. HStack {
  9. Spacer()
  10. Text("Choose Treatment:")
  11. .font(.subheadline)
  12. .foregroundStyle(.primary)
  13. Spacer()
  14. }
  15. // Options list
  16. VStack(spacing: 10) {
  17. ForEach(treatments) { treatment in
  18. Button(action: {
  19. selectedOption = treatment
  20. presentationMode.wrappedValue.dismiss() // Close after selecting
  21. }) {
  22. HStack(alignment: .center, spacing: 8) {
  23. switch treatment {
  24. case .mealBolusCombo:
  25. // First Icon
  26. HStack(spacing: 0) {
  27. Image(systemName: "fork.knife")
  28. .resizable()
  29. .aspectRatio(contentMode: .fit)
  30. .frame(width: 22, height: 22) // Icon size
  31. .padding(10) // Padding inside the circle
  32. .background(Color.orange) // Circle background color
  33. .clipShape(Circle())
  34. // Plus Icon
  35. Image(systemName: "plus")
  36. .font(.caption)
  37. .bold()
  38. .frame(width: 24, height: 24) // Ensures consistent sizing
  39. // Second Icon
  40. Image(systemName: "syringe.fill")
  41. .resizable()
  42. .aspectRatio(contentMode: .fit)
  43. .frame(width: 22, height: 22) // Icon size
  44. .padding(10)
  45. .background(Color.blue)
  46. .clipShape(Circle())
  47. }
  48. case .meal:
  49. Image(systemName: "fork.knife")
  50. .resizable()
  51. .aspectRatio(contentMode: .fit)
  52. .frame(width: 22, height: 22) // Icon size
  53. .padding(10)
  54. .background(Color.orange)
  55. .clipShape(Circle())
  56. case .bolus:
  57. Image(systemName: "syringe.fill")
  58. .resizable()
  59. .aspectRatio(contentMode: .fit)
  60. .frame(width: 22, height: 22) // Icon size
  61. .padding(10)
  62. .background(Color.blue)
  63. .clipShape(Circle())
  64. }
  65. }
  66. .foregroundColor(.white)
  67. .frame(maxWidth: .infinity)
  68. }
  69. .buttonStyle(PressableIconButtonStyle())
  70. }
  71. }
  72. .padding(.horizontal)
  73. .background(Color.clear)
  74. }
  75. .frame(maxWidth: .infinity, maxHeight: .infinity)
  76. .background(Color.clear)
  77. }
  78. }
  79. enum TreatmentOptions: String, CaseIterable, Identifiable {
  80. var id: String { rawValue }
  81. case mealBolusCombo
  82. case meal
  83. case bolus
  84. var displayName: String {
  85. switch self {
  86. case .mealBolusCombo: return "Meal & Bolus"
  87. case .meal: return "Meal"
  88. case .bolus: return "Bolus"
  89. }
  90. }
  91. }
  92. struct PressableIconButtonStyle: ButtonStyle {
  93. func makeBody(configuration: Configuration) -> some View {
  94. configuration.label
  95. .opacity(configuration.isPressed ? 0.6 : 1.0) // Change opacity when pressed
  96. .animation(.easeInOut(duration: 0.2), value: configuration.isPressed) // Smooth transition
  97. }
  98. }