portico/Sources/Portico/Views/VStack.swift

29 lines
916 B
Swift

import Gtk
/// A vertical container backed by `Gtk.Box(orientation: .vertical)`.
@MainActor public struct VStack: View {
let spacing: Int32
let content: () -> [AnyView]
public var body: Never { fatalError() }
/// Creates a vertical stack with the given spacing and children.
///
/// - Parameters:
/// - spacing: Spacing between children in pixels.
/// - content: A ``ViewBuilder`` closure producing the children.
public init(
spacing: Int32 = 0,
@ViewBuilder content: @escaping () -> [AnyView]
) {
self.spacing = spacing
self.content = content
}
}
@_spi(Portico) extension VStack: Mountable {
@_spi(Portico) public func mount(_ ctx: MountContext) -> Gtk.Widget {
let box = Gtk.Box(orientation: .vertical, spacing: spacing)
mountChildren(content, into: box, ctx) { box.appendChild($0) }
return box
}
}