macbackend/Sources/MacBackend/AnyView.swift
david-swift 43f53e1681
All checks were successful
Deploy Docs / publish (push) Successful in 2m59s
SwiftLint / SwiftLint (push) Successful in 2s
Add support for toolbars
2024-12-08 20:39:50 +01:00

50 lines
1.5 KiB
Swift

//
// AnyView.swift
// MacBackend
//
// Created by david-swift on 04.12.2024.
//
@_exported import Core
extension AnyView {
// swiftlint:disable function_default_parameter_at_end
/// Add an alert to a view.
/// - Parameters:
/// - title: The title.
/// - description: The description.
/// - isPresented: Whether the alert is visible.
/// - Returns: The alert.
public func alert(_ title: String, description: String = "", isPresented: Meta.Binding<Bool>) -> Alert {
.init(title: title, description: description, isPresented: isPresented, child: self)
}
// swiftlint:enable function_default_parameter_at_end
/// Set the padding.
/// - Parameters:
/// - padding: The padding.
/// - edges: The edges.
/// - Returns: The view.
public func padding(_ padding: Double, edges: Set<Edge> = .all) -> AnyView {
PaddingView(padding: padding, edges: edges, child: self)
}
/// A menu over the view.
/// - Parameters:
/// - isPresented: Whether the menu is currently visible.
/// - menu: The menu.
/// - Returns: The view.
public func menu(isPresented: Binding<Bool>, @ViewBuilder menu: @escaping () -> Body) -> AnyView {
MenuWrapper(content: { self }, isPresented: isPresented, menu: menu)
}
/// Set the toolbar.
/// - Parameter content: The toolbar's content.
/// - Returns: The view.
public func toolbar(@ViewBuilder content: () -> Body) -> AnyView {
ToolbarView(child: self, toolbarViews: content)
}
}