TreatmentMenuView.swift 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. NavigationView {
  8. List {
  9. ForEach(treatments) { treatment in
  10. Button(action: {
  11. selectedOption = treatment
  12. presentationMode.wrappedValue.dismiss() // Close after selecting
  13. }) {
  14. HStack(alignment: .center) {
  15. switch treatment {
  16. case .mealBolusCombo:
  17. mealIcon
  18. // Plus Icon
  19. Image(systemName: "plus")
  20. .font(.caption)
  21. .bold()
  22. .frame(width: 24, height: 24)
  23. bolusIcon
  24. case .meal:
  25. mealIcon
  26. case .bolus:
  27. bolusIcon
  28. }
  29. }
  30. .foregroundColor(.white)
  31. .frame(maxWidth: .infinity)
  32. }
  33. .buttonStyle(PressableIconButtonStyle())
  34. }.listRowBackground(Color.clear)
  35. }
  36. .navigationTitle("Pick Treatment")
  37. }
  38. .background(.clear)
  39. }
  40. var mealIcon: some View {
  41. Image(systemName: "fork.knife")
  42. .resizable()
  43. .aspectRatio(contentMode: .fit)
  44. .frame(width: 22, height: 22) // Icon size
  45. .padding(10)
  46. .background(Color.orange)
  47. .clipShape(Circle())
  48. }
  49. var bolusIcon: some View {
  50. Image(systemName: "syringe.fill")
  51. .resizable()
  52. .aspectRatio(contentMode: .fit)
  53. .frame(width: 22, height: 22) // Icon size
  54. .padding(10)
  55. .background(Color.blue)
  56. .clipShape(Circle())
  57. }
  58. }
  59. enum TreatmentOptions: String, CaseIterable, Identifiable {
  60. var id: String { rawValue }
  61. case mealBolusCombo
  62. case meal
  63. case bolus
  64. var displayName: String {
  65. switch self {
  66. case .mealBolusCombo: return "Meal & Bolus"
  67. case .meal: return "Meal"
  68. case .bolus: return "Bolus"
  69. }
  70. }
  71. }
  72. struct PressableIconButtonStyle: ButtonStyle {
  73. func makeBody(configuration: Configuration) -> some View {
  74. configuration.label
  75. .background(Color.clear)
  76. .opacity(configuration.isPressed ? 0.5 : 1.0) // Change opacity when pressed
  77. .animation(.easeInOut(duration: 0.2), value: configuration.isPressed) // Smooth transition
  78. }
  79. }