36 lines
1.1 KiB
Swift
36 lines
1.1 KiB
Swift
import Gtk
|
|
|
|
/// A configurable-orientation container backed by `Gtk.Box`.
|
|
@MainActor public struct Box: View {
|
|
let orientation: Gtk.Orientation
|
|
let spacing: Int32
|
|
let children: [AnyView]
|
|
|
|
public var body: Never { fatalError() }
|
|
|
|
/// Creates a box with the given orientation, spacing, and children.
|
|
///
|
|
/// - Parameters:
|
|
/// - orientation: `.vertical` (default) or `.horizontal`.
|
|
/// - spacing: Spacing between children in pixels.
|
|
/// - content: A ``ViewBuilder`` closure producing the children.
|
|
public init(
|
|
orientation: Gtk.Orientation = .vertical,
|
|
spacing: Int32 = 0,
|
|
@ViewBuilder content: () -> [AnyView]
|
|
) {
|
|
self.orientation = orientation
|
|
self.spacing = spacing
|
|
self.children = content()
|
|
}
|
|
}
|
|
|
|
@_spi(Portico) extension Box: Mountable {
|
|
@_spi(Portico) public func mount(_ ctx: MountContext) -> Gtk.Widget {
|
|
let box = Gtk.Box(orientation: orientation, spacing: spacing)
|
|
for child in children {
|
|
box.appendChild(child.makeWidget(ctx))
|
|
}
|
|
return box
|
|
}
|
|
}
|