Cotton code
94 lines · 4.0 KB · SwiftRaw
// The music ALBUM on the album face (card kind `album` on a table whose// card opens into tracks; the Codex album-1 card, 23 Oct 2026): its own art// large at the head — while it keeps none, a sleeve a size smaller printed// with its title and artist — the title typed heavy under it, the artist by// hand (`subtitle`), and the year, how many songs and how long (`year`,// `count`, `length`) typed in pencil, joined as the cards join words. Every// word is the core's (`DeckCard`); the deck tells an album of songs from an// album of pictures (`MusicWhole.of`, CottonUI).import CottonPaperimport CottonValuesimport SwiftUIpublic struct MusicAlbumFace<Art: View>: View {    let card: DeckCard    /// The album's own art; nil draws its sleeve.    var art: Art?    public init(card: DeckCard, art: Art?) {        self.card = card        self.art = art    }    public var body: some View {        GeometryReader { sheet in            let side = min(sheet.size.width * MusicWholeKnobs.artWidth, sheet.size.height * MusicWholeKnobs.artHeight)            VStack(spacing: 0) {                Spacer(minLength: 0)                Group {                    if let art {                        MountedPrint(photo: art).frame(width: side, height: side)                    } else {                        TypeSleeve(title: card.text("title"), artist: card.text("subtitle"))                            .frame(width: side * MusicPartsKnobs.sleeveShare, height: side * MusicPartsKnobs.sleeveShare)                    }                }                .accessibilityHidden(true)                .facePart(.picture)                VStack(spacing: 4) {                    if let title = card.text("title") {                        HeavyType(words: title, size: MusicWholeKnobs.titleSize)                            .multilineTextAlignment(.center)                            .lineLimit(2)                            .minimumScaleFactor(0.7)                            .accessibilityIdentifier("deck-title")                            .facePart(.title)                    }                    if let artist = card.text("subtitle") {                        Text(artist)                            .font(CottonFonts.hand(MusicWholeKnobs.artistHand))                            .lineLimit(1)                            .minimumScaleFactor(0.6)                            .faceInk(.ink)                            .accessibilityIdentifier("face-byline")                            .facePart(.subtitle)                    }                    if let facts = MusicWhole.joined([card.text("year"), card.text("count"), card.text("length")]) {                        Text(facts)                            .font(CottonFonts.type(MusicWholeKnobs.factsSize))                            .lineLimit(1)                            .minimumScaleFactor(0.8)                            .faceInk(.pencil)                            .accessibilityIdentifier("face-facts")                    }                }                .padding(.top, 20)                Spacer(minLength: 0)            }            .frame(maxWidth: .infinity)            .padding(MusicWholeKnobs.inset)        }        .onCardPaper(MusicAlbumFaceCatalogue.stock.laid(card.pace))    }}/// The music album face, and the cards it is reviewed in. No card kind names/// it yet (`music.album`): the deck draws it for an album whose whole deals/// tracks (the album face, `whole`); here it is drawn from its card alone,/// its art the picture the card names.public enum MusicAlbumFaceCatalogue {    public static let stock: FaceStock = .cream    public static let ground: FaceGround = .paper    public static let face = Face(id: "music.album", specimens: [Specimen("monsoon", monsoon)]) { card, picture, _ in        MusicAlbumFace(card: card, art: picture)    }    public static let monsoon = DeckCard(face: .musicAlbum, fields: [        "title": .text("Invented Monsoon"),        "subtitle": .text("Invented Quartet"),        "year": .text("2019"),        "count": .text("9 songs"),        "length": .text("41:12"),    ])}