瀏覽代碼

add checkmark for insulin....to do: logic for adding external insulin

polscm32 2 年之前
父節點
當前提交
4d43a96eeb

+ 20 - 0
FreeAPS/Sources/Helpers/CheckboxToggleStyle.swift

@@ -21,3 +21,23 @@ struct CheckboxToggleStyle: ToggleStyle {
         }
     }
 }
+
+struct Checkbox: ToggleStyle {
+    func makeBody(configuration: Self.Configuration) -> some View {
+        HStack {
+            RoundedRectangle(cornerRadius: 5)
+                .stroke(lineWidth: 2)
+                .foregroundColor(.secondary)
+                .frame(width: 20, height: 20)
+                .overlay {
+                    if configuration.isOn {
+                        Image(systemName: "checkmark").font(.body).fontWeight(.bold)
+                    }
+                }
+                .onTapGesture {
+                    configuration.isOn.toggle()
+                }
+            configuration.label
+        }
+    }
+}

+ 4 - 3
FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift

@@ -75,19 +75,20 @@ extension Bolus {
         @Published var note: String = ""
 
         @Published var date = Date()
-        // @Published var protein: Decimal = 0
-        // @Published var fat: Decimal = 0
+
         @Published var carbsRequired: Decimal?
         @Published var useFPUconversion: Bool = false
         @Published var dish: String = ""
         @Published var selection: Presets?
         @Published var summation: [String] = []
         @Published var maxCarbs: Decimal = 0
-        // @Published var note: String = ""
+
         @Published var id_: String = ""
         @Published var summary: String = ""
         @Published var skipBolus: Bool = false
 
+        @Published var externalInsulin: Bool = false
+
         let now = Date.now
 
         let coredataContext = CoreDataStack.shared.persistentContainer.viewContext

+ 8 - 0
FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift

@@ -434,6 +434,14 @@ extension Bolus {
 
                 if state.amount > 0 {
                     Section {
+                        HStack {
+                            Text("External insulin")
+                            Spacer()
+                            Toggle("", isOn: $state.externalInsulin).toggleStyle(Checkbox())
+                        }
+                    }
+
+                    Section {
                         Button {
                             Task {
                                 await state.add()