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