// A record's answers as typed verbs (`SlipAnswers`), under a slip, a polaroid // or a page section: each a tap, never a swipe. The agreeing answer, when the // definition names one (`primary`), is a filled capsule; the rest are typed // words underlined in pencil. They sit side by side and stack when the // column is narrow. Drawn once; whoever holds the face writes the value. import SwiftUI struct AnswerRow: View { @Environment(\.theme) private var theme let verbs: [AnswerVerb] let identifier: String let onAnswer: (AnswerVerb) -> Void var body: some View { if !verbs.isEmpty { ViewThatFits(in: .horizontal) { HStack(spacing: AnswerRowKnobs.faceAnswerButtonGap) { buttons } VStack(alignment: .leading, spacing: AnswerRowKnobs.faceAnswerStackGap) { buttons } } } } @ViewBuilder private var buttons: some View { ForEach(verbs, id: \.value) { verb in Group { if verb.primary { VerbCapsule(title: verb.words) { onAnswer(verb) } } else { PaperTypedButton(verb.words, size: AnswerRowKnobs.faceAnswerTypeSize) { onAnswer(verb) } } } .accessibilityIdentifier("\(identifier)-answer-\(verb.value)") } } } /// The agreeing answer: the words on a filled capsule. struct VerbCapsule: View { @Environment(\.theme) private var theme let title: String let action: () -> Void @Environment(\.isEnabled) private var isEnabled var body: some View { Button(action: action) { Text(title) .cottonType(.caption, ink: .inverse, weight: .semibold) .padding(.horizontal, AnswerRowKnobs.faceAnswerButtonHorizontalPadding) .frame(minHeight: AnswerRowKnobs.faceAnswerButtonMinHeight) .background(Capsule().fill(theme.colors.accent.color)) .opacity(isEnabled ? AnswerRowKnobs.faceAnswerDisabledOpacityEnabled : DisabledOpacity.actionPill) } .buttonStyle(MotionButtonStyle()) } } /// The sizes, counts and timings AnswerRow draws with: Swift's own, beside /// their reader — a theme sets only its tokens (`scale.tokens`). enum AnswerRowKnobs { static let faceAnswerButtonGap: CGFloat = 14 static let faceAnswerButtonHorizontalPadding: CGFloat = 16 static let faceAnswerButtonMinHeight: CGFloat = 36 static let faceAnswerDisabledOpacityEnabled: CGFloat = 1 static let faceAnswerStackGap: CGFloat = 4 static let faceAnswerTypeSize: CGFloat = 14 }