Explorar el Código

oref0 variables infoTexts

Jon Mårtensson hace 4 años
padre
commit
c9f5b9e718

+ 9 - 1
FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorDataFlow.swift

@@ -6,6 +6,7 @@ enum PreferencesEditor {
     class Field<T>: Identifiable {
         var displayName: String
         var keypath: WritableKeyPath<Preferences, T>
+        var infoText: String
         var value: T {
             didSet {
                 settable?.onSet(keypath, value: value)
@@ -14,10 +15,17 @@ enum PreferencesEditor {
 
         weak var settable: PreferencesSettable?
 
-        init(displayName: String, keypath: WritableKeyPath<Preferences, T>, value: T, settable: PreferencesSettable? = nil) {
+        init(
+            displayName: String,
+            keypath: WritableKeyPath<Preferences, T>,
+            value: T,
+            infoText: String,
+            settable: PreferencesSettable? = nil
+        ) {
             self.displayName = displayName
             self.keypath = keypath
             self.value = value
+            self.infoText = infoText
             self.settable = settable
         }
 

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 148 - 8
FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorViewModel.swift


+ 24 - 2
FreeAPS/Sources/Modules/PreferencesEditor/View/PreferencesEditorRootView.swift

@@ -1,5 +1,11 @@
 import SwiftUI
 
+struct InfoText: Identifiable {
+    var id: String { description }
+    let description: String
+    let oref0Variable: String
+}
+
 extension PreferencesEditor {
     struct RootView: BaseView {
         @EnvironmentObject var viewModel: ViewModel<Provider>
@@ -10,6 +16,8 @@ extension PreferencesEditor {
             return formatter
         }
 
+        @State private var infoButtonPressed: InfoText?
+
         var body: some View {
             Form {
                 Section(header: Text("FreeAPS X")) {
@@ -36,17 +44,24 @@ extension PreferencesEditor {
                     }
 
                     ForEach(viewModel.boolFields.indexed(), id: \.1.id) { index, field in
-                        Toggle(field.displayName, isOn: self.$viewModel.boolFields[index].value)
+                        HStack {
+                            Button("", action: {
+                                infoButtonPressed = InfoText(description: field.infoText, oref0Variable: field.displayName)
+                            })
+                            Toggle(field.displayName, isOn: self.$viewModel.boolFields[index].value)
+                        }
                     }
 
                     ForEach(viewModel.decimalFields.indexed(), id: \.1.id) { index, field in
                         HStack {
+                            Button("", action: {
+                                infoButtonPressed = InfoText(description: field.infoText, oref0Variable: field.displayName)
+                            })
                             Text(field.displayName)
                             DecimalTextField("0", value: self.$viewModel.decimalFields[index].value, formatter: formatter)
                         }
                     }
                 }
-
                 Section {
                     Text("Edit settings json").chevronCell()
                         .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.settings), from: self)
@@ -54,6 +69,13 @@ extension PreferencesEditor {
             }
             .navigationTitle("Preferences")
             .navigationBarTitleDisplayMode(.automatic)
+            .alert(item: $infoButtonPressed) { infoButton in
+                Alert(
+                    title: Text("\(infoButton.oref0Variable)"),
+                    message: Text("\(infoButton.description)"),
+                    dismissButton: .default(Text("OK"))
+                )
+            }
         }
     }
 }