Cotton code
182 lines · 7.2 KB · SwiftRaw
// The parts a studio's faces share (Sharmila's boards, 23 Oct 2026): the// sizes of the class and membership faces (`StudioFaceKnobs`) and of the// brand faces (`StudioBrandKnobs`), a fact by its symbol, a share drawn as a// rule, the sessions ring and a person's initials on a disc. The class and// the studio's own place stay in the app (CottonUI's `StudioFaces`,// `StudioBrandFaces`) while they draw people through the phone.import CottonPaperimport CottonValuesimport SwiftUIpublic enum StudioFaceKnobs {    public static let inset = EdgeInsets(top: 24, leading: 22, bottom: 22, trailing: 14)    /// The class's words take this share of the card; the photograph the rest.    public static let wordsShare: CGFloat = 0.56    public static let daySize: CGFloat = 11.5    public static let dayTracking: CGFloat = 1.4    public static let timeSize: CGFloat = 60    public static let suffixSize: CGFloat = 15    public static let lengthSize: CGFloat = 13    public static let ruleWidth: CGFloat = 30    public static let ruleHeight: CGFloat = 2    public static let titleSize: CGFloat = 26    public static let lineSize: CGFloat = 13.5    public static let aboutSize: CGFloat = 12    public static let aboutLines = 3    public static let personMount: CGFloat = 30    public static let bar: CGFloat = 6    public static let barFaint = 0.18    public static let planSize: CGFloat = 11    public static let planTracking: CGFloat = 2    public static let memberSize: CGFloat = 32    public static let figureSize: CGFloat = 52    public static let factSize: CGFloat = 13    public static let labelFaint = 0.75    public static let monogram: CGFloat = 44    public static let ring: CGFloat = 96    public static let ringLine: CGFloat = 7    public static let ringFigure: CGFloat = 30    public static let ruleFaint = 0.35    /// How much of the membership card the studio's photograph takes, at its foot.    public static let photoShare: CGFloat = 0.42}public enum StudioBrandKnobs {    public static let inset = EdgeInsets(top: 18, leading: 22, bottom: 22, trailing: 20)    /// The photograph's share of a trainer's card, and of the studio's.    public static let portraitShare: CGFloat = 0.6    public static let placeShare: CGFloat = 0.4    public static let placeRadius: CGFloat = 16    public static let nameSize: CGFloat = 28    public static let lineSize: CGFloat = 16    public static let aboutSize: CGFloat = 13    public static let headlineSize: CGFloat = 25    public static let wordmarkSize: CGFloat = 12    public static let wordmarkTracking: CGFloat = 2.4    public static let labelSize: CGFloat = 12    public static let founderMount: CGFloat = 54    public static let chipSize: CGFloat = 13    public static let chipPad = EdgeInsets(top: 6, leading: 12, bottom: 6, trailing: 12)    public static let chipFaint = 0.14    public static let clientBand: CGFloat = 0.3    public static let clientMount: CGFloat = 88    public static let clientName: CGFloat = 34    public static let cornerSize: CGFloat = 12    public static let cornerPad = EdgeInsets(top: 6, leading: 12, bottom: 6, trailing: 12)    public static let factSize: CGFloat = 14    public static let hairlineFaint = 0.8    /// The symbols the client's facts stand by, in the design's order.    public static let factSymbols = ["calendar", "clock", "chart.bar.fill"]}/// One of the core's lines by a symbol: its label, if it has one, then its/// words heavier ("Ends 12 Nov").public struct StudioFact: View {    let symbol: String    var label: String?    let said: String    let tint: Color    var size: CGFloat = StudioFaceKnobs.factSize + 1    @Environment(\.theme) private var theme    public init(symbol: String, label: String? = nil, said: String, tint: Color, size: CGFloat = StudioFaceKnobs.factSize + 1) {        self.symbol = symbol        self.label = label        self.said = said        self.tint = tint        self.size = size    }    public var body: some View {        HStack(alignment: .firstTextBaseline, spacing: 10) {            Image(systemName: symbol)                .font(theme.type.body(size + 1))                .foregroundStyle(tint)                .frame(width: size + 8)                .accessibilityHidden(true)            (label.map { Text($0 + " ").font(theme.type.body(size)) } ?? Text(verbatim: ""))                + Text(said).font(theme.type.title(size))        }        .lineLimit(2)        .foregroundStyle(theme.colors.inkBody.color)        .accessibilityElement(children: .combine)    }}/// A share drawn as a filled rule over its faint whole.public struct SeatRule: View {    let share: Double    let color: Color    public init(share: Double, color: Color) {        self.share = share        self.color = color    }    public var body: some View {        GeometryReader { rule in            ZStack(alignment: .leading) {                Capsule().fill(color.opacity(StudioFaceKnobs.barFaint))                Capsule().fill(color).frame(width: rule.size.width * share)            }        }        .frame(height: StudioFaceKnobs.bar)    }}/// The classes taken of the period as a ring in the look's accent, the/// number in its middle, the core's words for them under it.struct SessionsRing: View {    let taken: Int    let of: Int    var words: String?    @Environment(\.theme) private var theme    var body: some View {        VStack(spacing: 6) {            ZStack {                Circle().stroke(theme.colors.paper.color.opacity(0.22), lineWidth: StudioFaceKnobs.ringLine)                Circle()                    .trim(from: 0, to: StudioReading.ringShare(taken: taken, of: of))                    .stroke(theme.colors.accent.color, style: StrokeStyle(lineWidth: StudioFaceKnobs.ringLine, lineCap: .round))                    .rotationEffect(.degrees(-90))                Text(verbatim: "\(taken)")                    .font(theme.type.display(StudioFaceKnobs.ringFigure))                    .lineLimit(1)                    .minimumScaleFactor(0.5)            }            .frame(width: StudioFaceKnobs.ring, height: StudioFaceKnobs.ring)            if let words {                Text(words)                    .font(theme.type.body(StudioFaceKnobs.factSize))                    .multilineTextAlignment(.center)                    .lineLimit(2)                    .frame(width: StudioFaceKnobs.ring + 24)            }        }        .accessibilityElement(children: .combine)        .accessibilityIdentifier("face-seats")    }}/// A person with no picture of their own, drawn as their initials on a disc/// of the look's ink (or, `inverse`, of the paper on an ink card) — never a/// stock face.struct StudioMonogram: View {    let name: String    let size: CGFloat    var inverse = false    @Environment(\.theme) private var theme    var body: some View {        let disc = inverse ? theme.colors.paper.color : theme.colors.ink.color        let ink = inverse ? theme.colors.ink.color : theme.colors.paper.color        Text(CardPerson.initials(name) ?? "")            .font(theme.type.title(size * 0.4))            .foregroundStyle(ink)            .frame(width: size, height: size)            .background(Circle().fill(disc))            .accessibilityHidden(true)    }}