Restore ToolbarView convenience initializers
This commit is contained in:
parent
23d7508763
commit
b1e11a8553
1 changed files with 62 additions and 0 deletions
|
|
@ -2,6 +2,68 @@ 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]
|
||||
) {
|
||||
self.init(content: content, top: top, bottom: { })
|
||||
}
|
||||
|
||||
/// Creates a toolbar view with content and bottom bars.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - content: A closure producing the content widget.
|
||||
/// - bottom: A closure producing widgets to add as bottom bars.
|
||||
public init(
|
||||
@ViewBuilder content: () -> [AnyView],
|
||||
@ViewBuilder bottom: () -> [AnyView]
|
||||
) {
|
||||
self.init(content: content, top: { }, bottom: bottom)
|
||||
}
|
||||
|
||||
/// Creates a toolbar view with content, top bars, and bottom bars.
|
||||
///
|
||||
/// - 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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue