Price display: station sign drops the £ (134.9) — matches roadside signs; pounds & pence uses forecourt superscript style £1.29⁹/L (small superscript third digit, small /L); attributed Text on list/widgets/Live Activity, Unicode superscript in Siri cards

This commit is contained in:
FuelBoard Contributor
2026-08-14 18:14:10 +01:00
parent fd7fa5f9c9
commit 80113456ae
7 changed files with 76 additions and 33 deletions
+1 -3
View File
@@ -553,9 +553,7 @@ struct StationRow: View {
Circle() Circle()
.fill(ragColor) .fill(ragColor)
.frame(width: 8, height: 8) .frame(width: 8, height: 8)
Text(FuelStore.priceText(price, style: priceDisplayStyle)) FuelStore.priceTextAttributed(price, style: priceDisplayStyle, size: 20, weight: .bold)
.font(.title3.bold().monospaced())
.monospacedDigit()
} }
if let deltaText { if let deltaText {
Text(deltaText) Text(deltaText)
+1 -1
View File
@@ -103,7 +103,7 @@ struct SettingsView: View {
} header: { } header: {
Text("Units") Text("Units")
} footer: { } footer: {
Text("Distances and search radii across the app, widget and alerts are shown in this unit. Prices can be shown as on a station sign (£129.9) or in pounds and pence (£1.299).") Text("Distances and search radii across the app, widget and alerts are shown in this unit. Prices can be shown as on a station sign (129.9) or in pounds and pence (£1.29⁹/L).")
} }
Section { Section {
+1 -1
View File
@@ -51,7 +51,7 @@
/* Settings tab */ /* Settings tab */
"Units" = "Units"; "Units" = "Units";
"Price display" = "Price display"; "Price display" = "Price display";
"Distances and search radii across the app, widget and alerts are shown in this unit. Prices can be shown as on a station sign (£129.9) or in pounds and pence (£1.299)." = "Distances and search radii across the app, widget and alerts are shown in this unit. Prices can be shown as on a station sign (£129.9) or in pounds and pence (£1.299)."; "Distances and search radii across the app, widget and alerts are shown in this unit. Prices can be shown as on a station sign (129.9) or in pounds and pence (£1.29⁹/L)." = "Distances and search radii across the app, widget and alerts are shown in this unit. Prices can be shown as on a station sign (129.9) or in pounds and pence (£1.29⁹/L).";
"Show introduction" = "Show introduction"; "Show introduction" = "Show introduction";
"Replay the welcome screen, including the location and notification permission prompts." = "Replay the welcome screen, including the location and notification permission prompts."; "Replay the welcome screen, including the location and notification permission prompts." = "Replay the welcome screen, including the location and notification permission prompts.";
"Test alert notification (real data)" = "Test alert notification (real data)"; "Test alert notification (real data)" = "Test alert notification (real data)";
@@ -566,15 +566,18 @@ final class SiriCheapestLookupTests: XCTestCase {
final class PriceDisplayTests: XCTestCase { final class PriceDisplayTests: XCTestCase {
func testStationSignStyle() { func testStationSignStyle() {
XCTAssertEqual(FuelStore.priceText(129.9, style: .stationSign), "£129.9") // Bare pence figure, no £ exactly the roadside sign.
XCTAssertEqual(FuelStore.priceText(135.0, style: .stationSign), "£135.0") XCTAssertEqual(FuelStore.priceText(129.9, style: .stationSign), "129.9")
XCTAssertEqual(FuelStore.priceText(249.9, style: .stationSign), "£249.9") XCTAssertEqual(FuelStore.priceText(135.0, style: .stationSign), "135.0")
XCTAssertEqual(FuelStore.priceText(249.9, style: .stationSign), "249.9")
} }
func testPoundsPenceStyle() { func testPoundsPenceStyle() {
XCTAssertEqual(FuelStore.priceText(129.9, style: .poundsPence), "£1.299") // Forecourt superscript style: £ + 2dp + small superscript third digit + /L.
XCTAssertEqual(FuelStore.priceText(135.0, style: .poundsPence), "£1.350") XCTAssertEqual(FuelStore.priceText(129.9, style: .poundsPence), "£1.29⁹/L")
XCTAssertEqual(FuelStore.priceText(100.9, style: .poundsPence), "£1.009") XCTAssertEqual(FuelStore.priceText(135.0, style: .poundsPence), "£1.35⁰/L")
XCTAssertEqual(FuelStore.priceText(100.9, style: .poundsPence), "£1.00⁹/L")
XCTAssertEqual(FuelStore.priceText(199.9, style: .poundsPence), "£1.99⁹/L")
} }
func testSpokenAlwaysPounds() { func testSpokenAlwaysPounds() {
@@ -70,8 +70,7 @@ private struct FuelBoardLiveActivityView: View {
// RIGHT price // RIGHT price
VStack(alignment: .trailing, spacing: 2) { VStack(alignment: .trailing, spacing: 2) {
Text(context.state.priceText) FuelStore.priceTextAttributed(context.state.pricePence, size: 22, weight: .bold)
.font(.title2.bold().monospacedDigit())
Text("Tap for directions") Text("Tap for directions")
.font(.caption2) .font(.caption2)
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
@@ -87,8 +86,7 @@ private struct FuelBoardLiveActivityPriceView: View {
let context: ActivityViewContext<FuelBoardLiveActivityAttributes> let context: ActivityViewContext<FuelBoardLiveActivityAttributes>
var body: some View { var body: some View {
Text(context.state.priceText) FuelStore.priceTextAttributed(context.state.pricePence, size: 17, weight: .bold)
.font(.headline.bold().monospacedDigit())
} }
} }
@@ -128,7 +126,7 @@ extension FuelBoardLiveActivityAttributes.ContentState {
} }
/// Price string from pence, in the user's chosen display style /// Price string from pence, in the user's chosen display style
/// (station sign "£129.9" or pounds "£1.299"). /// (station sign "129.9" or pounds "£1.29/L").
var priceText: String { var priceText: String {
FuelStore.priceText(pricePence) FuelStore.priceText(pricePence)
} }
+2 -6
View File
@@ -395,9 +395,7 @@ struct FuelPriceWidgetView: View {
.font(.headline) .font(.headline)
.lineLimit(1) .lineLimit(1)
if let price = station.prices[entry.fuel] { if let price = station.prices[entry.fuel] {
Text(FuelStore.priceText(price)) FuelStore.priceTextAttributed(price, size: 26, weight: .bold, color: .green)
.font(.system(size: 26, weight: .bold).monospaced())
.foregroundStyle(.green)
} }
if let location = entry.location { if let location = entry.location {
Text(entry.unit.format(station.distanceKM(to: location.lat, lng2: location.lng)) + " away") Text(entry.unit.format(station.distanceKM(to: location.lat, lng2: location.lng)) + " away")
@@ -455,9 +453,7 @@ struct FuelPriceWidgetView: View {
Circle() Circle()
.fill(ragColor(for: price, cheapest: cheapest)) .fill(ragColor(for: price, cheapest: cheapest))
.frame(width: 6, height: 6) .frame(width: 6, height: 6)
Text(FuelStore.priceText(price)) FuelStore.priceTextAttributed(price, size: 12, weight: .bold)
.font(.caption.weight(.bold).monospaced())
.foregroundStyle(.primary)
} }
} }
} }
+59 -11
View File
@@ -9,6 +9,7 @@
import Foundation import Foundation
import Security import Security
import SwiftUI
// MARK: - Fuel types // MARK: - Fuel types
@@ -145,19 +146,20 @@ enum DistanceUnit: String, Codable, CaseIterable, Identifiable {
/// Display style for fuel prices. Internally prices are always stored and /// Display style for fuel prices. Internally prices are always stored and
/// computed in pence-per-litre (GOV.UK's unit, e.g. 129.9); the style only /// computed in pence-per-litre (GOV.UK's unit, e.g. 129.9); the style only
/// affects RENDERING: the station-sign convention shows the pence figure /// affects RENDERING: the station-sign convention shows the bare pence
/// ("£129.9", what a forecourt sign shows), pounds & pence shows the /// figure ("129.9", no £ exactly what a UK forecourt sign shows), pounds &
/// converted value ("£1.299"). Calculations never see this. /// pence shows the converted value in the forecourt's superscript style
/// ("£1.29/L"). Calculations never see this.
enum PriceDisplayStyle: String, Codable, CaseIterable, Identifiable { enum PriceDisplayStyle: String, Codable, CaseIterable, Identifiable {
case stationSign // £129.9 matches the sign case stationSign // 129.9 bare pence figure, like the roadside sign
case poundsPence // £1.299 case poundsPence // £1.29/L small superscript third digit, small /L
var id: String { rawValue } var id: String { rawValue }
var displayName: String { var displayName: String {
switch self { switch self {
case .stationSign: return "Station sign (£129.9)" case .stationSign: return "Station sign (129.9)"
case .poundsPence: return "Pounds & pence (£1.299)" case .poundsPence: return "Pounds & pence (£1.29)"
} }
} }
} }
@@ -454,7 +456,7 @@ struct FuelStore {
saveString(unit.rawValue, service: distanceUnitKey) saveString(unit.rawValue, service: distanceUnitKey)
} }
// MARK: Price display station-sign (£129.9) vs pounds & pence (£1.299). // MARK: Price display station sign (129.9) vs pounds & pence (£1.29/L).
// Prices are always stored/computed in pence-per-litre; this style only // Prices are always stored/computed in pence-per-litre; this style only
// changes how they are RENDERED, so it can never affect calculations. // changes how they are RENDERED, so it can never affect calculations.
// Default station sign = the forecourt convention. // Default station sign = the forecourt convention.
@@ -472,12 +474,58 @@ struct FuelStore {
saveString(style.rawValue, service: priceDisplayStyleKey) saveString(style.rawValue, service: priceDisplayStyleKey)
} }
/// Superscript digit glyphs for the pounds & pence format's small raised
/// third digit (the forecourt style: "£1.29").
private static let superscriptDigits: [Character] = ["", "¹", "²", "³", "", "", "", "", "", ""]
/// Render a pence-per-litre price per the saved style: /// Render a pence-per-litre price per the saved style:
/// stationSign -> "£129.9" (sign convention), poundsPence -> "£1.299". /// stationSign -> "129.9" (bare pence figure, no £ the roadside sign),
/// poundsPence -> "£1.29/L" (pounds with a superscript third digit and a
/// small /L unit, matching UK garage displays).
static func priceText(_ pence: Double, style: PriceDisplayStyle? = nil) -> String { static func priceText(_ pence: Double, style: PriceDisplayStyle? = nil) -> String {
switch style ?? loadPriceDisplayStyle() { switch style ?? loadPriceDisplayStyle() {
case .stationSign: return String(format: "£%.1f", pence) case .stationSign:
case .poundsPence: return String(format: "£%.3f", pence / 100) return String(format: "%.1f", pence)
case .poundsPence:
let tenths = Int((pence * 10).rounded())
let whole = tenths / 1000
let major = (tenths % 1000) / 10
let minor = tenths % 10
return String(format: "£%d.%02d", whole, major)
+ String(superscriptDigits[minor])
+ "/L"
}
}
/// Rich, forecourt-styled price text for SwiftUI surfaces. Same formats as
/// `priceText`, but the pounds & pence mode renders the third digit small
/// and superscripted and /L small and muted proper text styling instead
/// of Unicode glyphs. Pass the surface's size/weight/color; the returned
/// Text carries its own fonts, so do NOT apply `.font(...)` on top.
static func priceTextAttributed(_ pence: Double, style: PriceDisplayStyle? = nil,
size: CGFloat = 17, weight: Font.Weight = .semibold,
color: Color = .primary) -> Text {
let s = style ?? loadPriceDisplayStyle()
let base = Font.system(size: size, weight: weight).monospaced()
switch s {
case .stationSign:
return Text(priceText(pence, style: s)).font(base).foregroundColor(color)
case .poundsPence:
let tenths = Int((pence * 10).rounded())
let whole = tenths / 1000
let major = (tenths % 1000) / 10
let minor = tenths % 10
let main = Text(String(format: "£%d.%02d", whole, major))
.font(base)
.foregroundColor(color)
let sup = Text(String(superscriptDigits[minor]))
.font(.system(size: size * 0.6, weight: weight).monospaced())
.baselineOffset(size * 0.35)
.foregroundColor(color)
let perL = Text("/L")
.font(.system(size: size * 0.5, weight: .regular).monospaced())
.foregroundColor(color.opacity(0.55))
return main + sup + perL
} }
} }