// The object faces: a tool's card, a project's cap, a person's polaroid. Each is// the owner's phone's own drawing (`ToolCard`, `ProjectCap`, `InstantPrint`)// fed from a definition and a record instead of a screen's model.importCottonValuesimportSwiftUI/// A tool's card on the board: the photographed stock, the object, the name./// The table's picture names the object (`tool-todos`); the tool's key is that/// name less its prefix, which is also how the card picks its stock.publicstructCardFace: View {privatelet definition: TableDefinitionprivatelet record: TableRecord?privatelet width: CGFloat?privatelet now: Datepublicinit(definition: TableDefinition, record: TableRecord? = nil, width: CGFloat? = nil, now: Date = Date()) {self.definition = definitionself.record = recordself.width = widthself.now = now }/// The tool's key: its tool block's, else "tool-todos" → "todos"; a table/// with neither is keyed by its plural.publicstaticfunc toolKey(_ definition: TableDefinition) -> String {iflet key = definition.tool?.key { return key }guardcase .asset(let picture) = definition.picture, picture.hasPrefix("tool-") else {return definition.plural.lowercased() }returnString(picture.dropFirst("tool-".count)) }staticfunc objectPicture(_ definition: TableDefinition, record: TableRecord?) -> ToolPicture? {guardlet object = record.flatMap({ row in definition.slip.object.flatMap { row[$0].text } }) else {return definition.picture }return .asset(ToolObjects.asset(for: object) ?? object) }publicvar body: someView {ToolCard( key: record?.id ?? Self.toolKey(definition), name: record.map { $0.said?.slip.name ?? "" } ?? definition.plural, picture: Self.objectPicture(definition, record: record), stock: record == nil ? definition.tool?.cardStock : nil, now: now, width: width) }}/// A project's bottle cap, its enamel from the record's id.publicstructCapFace: View {privatelet definition: TableDefinitionprivatelet record: TableRecordprivatelet side: CGFloat?publicinit(definition: TableDefinition, record: TableRecord, side: CGFloat? = nil) {self.definition = definitionself.record = recordself.side = side }publicvar body: someView {ProjectCap(name: record.said?.slip.name ?? "", colour: FaceTint.cap(for: record.id), side: side) }}/// A record as a polaroid: the print of its slip's picture, three across in a/// list's grid or on a tile.////// A table of pictures names its words (`polaroid`): the margin caption ("0:42"/// beside a film's play mark, "12 pictures" under an album's cover), the title/// in the serif under the print and a line by hand under that, then the/// slip's byline ("suggested", in red where it says so) and its answers (Keep/// / Not this) — and its print is always drawn, a picture whose bytes are not/// here showing the empty window rather than a card of words.////// Without `polaroid` it is a person's: the print captioned with the first/// name when its bytes are here, the typed card with the whole name otherwise./// Never initials.publicstructPolaroidFace: View { @Environment(\.theme) privatevar themeprivatelet definition: TableDefinitionprivatelet record: TableRecord/// The width the caller named; nil is the worn grid print's.privatelet givenWidth: CGFloat?privatevar width: CGFloat { givenWidth ?? PrintSize.grid.suggestedWidth(in: theme.scale) }/// One of several across a list's grid: the object takes the cell's/// width, `width` only sizing the picture it decodes.privatelet fills: Boolprivatelet onAnswer: ((String) -> Void)? @Environment(\.linkTitles) privatevar links/// - Parameter onAnswer: what a tap on one of the slip's answers does;/// nil draws none (a tile).publicinit( definition: TableDefinition, record: TableRecord, width: CGFloat? = nil, fills: Bool = false, onAnswer: ((String) -> Void)? = nil ) {self.definition = definitionself.record = recordself.givenWidth = widthself.fills = fillsself.onAnswer = onAnswer }/// A slip that opens a record: on a fan tile's page, the record grows out of it (`TilePage`).publicvar body: someView { face.zoomSource() } @ViewBuilder privatevar face: someView {if definition.polaroid != nil { picture } else { person } }/// A table of pictures' polaroid.privatevar picture: someView {let badge = definition.slip.badge.flatMap { record.said?.slip.badge != nil ? $0 : nil }return VStack(alignment: .leading, spacing: ObjectFacesKnobs.facePolaroidWordsGap) {InstantPrint( seed: record.id, caption: definition.polaroidCaption(of: record, links: links.byID), captionGlyph: badge?.symbol, size: .grid ) {RecordPicture(avatarKey: record[definition.slip.photo].text, edge: width) } .accessibilityLabel(badge?.spoken ?? record.said?.slip.title ?? definition.name)iflet title = definition.polaroidTitle(of: record, links: links.byID) {Text(title) .paperTitle(theme.scale.titleSize - 2) .lineLimit(ObjectFacesKnobs.facePolaroidTitleLineLimit) .padding(.top, ObjectFacesKnobs.facePolaroidTitleTopPadding) }iflet line = definition.polaroidSubtitle(of: record, links: links.byID) {Text(line).paperHand(theme.scale.handSize, ink: .pencil).lineLimit(1) }iflet byline = record.said?.slip.byline?.words {Text(byline) .paperHand(theme.scale.handSize, ink: definition.bylineIsRed ? .red : .pencil) .lineLimit(1) .accessibilityIdentifier("polaroid-\(definition.id)-byline-\(record.id)") }iflet onAnswer {AnswerRow(verbs: definition.drawnAnswers(record), identifier: "polaroid-\(definition.id)-\(record.id)") { onAnswer($0.value) } } } .frame(width: fills ? nil : width, alignment: .leading) .frame(maxWidth: fills ? .infinity : nil, alignment: .leading) }/// A person's polaroid. @ViewBuilder privatevar person: someView {let name = record.said?.slip.name ?? ""// Keep the existing name card's one line under the full name.let detail = (record.said?.slip.subtitle_one ?? record.said?.slip.subtitle) ?? FaceText.slipLine(record[definition.slip.trailing], words: record.columnWords(definition.slip.trailing), column: definition.column(definition.slip.trailing), links: links.byID, currency: record[definition.column(definition.slip.trailing)?.currency].text, readsPlaceholder: false)// A face, always: the photo, else the initials in the print's own// window, so every card on the People list is a person's print// rather than a typed name card (walker 604bcce6). The one line// under it (the organisation) is caption size, never shrunk.let initials = CardPerson.initials(name) VStack(alignment: .leading, spacing: 4) {RecordPrint( key: record[definition.slip.photo].text, name: initials ?? name, detail: nil, seed: record.id, caption: definition.polaroidCaption(of: record, links: links.byID), edge: width, framesInitials: true, monogram: initials != nil )iflet detail {// Two lines, so an organisation stands whole at the caption// size rather than cut mid-word on one ("Panasoni…", walker294).Text(detail).paperMeta(theme.scale.metaSize) .lineLimit(ObjectFacesKnobs.facePolaroidDetailLineLimit) .multilineTextAlignment(.center) .fixedSize(horizontal: false, vertical: true) .accessibilityIdentifier("polaroid-\(definition.id)-detail-\(record.id)") } } .frame(width: fills ? nil : width) .frame(maxWidth: fills ? .infinity : nil) }}/// The sizes, counts and timings ObjectFaces draws with: Swift's own, beside/// their reader — a theme sets only its tokens (`scale.tokens`).enumObjectFacesKnobs {staticlet facePolaroidTitleLineLimit = 2staticlet facePolaroidDetailLineLimit = 2staticlet facePolaroidTitleTopPadding: CGFloat = 4staticlet facePolaroidWordsGap: CGFloat = 4}