DFDefaultHomeFaceView.swift
2.96 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
//
// DFDefaultHomeFaceView.swift
// hippo-watch-extension
//
import SwiftUI
struct DFDefaultHomeFaceView: View {
let entry: DFWatchFaceEntry
var body: some View {
GeometryReader { proxy in
let scale = min(proxy.size.width / 172, proxy.size.height / 74)
let content = entry.theme?.faceContent(for: entry.data.myStatus)
HStack(spacing: 8 * scale) {
VStack(alignment: .leading, spacing: 2 * scale) {
HStack(spacing: 4 * scale) {
Text(entry.date, format: .dateTime.weekday(.abbreviated))
.foregroundStyle(DFWatchFaceColor.purple)
Text(entry.date, format: .dateTime.day())
.foregroundStyle(.white)
}
.font(.system(size: 11 * scale, weight: .semibold))
Text(entry.date, style: .time)
.font(.system(size: 25 * scale, weight: .medium, design: .rounded))
.foregroundStyle(.white)
.lineLimit(1)
.minimumScaleFactor(0.7)
DFSegmentBar(selected: entry.data.hasData ? entry.data.myStatus : nil)
.frame(height: 7 * scale)
}
if let image = content?.image {
image
.resizable()
.scaledToFit()
.frame(width: 30 * scale, height: 30 * scale)
}
VStack(alignment: .trailing, spacing: 5 * scale) {
HStack(spacing: 5 * scale) {
DFMiniMetric(value: entry.data.hasData ? "\(entry.data.heartRate)" : "0", icon: "heart.fill", tint: DFWatchFaceColor.red)
DFMiniMetric(value: "\(entry.data.closePercent)", icon: "sparkles", tint: DFWatchFaceColor.purple)
DFMiniMetric(value: entry.data.hasData ? shortSteps(entry.data.steps) : "0", icon: "shoeprints.fill", tint: DFWatchFaceColor.green)
}
Text(entry.data.hasData ? "\(content?.title ?? entry.data.myStatus.title) · \(entry.data.hrvValue)ms" : "暂无数据 · --ms")
.font(.system(size: 10 * scale, weight: .semibold))
.foregroundStyle(entry.data.hasData ? entry.data.myStatus.color : DFWatchFaceColor.grayText)
.lineLimit(1)
.minimumScaleFactor(0.7)
Text(entry.data.hasData ? entry.data.hrvTime : "--:--")
.font(.system(size: 9 * scale, weight: .medium))
.foregroundStyle(.white.opacity(0.78))
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(.horizontal, 6)
}
}
private func shortSteps(_ steps: Int) -> String {
steps >= 1000 ? "\(steps / 1000)k" : "\(steps)"
}
}