From d37aab04f1998093dc042c72d740b6091ac6b4f7 Mon Sep 17 00:00:00 2001 From: FuelBoard Contributor Date: Wed, 12 Aug 2026 16:35:42 +0100 Subject: [PATCH] =?UTF-8?q?Widget:=20family-aware=20row=20cap=20=E2=80=94?= =?UTF-8?q?=20large/extraLarge=20show=205=20stations,=20medium=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 3-row cap was hardcoded for the medium widget height; large widgets have ~2x the height and fit 5 compact rows. Timeline now carries up to 8 stations (was 4) so the large list never starves. Distance picker still controls which stations are in range; the visible row count now depends on widget size, not the distance setting. --- FuelBoardWidgets/FuelPriceWidget.swift | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/FuelBoardWidgets/FuelPriceWidget.swift b/FuelBoardWidgets/FuelPriceWidget.swift index c28205c..0f20f60 100644 --- a/FuelBoardWidgets/FuelPriceWidget.swift +++ b/FuelBoardWidgets/FuelPriceWidget.swift @@ -64,7 +64,7 @@ struct FuelPriceTimelineProvider: AppIntentTimelineProvider { .filter { $0.prices[.e10] != nil } .sorted { $0.prices[.e10]! < $1.prices[.e10]! } return FuelPriceEntry( - date: Date(), stations: Array(sample.prefix(4)), + date: Date(), stations: Array(sample.prefix(8)), fuel: .e10, sort: .cheapest, isFavourites: false, location: nil, locationSource: "none", unit: unit ) @@ -189,7 +189,7 @@ struct FuelPriceTimelineProvider: AppIntentTimelineProvider { } return FuelPriceEntry( - date: Date(), stations: Array(ordered.prefix(4)), + date: Date(), stations: Array(ordered.prefix(8)), fuel: fuel, sort: sort, isFavourites: isFavourites, location: location, locationSource: source, unit: unit @@ -287,6 +287,16 @@ struct FuelPriceWidgetView: View { .widgetURL(station.widgetDirectionsURL) } + /// How many station rows each family can fit: medium widgets are short + /// (158pt) so 3 rows is the safe cap; large/extraLarge have ~2× the height + /// and fit 5 compact rows. Small widgets use singleStation instead. + private var maxRows: Int { + switch family { + case .systemMedium: return 3 + default: return 5 + } + } + private var stationList: some View { let cheapest = entry.stations.compactMap { $0.prices[entry.fuel] }.min() return VStack(alignment: .leading, spacing: 6) { @@ -302,7 +312,7 @@ struct FuelPriceWidgetView: View { .font(.caption2) .foregroundStyle(.secondary) } - ForEach(entry.stations.prefix(3)) { station in + ForEach(entry.stations.prefix(maxRows)) { station in Link(destination: station.widgetDirectionsURL ?? URL(string: "maps://")!) { HStack(spacing: 8) { Text(station.name)