// What the gauge faces share (the machine's dials, the quota's meter): their // knobs, and a gauge's numbers read off the card as the core gave them — // numbers, never words. import CottonValues import SwiftUI enum GaugeFacesKnobs { static let inset = EdgeInsets(top: 30, leading: 24, bottom: 22, trailing: 22) static let nameSize: CGFloat = 36 /// The Mac under the name: at most this share of the card's width, and /// the room round it. static let artShare: CGFloat = 0.8 static let artGap: CGFloat = 4 static let factGap: CGFloat = 3 static let tableSize: CGFloat = 12.5 /// The longest label the facts' label column holds, in letters. static let labelLetters = 8 /// The dials just under the table, and the foot's rule under them. static let dialGap: CGFloat = 10 static let footGap: CGFloat = 10 static let footHand: CGFloat = 22 /// A machine's dial: its width over the card's, the scale's sweep in /// degrees, its brass bezel, the wash's band and inset, the ticks (every /// `dialMajor`th long), the needle and the hub, each a share of the dial. static let dialShare: CGFloat = 0.29 static let dialSweep: Double = 250 static let bezel: CGFloat = 0.075 static let washBand: CGFloat = 0.08 static let washInset: CGFloat = 0.17 static let dialTicks = 20 static let dialMajor = 5 static let tickRadius: CGFloat = 0.36 static let needleLength: CGFloat = 0.36 static let needleWidth: CGFloat = 0.06 static let hub: CGFloat = 0.13 /// The Macs drawn, by a word of the model the card names; the desk Mac /// (a display over a Mac Studio) when it names none of them. static let macArt: [(model: String, art: String)] = [ ("mini", "face-art-mac-mini"), ("macbook", "face-art-laptop"), ("studio", "face-art-computer"), ] static let deskMac = "face-art-computer" /// A quota: its title, the meter's height over the card's width, its /// band and needle and hub as shares of its radius, its ticks (every /// `meterMajor`th long) and the room its marks stand in. static let quotaTitle: CGFloat = 18 /// The pencil line under when it resets. static let underline: CGFloat = 1.2 static let underlineOpacity: Double = 0.7 static let underlineTurn: Double = -1.5 static let quotaGap: CGFloat = 8 static let meterHeight: CGFloat = 0.54 static let meterBand: CGFloat = 0.3 /// The band's wash: green at the low end through buff to red at the top. static let zoneWash: Double = 0.44 static let meterNeedle: CGFloat = 0.05 static let meterHub: CGFloat = 0.16 static let meterTicks = 40 static let meterMajor = 8 static let markRoom: CGFloat = 22 static let markSize: CGFloat = 11 static let usedSize: CGFloat = 22 static let leftSize: CGFloat = 16 static let resetHand: CGFloat = 24 /// The trend under it: its width over the card's, its height, a dot, /// the room its typed shares stand in, their size, and how many /// readings are all typed. static let trendShare: CGFloat = 0.6 static let trendHeight: CGFloat = 52 static let trendDot: CGFloat = 4.5 static let trendLine: CGFloat = 1 static let trendWash: Double = 0.16 static let trendLabel: CGFloat = 16 static let trendType: CGFloat = 11 static let trendTypedAll = 4 /// The scale's marks: every fifth of a hundred. static let marks = stride(from: 0, through: 100, by: 20).map { "\($0)" } } extension DeckCard { /// A gauge part as the core gave it: a number, never words. public func number(_ slot: String) -> Double? { guard case .number(let value)? = fields[slot] else { return nil } return value } /// How full a gauge is, nought to one: `used` of `limit` (of a hundred /// when there is none), or what `free` leaves of `limit`. public var gaugeShare: Double? { if let used = number("used") { return min(1, max(0, used / (number("limit") ?? 100))) } if let free = number("free"), let limit = number("limit"), limit > 0 { return min(1, max(0, 1 - free / limit)) } return nil } }