Cotton code
93 lines · 3.9 KB · SwiftRaw
// The TOOLS deck (row B of the deck faces): the Tools card on the dial opens// a deck with one card per installed tool, never a grid or a list. Each card// is the framed cream card with the tool's own picture large at its top, its// name typed heavy, what it is for (`purpose`) typed under it, and at the// foot what its home table holds, in the core's words ("42 open · 3 due").// A tap opens the tool; a hold lifts the card with its acts. The picture is// the app's (`object`, CottonUI's `ToolObject` at the side the face gives// it).import CottonPaperimport CottonValuesimport SwiftUIenum ToolFaceKnobs {    static let inset = EdgeInsets(top: 26, leading: 26, bottom: 22, trailing: 22)    static let pictureShare: CGFloat = 0.58    static let nameSize: CGFloat = 30    static let purposeSize: CGFloat = 15    static let figureSize: CGFloat = 13}public struct ToolFace<Object: View>: View {    let name: String    let purpose: String?    /// What its home table holds, as the core said it.    let figure: String?    /// The tool's picture, at the side the face gives it.    let object: (_ side: CGFloat) -> Object    public init(name: String, purpose: String?, figure: String?, @ViewBuilder object: @escaping (_ side: CGFloat) -> Object) {        self.name = name        self.purpose = purpose        self.figure = figure        self.object = object    }    public var body: some View {        GeometryReader { sheet in            VStack(alignment: .leading, spacing: 0) {                object(sheet.size.width * ToolFaceKnobs.pictureShare)                    .frame(width: sheet.size.width * ToolFaceKnobs.pictureShare, height: sheet.size.width * ToolFaceKnobs.pictureShare)                    .facePart(.picture)                    .frame(maxWidth: .infinity)                    .accessibilityHidden(true)                HeavyType(words: name, size: ToolFaceKnobs.nameSize)                    .lineLimit(1)                    .minimumScaleFactor(0.6)                    .padding(.top, 14)                    .accessibilityIdentifier("deck-title")                    .facePart(.title)                if let purpose {                    Text(purpose)                        .font(CottonFonts.type(ToolFaceKnobs.purposeSize))                        .lineSpacing(3)                        .lineLimit(5)                        .faceInk(.ink)                        .fixedSize(horizontal: false, vertical: true)                        .padding(.top, 8)                        .facePart(.body)                }                Spacer(minLength: 8)                if let figure {                    FaceHairline()                    Text(figure)                        .font(CottonFonts.type(ToolFaceKnobs.figureSize))                        .lineLimit(2)                        .faceInk(.pencil)                        .padding(.top, 8)                }            }            .padding(ToolFaceKnobs.inset)        }        .onCardPaper(ToolFaceCatalogue.stock.laid(nil))    }}/// The tool face, and the cards it is reviewed in. No card kind names it: the/// Tools deck draws each installed tool with it (CottonUI's `ToolsDeck`)./// From a card, its name (`title`), what it is for (`body`) and what its/// home table holds (`count`).public enum ToolFaceCatalogue {    public static let stock: FaceStock = .framed    public static let ground: FaceGround = .paper    public static let face = Face(id: "cotton.tool", specimens: [Specimen("calendar", calendar)]) { card, picture, _ in        ToolFace(name: card.text("title") ?? "", purpose: card.text("body"), figure: card.text("count")) { side in            if let picture { picture.frame(width: side, height: side) }        }    }    public static let calendar = DeckCard(face: .plain, fields: [        "title": .text("Calendar"), "body": .text("Events and time you have planned."), "count": .text("3 today"),    ])}