Cotton code
65 lines · 2.6 KB · SwiftRaw
// The hand before Search: what the core says its tap wears (`shell.deck`'s// `hand_next`), committed as the core said. Which faces a table offers, the// one chosen and the one after it are the core's.import CottonKitimport CottonValuesimport SwiftUIprivate struct FaceChoiceTableKey: EnvironmentKey { static let defaultValue: String? = nil }extension EnvironmentValues {    var faceChoiceTable: String? {        get { self[FaceChoiceTableKey.self] }        set { self[FaceChoiceTableKey.self] = newValue }    }}/// The hand on the deck's top row, the circle before Search, where the/// deck's table offers more than one face: a shortcut that cycles them (the/// owner, 3 Nov 2026: "the icon on the top is for cycling"). The opened/// card's Face act keeps the tier.struct FaceChoiceControl: View {    /// What a tap wears (`shell.deck`'s `hand_next`).    let next: DeckAnswer.HandNext    @Environment(\.cottonCore) private var core    @Environment(ToastCenter.self) private var toasts: ToastCenter?    @State private var writing = false    var body: some View {        Button {            guard let core, !writing else { return }            writing = true            Task {                if let refusal = await DeckEditor.commitRow(next.writes, core: core) { toasts?.show(refusal, tone: .error) }                writing = false            }        } label: {            ZStack {                Circle().fill(NavChrome.circleFill)                    .frame(width: NavCircleKnobs.chromeNavCircleDiameter, height: NavCircleKnobs.chromeNavCircleDiameter)                    .softShadow()                FaceHandMark().stroke(lineWidth: 1.4)                    .foregroundStyle(NavChrome.glyphInk)                    .frame(width: 24, height: 24)            }            .frame(width: ScreenBarKnobs.chromeNavCircleTarget, height: ScreenBarKnobs.chromeNavCircleTarget)            .contentShape(Rectangle())        }        .buttonStyle(MotionButtonStyle())        .disabled(writing)        .accessibilityLabel(next.label ?? "")        .accessibilityIdentifier("deck-face-choice")    }}/// The shell's hand of three cards, in the same line as the head's controls.struct FaceHandMark: Shape {    func path(in rect: CGRect) -> Path {        var path = Path()        for angle in [-0.28, 0, 0.28] {            let card = Path(roundedRect: CGRect(x: -6, y: -17, width: 12, height: 17), cornerRadius: 1.5)            path.addPath(card, transform: CGAffineTransform(rotationAngle: angle)                .concatenating(CGAffineTransform(translationX: rect.midX, y: rect.maxY - 2)))        }        return path    }}