// The BIRTHDAY face (reference `birthdays.png` and its cases) — the face of // a tool that reads another tool's table (Birthdays reads people). The // person in a round mount at the top with a sprig beside it, the name typed // heavy under it, their place in pencil and the corner's "why now" written in // red over a stroke of the pen when the core says one, a rule, then the cake // at the left and the facts at the right, filling the card's foot — the // birthday by hand under its label, the age it turns, whether wishes are // sent, when last wished. Every word is the core's (`DeckCard`). import CottonPaper import CottonValues import SwiftUI enum BirthdayFaceKnobs { static let inset = EdgeInsets(top: 22, leading: 22, bottom: 20, trailing: 20) static let mountShare: CGFloat = 0.42 static let nameSize: CGFloat = 25 static let placeSize: CGFloat = 13 static let cornerHand: CGFloat = 25 static let swash: CGSize = CGSize(width: 150, height: 7) static let factSize: CGFloat = 15.5 static let factGap: CGFloat = 7 static let dateHand: CGFloat = 29 static let cakeShare: CGFloat = 0.43 static let wishMark: CGFloat = 30 } public struct BirthdayFace: View { let card: DeckCard /// The person's photograph filling its frame; nil draws their initials. var photo: Photo? @Environment(\.theme) private var theme public init(card: DeckCard, photo: Photo? = nil) { self.card = card self.photo = photo } public var body: some View { GeometryReader { sheet in let mount = sheet.size.width * BirthdayFaceKnobs.mountShare VStack(spacing: 0) { ZStack { Group { if let photo { MountedPrint(photo: photo) } else { InitialsMount(name: card.text("title") ?? "") } } .frame(width: mount, height: mount) .clipShape(Circle()) .overlay(Circle().stroke(theme.print(.pencil).opacity(0.6), lineWidth: 1)) .padding(4) .overlay(Circle().stroke(theme.print(.pencil).opacity(0.35), lineWidth: 0.8)) .facePart(.picture) FaceArt(name: "face-art-sprig") .frame(height: mount * 0.95) .offset(x: mount * 0.72) } if let name = card.text("title") { HeavyType(words: name, size: BirthdayFaceKnobs.nameSize) .lineLimit(1) .minimumScaleFactor(0.7) .padding(.top, 10) .accessibilityIdentifier("deck-title") .facePart(.title) } if let place = card.text("subtitle") { Text(place) .font(CottonFonts.type(BirthdayFaceKnobs.placeSize)) .lineLimit(1) .faceInk(.pencil) .padding(.top, 2) .facePart(.subtitle) } // The corner's "why now" ("Birthday in 3 days") written in red // with a stroke of the pen under it, when the core says one. if let corner = card.corner { Text(HandRun.tail(corner)) .font(CottonFonts.hand(BirthdayFaceKnobs.cornerHand)) .lineLimit(1) .minimumScaleFactor(0.7) .faceInk(.red) .overlay(alignment: .bottom) { PenSwash() .stroke(theme.print(.red), style: StrokeStyle(lineWidth: 1.3, lineCap: .round)) .frame(width: BirthdayFaceKnobs.swash.width, height: BirthdayFaceKnobs.swash.height) .offset(y: BirthdayFaceKnobs.swash.height) .blendMode(theme.printBlend) } .rotationEffect(.degrees(-3)) .padding(.top, 2) .accessibilityIdentifier("face-corner") .facePart(.when) } FaceHairline() .padding(.top, 8) HStack(alignment: .center, spacing: 10) { FaceArt(name: "face-art-cake") .frame(width: sheet.size.width * BirthdayFaceKnobs.cakeShare) VStack(alignment: .leading, spacing: BirthdayFaceKnobs.factGap) { if let date = card.text("date") { VStack(alignment: .leading, spacing: 0) { if let label = card.label("date") { FaceLabel(words: label) } Text(HandRun.tail(date)) .font(CottonFonts.hand(BirthdayFaceKnobs.dateHand)) .lineLimit(1) .minimumScaleFactor(0.7) .faceInk(.ink) .fixedSize(horizontal: false, vertical: true) } .facePart(.when) .layoutPriority(1) } // The age it comes round to ("turns 35", said whole), // then when they were last wished under its label. if let turns = card.text("turns") { FaceHairline() FaceFact(value: turns, size: BirthdayFaceKnobs.factSize) } // Wishes are sent: the words, the inked envelope after them. if card.fields["wishes"] == .bool(true) { FaceHairline() HStack(spacing: 8) { if let label = card.label("wishes") { Text(label) .font(CottonFonts.type(BirthdayFaceKnobs.factSize)) .lineLimit(1) .minimumScaleFactor(0.7) .faceInk(.ink) } FaceArt(name: "act-bubble") .frame(height: BirthdayFaceKnobs.wishMark) } .accessibilityElement(children: .combine) } if let wished = card.text("last_wished") { FaceHairline() FaceFact(label: card.label("last_wished"), value: wished, size: BirthdayFaceKnobs.factSize) } } } .padding(.vertical, 8) .frame(maxHeight: .infinity) } .padding(BirthdayFaceKnobs.inset) } .onCardPaper(BirthdayFaceCatalogue.stock.laid(card.pace)) } } /// The birthday face, by the kind's name, and the cards it is reviewed in. public enum BirthdayFaceCatalogue { public static let stock: FaceStock = .cream public static let ground: FaceGround = .paper public static let face = Face(id: "birthday", specimens: [Specimen("birthday", birthday, picture: "portrait")]) { card, picture, _ in BirthdayFace(card: card, photo: picture) } public static let birthday = DeckCard(face: .birthday, fields: [ "title": .text("Ravi Example"), "date": .text("Thu 29 Oct"), "turns": .text("turns 52"), "wishes": .bool(true), "last_wished": .text("a year ago"), "photo": .text("portrait"), ]) }