// The databases a person holds, as caps on a second arc under a fan Home's// tiles (fan2 part 6, the Home board's `databases` part; fan3 part 1: the row// became an arc). One cap per held database, in the Databases screen's own// order; none when only one is held. The arc is concentric with the tiles' —// the same pivot below the screen, a smaller radius, one band gap under the// raised tile (`DatabaseCapRow.geometry`) — and// turned as the tiles are: the same arc, motion, fling, rubber band and// haptic per cap crossing (`FanArcDeck`, `FanMotion`), with its own size and// step. The cap at the centre is the chosen one, raised and larger — its own// printed name and the header say which; the arc heading for another cap// switches to that database: its kept Home is read while the old one stands,// then shown whole in one frame (`DatabaseScene.show`), and the thought the// record button keeps goes there.importCottonKitimportSwiftUI/// The rules of the caps, apart from how they are drawn.@MainActorenumDatabaseCapRow {/// One cap on the arc: a held database, or the last cap, which opens the/// Databases screen (new or join).enumCap: Equatable {case database(HeldDatabase)case databases/// The cap's key on the arc, and the database it shows if any.var key: String {switchself {case .database(let held): return held.databaseIdcase .databases: return"databases" } }var database: HeldDatabase? {ifcase .database(let held) = self { return held }returnnil } }/// The caps the arc draws (defaults, night plan, 16 Oct 2026): the/// personal database at the centre, the others either side by name, and/// last the cap that opens the Databases screen — the head draws no/// database symbol, so the arc stands whenever a database is held.staticfunc caps(_ model: DatabasesModel?) -> [Cap] {let held = model?.ordered ?? []guard !held.isEmpty else { return [] }return arc(held).map(Cap.database) + [.databases] }/// The held databases in the arc's order: the others by name, split/// either side of the personal database so that it stands at the centre/// of the whole arc, the last cap included (the odd one goes left).staticfunc arc(_ held: [HeldDatabase]) -> [HeldDatabase] {let others = held.filter { !$0.isPersonal } .sorted { $0.name.localizedStandardCompare($1.name) == .orderedAscending }let left = (others.count + 1) / 2returnArray(others.prefix(left)) + held.filter(\.isPersonal) + Array(others.dropFirst(left)) }/// A cap chosen: its database is shown, as a pick on the Databases screen/// is — the window's calls, the page and the record button's thoughts/// all move to it. The cap of the database shown keeps it, and a switch/// still reading for another cap turns nothing.staticfunc choose(_ id: String, scene: DatabaseScene?, in model: DatabasesModel?) async {guardlet scene, let model, model.database(id) != nilelse { return }guard id != scene.shownId else { return scene.stay() }await scene.pick(id, in: model) }/// A database an act brought back (`CommandOpened.database`, a Restore/// in the Bin): whatever was pushed over Home closes, the held list is/// read again so its cap stands on the arc, and it is shown as a chosen/// cap is (architect, 16 Oct 2026).staticfunc show(_ id: String, scene: DatabaseScene?, in model: DatabasesModel?, navigator: Navigator?) async { navigator?.popToRoot()await model?.refresh()await choose(id, scene: scene, in: model) }/// The caps' arc about the tiles' pivot: a cap is `fan_cap_size` square,/// its step the cap and the gap between two caps along the arc, the/// chosen one raised by `fan_cap_lift` and larger by as much. `fan` is/// the tiles' arc and `above` the height of the tiles' band over this/// one, so the two arcs share one pivot. The band and the radius come/// from the tile's size (architect, 15 Oct 2026, 16:50 IST): the band is/// the raised chosen cap, whose top stands at the band's top — one band/// gap under the raised tile — so the radius is the pivot's depth less/// the raised cap's lift and half its size.staticfunc geometry(scale: ThemeScale, fan: FanGeometry, above: Double) -> FanGeometry {let side = Double(scale[.fanCapSize])let lift = Double(scale[.fanCapLift])let pivot = fan.top + fan.tileHeight / 2 + fan.radius - abovelet radius = pivot - lift - (side + lift) / 2let pointsPerDegree = Double.pi * radius / 180returnFanGeometry( tileWidth: side, tileHeight: side, radius: radius, step: (side + Double(scale[.fanCapsGap])) / pointsPerDegree, visible: fan.visible, height: side + lift, top: pivot - radius - side / 2, lift: lift, settledScale: (side + lift) / side, overscroll: fan.overscroll, flingMin: fan.flingMin, flingFull: fan.flingFull, flingReach: fan.flingReach, swipeLean: fan.swipeLean, tapSlop: fan.tapSlop, turnPerDegree: fan.turnPerDegree, turnLongest: fan.turnLongest, turnShortest: fan.turnShortest) }}#if os(iOS)/// The caps on their arc.structDatabaseCapArc: View {/// The tiles' arc, and the height of their band over this one.let fan: FanGeometrylet above: Double @Environment(DatabasesModel.self) privatevar databases: DatabasesModel? @Environment(DatabaseScene.self) privatevar scene: DatabaseScene? @Environment(\.theme) privatevar theme @Environment(\.cottonHaptics) privatevar haptics @Environment(\.accessibilityReduceMotion) privatevar reduceMotion @Environment(\.displayScale) privatevar displayScale @Environment(\.self) privatevar environment @State privatevar motion: FanMotion? @State privatevar prints = FanPrints<CapPrint>()/// What a cap's picture shows.structCapPrint: Equatable {let name: Stringlet colour: CapColourlet side: Double }privatevar geometry: FanGeometry { DatabaseCapRow.geometry(scale: theme.scale, fan: fan, above: above) }var body: someView {let caps = DatabaseCapRow.caps(databases)let scale = theme.scalelet geometry = geometry ZStack(alignment: .topLeading) {if !caps.isEmpty, let motion {FanArcDeck( items: caps.map { cap inFanArcItem(key: cap.key, label: cap.database?.name ?? DatabaseCapWords.databases, picture: prints.picture(cap.key, look(of: cap)), identifier: cap.database.map { "fan-database-\($0.databaseId)" } ?? "fan-databases") }, motion: motion, geometry: geometry, reach: geometry.lift, faintest: Double(scale[.fanCapsFaint]), reduceMotion: reduceMotion ) { index in haptics.press() motion.turn(to: index, animated: !reduceMotion, byPerson: true) } } } .frame(maxWidth: .infinity) .frame(height: caps.isEmpty ? 0 : geometry.height, alignment: .top) .onAppear { start(caps) } .onChange(of: caps.map(\.key)) { _, _ in start(DatabaseCapRow.caps(databases)) }// The database shown is known once the launch has read it: the arc// stands on its cap then, not on whichever cap it mounted at. .onChange(of: scene?.shownId) { _, _ in start(DatabaseCapRow.caps(databases)) } .onChange(of: theme) { _, _ in prints.clear() drawPrints(DatabaseCapRow.caps(databases)) }// The arc heading for another cap — a tap, or a finger lifting: the// switch to its database happens now (`SwitchClock`), not when the// arc comes to rest — the fan stood on the old database's cards under// the new cap for the whole of the caps' spring (292, walker291).// The old Home stands while the new one is read from the phone's// copy, then the new one stands whole (`DatabaseScene.show`);// heading back to the database shown keeps it. Not the arc standing// on the chosen cap as it mounts: nobody chose that.// A swipe chooses where it rests, never on its way (`ArcChoice.chooses`). .onChange(of: motion?.heading) { was, heading inguard was != nil, let heading else { return } choose(at: heading, .heading) }// The arc at rest on the last cap: the Databases screen opens and the// arc turns back to the database shown (a database's cap was shown// as the arc headed for it). Only a rest a person brought: the arc// mounting, its caps arriving and a turn back are nobody's choice,// and a launch draws Me with no sheet over it (walker pass 4). .onChange(of: motion?.settled) { _, settled inlet caps = DatabaseCapRow.caps(databases)guard motion?.byPerson == true, let settled, caps.indices.contains(settled) else { return }guard caps[settled].database == nilelse { return choose(at: settled, .settled) } scene?.openDatabases()iflet shown = caps.firstIndex(where: { $0.database?.databaseId == scene?.shownId }) { motion?.turn(to: shown, animated: !reduceMotion) } } }/// The cap at `index` chosen, when the arc's move is a person's choice.privatefunc choose(at index: Int, _ move: ArcChoice.Move) {let caps = DatabaseCapRow.caps(databases)guardlet motion, caps.indices.contains(index), let chosen = caps[index].database?.databaseId,ArcChoice.chooses(move, byPerson: motion.byPerson, swiped: motion.swiped)else { return }if chosen != scene?.shownId { SwitchClock.asked(chosen) }Task { awaitDatabaseCapRow.choose(chosen, scene: scene, in: databases) } }privatefunc look(of cap: DatabaseCapRow.Cap) -> CapPrint {guardlet held = cap.database else {returnCapPrint(name: DatabaseCapWords.databases, colour: .navy, side: geometry.tileWidth) }returnCapPrint( name: databases?.capName(held) ?? held.name, colour: databases?.colours[held.databaseId] ?? .navy, side: geometry.tileWidth) }/// The arc stands on the chosen cap, its pictures drawn.privatefunc start(_ caps: [DatabaseCapRow.Cap]) {let motion = self.motion ?? FanMotion(geometry: geometry, spring: FanSpring(scale: theme.scale)) motion.geometry = geometry motion.onCross = { [haptics] in haptics.select() } motion.recount(caps.count)iflet chosen = caps.firstIndex(where: { $0.database?.databaseId == scene?.shownId }) { motion.turn(to: chosen, animated: false) }self.motion = motion prints.keepOnly(Set(caps.map(\.key))) drawPrints(caps) }privatefunc drawPrints(_ caps: [DatabaseCapRow.Cap]) {let geometry = geometryfor cap in caps where prints.picture(cap.key, look(of: cap)) == nil {let look = look(of: cap)let scale = Double(displayScale) * geometry.settledScaleif cap.database == nil { prints.draw(cap.key, look, scale: scale, environment: environment, content: EmptyCap(side: CGFloat(look.side)).padding(geometry.lift)) } else { prints.draw(cap.key, look, scale: scale, environment: environment, content: DatabaseCap(name: look.name, colour: look.colour, side: CGFloat(look.side)) .padding(geometry.lift)) } } }}#endif/// The words the caps' arc says.enumDatabaseCapWords {/// The last cap: it opens the Databases screen, where one is made or joined.staticvar databases: String { ShellLines.line("board", "caps.databases") }}