// A picture a face shows, by its key. The face does not know where pictures // come from: the app draws a key from the phone (`PagePicture` in CottonUI, // installed as `facePictureDrawer`), the Loom app and the face shots from // their bundled fixtures. Unset, a picture draws nothing — a // visible hole, never a stand-in. import SwiftUI public struct FacePicture: View { public let key: String /// The longest side it is drawn at, in points: what the drawer asks the /// phone for. public let edge: CGFloat @Environment(\.facePictureDrawer) private var drawer public init(key: String, edge: CGFloat) { self.key = key self.edge = edge } public var body: some View { drawer(key, edge) } } /// How a `FacePicture` is drawn: the key and the edge in, the picture out. public typealias FacePictureDrawer = @MainActor @Sendable (_ key: String, _ edge: CGFloat) -> AnyView /// A picture's shape by its key: its width over its height, as whatever /// draws pictures knows it; nil where it does not. A card carries no /// picture's shape, and a face that lays a picture at its own shape (a lab /// print) asks this: the Loom app and the face shots answer from their /// fixtures' files (`FixturePictures.aspect`); the phone answers nothing /// until a kit names such a face. public typealias FacePictureAspect = @MainActor @Sendable (_ key: String) -> CGFloat? /// A picture's colour by its key: the mean of its pixels, as whatever /// draws pictures knows it; nil where it does not. A card carries no /// picture's colour, and a face that tints its stock from a picture (an /// album's spine behind an artist's divider) asks this: the Loom app and /// the face shots answer from their fixtures' files (`FixturePictures.tint`); /// the phone answers nothing until its pictures are read for it. public typealias FacePictureTint = @MainActor @Sendable (_ key: String) -> Color? extension EnvironmentValues { @Entry public var facePictureDrawer: FacePictureDrawer = { _, _ in AnyView(EmptyView()) } @Entry public var facePictureAspect: FacePictureAspect = { _ in nil } @Entry public var facePictureTint: FacePictureTint = { _ in nil } }