From c7ff9322ef144dae7eae9e93a994c3ff32cb6cac Mon Sep 17 00:00:00 2001 From: Stefan Lange-Hegermann Date: Tue, 21 Oct 2025 23:17:53 +0200 Subject: [PATCH] useful battery editor view --- Cable/BatteryEditorView.swift | 70 ++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 6 deletions(-) diff --git a/Cable/BatteryEditorView.swift b/Cable/BatteryEditorView.swift index fd9ff4d..f8d8ed5 100644 --- a/Cable/BatteryEditorView.swift +++ b/Cable/BatteryEditorView.swift @@ -158,13 +158,18 @@ struct BatteryEditorView: View { } var body: some View { - List { - configurationSection - sliderSection + VStack(spacing: 0) { + headerInfoBar + List { + configurationSection + summarySection + sliderSection + } + .listStyle(.plain) + .scrollIndicators(.hidden) + .scrollContentBackground(.hidden) + .background(Color.clear) } - .listStyle(.plain) - .scrollIndicators(.hidden) - .scrollContentBackground(.hidden) .background(Color(.systemGroupedBackground).ignoresSafeArea()) .navigationTitle("") .navigationBarTitleDisplayMode(.inline) @@ -500,6 +505,59 @@ struct BatteryEditorView: View { .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 { let rounded = (value * 10).rounded() / 10 if let snapped = nearestValue(to: rounded, in: voltageSnapValues, tolerance: voltageSnapTolerance) {