StatConfigRootView.swift 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import SwiftUI
  2. import Swinject
  3. extension StatConfig {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. private var glucoseFormatter: NumberFormatter {
  8. let formatter = NumberFormatter()
  9. formatter.numberStyle = .decimal
  10. formatter.maximumFractionDigits = 0
  11. if state.units == .mmolL {
  12. formatter.maximumFractionDigits = 1
  13. }
  14. formatter.roundingMode = .halfUp
  15. return formatter
  16. }
  17. private var carbsFormatter: NumberFormatter {
  18. let formatter = NumberFormatter()
  19. formatter.numberStyle = .decimal
  20. formatter.maximumFractionDigits = 0
  21. return formatter
  22. }
  23. var body: some View {
  24. Form {
  25. Section {
  26. Toggle("Display Chart X - Grid lines", isOn: $state.xGridLines)
  27. Toggle("Display Chart Y - Grid lines", isOn: $state.yGridLines)
  28. Toggle("Display Chart Threshold lines for Low and High", isOn: $state.rulerMarks)
  29. Toggle("Standing / Laying TIR Chart", isOn: $state.oneDimensionalGraph)
  30. HStack {
  31. Text("Hours X-Axis (6 default)")
  32. Spacer()
  33. DecimalTextField("6", value: $state.hours, formatter: carbsFormatter)
  34. Text("hours").foregroundColor(.secondary)
  35. }
  36. } header: { Text("Home Chart settings ") }
  37. Section {
  38. HStack {
  39. Text("Low")
  40. Spacer()
  41. DecimalTextField("0", value: $state.low, formatter: glucoseFormatter)
  42. Text(state.units.rawValue).foregroundColor(.secondary)
  43. }
  44. HStack {
  45. Text("High")
  46. Spacer()
  47. DecimalTextField("0", value: $state.high, formatter: glucoseFormatter)
  48. Text(state.units.rawValue).foregroundColor(.secondary)
  49. }
  50. Toggle("Override HbA1c Unit", isOn: $state.overrideHbA1cUnit)
  51. } header: { Text("Statistics settings ") }
  52. Section {
  53. Toggle("Skip Bolus screen after carbs", isOn: $state.skipBolusScreenAfterCarbs)
  54. Toggle("Display and allow Fat and Protein entries", isOn: $state.useFPUconversion)
  55. } header: { Text("Add Meal View settings ") }
  56. }
  57. .onAppear(perform: configureView)
  58. .navigationBarTitle("UI/UX Settings")
  59. .navigationBarTitleDisplayMode(.automatic)
  60. }
  61. }
  62. }