forked from meshtastic/Meshtastic-Apple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBatteryLevel.swift
75 lines (66 loc) · 2.15 KB
/
BatteryLevel.swift
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
//
// BatteryLevel.swift
// Meshtastic
//
// Copyright Garth Vander Houwen 3/24/23.
//
import SwiftUI
struct BatteryIcon: View {
var batteryLevel: Int32?
var font: Font
var color: Color
var body: some View {
if batteryLevel == 100 {
Image(systemName: "battery.100.bolt")
.font(font)
.foregroundColor(color)
.symbolRenderingMode(.hierarchical)
} else if batteryLevel! < 100 && batteryLevel! > 74 {
Image(systemName: "battery.75")
.font(font)
.foregroundColor(color)
.symbolRenderingMode(.hierarchical)
} else if batteryLevel! < 75 && batteryLevel! > 49 {
Image(systemName: "battery.50")
.font(font)
.foregroundColor(color)
.symbolRenderingMode(.hierarchical)
} else if batteryLevel! < 50 && batteryLevel! > 14 {
Image(systemName: "battery.25")
.font(font)
.foregroundColor(color)
.symbolRenderingMode(.hierarchical)
} else if batteryLevel! < 15 && batteryLevel! > 0 {
Image(systemName: "battery.0")
.font(font)
.foregroundColor(color)
.symbolRenderingMode(.hierarchical)
} else if batteryLevel! == 0 {
Image(systemName: "battery.0")
.font(font)
.foregroundColor(.red)
.symbolRenderingMode(.hierarchical)
} else if batteryLevel! > 100 {
Image(systemName: "powerplug")
.font(font)
.foregroundColor(color)
.symbolRenderingMode(.hierarchical)
}
}
}
struct BatteryIcon_Previews: PreviewProvider {
static var previews: some View {
BatteryIcon(batteryLevel: 111, font: .title2, color: Color.accentColor)
.previewLayout(.fixed(width: 75, height: 75))
BatteryIcon(batteryLevel: 100, font: .title2, color: Color.accentColor)
.previewLayout(.fixed(width: 75, height: 75))
BatteryIcon(batteryLevel: 99, font: .title2, color: Color.accentColor)
.previewLayout(.fixed(width: 75, height: 75))
BatteryIcon(batteryLevel: 74, font: .title2, color: Color.accentColor)
.previewLayout(.fixed(width: 75, height: 75))
BatteryIcon(batteryLevel: 49, font: .title2, color: Color.accentColor)
.previewLayout(.fixed(width: 75, height: 75))
BatteryIcon(batteryLevel: 14, font: .title2, color: Color.accentColor)
.previewLayout(.fixed(width: 75, height: 75))
}
}