diff --git a/NucleicRemote/NucleicRemote/Views/HomeView.swift b/NucleicRemote/NucleicRemote/Views/HomeView.swift index dffb1c0..773b729 100644 --- a/NucleicRemote/NucleicRemote/Views/HomeView.swift +++ b/NucleicRemote/NucleicRemote/Views/HomeView.swift @@ -128,18 +128,23 @@ private struct InProgressSessions: View { } private struct StatCard: View { - let value: String + /// Candidate renderings of the value, widest first: the card shows the fullest one its width + /// allows (via `ViewThatFits`) and falls back to the narrowest. A single entry for the plain + /// integer cards; several for the token card, so a wide card shows more digits than "1.6B". + let values: [String] let label: String let icon: String init(value: Int, label: String, icon: String) { - self.value = "\(value)" - self.label = label - self.icon = icon + self.init(values: ["\(value)"], label: label, icon: icon) } init(value: String, label: String, icon: String) { - self.value = value + self.init(values: [value], label: label, icon: icon) + } + + init(values: [String], label: String, icon: String) { + self.values = values.isEmpty ? [""] : values self.label = label self.icon = icon } @@ -147,7 +152,14 @@ private struct StatCard: View { var body: some View { VStack(alignment: .leading, spacing: 4) { Image(systemName: icon).foregroundStyle(Palette.accent) - Text(value).font(.title2.weight(.semibold).monospacedDigit()) + // Show the fullest value the card's width fits, shrinking toward the compact form when + // narrow; ViewThatFits renders the last candidate if none fit, so it never overflows. + ViewThatFits(in: .horizontal) { + ForEach(Array(values.enumerated()), id: \.offset) { _, value in + Text(value).font(.title2.weight(.semibold).monospacedDigit()) + .lineLimit(1) + } + } Text(label).font(.caption).foregroundStyle(.secondary) } .frame(maxWidth: .infinity, alignment: .leading)