From b1e11a8553bc39a7c0e7cb6156c263aeb7dfb5bb Mon Sep 17 00:00:00 2001 From: Brendan Szymanski Date: Sun, 9 Aug 2026 19:15:25 -0400 Subject: [PATCH] Restore ToolbarView convenience initializers --- .../Extensions/ToolbarView+Extras.swift | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/Sources/Portico/Extensions/ToolbarView+Extras.swift b/Sources/Portico/Extensions/ToolbarView+Extras.swift index 7dc9dd8..35f5032 100644 --- a/Sources/Portico/Extensions/ToolbarView+Extras.swift +++ b/Sources/Portico/Extensions/ToolbarView+Extras.swift @@ -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.