adwaita-swift/Sources/Core/View/HeaderBar+.swift
david-swift 8eeda083e9
All checks were successful
Deploy Docs / publish (push) Successful in 18m28s
SwiftLint / SwiftLint (push) Successful in 5s
Separate AnyView extensions from widgets
2024-10-16 14:22:34 +02:00

53 lines
1.5 KiB
Swift

//
// HeaderBar+.swift
// Adwaita
//
// Created by david-swift on 21.01.23.
//
extension HeaderBar {
/// Initialize a header bar.
/// - Parameters:
/// - titleButtons: Whether the title buttons (e.g. close button) are visible.
/// - start: The start content.
/// - end: The end content.
public init(
titleButtons: Bool = true,
@ViewBuilder start: @escaping () -> Body,
@ViewBuilder end: @escaping () -> Body
) {
self.init()
self = self.showStartTitleButtons(titleButtons).showEndTitleButtons(titleButtons)
self = self.start(start).end(end)
}
/// Initialize an empty header bar.
/// - Returns: The header bar.
public static func empty() -> Self {
.init(start: { }, end: { })
}
/// Initialize a header bar with only views at the start.
/// - Parameter start: The views.
/// - Returns: The header bar.
public static func start(@ViewBuilder start: @escaping () -> Body) -> Self {
.init(start: start) { }
}
/// Initialize a header bar with only views at the end.
/// - Parameter start: The views.
/// - Returns: The header bar.
public static func end(@ViewBuilder end: @escaping () -> Body) -> Self {
.init(start: { }, end: end)
}
/// Set the title widget for the header bar.
/// - Parameter view: The widget in the header bar.
/// - Returns: The header bar.
public func headerBarTitle(@ViewBuilder view: @escaping () -> Body) -> Self {
titleWidget(view)
}
}