import CottonPaper import SwiftUI /// A view's painted fan tile (Round 17, variation b, the owner's pick for Cotton /// Books, 5 Nov 2026): a cream card with one small painted object at its /// head, wordless, is the whole tile face, its alpha kept — the card's own /// worn edge and corners are the picture's. Beneath the object the view's /// name is typed centred in Courier Prime, its count under it, in the ink /// the plain card's words take. The picture is the view's (`ToolView.picture`, /// one of the core's `VIEW_PICTURES`), kept once at 3x of the 158 x 232 pt /// tile as `view-` (`scripts/import-books-materials.py views`). A /// view without one draws the plain cream card (`FanTierCard`). struct ViewTile: View { /// The tile's catalogue name (`asset`). let painted: String let label: String let count: Int? let width: Double let height: Double /// The phone's text size, as far as the words still fit the card's /// lower part (`FanTierWords`). var growth: CGFloat = 1 @Environment(\.theme) private var theme /// The catalogue name a view's picture is kept under. nonisolated static func asset(_ picture: String) -> String { "view-\(picture)" } var body: some View { ZStack(alignment: .top) { if let picture = CottonMedia.image(painted) { picture.resizable().interpolation(.high) } VStack(spacing: height * ViewTileKnobs.gap) { // Never cut: two lines, then smaller (`FanTierWords`). let size = FanTierWords.size(label, cardWidth: width, preferred: ViewTileKnobs.name * growth) Text(FanTierWords.broken(label, size: size, cardWidth: width)) .font(CottonFonts.type(size)) .multilineTextAlignment(.center) .lineLimit(FanTierWords.lines) .fixedSize(horizontal: false, vertical: true) if let count { Text(String(count)) .font(CottonFonts.type(FanTierWords.size(String(count), cardWidth: width, preferred: ViewTileKnobs.count * growth, lines: 1))) .lineLimit(1) .fixedSize(horizontal: false, vertical: true) } } .foregroundStyle(theme.print(.ink)) .frame(width: width * FanGeometry.labelWidthRatio) .padding(.top, height * ViewTileKnobs.wordsTop) } .frame(width: width, height: height) .softShadow() } } /// Measured off Round 17's composite proof (`fan.png`): the object fills the /// card's upper half; the name starts a little past the middle, the count /// under it. enum ViewTileKnobs { /// Where the name's first line starts, from the card's top. static let wordsTop = 0.55 /// The space between the name and the count. static let gap = 0.05 /// The name's and the count's type, against the card's width. static let name = 0.1 static let count = 0.09 }