GraphSettingsView.swift 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // LoopFollow
  2. // GraphSettingsView.swift
  3. import SwiftUI
  4. struct GraphSettingsView: View {
  5. @ObservedObject private var showDots = Storage.shared.showDots
  6. @ObservedObject private var showLines = Storage.shared.showLines
  7. @ObservedObject private var showValues = Storage.shared.showValues
  8. @ObservedObject private var showAbsorption = Storage.shared.showAbsorption
  9. @ObservedObject private var showDIALines = Storage.shared.showDIALines
  10. @ObservedObject private var show30MinLine = Storage.shared.show30MinLine
  11. @ObservedObject private var show90MinLine = Storage.shared.show90MinLine
  12. @ObservedObject private var showMidnightLines = Storage.shared.showMidnightLines
  13. @ObservedObject private var smallGraphTreatments = Storage.shared.smallGraphTreatments
  14. @ObservedObject private var smallGraphHeight = Storage.shared.smallGraphHeight
  15. @ObservedObject private var predictionToLoad = Storage.shared.predictionToLoad
  16. @ObservedObject private var predictionDisplayType = Storage.shared.predictionDisplayType
  17. @ObservedObject private var minBasalScale = Storage.shared.minBasalScale
  18. @ObservedObject private var minBGScale = Storage.shared.minBGScale
  19. @ObservedObject private var downloadDays = Storage.shared.downloadDays
  20. private var nightscoutEnabled: Bool { IsNightscoutEnabled() }
  21. var body: some View {
  22. Form {
  23. // ── Graph Display ────────────────────────────────────────────
  24. Section("Graph Display") {
  25. Toggle("Display Dots", isOn: $showDots.value)
  26. .onChange(of: showDots.value) { _ in markDirty() }
  27. Toggle("Display Lines", isOn: $showLines.value)
  28. .onChange(of: showLines.value) { _ in markDirty() }
  29. if nightscoutEnabled {
  30. Toggle("Show DIA Lines", isOn: $showDIALines.value)
  31. .onChange(of: showDIALines.value) { _ in markDirty() }
  32. Toggle("Show −30 min Line", isOn: $show30MinLine.value)
  33. .onChange(of: show30MinLine.value) { _ in markDirty() }
  34. Toggle("Show −90 min Line", isOn: $show90MinLine.value)
  35. .onChange(of: show90MinLine.value) { _ in markDirty() }
  36. }
  37. Toggle("Show Midnight Lines", isOn: $showMidnightLines.value)
  38. .onChange(of: showMidnightLines.value) { _ in markDirty() }
  39. }
  40. // ── Treatments ───────────────────────────────────────────────
  41. if nightscoutEnabled {
  42. Section("Treatments") {
  43. Toggle("Show Carb/Bolus Values", isOn: $showValues.value)
  44. Toggle("Show Carb Absorption", isOn: $showAbsorption.value)
  45. Toggle("Treatments on Small Graph",
  46. isOn: $smallGraphTreatments.value)
  47. }
  48. }
  49. // ── Small Graph ──────────────────────────────────────────────
  50. Section("Small Graph") {
  51. SettingsStepperRow(
  52. title: "Height",
  53. range: 40 ... 80,
  54. step: 5,
  55. value: $smallGraphHeight.value,
  56. format: { "\(Int($0)) pt" }
  57. )
  58. .onChange(of: smallGraphHeight.value) { _ in markDirty() }
  59. }
  60. // ── Prediction ───────────────────────────────────────────────
  61. if nightscoutEnabled {
  62. Section("Prediction") {
  63. SettingsStepperRow(
  64. title: "Hours of Prediction",
  65. range: 0 ... 6,
  66. step: 0.25,
  67. value: $predictionToLoad.value,
  68. format: { "\($0.localized(maxFractionDigits: 2)) h" }
  69. )
  70. if Storage.shared.device.value != "Loop" {
  71. Picker("Prediction Style", selection: $predictionDisplayType.value) {
  72. ForEach(PredictionDisplayType.allCases, id: \.self) { type in
  73. Text(type.displayName).tag(type)
  74. }
  75. }
  76. .onChange(of: predictionDisplayType.value) { _ in markDirty() }
  77. }
  78. }
  79. }
  80. // ── Basal / BG scale ─────────────────────────────────────────
  81. if nightscoutEnabled {
  82. Section("Basal / BG Scale") {
  83. SettingsStepperRow(
  84. title: "Min Basal",
  85. range: 0.5 ... 20,
  86. step: 0.5,
  87. value: $minBasalScale.value,
  88. format: { "\($0.localized(maxFractionDigits: 1)) U/h" }
  89. )
  90. BGPicker(
  91. title: "Min BG Scale",
  92. range: 40 ... 400,
  93. value: $minBGScale.value
  94. )
  95. .onChange(of: minBGScale.value) { _ in markDirty() }
  96. }
  97. }
  98. // ── History window ───────────────────────────────────────────
  99. if nightscoutEnabled {
  100. Section("History") {
  101. SettingsStepperRow(
  102. title: "Show Days Back",
  103. range: 1 ... 4,
  104. step: 1,
  105. value: $downloadDays.value,
  106. format: { "\(Int($0)) d" }
  107. )
  108. }
  109. }
  110. }
  111. .preferredColorScheme(Storage.shared.appearanceMode.value.colorScheme)
  112. .navigationBarTitle("Graph Settings", displayMode: .inline)
  113. }
  114. /// Marks the chart as needing a redraw
  115. private func markDirty() {
  116. Observable.shared.chartSettingsChanged.value = true
  117. }
  118. }