Guardrail+UI.swift 783 B

12345678910111213141516171819202122232425262728293031
  1. //
  2. // Guardrail+UI.swift
  3. // LoopKitUI
  4. //
  5. // Created by Michael Pangburn on 7/15/20.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. import HealthKit
  10. import LoopKit
  11. extension Guardrail where Value == HKQuantity {
  12. func color(for quantity: HKQuantity,
  13. guidanceColors: GuidanceColors) -> Color
  14. {
  15. switch classification(for: quantity) {
  16. case .withinRecommendedRange:
  17. return guidanceColors.acceptable
  18. case .outsideRecommendedRange(let threshold):
  19. switch threshold {
  20. case .minimum, .maximum:
  21. return guidanceColors.critical
  22. case .belowRecommended, .aboveRecommended:
  23. return guidanceColors.warning
  24. }
  25. }
  26. }
  27. }