Favourites tab: fuel-type selector gets the same coloured pump icons
- FuelTypeSegmentedPicker promoted to shared (was private in StationsView) and parameterised by fuel list so Favourites passes only fuels with favourites - Favourites tab swaps native .segmented picker for the capsule control with green/purple/grey fuelpump icons, matching Stations
This commit is contained in:
@@ -84,12 +84,10 @@ struct FavouritesView: View {
|
||||
}
|
||||
} else {
|
||||
Section("Fuel type") {
|
||||
Picker("Fuel type", selection: $fuel) {
|
||||
ForEach(availableFuels) { fuel in
|
||||
Text(fuel.shortName).tag(fuel)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
FuelTypeSegmentedPicker(
|
||||
selection: $fuel,
|
||||
fuels: availableFuels
|
||||
)
|
||||
}
|
||||
|
||||
Section("\(activeFuel.displayName) favourites — cheapest first") {
|
||||
|
||||
@@ -204,14 +204,18 @@ extension FuelType {
|
||||
/// Fuel-type selector styled like a segmented control, with a coloured pump
|
||||
/// icon per fuel (green = unleaded, purple = premium, grey = diesel). Built
|
||||
/// custom because the native `.segmented` picker tints every segment the same
|
||||
/// accent colour — it can't show per-fuel pump colours.
|
||||
private struct FuelTypeSegmentedPicker: View {
|
||||
/// accent colour — it can't show per-fuel pump colours. Shared by the Stations
|
||||
/// and Favourites tabs.
|
||||
struct FuelTypeSegmentedPicker: View {
|
||||
@Binding var selection: FuelType
|
||||
var onSelect: (FuelType) -> Void
|
||||
/// Which fuels to show. Defaults to all; the Favourites tab passes only
|
||||
/// the fuels that actually have favourites.
|
||||
var fuels: [FuelType] = FuelType.allCases
|
||||
var onSelect: (FuelType) -> Void = { _ in }
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 3) {
|
||||
ForEach(FuelType.allCases) { fuel in
|
||||
ForEach(fuels) { fuel in
|
||||
let isSelected = fuel == selection
|
||||
Button {
|
||||
selection = fuel
|
||||
|
||||
Reference in New Issue
Block a user