StatConfigRootView.swift 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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(header: Text("Settings")) {
  26. Toggle("Change HbA1c Unit", isOn: $state.overrideHbA1cUnit)
  27. Toggle("Display Chart X - Grid lines", isOn: $state.xGridLines)
  28. Toggle("Display Chart Y - Grid lines", isOn: $state.yGridLines)
  29. Toggle("Display Chart Threshold lines for Low and High", isOn: $state.rulerMarks)
  30. Toggle("Standing / Laying TIR Chart", isOn: $state.oneDimensionalGraph)
  31. HStack {
  32. Text("Hours X-Axis (6 default)")
  33. Spacer()
  34. DecimalTextField("6", value: $state.hours, formatter: carbsFormatter)
  35. Text("hours").foregroundColor(.secondary)
  36. }
  37. HStack {
  38. Text("Low")
  39. Spacer()
  40. DecimalTextField("0", value: $state.low, formatter: glucoseFormatter)
  41. Text(state.units.rawValue).foregroundColor(.secondary)
  42. }
  43. HStack {
  44. Text("High")
  45. Spacer()
  46. DecimalTextField("0", value: $state.high, formatter: glucoseFormatter)
  47. Text(state.units.rawValue).foregroundColor(.secondary)
  48. }
  49. }
  50. }
  51. .onAppear(perform: configureView)
  52. .navigationBarTitle("Statistics")
  53. .navigationBarTitleDisplayMode(.automatic)
  54. }
  55. }
  56. }