diff --git a/Sources/Core/Model/Enumerations/Axis.swift b/Sources/Core/Model/Enumerations/Axis.swift new file mode 100644 index 0000000..99f6d07 --- /dev/null +++ b/Sources/Core/Model/Enumerations/Axis.swift @@ -0,0 +1,18 @@ +// +// Axis.swift +// MacBackend +// +// Created by david-swift on 29.12.2024. +// + +import SwiftUI + +/// An axis. +public enum Axis { + + /// The vertical axis. + case vertical + /// The horizontal axis. + case horizontal + +} diff --git a/Sources/Core/Model/Extensions/Set.swift b/Sources/Core/Model/Extensions/Set.swift index 5d55aaa..46a5c80 100644 --- a/Sources/Core/Model/Extensions/Set.swift +++ b/Sources/Core/Model/Extensions/Set.swift @@ -63,3 +63,36 @@ extension Set where Element == Edge { } } + +extension Set where Element == Axis { + + /// The vertical axis. + public static var vertical: Self { + [.vertical] + } + + /// The horizontal axis. + public static var horizontal: Self { + [.horizontal] + } + + /// The vertical and horizontal axes. + public static var both: Self { + [.horizontal, .vertical] + } + + /// The SwiftUI axis set. + var swiftUI: SwiftUI.Axis.Set { + switch self { + case [.vertical]: + .vertical + case [.horizontal]: + .horizontal + case [.vertical, .horizontal]: + [.vertical, .horizontal] + default: + [] + } + } + +} diff --git a/Sources/Core/View/ScrollView.swift b/Sources/Core/View/ScrollView.swift index bc2d483..769851c 100644 --- a/Sources/Core/View/ScrollView.swift +++ b/Sources/Core/View/ScrollView.swift @@ -10,6 +10,8 @@ import SwiftUI /// The scroll view widget. public struct ScrollView: SwiftUIWidget { + /// The axes. + var axes: Set /// The view's content. var content: Body @@ -20,15 +22,16 @@ public struct ScrollView: SwiftUIWidget { /// Initialize the scroll view. /// - Parameter content: The content view. - public init(@Meta.ViewBuilder content: () -> Body) { + public init(_ axes: Set = .vertical, @Meta.ViewBuilder content: () -> Body) { self.content = content() + self.axes = axes } /// Get the SwiftUI view. /// - Parameter properties: The widget data. /// - Returns: The SwiftUI view. public static func view(properties: Self) -> some SwiftUI.View { - SwiftUI.ScrollView { + SwiftUI.ScrollView(properties.axes.swiftUI) { MacBackendView(.mainContent) } }