OverrideViewCell.swift 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // OverrideViewCell.swift
  3. // LoopKitUI
  4. //
  5. // Created by Anna Quinlan on 8/1/20.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. public struct OverrideViewCell: View {
  10. @Environment(\.lightenedInsulinTintColor) private var lightInsulin
  11. @Environment(\.darkenedInsulinTintColor) private var darkInsulin
  12. static let symbolWidth: CGFloat = 40
  13. var symbolLabel: Text
  14. var nameLabel: Text
  15. var targetRangeLabel: Text
  16. var durationLabel: Text
  17. var subtitleLabel: Text
  18. var insulinNeedsScaleFactor: Double?
  19. public init(
  20. symbol: Text,
  21. name: Text,
  22. targetRange: Text,
  23. duration: Text,
  24. subtitle: Text,
  25. insulinNeedsScaleFactor: Double?
  26. ) {
  27. self.symbolLabel = symbol
  28. self.nameLabel = name
  29. self.targetRangeLabel = targetRange
  30. self.durationLabel = duration
  31. self.subtitleLabel = subtitle
  32. self.insulinNeedsScaleFactor = insulinNeedsScaleFactor
  33. }
  34. public var body: some View {
  35. HStack {
  36. symbolLabel
  37. .font(.largeTitle)
  38. .frame(width: Self.symbolWidth) // for alignment
  39. VStack(alignment: .leading, spacing: 3) {
  40. nameLabel
  41. targetRangeLabel
  42. .font(.caption)
  43. .foregroundColor(Color.gray)
  44. if self.insulinNeedsScaleFactor != nil {
  45. insulinNeedsBar
  46. }
  47. }
  48. Spacer()
  49. VStack {
  50. HStack(spacing: 4) {
  51. timer
  52. durationLabel
  53. .font(.caption)
  54. }
  55. .foregroundColor(Color.gray)
  56. subtitleLabel
  57. .font(.caption)
  58. }
  59. }
  60. .frame(minHeight: 53)
  61. }
  62. private var insulinNeedsBar: some View {
  63. GeometryReader { geo in
  64. HStack {
  65. Group {
  66. if self.insulinNeedsScaleFactor != nil {
  67. SegmentedGaugeBar(insulinNeedsScaler: self.insulinNeedsScaleFactor!, startColor: lightInsulin, endColor: darkInsulin)
  68. .frame(minHeight: 12)
  69. }
  70. }
  71. Spacer(minLength: geo.size.width * 0.35) // Hack to fix spacing
  72. }
  73. }
  74. }
  75. var timer: some View {
  76. Image(systemName: "timer")
  77. .resizable()
  78. .frame(width: 12.0, height: 12.0)
  79. }
  80. }