69 lines
2.4 KiB
Swift
69 lines
2.4 KiB
Swift
import Adw
|
|
import Gtk
|
|
|
|
extension ToolbarView {
|
|
/// Creates a toolbar view with content and optional top and bottom bars.
|
|
///
|
|
/// The content closure's first view is mounted as the content widget. Every
|
|
/// view returned by the top and bottom closures is mounted directly as a
|
|
/// corresponding toolbar bar.
|
|
///
|
|
/// - Parameters:
|
|
/// - content: A closure producing the content widget.
|
|
/// - top: A closure producing widgets to add as top bars.
|
|
/// - bottom: A closure producing widgets to add as bottom bars.
|
|
public init(
|
|
@ViewBuilder content: () -> [AnyView],
|
|
@ViewBuilder top: () -> [AnyView],
|
|
@ViewBuilder bottom: () -> [AnyView]
|
|
) {
|
|
let contentViews = content()
|
|
let topViews = top()
|
|
let bottomViews = bottom()
|
|
|
|
self.init()
|
|
if let contentView = contentViews.first {
|
|
self = self.appending { toolbar, context in
|
|
toolbar.setContent(content: contentView.makeWidget(context))
|
|
}
|
|
}
|
|
for view in topViews {
|
|
self = self.appending { toolbar, context in
|
|
toolbar.addTopBar(widget: view.makeWidget(context))
|
|
}
|
|
}
|
|
for view in bottomViews {
|
|
self = self.appending { toolbar, context in
|
|
toolbar.addBottomBar(widget: view.makeWidget(context))
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Adds widgets produced by `content` as top bars.
|
|
///
|
|
/// - Parameter content: A closure producing widgets to add as top bars.
|
|
/// - Returns: A copy of this view with the bars added at mount time.
|
|
public func top(@ViewBuilder _ content: () -> [AnyView]) -> Self {
|
|
var view = self
|
|
for child in content() {
|
|
view = view.appending { toolbar, context in
|
|
toolbar.addTopBar(widget: child.makeWidget(context))
|
|
}
|
|
}
|
|
return view
|
|
}
|
|
|
|
/// Adds widgets produced by `content` as bottom bars.
|
|
///
|
|
/// - Parameter content: A closure producing widgets to add as bottom bars.
|
|
/// - Returns: A copy of this view with the bars added at mount time.
|
|
public func bottom(@ViewBuilder _ content: () -> [AnyView]) -> Self {
|
|
var view = self
|
|
for child in content() {
|
|
view = view.appending { toolbar, context in
|
|
toolbar.addBottomBar(widget: child.makeWidget(context))
|
|
}
|
|
}
|
|
return view
|
|
}
|
|
}
|