import Foundation import CockpitKern import SwiftUI /// : oben die Tische (Klick holt einen nach vorn), darunter was gerade geschah. Sitzt der Laeufer /// nirgends, steht dort, was bis zum Spielen fehlt, und wie die letzte Sitzung lief. /// Die Sitzungsleiste ganz oben (wie WinUI LiveTeil/Rust sitzungsleiste.rs): das Ergebnis gross, /// darunter neun Kennzahlen im Dreierraster und der Abstand zum Sitzungs-Stop als Balken. struct SitzungsleisteAnsicht: View { var s: Sitzungsleiste var body: some View { VStack(alignment: .leading, spacing: 8) { HStack(spacing: 6) { Circle().fill(s.laeuft ? Color.green : Color.secondary).frame(width: 7, height: 7) Text(s.titel).font(.caption.weight(.semibold)).foregroundStyle(.secondary) Spacer() if !s.ende.isEmpty { Text(s.ende).font(s.warn ? .caption2.weight(.semibold) : .caption2) .foregroundStyle(s.warn ? AnyShapeStyle(Color.orange) : AnyShapeStyle(.tertiary)).lineLimit(2) } } HStack(alignment: .lastTextBaseline, spacing: 8) { Text(s.geld).font(.system(size: 30, weight: .bold, design: .rounded)).monospacedDigit() .foregroundStyle(Farben.name(s.ton)) if !s.bb.isEmpty { Text(s.bb).font(.callout.weight(.semibold)).monospacedDigit().foregroundStyle(Farben.name(s.ton)) } } // Wie WinUI: "Hände" steht im Tooltip der Tische-Zelle, nicht als eigene Zelle let haende = s.zellen.first { $0.titel == "Hände" } LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 6), count: 3), spacing: 6) { ForEach(Array(s.zellen.filter { $0.titel != "Hände" }.enumerated()), id: \.offset) { _, z in VStack(alignment: .leading, spacing: 1) { Text(z.titel).font(.caption2).foregroundStyle(.secondary).lineLimit(1) Text(z.wert).font(.system(size: 15, weight: .semibold, design: .rounded)).monospacedDigit() .foregroundStyle(Farben.name(z.ton)).lineLimit(1).minimumScaleFactor(0.7) } .frame(maxWidth: .infinity, alignment: .leading) .padding(8) .background(.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 10)) .help(z.titel == "Tische" && haende != nil ? "\(z.titel): \(z.wert)\nHände: \(haende!.wert)" : "\(z.titel): \(z.wert)") } } if let anteil = s.stoppAnteil { VStack(alignment: .leading, spacing: 3) { ProgressView(value: min(1, max(0, anteil))).tint(Farben.name(s.stoppTon)) Text(s.stoppText).font(.caption2).foregroundStyle(.secondary) } } else if !s.stoppText.isEmpty { Text(s.stoppText).font(.caption2).foregroundStyle(.secondary) } } .padding(12) .background(.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 14)) } } struct Abschnitt: View { var titel: String var hinweis: String? @ViewBuilder var rechts: Rechts var body: some View { HStack(alignment: .firstTextBaseline, spacing: 6) { Text(titel).font(.caption.weight(.semibold)).foregroundStyle(.secondary) if let hinweis { Text(hinweis).font(.caption2).foregroundStyle(.tertiary) } Spacer(minLength: 0) rechts } .padding(.top, 4) } } /// Ein einklappbarer Abschnitt: Kopfzeile mit Symbol und Chevron, Inhalt nur offen. Der Zustand /// merkt sich je `schluessel` (bleibt über Neustarts). So wird die lange Seite kurz - Nebeninfos /// liegen hinter einem Klick (Owner 7.11.: Infos hinter Expandables verstecken). struct EinklappAbschnitt: View { var titel: String var symbol: String var hinweis: String? var schluessel: String @ViewBuilder var inhalt: Inhalt @State private var offen: Bool init(titel: String, symbol: String, hinweis: String? = nil, schluessel: String, vorgabe: Bool = true, @ViewBuilder inhalt: () -> Inhalt) { self.titel = titel; self.symbol = symbol; self.hinweis = hinweis; self.schluessel = schluessel self.inhalt = inhalt() _offen = State(initialValue: UserDefaults.standard.object(forKey: schluessel) as? Bool ?? vorgabe) } var body: some View { VStack(alignment: .leading, spacing: 8) { Button { offen.toggle() UserDefaults.standard.set(offen, forKey: schluessel) } label: { HStack(alignment: .firstTextBaseline, spacing: 6) { Image(systemName: symbol).font(.caption2).foregroundStyle(.secondary).frame(width: 14) Text(titel).font(.caption.weight(.semibold)).foregroundStyle(.secondary) if let hinweis { Text(hinweis).font(.caption2).foregroundStyle(.tertiary) } Spacer(minLength: 0) Image(systemName: offen ? "chevron.down" : "chevron.right") .font(.caption2).foregroundStyle(.tertiary) } .contentShape(Rectangle()) } .buttonStyle(.plain) if offen { inhalt } } .padding(.top, 4) } } struct Foto: View { var url: URL var body: some View { AsyncImage(url: url) { bild in bild.resizable().scaledToFit().clipShape(RoundedRectangle(cornerRadius: 8)) } placeholder: { ProgressView().frame(maxWidth: .infinity, minHeight: 80) } } } /// Die Karte gibt beim Drücken sichtbar nach - man sieht, dass der Klick ankam. struct KartenDruck: ButtonStyle { func makeBody(configuration: Configuration) -> some View { configuration.label .scaleEffect(configuration.isPressed ? 0.98 : 1) .brightness(configuration.isPressed ? 0.06 : 0) .animation(.snappy(duration: 0.12), value: configuration.isPressed) } }