Kaynağa Gözat

Meal presets. Add "-" portion

Jon Mårtensson 3 yıl önce
ebeveyn
işleme
d28e7725ce

+ 16 - 0
FreeAPS/Sources/Modules/AddCarbs/View/AddCarbsRootView.swift

@@ -125,6 +125,21 @@ extension AddCarbs {
                         }
                         }
                     )
                     )
                     Button {
                     Button {
+                        if state.carbs != 0 { state.carbs -= ((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal }
+                        if state.fat != 0 { state.fat -= ((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal }
+                        if state.protein != 0 { state.protein -= ((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal }
+                    }
+                    label: { Text("- 1") }
+                        .disabled(state.selection == nil || (
+                            (((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal) == state
+                                .carbs && (((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal) == state
+                                .fat && (((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal) == state
+                                .protein
+                        ))
+                        .buttonStyle(BorderlessButtonStyle())
+                        .frame(maxWidth: .infinity, alignment: .trailing)
+                        .accentColor(.red)
+                    Button {
                         state.carbs += ((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal
                         state.carbs += ((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal
                         state.fat += ((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal
                         state.fat += ((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal
                         state.protein += ((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal }
                         state.protein += ((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal }
@@ -132,6 +147,7 @@ extension AddCarbs {
                         .disabled(state.selection == nil)
                         .disabled(state.selection == nil)
                         .buttonStyle(BorderlessButtonStyle())
                         .buttonStyle(BorderlessButtonStyle())
                         .frame(maxWidth: .infinity, alignment: .trailing)
                         .frame(maxWidth: .infinity, alignment: .trailing)
+                        .accentColor(.green)
                 }
                 }
             }
             }
         }
         }