StatConfigRootView.swift 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. Toggle("Enable total insulin in scope", isOn: $state.tins)
  31. } header: { Text("Home Chart settings ") }
  32. Section {
  33. HStack {
  34. Text("Low")
  35. Spacer()
  36. DecimalTextField("0", value: $state.low, formatter: glucoseFormatter)
  37. Text(state.units.rawValue).foregroundColor(.secondary)
  38. }
  39. HStack {
  40. Text("High")
  41. Spacer()
  42. DecimalTextField("0", value: $state.high, formatter: glucoseFormatter)
  43. Text(state.units.rawValue).foregroundColor(.secondary)
  44. }
  45. Toggle("Override HbA1c Unit", isOn: $state.overrideHbA1cUnit)
  46. } header: { Text("Statistics settings ") }
  47. Section {
  48. Toggle("Skip Bolus screen after carbs", isOn: $state.skipBolusScreenAfterCarbs)
  49. Toggle("Display and allow Fat and Protein entries", isOn: $state.useFPUconversion)
  50. } header: { Text("Add Meal View settings ") }
  51. Section {
  52. Picker(
  53. selection: $state.historyLayout,
  54. label: Text("History Layout")
  55. ) {
  56. ForEach(HistoryLayout.allCases) { selection in
  57. Text(selection.displayName).tag(selection)
  58. }
  59. }
  60. } header: { Text("History Settings") }
  61. }
  62. .onAppear(perform: configureView)
  63. .navigationBarTitle("UI/UX")
  64. .navigationBarTitleDisplayMode(.automatic)
  65. .navigationBarItems(trailing: Button("Close", action: state.hideModal))
  66. }
  67. }
  68. }