Cotton code
91 lines · 4.1 KB · SwiftRaw
// AN EMPTY DECK SAYS ITS LINE ALONE (the coordinator, 4 Nov 2026: the Books// Plus walk's empty Reading drew a blank grey card over "A place for your// next book."). With no card to show there is no card drawn: no blank// sheet, no tool picture standing in for one. The line stands on the ground// where the card's centre would be — the 4:5 card as large as the deck's room// allows, laid from its top (`DeckSurface.deck`, `CardDeck.deck`) — so the// words sit where the eye already is, and the fan's acts tier beneath it as// they do under a card. Every deck's empty state is this: a view's own line,// the table's first-record words, ink that narrowed to nothing, a table that// could not be read with Try again, a deck of tools or of Home's cards. On// a dark ground the shell lays (an empty Cotton Books deck on its navy// felt, `DeckGround.laid`) the words take the ground's light ink whole// (`DeckGround.ink(.ink)`), never its pencil: the pencil, the cream thinned// to the print's pencil, read low on the navy felt (Books 1.0.0 (3) and (4)// walks, 7 Nov 2026); on a light ground of its own, the print's ink whole,// as paper's grey vanished on the terrazzo and the rose linen (12 Nov 2026).// One rule for every ground.import CottonFacesimport CottonPaperimport SwiftUIstruct DeckEmptyLine: View {    let title: String    var message: String = ""    /// The one forward verb (Back up, Try again), under the words.    var actionLabel: String? = nil    var actionIdentifier: String? = nil    var action: (() -> Void)? = nil    @Environment(\.theme) private var theme    @Environment(\.fanCover) private var cover    /// Where the card's centre would stand in a deck's room of `size`,    /// down from the room's top: the 4:5 card as large as the room allows,    /// laid from the top, as the deck lays its front card.    static func centre(in size: CGSize) -> CGFloat {        let width = max(0, min(size.width, size.height * CardPaperKnobs.aspect))        return width / CardPaperKnobs.aspect / 2    }    /// The words' ink on `ground`: on a ground of its own its ink, whole    /// (light on a dark ground, dark on a light one); on paper the theme's    /// secondary ink.    static func ink(on ground: FaceGround?, theme: Theme) -> Color {        DeckGround.own(ground) ? DeckGround.ink(.ink, on: ground, theme: theme) : theme.colors.inkSecondary.color    }    var body: some View {        GeometryReader { room in            words                .padding(.horizontal, DeckEmptyLineKnobs.side)                .frame(width: room.size.width)                .fixedSize(horizontal: false, vertical: true)                .position(x: room.size.width / 2, y: Self.centre(in: room.size))        }    }    private var words: some View {        VStack(spacing: DeckEmptyLineKnobs.actionGap) {            VStack(spacing: DeckEmptyLineKnobs.lineGap) {                Text(title)                    .scaledFace { theme.type.body((theme.scale.bodySize + 1) * $0) }                if !message.isEmpty {                    Text(message)                        .scaledFace { theme.type.body((theme.scale.bodySize - 1) * $0) }                }            }            .foregroundStyle(Self.ink(on: cover?.ground, theme: theme))            .multilineTextAlignment(.center)            .accessibilityElement(children: .combine)            if let actionLabel, let action {                Button(actionLabel, action: action)                    .buttonStyle(MotionButtonStyle())                    .scaledFace { theme.type.body(theme.scale.bodySize * $0) }                    .foregroundStyle(theme.colors.accent.color)                    .frame(minHeight: DeckEmptyLineKnobs.actionMinHeight)                    .accessibilityIdentifier(actionIdentifier ?? "")            }        }    }}/// The sizes DeckEmptyLine draws with: Swift's own, beside their reader.enum DeckEmptyLineKnobs {    /// The words' reach from the screen's sides.    static let side: CGFloat = 28    static let lineGap: CGFloat = 6    static let actionGap: CGFloat = 18    static let actionMinHeight: CGFloat = 44}