DFStatusOrb.swift
1.98 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
//
// DFStatusOrb.swift
// hippo-watch-extension
//
import SwiftUI
struct DFStatusOrb: View {
let status: DFStressStatus
let value: String
let themeImage: Image?
init(status: DFStressStatus, value: String, themeImage: Image? = nil) {
self.status = status
self.value = value
self.themeImage = themeImage
}
var body: some View {
ZStack {
Circle()
.fill(status.color.opacity(0.16))
if let themeImage {
themeImage
.resizable()
.scaledToFit()
.clipShape(Circle())
.padding(4)
}
Circle()
.stroke(status.color.opacity(0.34), lineWidth: 5)
Circle()
.trim(from: 0.12, to: 0.82)
.stroke(status.color, style: StrokeStyle(lineWidth: 5, lineCap: .round))
.rotationEffect(.degrees(110))
if value.isEmpty {
if themeImage == nil {
Image(systemName: "heart.text.square.fill")
.font(.system(size: 12, weight: .semibold))
.foregroundStyle(status.color)
}
} else if themeImage == nil {
VStack(spacing: -1) {
Text(value)
.font(.system(size: 14, weight: .bold, design: .rounded))
.foregroundStyle(.white)
Text("ms")
.font(.system(size: 7, weight: .medium))
.foregroundStyle(.white.opacity(0.74))
}
} else {
Text(value)
.font(.system(size: 13, weight: .bold, design: .rounded))
.foregroundStyle(.white)
.padding(.horizontal, 4)
.padding(.vertical, 2)
.background(Color.black.opacity(0.45), in: Capsule())
}
}
}
}