From 8868368392a708e17fa464f91898b974bb625844 Mon Sep 17 00:00:00 2001 From: Stefan Lange-Hegermann Date: Tue, 28 Oct 2025 22:53:37 +0100 Subject: [PATCH] better layout of the advanced sections --- Cable/Batteries/BatteryEditorView.swift | 176 +++++++++++++----------- Cable/Loads/CalculatorView.swift | 37 ++--- 2 files changed, 112 insertions(+), 101 deletions(-) diff --git a/Cable/Batteries/BatteryEditorView.swift b/Cable/Batteries/BatteryEditorView.swift index 3ccb8e4..aabc50d 100644 --- a/Cable/Batteries/BatteryEditorView.swift +++ b/Cable/Batteries/BatteryEditorView.swift @@ -886,18 +886,6 @@ struct BatteryEditorView: View { .listRowSeparator(.hidden) .listRowBackground(Color(.systemBackground)) } - } footer: { - if isAdvancedExpanded { - VStack(alignment: .leading, spacing: 8) { - Text(usableCapacityFooterText) - Text(chargeVoltageHelperText) - Text(cutOffVoltageHelperText) - Text(temperatureRangeHelperText) - } - .font(.caption) - .foregroundStyle(.secondary) - .opacity(advancedEnabled ? 1 : 0.35) - } } .listRowSeparator(.hidden) .listRowInsets(EdgeInsets(top: 12, leading: 18, bottom: 12, trailing: 18)) @@ -906,84 +894,104 @@ struct BatteryEditorView: View { private var advancedControls: some View { VStack(spacing: 16) { - EditableSliderRow( - title: usableCapacitySliderTitle, - unit: "%", - range: usableCapacitySliderRange, - value: Binding( - get: { configuration.usableCapacityFraction * 100 }, - set: { newValue in - updateUsableCapacityPercent(newValue) - } - ), - buttonText: resetButtonTitle, - buttonAction: resetUsableCapacityToDefault, - isButtonVisible: hasUsableCapacityOverride, - snapValues: usableCapacitySnapValues, - sliderTransform: roundToTenth, - alertTransform: roundToTenth, - formatValue: formattedEditValue, - parseInput: parseInput, - alertCopy: EditableSliderRow.AlertCopy( - title: usableCapacityAlertTitle, - placeholder: usableCapacityAlertPlaceholder, - message: usableCapacityAlertMessage, - cancelTitle: alertCancelTitle, - saveTitle: alertSaveTitle + VStack(alignment: .leading, spacing: 8) { + EditableSliderRow( + title: usableCapacitySliderTitle, + unit: "%", + range: usableCapacitySliderRange, + value: Binding( + get: { configuration.usableCapacityFraction * 100 }, + set: { newValue in + updateUsableCapacityPercent(newValue) + } + ), + buttonText: resetButtonTitle, + buttonAction: resetUsableCapacityToDefault, + isButtonVisible: hasUsableCapacityOverride, + snapValues: usableCapacitySnapValues, + sliderTransform: roundToTenth, + alertTransform: roundToTenth, + formatValue: formattedEditValue, + parseInput: parseInput, + alertCopy: EditableSliderRow.AlertCopy( + title: usableCapacityAlertTitle, + placeholder: usableCapacityAlertPlaceholder, + message: usableCapacityAlertMessage, + cancelTitle: alertCancelTitle, + saveTitle: alertSaveTitle + ) ) - ) + Text(usableCapacityFooterText) + .font(.caption) + .foregroundStyle(.secondary) + } - EditableSliderRow( - title: chargeVoltageTitle, - unit: "V", - range: chargeVoltageSliderRange, - value: Binding( - get: { configuration.chargeVoltage }, - set: { newValue in - let clamped = max(newValue, configuration.cutOffVoltage) - configuration.chargeVoltage = clamped - } - ), - snapValues: chargeVoltageSnapValues, - sliderTransform: normalizedChargeVoltage, - alertTransform: roundToTenth, - formatValue: formattedEditValue, - parseInput: parseInput, - alertCopy: EditableSliderRow.AlertCopy( - title: chargeVoltageAlertTitle, - placeholder: chargeVoltageAlertPlaceholder, - message: chargeVoltageAlertMessage, - cancelTitle: alertCancelTitle, - saveTitle: alertSaveTitle + VStack(alignment: .leading, spacing: 8) { + EditableSliderRow( + title: chargeVoltageTitle, + unit: "V", + range: chargeVoltageSliderRange, + value: Binding( + get: { configuration.chargeVoltage }, + set: { newValue in + let clamped = max(newValue, configuration.cutOffVoltage) + configuration.chargeVoltage = clamped + } + ), + snapValues: chargeVoltageSnapValues, + sliderTransform: normalizedChargeVoltage, + alertTransform: roundToTenth, + formatValue: formattedEditValue, + parseInput: parseInput, + alertCopy: EditableSliderRow.AlertCopy( + title: chargeVoltageAlertTitle, + placeholder: chargeVoltageAlertPlaceholder, + message: chargeVoltageAlertMessage, + cancelTitle: alertCancelTitle, + saveTitle: alertSaveTitle + ) ) - ) + Text(chargeVoltageHelperText) + .font(.caption) + .foregroundStyle(.secondary) + } - EditableSliderRow( - title: cutOffVoltageTitle, - unit: "V", - range: cutOffVoltageSliderRange, - value: Binding( - get: { configuration.cutOffVoltage }, - set: { newValue in - let clamped = min(newValue, configuration.chargeVoltage) - configuration.cutOffVoltage = clamped - } - ), - snapValues: cutOffVoltageSnapValues, - sliderTransform: normalizedCutOffVoltage, - alertTransform: roundToTenth, - formatValue: formattedEditValue, - parseInput: parseInput, - alertCopy: EditableSliderRow.AlertCopy( - title: cutOffVoltageAlertTitle, - placeholder: cutOffVoltageAlertPlaceholder, - message: cutOffVoltageAlertMessage, - cancelTitle: alertCancelTitle, - saveTitle: alertSaveTitle + VStack(alignment: .leading, spacing: 8) { + EditableSliderRow( + title: cutOffVoltageTitle, + unit: "V", + range: cutOffVoltageSliderRange, + value: Binding( + get: { configuration.cutOffVoltage }, + set: { newValue in + let clamped = min(newValue, configuration.chargeVoltage) + configuration.cutOffVoltage = clamped + } + ), + snapValues: cutOffVoltageSnapValues, + sliderTransform: normalizedCutOffVoltage, + alertTransform: roundToTenth, + formatValue: formattedEditValue, + parseInput: parseInput, + alertCopy: EditableSliderRow.AlertCopy( + title: cutOffVoltageAlertTitle, + placeholder: cutOffVoltageAlertPlaceholder, + message: cutOffVoltageAlertMessage, + cancelTitle: alertCancelTitle, + saveTitle: alertSaveTitle + ) ) - ) + Text(cutOffVoltageHelperText) + .font(.caption) + .foregroundStyle(.secondary) + } - temperatureRangeRow + VStack(alignment: .leading, spacing: 8) { + temperatureRangeRow + Text(temperatureRangeHelperText) + .font(.caption) + .foregroundStyle(.secondary) + } } .padding(.top, 6) } diff --git a/Cable/Loads/CalculatorView.swift b/Cable/Loads/CalculatorView.swift index 26880c5..35af11a 100644 --- a/Cable/Loads/CalculatorView.swift +++ b/Cable/Loads/CalculatorView.swift @@ -1040,26 +1040,29 @@ struct CalculatorView: View { .listRowSeparator(.hidden) .listRowBackground(Color(.systemBackground)) } - dutyCycleSlider - .listRowSeparator(.hidden) - .listRowBackground(Color(.systemBackground)) - .opacity(advancedEnabled ? 1 : 0.35) - .allowsHitTesting(advancedEnabled) - usageHoursSlider - .listRowSeparator(.hidden) - .listRowBackground(Color(.systemBackground)) - .opacity(advancedEnabled ? 1 : 0.35) - .allowsHitTesting(advancedEnabled) - } - } footer: { - if isAdvancedExpanded { VStack(alignment: .leading, spacing: 8) { + dutyCycleSlider + .listRowSeparator(.hidden) + .listRowBackground(Color(.systemBackground)) + .opacity(advancedEnabled ? 1 : 0.35) + .allowsHitTesting(advancedEnabled) Text(dutyCycleHelperText) - Text(usageHoursHelperText) + .font(.caption) + .foregroundStyle(.secondary) + .opacity(advancedEnabled ? 1 : 0.35) + } + + VStack(alignment: .leading, spacing: 8) { + usageHoursSlider + .listRowSeparator(.hidden) + .listRowBackground(Color(.systemBackground)) + .opacity(advancedEnabled ? 1 : 0.35) + .allowsHitTesting(advancedEnabled) + Text(usageHoursHelperText) + .font(.caption) + .foregroundStyle(.secondary) + .opacity(advancedEnabled ? 1 : 0.35) } - .font(.caption) - .foregroundStyle(.secondary) - .opacity(advancedEnabled ? 1 : 0.35) } } .listRowSeparator(.hidden)