// THE PAINTED TILE: a fan tile drawn on its tool's painted stock, whatever// its type — Cinemas' black felt letterboard in a thin brass frame (Round 19,// the owner's pick, 6 Nov 2026), Downloads' kraft parcel, Money's ruled index// card, Podcasts' bakelite preset (Round 25, 8 Nov 2026) — a pictogram at// its head, its name and count set beneath in the type the tile names.//// Every picture is DATA: the stock (`tile-blank`, painted wordless) and the// pictogram are the tool's kit pictures (`fan_tile`), handed in decoded;// nothing is painted here and no highlight is added over the stock. What the// tile draws itself is only what the painter left to the app (`notes.md`):// the live words, the cast shadow, and the centred tile's lift — about 12%// brighter than its neighbours, laid as the tile again over itself, added// (`plusLighter`), so a dark stays dark and the lights rise.//// THE TYPE (`PaintedTileType`) decides only the words: the letterboard's// cream upright condensed capitals (Barlow Condensed), or courier — the// shell's typed face (Courier Prime, the plain tile's) in the theme's ink, in// the words' own case, low on the stock where every courier blank leaves its// label (Downloads' address field, Podcasts' legend badge).//// THE LAYOUT IS THE PAINTER'S (`layout.json`), in fractions of the 474 x 696// stock: the pictogram's box (219 square, its centre 190.5 down — the same// on every Round 19 and Round 25 blank), and per type the name's baseline// and cap height, the line step and the count's place. Where a tile names// its words (`fan_tile.words`: Music's pale legend field, Keys' brass tag),// their ink and baselines are its own (`PaintedTileType.worded`), the name// and the count in one ink; a key it leaves out is the type's. The pictogram, the// name and the count stand CENTRED across the tile, as the composites// (`fan.png`) have them — the proof sheet's off-centre box is the sheet's,// not the tile's.//// THE WORDS ARE NEVER CUT (`FanTierWords`' rule): they wrap to two lines at// a word, then set smaller; a word longer than the tile sets smaller on its// line, never broken inside. They grow with the phone's text size as far as// the stock holds them, the count beneath never under two thirds of the// name's size. A red act keeps its red as its ink: the words and the// pictogram turn to the kit's red, the stock stays as painted.importCoreTextimportSwiftUI/// How a painted tile's words are set: the tile's `type` (`fan_tile`).publicstructPaintedTileType: Equatable, Sendable {/// The face the words are set in.publiclet face: ThemeFace/// The words are set in capitals.publiclet capitals: Bool/// The name's first baseline and its cap height against the stock's/// height; the face's cap height against its size.publiclet nameBaseline: CGFloatpubliclet nameCap: CGFloatpubliclet capRatio: CGFloat/// A second line's baseline below the first, and the count's baseline/// below the name's last, against the name's size.publiclet lineStep: CGFloatpubliclet countGap: CGFloat/// The count's size against the name's.publiclet countRatio: CGFloat/// The words' width against the stock's: clear of its frame or inside/// its label.publiclet wordsWidth: Double/// The foot no count's baseline passes, against the stock's height.publiclet wordsFoot: CGFloat/// The words' ink, name and count alike; nil, the type's own — the/// letterboard's cream, courier's the theme's ink.publicvar ink: ThemeColor? = nil/// Round 19's `layout.json` (the 474 x 696 board and the fan composite's/// type) and `fan.png`: cream capitals pressed beneath the box.publicstaticlet letterboard = PaintedTileType( face: .letterboard, capitals: true,// Baseline 403, cap 37 of 696; Barlow Condensed's cap: 700 of 1000. nameBaseline: 403.0 / 696.0, nameCap: 37.0 / 696.0, capRatio: 0.7,// A second line 62, the count 99 below the last, at 52 px type. lineStep: 62.0 / 52.0, countGap: 99.0 / 52.0,// The count's cap 32 of the name's 37. countRatio: 32.0 / 37.0,// Inside the felt (the safe rect is 418 of 474), clear of the frame. wordsWidth: 0.8,// The felt's foot (the safe rect's, 640 of 696, less a little). wordsFoot: 0.9)/// Round 25's `layout.json` for the courier blanks (Downloads, Podcasts:/// baseline 500; Money's ruled card 430, set here at 500 with the rest,/// still on its rules) and `fan.png`: typed words in the label.publicstaticlet courier = PaintedTileType( face: .courier, capitals: false,// Baseline 500, cap 30 of 696; Courier Prime's cap: 580 of 1000. nameBaseline: 500.0 / 696.0, nameCap: 30.0 / 696.0, capRatio: 0.58,// A second line 58, the count 86 below the last, at 52 px type. lineStep: 58.0 / 52.0, countGap: 86.0 / 52.0,// The count at 44 px against the name's 52. countRatio: 44.0 / 52.0,// Inside the narrowest label, Podcasts' badge (395 of 474). wordsWidth: 0.76,// The badge's foot (615 of 696), less a little. wordsFoot: 0.875)/// The type with its words where the tile's painter set them/// (`fan_tile.words`): `ink`, and the name's first baseline and the/// count's under a name of one line and of two, in pixels on the/// 696-high stock. At the painted size each stands where it is given;/// grown or set smaller, the gaps scale with the name as the type's own/// do. A value not given is the type's.publicfunc worded(ink: ThemeColor?, nameBaseline: Double?, countOne: Double?, countTwo: Double?) -> PaintedTileType {let stock = Double(PaintedTileKnobs.stockHeight)let painted = stock * Double(nameCap / capRatio)let name = nameBaseline ?? stock * Double(self.nameBaseline)let one = countOne ?? name + painted * Double(countGap)let two = countTwo ?? one + painted * Double(lineStep)returnPaintedTileType( face: face, capitals: capitals, nameBaseline: CGFloat(name / stock), nameCap: nameCap, capRatio: capRatio, lineStep: CGFloat((two - one) / painted), countGap: CGFloat((one - name) / painted), countRatio: countRatio, wordsWidth: wordsWidth,// A two-line name's count stands where the painter set it. wordsFoot: max(wordsFoot, CGFloat(two / stock)), ink: ink ?? self.ink) }/// The type's words are the letterboard's (its face), however inked or placed.publicvar letterboard: Bool { face == .letterboard }/// `words` as the type sets them.publicfunc cased(_ words: String) -> String { capitals ? words.uppercased() : words }/// The type at `size`.publicfunc font(_ size: CGFloat) -> Font { face.font(size) }}/// A painted fan tile (see the file's header). `mark` is what stands in the/// pictogram's box: a pictogram (`PaintedPictogram`), or a list's own/// picture or its members' covers.publicstructPaintedTile<Mark: View>: View {let stock: Image?let type: PaintedTileTypelet label: String/// What stands beneath the name: its count, or a day's detail.let figure: String?let ink: Color?let centred: Boollet width: Doublelet height: Doublelet growth: CGFloatlet mark: Mark @Environment(\.theme) privatevar theme/// `ink`: a red act's red; nil, the type's own — the tile's words' ink/// where it names one, else the letterboard's cream, courier's the/// theme's ink.publicinit(stock: Image?, type: PaintedTileType = .letterboard, label: String, figure: String?, ink: Color? = nil, centred: Bool = false, width: Double, height: Double, growth: CGFloat = 1, @ViewBuilder mark: () -> Mark) {self.stock = stockself.type = typeself.label = labelself.figure = figureself.ink = inkself.centred = centredself.width = widthself.height = heightself.growth = growthself.mark = mark() }privatevar drawnInk: Color { ink ?? type.ink?.color ?? (type.letterboard ? PaintedTileKnobs.cream : theme.print(.ink)) }/// A stock not in hand yet: the letterboard's felt, courier's cream.privatevar blank: Color { type.letterboard ? PaintedTileKnobs.felt : theme.sheet(.cream) }publicvar body: someView {let words = PaintedTileWords.set(label, figure: figure, type: type, width: width, height: height, growth: growth) board(words) .overlay {if centred { board(words).blendMode(.plusLighter).opacity(PaintedTileKnobs.lift) } } .compositingGroup() .shadow(color: .black.opacity(PaintedTileKnobs.shadowOpacity), radius: PaintedTileKnobs.shadowRadius, x: PaintedTileKnobs.shadowX, y: PaintedTileKnobs.shadowY) .frame(width: width, height: height) }privatefunc board(_ words: PaintedTileWords.Set) -> someView { ZStack(alignment: .top) {Group {iflet stock { stock.resizable().interpolation(.high) } else {RoundedRectangle(cornerRadius: width * PaintedTileKnobs.blankCorner).fill(blank) } } .frame(width: width, height: height) mark .frame(width: width * PaintedTileKnobs.markSide, height: width * PaintedTileKnobs.markSide) .position(x: width / 2, y: height * PaintedTileKnobs.markCentre) .frame(width: width, height: height) } .frame(width: width, height: height)// The words lie over the stock, each line's baseline where the// painter set it: an overlay is laid inside the tile and never// moves it, however tall the line's type. .overlay(alignment: .top) { ZStack(alignment: .top) {ForEach(Array(words.lines.enumerated()), id: \.offset) { at, line in pressed(line, size: words.name, baseline: words.baselines[at]) }iflet figure { pressed(type.cased(figure), size: words.count, baseline: words.countBaseline) } } .frame(width: width, height: height, alignment: .top) } }/// One line of the words, centred, its baseline at `baseline` points from the top.privatefunc pressed(_ line: String, size: CGFloat, baseline: CGFloat) -> someView {Text(line) .font(type.font(size)) .foregroundStyle(drawnInk) .lineLimit(1) .fixedSize() .alignmentGuide(.top) { $0[.firstTextBaseline] } .offset(y: baseline)// A fixed frame: its top is the baseline's, so however tall the// type, nothing round it moves. .frame(width: width, height: height, alignment: .top) }}/// A kit pictogram in a painted tile's box: as painted, or turned to the/// act's red (`red`) where the act is red — the letterboard's cream plastic/// multiplied by it, a courier stock's dark print filled with it.publicstructPaintedPictogram: View {let image: Imagelet red: Color?let type: PaintedTileTypepublicinit(_ image: Image, red: Color? = nil, type: PaintedTileType = .letterboard) {self.image = imageself.red = redself.type = type }publicvar body: someView {let drawn = image.resizable().interpolation(.high).scaledToFit()iflet red, type.letterboard { drawn.colorMultiply(red) } elseiflet red {Rectangle().fill(red).mask(drawn) } else { drawn } }}/// How a painted tile's words are set: the name's lines and size, each/// line's baseline, and the count's size and baseline, in points.publicenumPaintedTileWords {publicstructSet: Equatable {publicvar lines: [String]publicvar name: CGFloatpublicvar baselines: [CGFloat]publicvar count: CGFloatpublicvar countBaseline: CGFloat }publicstaticlet lines = 2/// `label`, as `type` cases it, at the largest size from the painter's,/// grown by `growth`, at which it stands in two lines inside the tile's/// words width, broken only between words, and its count beneath stands/// above the type's foot.publicstaticfunc set(_ label: String, figure: String?, type: PaintedTileType = .letterboard, width: Double, height: Double, growth: CGFloat = 1) -> Set {let words = type.cased(label)let room = CGFloat(width * type.wordsWidth)let painted = CGFloat(height) * type.nameCap / type.capRatio// The name's capitals never rise into the pictogram's box: grown,// their top stands a little under the box's foot.let boxFoot = CGFloat(height) * PaintedTileKnobs.markCentre + CGFloat(width * PaintedTileKnobs.markSide) / 2let ceiling = (CGFloat(height) * (type.nameBaseline - PaintedTileKnobs.markGap) - boxFoot) / type.capRatiolet preferred = max(painted, min(painted * max(growth, 1), ceiling))let floor = painted * PaintedTileKnobs.leastSharelet step = max(0.25, preferred * 0.02)var size = preferredvar broken = laid(words, face: type.face, size: size, room: room)while size > floor {iflet lines = broken, lines.count <= Self.lines, stands(lines.count, size: size, type: type, height: height, figure: figure) { break } size -= step broken = laid(words, face: type.face, size: size, room: room) } size = max(size, floor)var lines = laid(words, face: type.face, size: size, room: room) ?? []// Not even the floor holds the words whole in two lines: they go in// two lines at their spaces, each set smaller until it stands.if lines.isEmpty || lines.count > Self.lines {let parts = words.split(separator: " ").map(String.init)let half = max(1, (parts.count + 1) / 2) lines = parts.count < 2 ? [words] : [parts.prefix(half).joined(separator: " "), parts.dropFirst(half).joined(separator: " ")] size = lines.map { InkFit.oneLine($0, face: type.face, size: size, width: room) }.min() ?? size }let first = CGFloat(height) * type.nameBaselinelet lineStep = size * type.lineSteplet baselines = lines.indices.map { first + CGFloat($0) * lineStep }let countSize = max(size * type.countRatio, size * PaintedTileKnobs.countLeast)returnSet(lines: lines, name: size, baselines: baselines, count: countSize, countBaseline: (baselines.last ?? first) + size * type.countGap) }/// The lines `words` wrap to at `size` inside `room`, broken only between/// words, as CoreText lays them; nil when a word alone is wider.privatestaticfunc laid(_ words: String, face: ThemeFace, size: CGFloat, room: CGFloat) -> [String]? {guardlet laid = InkFit.laid(words, face: face, size: size, width: room) else { returnnil }let text = words as NSStringlet lines = laid.map { line -> Stringinlet range = CTLineGetStringRange(line)return text.substring(with: NSRange(location: range.location, length: range.length)).trimmingCharacters(in: .whitespaces) }// Every line's ink inside the room once centred.returnInkFit.fits(words, face: face, size: size, width: room, lines: lines.count) ? lines : nil }/// `lines` of the name at `size` and the count beneath stand above the type's foot.privatestaticfunc stands(_ lines: Int, size: CGFloat, type: PaintedTileType, height: Double, figure: String?) -> Bool {let last = CGFloat(height) * type.nameBaseline + CGFloat(lines - 1) * size * type.lineSteplet foot = figure == nil ? last : last + size * type.countGapreturn foot <= CGFloat(height) * type.wordsFoot }}/// What every painted tile shares, measured off Round 19's and Round 25's/// `layout.json` (the 474 x 696 stock) and `fan.png`.publicenumPaintedTileKnobs {/// The stock's height in its painter's pixels, which a tile's words'/// baselines are given on (`fan_tile.words`).publicstaticlet stockHeight: CGFloat = 696/// The pictogram's box: its side against the stock's width (219 of 474)/// and its centre against the stock's height (190.5 of 696).publicstaticlet markSide = 219.0 / 474.0publicstaticlet markCentre = 190.5 / 696.0/// The count's size never under two thirds of the name's.publicstaticlet countLeast: CGFloat = 2.0 / 3.0/// The least clear stock between the pictogram's box and the name's/// capitals, against the stock's height.publicstaticlet markGap: CGFloat = 0.02/// The least the name sets at, against the painter's size.publicstaticlet leastShare: CGFloat = 0.4/// The cream of the letterboard's plastic letters, matched to the/// pictograms' faces.publicstaticlet cream = CinemasMaterial.letters.colour/// A letterboard with no stock in hand yet: black felt, rounded as the frame is.publicstaticlet felt = CinemasMaterial.letterFelt.colourpublicstaticlet blankCorner = 0.06/// The centred tile's lift: 12% brighter (`fan.png`, centreBrightness 1.12).publicstaticlet lift = 0.12/// The cast shadow the app draws (`fan.png`: 65% black, 4 px blur, 1 x 5/// px), held inside the fan's print padding.publicstaticlet shadowOpacity = 0.65publicstaticlet shadowRadius: CGFloat = 1.6publicstaticlet shadowX: CGFloat = 0.6publicstaticlet shadowY: CGFloat = 2.4}