Cotton code
81 lines · 2.8 KB · SwiftRaw
// The nav circle.//// Every nav control is a CIRCLE. Its fill is the cream PAPER the objects are// cut from, and the affordance is the soft shadow under it — every picture of// the redesign draws the back, the kebab and the plus this way, a paper disc// floating over the plaster. It was the white page ground, which read as a// white button laid on a cream page. The glyph is the paper's own ink, not the// chrome's grey.//// A sheet's close is the same circle wearing an X, top-right.import SwiftUIpublic struct NavCircle: View {    private let symbol: String    private let label: String    private let action: () -> Void    private let isDisabled: Bool    @Environment(\.theme) private var theme    public init(        symbol: String,        label: String,        disabled: Bool = false,        action: @escaping () -> Void    ) {        self.symbol = symbol        self.label = label        self.isDisabled = disabled        self.action = action    }    public var body: some View {        Button(action: action) {            NavDisc(symbol: symbol).opacity(isDisabled ? DisabledOpacity.control : 1)        }        .buttonStyle(MotionButtonStyle())        .disabled(isDisabled)        .accessibilityLabel(label)    }}/// The nav circle's face without its button: what a control that is not a/// `Button` (a `ShareLink`, a `Menu`) wears to read as a nav circle.public struct NavDisc: View {    let symbol: String    public init(symbol: String) { self.symbol = symbol }    public var body: some View {        ZStack {            Circle()                .fill(NavChrome.circleFill)                .frame(width: NavCircleKnobs.chromeNavCircleDiameter, height: NavCircleKnobs.chromeNavCircleDiameter)                .softShadow()            Image(systemName: symbol)                .font(.system(size: NavCircleKnobs.chromeNavGlyphSize, weight: .regular))                .foregroundStyle(NavChrome.glyphInk)        }        // The 39pt circle inside a 44pt target: the disc is what you see,        // the target is what you hit.        .frame(width: ScreenBarKnobs.chromeNavCircleTarget, height: ScreenBarKnobs.chromeNavCircleTarget)        .contentShape(Rectangle())    }}enum NavChrome {    /// The disc a nav control is drawn on: the cream paper's own paint.    public static var circleFill: Color { PaperDye.cream.fill }    /// The glyph on the disc — the ink the paper is printed in.    public static var glyphInk: Color { CottonColors.ink }}/// The sizes, counts and timings NavCircle draws with: Swift's own, beside/// their reader — a theme sets only its tokens (`scale.tokens`).enum NavCircleKnobs {    static let chromeNavCircleDiameter: CGFloat = 39    /// The glyph on the disc.    static let chromeNavGlyphSize: CGFloat = 18}