2021-09-18 15:33:35 -07:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
|
|
struct BatteryIcon: View {
|
|
|
|
|
var batteryLevel: Int32?
|
|
|
|
|
var font: Font
|
|
|
|
|
var color: Color
|
2021-11-29 15:59:06 -08:00
|
|
|
|
2021-09-18 15:33:35 -07:00
|
|
|
var body: some View {
|
2021-11-29 15:59:06 -08:00
|
|
|
|
2021-09-18 15:33:35 -07:00
|
|
|
if batteryLevel == 100 {
|
2021-11-29 15:59:06 -08:00
|
|
|
|
2021-10-01 08:33:11 -07:00
|
|
|
Image(systemName: "battery.100.bolt")
|
2021-09-18 15:33:35 -07:00
|
|
|
.font(font)
|
|
|
|
|
.foregroundColor(color)
|
2021-09-20 22:29:10 -07:00
|
|
|
.symbolRenderingMode(.hierarchical)
|
2021-11-29 15:59:06 -08:00
|
|
|
} else if batteryLevel! < 100 && batteryLevel! > 74 {
|
|
|
|
|
|
2021-09-18 15:33:35 -07:00
|
|
|
Image(systemName: "battery.75")
|
|
|
|
|
.font(font)
|
|
|
|
|
.foregroundColor(color)
|
2021-09-20 22:29:10 -07:00
|
|
|
.symbolRenderingMode(.hierarchical)
|
2021-11-29 15:59:06 -08:00
|
|
|
} else if batteryLevel! < 75 && batteryLevel! > 49 {
|
|
|
|
|
|
2021-09-18 15:33:35 -07:00
|
|
|
Image(systemName: "battery.50")
|
|
|
|
|
.font(font)
|
|
|
|
|
.foregroundColor(color)
|
2021-09-20 22:29:10 -07:00
|
|
|
.symbolRenderingMode(.hierarchical)
|
2021-11-29 15:59:06 -08:00
|
|
|
} else if batteryLevel! < 50 && batteryLevel! > 14 {
|
|
|
|
|
|
2021-09-18 15:33:35 -07:00
|
|
|
Image(systemName: "battery.25")
|
|
|
|
|
.font(font)
|
|
|
|
|
.foregroundColor(color)
|
2021-10-01 08:33:11 -07:00
|
|
|
.symbolRenderingMode(.hierarchical)
|
2021-11-29 15:59:06 -08:00
|
|
|
} else if batteryLevel! == 0 {
|
|
|
|
|
|
2021-10-01 08:33:11 -07:00
|
|
|
Image(systemName: "powerplug")
|
|
|
|
|
.font(font)
|
|
|
|
|
.foregroundColor(color)
|
2021-09-20 22:29:10 -07:00
|
|
|
.symbolRenderingMode(.hierarchical)
|
2021-11-29 15:59:06 -08:00
|
|
|
} else {
|
|
|
|
|
|
2021-09-18 15:33:35 -07:00
|
|
|
Image(systemName: "battery.0")
|
|
|
|
|
.font(font)
|
|
|
|
|
.foregroundColor(color)
|
2021-09-20 22:29:10 -07:00
|
|
|
.symbolRenderingMode(.hierarchical)
|
2021-09-18 15:33:35 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct BatteryIcon_Previews: PreviewProvider {
|
|
|
|
|
static var previews: some View {
|
2021-10-17 20:30:04 -07:00
|
|
|
BatteryIcon(batteryLevel: 100, font: .title2, color: Color.accentColor)
|
2021-09-18 17:10:22 -07:00
|
|
|
.previewLayout(.fixed(width: 75, height: 75))
|
2021-10-17 20:30:04 -07:00
|
|
|
BatteryIcon(batteryLevel: 99, font: .title2, color: Color.accentColor)
|
2021-09-18 17:10:22 -07:00
|
|
|
.previewLayout(.fixed(width: 75, height: 75))
|
2021-10-17 20:30:04 -07:00
|
|
|
BatteryIcon(batteryLevel: 74, font: .title2, color: Color.accentColor)
|
2021-09-18 17:10:22 -07:00
|
|
|
.previewLayout(.fixed(width: 75, height: 75))
|
2021-10-17 20:30:04 -07:00
|
|
|
BatteryIcon(batteryLevel: 49, font: .title2, color: Color.accentColor)
|
2021-09-18 17:10:22 -07:00
|
|
|
.previewLayout(.fixed(width: 75, height: 75))
|
2021-10-17 20:30:04 -07:00
|
|
|
BatteryIcon(batteryLevel: 14, font: .title2, color: Color.accentColor)
|
2021-09-18 17:10:22 -07:00
|
|
|
.previewLayout(.fixed(width: 75, height: 75))
|
2021-09-18 15:33:35 -07:00
|
|
|
}
|
|
|
|
|
}
|