better layout of the advanced sections

This commit is contained in:
Stefan Lange-Hegermann
2025-10-28 22:53:37 +01:00
parent a2314585ea
commit 8868368392
2 changed files with 112 additions and 101 deletions

View File

@@ -886,18 +886,6 @@ struct BatteryEditorView: View {
.listRowSeparator(.hidden) .listRowSeparator(.hidden)
.listRowBackground(Color(.systemBackground)) .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) .listRowSeparator(.hidden)
.listRowInsets(EdgeInsets(top: 12, leading: 18, bottom: 12, trailing: 18)) .listRowInsets(EdgeInsets(top: 12, leading: 18, bottom: 12, trailing: 18))
@@ -906,84 +894,104 @@ struct BatteryEditorView: View {
private var advancedControls: some View { private var advancedControls: some View {
VStack(spacing: 16) { VStack(spacing: 16) {
EditableSliderRow( VStack(alignment: .leading, spacing: 8) {
title: usableCapacitySliderTitle, EditableSliderRow(
unit: "%", title: usableCapacitySliderTitle,
range: usableCapacitySliderRange, unit: "%",
value: Binding( range: usableCapacitySliderRange,
get: { configuration.usableCapacityFraction * 100 }, value: Binding(
set: { newValue in get: { configuration.usableCapacityFraction * 100 },
updateUsableCapacityPercent(newValue) set: { newValue in
} updateUsableCapacityPercent(newValue)
), }
buttonText: resetButtonTitle, ),
buttonAction: resetUsableCapacityToDefault, buttonText: resetButtonTitle,
isButtonVisible: hasUsableCapacityOverride, buttonAction: resetUsableCapacityToDefault,
snapValues: usableCapacitySnapValues, isButtonVisible: hasUsableCapacityOverride,
sliderTransform: roundToTenth, snapValues: usableCapacitySnapValues,
alertTransform: roundToTenth, sliderTransform: roundToTenth,
formatValue: formattedEditValue, alertTransform: roundToTenth,
parseInput: parseInput, formatValue: formattedEditValue,
alertCopy: EditableSliderRow.AlertCopy( parseInput: parseInput,
title: usableCapacityAlertTitle, alertCopy: EditableSliderRow.AlertCopy(
placeholder: usableCapacityAlertPlaceholder, title: usableCapacityAlertTitle,
message: usableCapacityAlertMessage, placeholder: usableCapacityAlertPlaceholder,
cancelTitle: alertCancelTitle, message: usableCapacityAlertMessage,
saveTitle: alertSaveTitle cancelTitle: alertCancelTitle,
saveTitle: alertSaveTitle
)
) )
) Text(usableCapacityFooterText)
.font(.caption)
.foregroundStyle(.secondary)
}
EditableSliderRow( VStack(alignment: .leading, spacing: 8) {
title: chargeVoltageTitle, EditableSliderRow(
unit: "V", title: chargeVoltageTitle,
range: chargeVoltageSliderRange, unit: "V",
value: Binding( range: chargeVoltageSliderRange,
get: { configuration.chargeVoltage }, value: Binding(
set: { newValue in get: { configuration.chargeVoltage },
let clamped = max(newValue, configuration.cutOffVoltage) set: { newValue in
configuration.chargeVoltage = clamped let clamped = max(newValue, configuration.cutOffVoltage)
} configuration.chargeVoltage = clamped
), }
snapValues: chargeVoltageSnapValues, ),
sliderTransform: normalizedChargeVoltage, snapValues: chargeVoltageSnapValues,
alertTransform: roundToTenth, sliderTransform: normalizedChargeVoltage,
formatValue: formattedEditValue, alertTransform: roundToTenth,
parseInput: parseInput, formatValue: formattedEditValue,
alertCopy: EditableSliderRow.AlertCopy( parseInput: parseInput,
title: chargeVoltageAlertTitle, alertCopy: EditableSliderRow.AlertCopy(
placeholder: chargeVoltageAlertPlaceholder, title: chargeVoltageAlertTitle,
message: chargeVoltageAlertMessage, placeholder: chargeVoltageAlertPlaceholder,
cancelTitle: alertCancelTitle, message: chargeVoltageAlertMessage,
saveTitle: alertSaveTitle cancelTitle: alertCancelTitle,
saveTitle: alertSaveTitle
)
) )
) Text(chargeVoltageHelperText)
.font(.caption)
.foregroundStyle(.secondary)
}
EditableSliderRow( VStack(alignment: .leading, spacing: 8) {
title: cutOffVoltageTitle, EditableSliderRow(
unit: "V", title: cutOffVoltageTitle,
range: cutOffVoltageSliderRange, unit: "V",
value: Binding( range: cutOffVoltageSliderRange,
get: { configuration.cutOffVoltage }, value: Binding(
set: { newValue in get: { configuration.cutOffVoltage },
let clamped = min(newValue, configuration.chargeVoltage) set: { newValue in
configuration.cutOffVoltage = clamped let clamped = min(newValue, configuration.chargeVoltage)
} configuration.cutOffVoltage = clamped
), }
snapValues: cutOffVoltageSnapValues, ),
sliderTransform: normalizedCutOffVoltage, snapValues: cutOffVoltageSnapValues,
alertTransform: roundToTenth, sliderTransform: normalizedCutOffVoltage,
formatValue: formattedEditValue, alertTransform: roundToTenth,
parseInput: parseInput, formatValue: formattedEditValue,
alertCopy: EditableSliderRow.AlertCopy( parseInput: parseInput,
title: cutOffVoltageAlertTitle, alertCopy: EditableSliderRow.AlertCopy(
placeholder: cutOffVoltageAlertPlaceholder, title: cutOffVoltageAlertTitle,
message: cutOffVoltageAlertMessage, placeholder: cutOffVoltageAlertPlaceholder,
cancelTitle: alertCancelTitle, message: cutOffVoltageAlertMessage,
saveTitle: alertSaveTitle 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) .padding(.top, 6)
} }

View File

@@ -1040,26 +1040,29 @@ struct CalculatorView: View {
.listRowSeparator(.hidden) .listRowSeparator(.hidden)
.listRowBackground(Color(.systemBackground)) .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) { VStack(alignment: .leading, spacing: 8) {
dutyCycleSlider
.listRowSeparator(.hidden)
.listRowBackground(Color(.systemBackground))
.opacity(advancedEnabled ? 1 : 0.35)
.allowsHitTesting(advancedEnabled)
Text(dutyCycleHelperText) 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) .listRowSeparator(.hidden)