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 {
|
} else {
|
||||||
Section("Fuel type") {
|
Section("Fuel type") {
|
||||||
Picker("Fuel type", selection: $fuel) {
|
FuelTypeSegmentedPicker(
|
||||||
ForEach(availableFuels) { fuel in
|
selection: $fuel,
|
||||||
Text(fuel.shortName).tag(fuel)
|
fuels: availableFuels
|
||||||
}
|
)
|
||||||
}
|
|
||||||
.pickerStyle(.segmented)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Section("\(activeFuel.displayName) favourites — cheapest first") {
|
Section("\(activeFuel.displayName) favourites — cheapest first") {
|
||||||
|
|||||||
@@ -204,14 +204,18 @@ extension FuelType {
|
|||||||
/// Fuel-type selector styled like a segmented control, with a coloured pump
|
/// Fuel-type selector styled like a segmented control, with a coloured pump
|
||||||
/// icon per fuel (green = unleaded, purple = premium, grey = diesel). Built
|
/// icon per fuel (green = unleaded, purple = premium, grey = diesel). Built
|
||||||
/// custom because the native `.segmented` picker tints every segment the same
|
/// custom because the native `.segmented` picker tints every segment the same
|
||||||
/// accent colour — it can't show per-fuel pump colours.
|
/// accent colour — it can't show per-fuel pump colours. Shared by the Stations
|
||||||
private struct FuelTypeSegmentedPicker: View {
|
/// and Favourites tabs.
|
||||||
|
struct FuelTypeSegmentedPicker: View {
|
||||||
@Binding var selection: FuelType
|
@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 {
|
var body: some View {
|
||||||
HStack(spacing: 3) {
|
HStack(spacing: 3) {
|
||||||
ForEach(FuelType.allCases) { fuel in
|
ForEach(fuels) { fuel in
|
||||||
let isSelected = fuel == selection
|
let isSelected = fuel == selection
|
||||||
Button {
|
Button {
|
||||||
selection = fuel
|
selection = fuel
|
||||||
|
|||||||
Reference in New Issue
Block a user