import Foundation import CockpitKern import SwiftUI // Der Überblick, wenn der Laeufer nirgends sitzt: was bis zum Spielen fehlt, wie die letzte Sitzung // lief, wo das Geld gegen die Stopps steht und was gerade geschah - als Bilder statt Tabellen. /// Bricht Marken um, wenn die Zeile voll ist. struct FlussLayout: Layout { var abstand: CGFloat func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize { let zeilen = anordnen(breite: proposal.width ?? .infinity, subviews) return CGSize(width: proposal.width ?? zeilen.map(\.breite).max() ?? 0, height: zeilen.map(\.hoehe).reduce(0, +) + abstand * CGFloat(max(0, zeilen.count - 1))) } func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) { var y = bounds.minY for z in anordnen(breite: bounds.width, subviews) { var x = bounds.minX for i in z.teile { let g = subviews[i].sizeThatFits(.unspecified) subviews[i].place(at: CGPoint(x: x, y: y), proposal: .unspecified) x += g.width + abstand } y += z.hoehe + abstand } } private func anordnen(breite: CGFloat, _ subviews: Subviews) -> [(teile: [Int], breite: CGFloat, hoehe: CGFloat)] { var zeilen: [(teile: [Int], breite: CGFloat, hoehe: CGFloat)] = [] for (i, s) in subviews.enumerated() { let g = s.sizeThatFits(.unspecified) if let letzte = zeilen.last, letzte.breite + abstand + g.width <= breite { zeilen[zeilen.count - 1].teile.append(i) zeilen[zeilen.count - 1].breite += abstand + g.width zeilen[zeilen.count - 1].hoehe = max(letzte.hoehe, g.height) } else { zeilen.append(([i], g.width, g.height)) } } return zeilen } } /// Eine kleine Spielkarte für Listen. struct MiniKarte: View { var code: String var body: some View { let k = Karte(code) VStack(spacing: -2) { Text(k?.rang ?? "?").font(.system(size: 10, weight: .bold, design: .rounded)) Text(k?.farbe.symbol ?? "").font(.system(size: 8)) } .foregroundStyle(k?.farbe.rot == true ? Color.red : Color.black) .frame(width: 16, height: 22) .background(Color.white.opacity(0.92), in: RoundedRectangle(cornerRadius: 3)) } } /// "Heute 10:09", "Gestern 01:36", sonst Datum und Uhrzeit. enum Tag { static func relativ(_ t: Double) -> String { let d = t.datum let kal = Calendar.current let uhr = Zeit.kurz(t) if kal.isDateInToday(d) { return "Heute \(uhr)" } if kal.isDateInYesterday(d) { return "Gestern \(uhr)" } return d.formatted(.dateTime.day().month(.abbreviated)) + " \(uhr)" } }