Cotton code
103 lines · 3.9 KB · SwiftRaw
// The VIDEO face (image 11): a video is the still laid straight on the cream// stock with a play button and its length on it, its title typed under it// and its date in the hand. A tap on the still opens it in the one viewer// (`DeckViewer`). Every word is the core's (`FaceRead`).import CottonPaperimport CottonValuesimport SwiftUIpublic enum VideoFaceKnobs {    static let stillInset = EdgeInsets(top: 13, leading: 16, bottom: 0, trailing: 13)    static let stillShare: CGFloat = 0.76    static let play: CGFloat = 42    public static let playOpacity: Double = 0.78    static let lengthSize: CGFloat = 10.5    static let titleSize: CGFloat = 13.5    static let dateHand: CGFloat = 16    static let textLead: CGFloat = 26}public struct VideoFace<Still: View>: View {    let card: DeckCard    /// The film's poster filling its frame.    let still: Still?    public init(card: DeckCard, still: Still?) {        self.card = card        self.still = still    }    public var body: some View {        GeometryReader { sheet in            VStack(alignment: .leading, spacing: 0) {                ZStack {                    if let still { MountedPrint(photo: still) } else { Color.clear }                    PlayDisc(size: VideoFaceKnobs.play)                    if let length = card.text("length") {                        LengthBadge(words: length)                            .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing)                            .padding(8)                    }                }                .accessibilityElement(children: .ignore)                .accessibilityLabel(card.text("title") ?? "")                .frame(height: sheet.size.height * VideoFaceKnobs.stillShare)                .padding(VideoFaceKnobs.stillInset)                .facePart(.picture)                VStack(alignment: .leading, spacing: 8) {                    if let title = card.text("title") {                        Text(title)                            .font(CottonFonts.type(VideoFaceKnobs.titleSize))                            .lineLimit(2)                            .faceInk(.ink)                            .facePart(.title)                    }                    if let date = card.text("date") {                        Text(date)                            .font(CottonFonts.hand(VideoFaceKnobs.dateHand))                            .faceInk(.pencil)                            .facePart(.when)                    }                }                .padding(.horizontal, VideoFaceKnobs.textLead)                .padding(.top, 20)                Spacer(minLength: 0)            }        }        .onCardPaper(VideoFaceCatalogue.stock.laid(card.pace))    }}/// A video's length on a small dark plate in the still's corner.struct LengthBadge: View {    let words: String    @Environment(\.theme) private var theme    var body: some View {        Text(words)            .font(CottonFonts.type(VideoFaceKnobs.lengthSize))            .foregroundStyle(theme.colors.paper.color)            .padding(.horizontal, 6)            .padding(.vertical, 3)            .background(RoundedRectangle(cornerRadius: 3, style: .continuous).fill(theme.print(.ink).opacity(0.82)))    }}/// The video face, by the kind's name, and the cards it is reviewed in. The/// still is always handed over, held or not (`HeldPicture`), as a deck hands/// it.public enum VideoFaceCatalogue {    public static let stock: FaceStock = .cream    public static let ground: FaceGround = .paper    public static let face = Face(id: "video", specimens: [Specimen("falls", falls, picture: "waterfall")]) { card, picture, taps in        VideoFace(card: card, still: HeldPicture(picture))    }    public static let falls = DeckCard(face: .video, fields: [        "title": .text("Abbey Falls, after the rain"),        "date": .text("11 Sep 2026"),        "length": .text("0:42"),        "photo": .text("waterfall"),    ])}