Cotton code
70 lines · 3.1 KB · SwiftRaw
// The one mount a person without a photograph shows, on every face that// draws a person: a quiet wash, their initial ringed in pencil with a fainter// echo of the ring, in the look's monogram ink.import CottonPaperimport CottonValuesimport SwiftUIenum InitialsMountKnobs {    /// The monogram's ring and letter, as shares of the mount's shorter side.    static let ringShare: CGFloat = 0.72    static let letterShare: CGFloat = 0.42    static let washOpacity: Double = 0.2    static let ringOpacity: Double = 0.75    static let ringLine: CGFloat = 1.2    /// The pencil's second pass round the ring, a hair off the first.    static let echoOpacity: Double = 0.35    static let echoLine: CGFloat = 0.8    static let echoStretch = CGSize(width: 1.02, height: 0.99)    static let echoShift = CGSize(width: 1.2, height: -0.8)}/// The one mount a person without a photograph shows, on every face: a quiet/// wash, their initial ringed in pencil with a fainter echo of the ring, in/// the look's monogram ink. Round mounts clip it; the person's panel frames it.public struct InitialsMount: View {    let name: String    let typed: Bool    @Environment(\.theme) private var theme    public init(name: String, typed: Bool = false) {        self.name = name        self.typed = typed    }    public var body: some View {        GeometryReader { mount in            let side = min(mount.size.width, mount.size.height)            let ring = side * InitialsMountKnobs.ringShare            if typed {                ZStack {                    theme.sheet(.cream)                    Text(CardPerson.initials(name) ?? "")                        .font(CottonFonts.type(side * 0.35))                        .foregroundStyle(theme.faceStocks.mountInk)                        .blendMode(theme.printBlend)                }                .frame(width: mount.size.width, height: mount.size.height)            } else {                ZStack {                    theme.faceStocks.buff.opacity(InitialsMountKnobs.washOpacity)                        .blendMode(theme.printBlend)                    Circle()                        .stroke(theme.print(.pencil).opacity(InitialsMountKnobs.ringOpacity), lineWidth: InitialsMountKnobs.ringLine)                        .frame(width: ring, height: ring)                    Circle()                        .stroke(theme.print(.pencil).opacity(InitialsMountKnobs.echoOpacity), lineWidth: InitialsMountKnobs.echoLine)                        .frame(width: ring * InitialsMountKnobs.echoStretch.width, height: ring * InitialsMountKnobs.echoStretch.height)                        .offset(InitialsMountKnobs.echoShift)                    Text(CardPerson.initials(name).map { String($0.prefix(1)) } ?? "")                        .font(CottonFonts.display(side * InitialsMountKnobs.letterShare))                        .foregroundStyle(theme.faceStocks.mountInk)                        .blendMode(theme.printBlend)                }                .frame(width: mount.size.width, height: mount.size.height)            }        }        .accessibilityHidden(true)    }}