Fuel Savings: the feature's own settings grey out when it is switched off

With "Enable Worth the Drive" off, the MPG slider, the fill-up unit picker
and the fill-up slider stayed live — editable settings for a switched-off
feature. They now sit in a Group disabled by `enabled`, so they grey out but
stay on screen and keep their values (the same rule as the distance picker
in Closest mode), and re-enabling restores exactly what was there.

The surfaces that USE the feature were already gated on `isConfigured`
(which includes `enabled`), so the in-list fill-up control and the Worth the
Drive sort option still disappear entirely rather than greying out.

Verified on the simulator with the toggle off vs forced on: the MPG slider
row and the unit picker row both measurably dim — MPG row mean RGB
33.06/35.62/39.49 off vs 37.61/42.70/48.43 on; picker 40.00/40.00/42.62 vs
53.35/53.36/56.82 — while the toggle row itself changes as expected
(54.85/64.77/58.96 with the switch on).
This commit is contained in:
FuelBoard Contributor
2026-10-11 19:15:26 +01:00
parent cf3abb3fa7
commit 85f601fffd
+43 -33
View File
@@ -151,41 +151,51 @@ struct SettingsView: View {
Section {
Toggle("Enable Worth the Drive", isOn: fuelSavingsEnabledBinding)
HStack {
Text("Average fuel economy")
Spacer()
Text(mpgText)
.monospacedDigit()
.foregroundStyle(.secondary)
}
Slider(value: fuelSavingsMPGBinding,
in: FuelSavingsCalculator.mpgSliderRange,
step: FuelSavingsCalculator.mpgSliderStep)
.accessibilityLabel("Average fuel economy")
.accessibilityValue(mpgText)
Picker("Fill-up unit", selection: fuelSavingsUnitBinding) {
ForEach(FuelSavingsFillUnit.allCases) { unit in
Text(unit.displayName).tag(unit)
// The feature's own controls follow its toggle: switched
// off they grey out but stay on screen (same rule as the
// distance picker in Closest mode) and keep their values, so
// re-enabling restores exactly what was there. The sections
// that USE the feature — the in-list fill-up control and the
// Worth the Drive sort option — are gated on `isConfigured`,
// which already includes `enabled`, so they hide entirely.
Group {
HStack {
Text("Average fuel economy")
Spacer()
Text(mpgText)
.monospacedDigit()
.foregroundStyle(.secondary)
}
Slider(value: fuelSavingsMPGBinding,
in: FuelSavingsCalculator.mpgSliderRange,
step: FuelSavingsCalculator.mpgSliderStep)
.accessibilityLabel("Average fuel economy")
.accessibilityValue(mpgText)
Picker("Fill-up unit", selection: fuelSavingsUnitBinding) {
ForEach(FuelSavingsFillUnit.allCases) { unit in
Text(unit.displayName).tag(unit)
}
}
.pickerStyle(.segmented)
HStack {
Text("Typical fill-up")
Spacer()
Text(fillUpText)
.monospacedDigit()
.foregroundStyle(.secondary)
}
Slider(value: fuelSavingsAmountBinding,
in: FuelSavingsCalculator.fillAmountSliderRange(for: fuelSavingsSettings.preferredAmount.unit),
step: FuelSavingsCalculator.fillAmountSliderStep(for: fuelSavingsSettings.preferredAmount.unit))
.accessibilityLabel("Typical fill-up")
.accessibilityValue(fillUpText)
if !fuelSavingsSettings.isConfigured && fuelSavingsSettings.enabled {
Text("Set a realistic UK MPG and fill-up amount before Worth the Drive appears in sorting.")
.font(.caption)
.foregroundStyle(.orange)
}
}
.pickerStyle(.segmented)
HStack {
Text("Typical fill-up")
Spacer()
Text(fillUpText)
.monospacedDigit()
.foregroundStyle(.secondary)
}
Slider(value: fuelSavingsAmountBinding,
in: FuelSavingsCalculator.fillAmountSliderRange(for: fuelSavingsSettings.preferredAmount.unit),
step: FuelSavingsCalculator.fillAmountSliderStep(for: fuelSavingsSettings.preferredAmount.unit))
.accessibilityLabel("Typical fill-up")
.accessibilityValue(fillUpText)
if !fuelSavingsSettings.isConfigured && fuelSavingsSettings.enabled {
Text("Set a realistic UK MPG and fill-up amount before Worth the Drive appears in sorting.")
.font(.caption)
.foregroundStyle(.orange)
}
.disabled(!fuelSavingsSettings.enabled)
} header: {
Text("Fuel Savings")
} footer: {