Cotton code
61 lines · 2.5 KB · SwiftRaw
// A record named by a link column, worn as a small straw paper tag with its// string hole (a solid tag in the palette's tag colours, in plain) — a picture's albums, each opening its page. Drawn once for any// link column holding several records (`multiple`), on any page.import CottonKitimport SwiftUI/// One linked record as a tag.struct PaperTag: View {    @Environment(\.theme) private var theme    let title: String    let seed: String    var body: some View {        switch theme.family {        case .paper:            Paper(dye: .straw, edge: .cut, seed: seed, tilt: true, inset: 0) {                HStack(spacing: PaperTagKnobs.faceTagGap) {                    Circle()                        .strokeBorder(theme.print(.pencil), lineWidth: 1)                        .frame(width: PaperTagKnobs.faceTagDotSize, height: PaperTagKnobs.faceTagDotSize)                    Text(title)                        .paperBody(theme.scale.bodySize - 1)                        .lineLimit(1)                }                .padding(.horizontal, PaperTagKnobs.faceTagHorizontalPadding)                .padding(.vertical, PaperTagKnobs.faceTagVerticalPadding)            }            .fixedSize()        case .plain:            // Plain's tags are solid: the palette's tag fill, its ink on it.            let tag = Self.solid(theme)            HStack(spacing: PaperTagKnobs.faceTagGap) {                Circle()                    .strokeBorder(tag.ink.color, lineWidth: 1)                    .frame(width: PaperTagKnobs.faceTagDotSize, height: PaperTagKnobs.faceTagDotSize)                Text(title)                    .font(theme.type.body(theme.scale.bodySize - 1))                    .lineLimit(1)            }            .foregroundStyle(tag.ink.color)            .padding(.horizontal, PaperTagKnobs.faceTagHorizontalPadding)            .padding(.vertical, PaperTagKnobs.faceTagVerticalPadding)            .background(tag.fill.color, in: RoundedRectangle(cornerRadius: theme.scale.radius * 0.5))            .fixedSize()        }    }    /// The fill and ink a solid tag wears in `theme` — its palette's tags.    static func solid(_ theme: Theme) -> ThemeTags { theme.colors.tags }}/// The sizes, counts and timings PaperTag draws with: Swift's own, beside/// their reader — a theme sets only its tokens (`scale.tokens`).enum PaperTagKnobs {    static let faceTagDotSize: CGFloat = 7    static let faceTagGap: CGFloat = 8    static let faceTagHorizontalPadding: CGFloat = 12    static let faceTagVerticalPadding: CGFloat = 8}