portico/Sources/Portico/Core/View.swift

25 lines
1 KiB
Swift

import Gtk
/// The core protocol for declarative UI components in Portico.
///
/// Conforming types describe their visual hierarchy in `body` using the
/// ``SingleViewBuilder`` result builder. The body is evaluated exactly once at
/// mount time - Portico erases heterogeneous conditional branches to
/// ``AnyView`` while retaining its build-once, bind-live model.
@MainActor public protocol View {
/// The type of view representing the body of this view.
associatedtype Body: View
/// The content and behavior of the view, composed using ``SingleViewBuilder``.
///
/// The body is evaluated exactly once at mount time. Heterogeneous
/// conditional branches are erased to ``AnyView``; Portico uses a
/// build-once, bind-live model rather than recompute-and-diff.
@SingleViewBuilder var body: Body { get }
}
/// Terminal conformance `Never` has no body and terminates the
/// `View` associated-type chain.
extension Never: View {
public var body: Never { fatalError("Never has no body") }
}