Cotton code
148 lines · 5.9 KB · SwiftRaw
// A studio's TRAINER in its own look (Codex round 2: syz-trainer; the// coordinator's review of aa7f6389e): the photograph across the top to the// card's edge, the name heavy, the styles in teal (`subtitle`), a line of who// they are (`body`), and their next classes as coral chips under the core's// label for them (`facts`: each class's words, the first's label). A trainer// whose card names no photograph is drawn on their initials, as a client is// (`ClientFace`). No action is drawn on the card. Every word is the core's.import CottonPaperimport CottonValuesimport SwiftUI/// A trainer: the photograph across the top, the name, the styles, a line/// of who they are, the next classes as coral chips; with no photograph,/// the client's face on their initials.public struct TrainerFace<Photo: View>: View {    let card: DeckCard    var photo: Photo?    /// The pages its card turns to after it (`card.pages`), each a column's    /// words under its label (`FaceTurns`).    var pages: [CardPage] = []    public init(card: DeckCard, photo: Photo?, pages: [CardPage] = []) {        self.card = card        self.photo = photo        self.pages = pages    }    public var body: some View {        if card.text("photo") == nil {            ClientFace(card: card, pages: pages)        } else {            FaceTurns(pages: pages) { pictured }                .onCardPaper(TrainerFaceCatalogue.stock.laid(card.pace))        }    }    private var pictured: some View {        GeometryReader { sheet in            VStack(alignment: .leading, spacing: 0) {                if let photo {                    photo                        .frame(width: sheet.size.width, height: sheet.size.height * StudioBrandKnobs.portraitShare)                        .clipped()                        .accessibilityIdentifier("face-photo")                        .facePart(.picture)                }                TrainerWords(card: card)                    .padding(StudioBrandKnobs.inset)                    .frame(width: sheet.size.width, alignment: .topLeading)            }            .frame(width: sheet.size.width, height: sheet.size.height, alignment: .topLeading)            .clipped()        }    }}private struct TrainerWords: View {    let card: DeckCard    @Environment(\.theme) private var theme    var body: some View {        VStack(alignment: .leading, spacing: 6) {            if let name = card.text("title") {                Text(name)                    .font(theme.type.display(StudioBrandKnobs.nameSize))                    .lineLimit(1)                    .minimumScaleFactor(0.6)                    .faceInk(.ink)                    .accessibilityIdentifier("deck-title")                    .facePart(.title)            }            if let line = card.text("subtitle") {                Text(line)                    .font(theme.type.title(StudioBrandKnobs.lineSize))                    .lineLimit(1)                    .minimumScaleFactor(0.75)                    .foregroundStyle(theme.colors.ink.color)                    .facePart(.subtitle)            }            if let about = card.text("body") {                Text(about)                    .font(theme.type.body(StudioBrandKnobs.aboutSize))                    .lineLimit(2)                    .foregroundStyle(theme.colors.inkBody.color.opacity(StudioFaceKnobs.labelFaint))                    .facePart(.body)            }            TrainerClasses(card: card).padding(.top, 6)        }    }}/// The next classes: the core's label for them by a calendar, each class's/// words on a coral chip.private struct TrainerClasses: View {    let card: DeckCard    @Environment(\.theme) private var theme    var body: some View {        let facts = StudioReading.facts(card)        if !facts.isEmpty {            HStack(spacing: 8) {                Image(systemName: "calendar")                    .font(theme.type.body(StudioBrandKnobs.chipSize + 3))                    .foregroundStyle(theme.colors.accent.color)                    .accessibilityHidden(true)                if let label = facts.first?.label {                    Text(label)                        .font(theme.type.body(StudioBrandKnobs.chipSize))                        .lineLimit(1)                        .fixedSize()                        .foregroundStyle(theme.colors.inkBody.color)                }                ForEach(Array(facts.prefix(2).enumerated()), id: \.offset) { _, fact in                    Text(fact.said)                        .font(theme.type.title(StudioBrandKnobs.chipSize))                        .lineLimit(1)                        .minimumScaleFactor(0.7)                        .foregroundStyle(theme.colors.accent.color)                        .padding(StudioBrandKnobs.chipPad)                        .background(Capsule().fill(theme.colors.accent.color.opacity(StudioBrandKnobs.chipFaint)))                }            }            .accessibilityElement(children: .combine)            .accessibilityIdentifier("face-classes")        }    }}/// The trainer face, and the cards it is reviewed in. A studio's kit names/// it for its trainers (`sharmila.trainer`), with the pages its card turns/// to.public enum TrainerFaceCatalogue {    public static let stock: FaceStock = .cream    public static let ground: FaceGround = .paper    public static let face = Face(id: "sharmila.trainer", specimens: [Specimen("trainer", trainer)]) { card, picture, _ in        TrainerFace(card: card, photo: picture, pages: card.pages)    }    public static let trainer = DeckCard(face: .sharmilaTrainer, fields: [        "photo": .text("k"), "title": .text("Invented Trainer"), "subtitle": .text("Yoga Instructor"),        "body": .text("An invented line."),        "facts": .list([            .object(["label": .text("Invented label"), "said": .text("Mon 9:15 AM")]),            .object(["label": .text("Invented label"), "said": .text("Wed 11:30 AM")]),        ]),    ])}