Jonas Björkert 1 год назад
Родитель
Сommit
41cfa368aa

+ 9 - 6
LoopFollow/Alarm/AlarmEditing/Components/AlarmBGSection.swift

@@ -32,8 +32,13 @@ struct AlarmBGSection: View {
 
     private var unit: HKUnit { UserDefaultsRepository.getPreferredUnit() }
 
-    private var displayValue: String {
-        "\(Localizer.formatQuantity(value)) \(unit.localizedShortUnitString)"
+    private var snappedValue: Binding<Double> {
+        Binding(
+            get: {
+                allValues.min(by: { abs($0 - value) < abs($1 - value) }) ?? value
+            },
+            set: { value = $0 }
+        )
     }
 
     private var allValues: [Double] {
@@ -54,10 +59,8 @@ struct AlarmBGSection: View {
             footer: footer.map(Text.init)
         ) {
             Picker(
-                selection: $value,
-                label: HStack {
-                    Text(title)
-                }
+                selection: snappedValue,
+                label: HStack { Text(title) }
             ) {
                 ForEach(allValues, id: \.self) { v in
                     Text("\(Localizer.formatQuantity(v)) \(unit.localizedShortUnitString)")

+ 4 - 8
LoopFollow/Alarm/AlarmEditing/Editors/FastDropAlarmEditor.swift

@@ -26,8 +26,8 @@ struct FastDropAlarmEditor: View {
                 title: "Drop per reading",
                 range: 3...20,
                 value: Binding(
-                    get: { alarm.threshold ?? 4 },
-                    set: { alarm.threshold = $0 }
+                    get: { alarm.delta ?? 18 },
+                    set: { alarm.delta = $0 }
                 )
             )
 
@@ -44,10 +44,6 @@ struct FastDropAlarmEditor: View {
                 )
             )
 
-            //TODO: Vi måste bestämma var denna bglimit lagras.
-            //Kanske införa en bgLimit för tydlighets skull
-/*
-            // ────────── BG LIMIT ───────────
             Section {
                 Toggle("Only alert when below BG limit", isOn: $useLimit)
                     .onAppear {
@@ -69,8 +65,8 @@ struct FastDropAlarmEditor: View {
                 )
                 .disabled(!useLimit)
                 .opacity(useLimit ? 1 : 0.35)
-            }   // Section
-*/
+            }
+
             AlarmAudioSection(alarm: $alarm)
 
             AlarmActiveSection(alarm: $alarm)