useful battery editor view
This commit is contained in:
@@ -158,13 +158,18 @@ struct BatteryEditorView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
VStack(spacing: 0) {
|
||||||
configurationSection
|
headerInfoBar
|
||||||
sliderSection
|
List {
|
||||||
|
configurationSection
|
||||||
|
summarySection
|
||||||
|
sliderSection
|
||||||
|
}
|
||||||
|
.listStyle(.plain)
|
||||||
|
.scrollIndicators(.hidden)
|
||||||
|
.scrollContentBackground(.hidden)
|
||||||
|
.background(Color.clear)
|
||||||
}
|
}
|
||||||
.listStyle(.plain)
|
|
||||||
.scrollIndicators(.hidden)
|
|
||||||
.scrollContentBackground(.hidden)
|
|
||||||
.background(Color(.systemGroupedBackground).ignoresSafeArea())
|
.background(Color(.systemGroupedBackground).ignoresSafeArea())
|
||||||
.navigationTitle("")
|
.navigationTitle("")
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
@@ -500,6 +505,59 @@ struct BatteryEditorView: View {
|
|||||||
.listRowInsets(EdgeInsets(top: 12, leading: 18, bottom: 12, trailing: 18))
|
.listRowInsets(EdgeInsets(top: 12, leading: 18, bottom: 12, trailing: 18))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var headerInfoBar: some View {
|
||||||
|
HStack(spacing: 12) {
|
||||||
|
overviewChip(
|
||||||
|
icon: "bolt.fill",
|
||||||
|
title: summaryVoltageLabel.uppercased(),
|
||||||
|
value: formattedValue(configuration.nominalVoltage, unit: "V"),
|
||||||
|
tint: .orange
|
||||||
|
)
|
||||||
|
|
||||||
|
overviewChip(
|
||||||
|
icon: "gauge.medium",
|
||||||
|
title: summaryCapacityLabel.uppercased(),
|
||||||
|
value: formattedValue(configuration.capacityAmpHours, unit: "Ah"),
|
||||||
|
tint: .blue
|
||||||
|
)
|
||||||
|
|
||||||
|
overviewChip(
|
||||||
|
icon: "battery.100.bolt",
|
||||||
|
title: summaryEnergyLabel.uppercased(),
|
||||||
|
value: formattedValue(configuration.energyWattHours, unit: "Wh"),
|
||||||
|
tint: .purple
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
.padding(.horizontal)
|
||||||
|
.padding(.vertical, 8)
|
||||||
|
.background(Color(.systemGroupedBackground))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func overviewChip(icon: String, title: String, value: String, tint: Color) -> some View {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
HStack(spacing: 6) {
|
||||||
|
Image(systemName: icon)
|
||||||
|
.font(.system(size: 14, weight: .semibold))
|
||||||
|
.foregroundStyle(tint)
|
||||||
|
Text(value)
|
||||||
|
.font(.subheadline.weight(.semibold))
|
||||||
|
.foregroundStyle(.primary)
|
||||||
|
}
|
||||||
|
Text(title)
|
||||||
|
.font(.caption2)
|
||||||
|
.fontWeight(.medium)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 10)
|
||||||
|
.padding(.vertical, 8)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: 10, style: .continuous)
|
||||||
|
.fill(tint.opacity(0.12))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private func normalizedVoltage(for value: Double) -> Double {
|
private func normalizedVoltage(for value: Double) -> Double {
|
||||||
let rounded = (value * 10).rounded() / 10
|
let rounded = (value * 10).rounded() / 10
|
||||||
if let snapped = nearestValue(to: rounded, in: voltageSnapValues, tolerance: voltageSnapTolerance) {
|
if let snapped = nearestValue(to: rounded, in: voltageSnapValues, tolerance: voltageSnapTolerance) {
|
||||||
|
|||||||
Reference in New Issue
Block a user