Add support for horizontal scroll views
All checks were successful
Deploy Docs / publish (push) Successful in 3m28s
SwiftLint / SwiftLint (push) Successful in 4s

This commit is contained in:
david-swift 2024-12-30 11:53:09 +01:00
parent 3c2cc8cb48
commit cccf048d67
3 changed files with 56 additions and 2 deletions

View File

@ -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
}

View File

@ -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:
[]
}
}
}

View File

@ -10,6 +10,8 @@ import SwiftUI
/// The scroll view widget. /// The scroll view widget.
public struct ScrollView: SwiftUIWidget { public struct ScrollView: SwiftUIWidget {
/// The axes.
var axes: Set<Axis>
/// The view's content. /// The view's content.
var content: Body var content: Body
@ -20,15 +22,16 @@ public struct ScrollView: SwiftUIWidget {
/// Initialize the scroll view. /// Initialize the scroll view.
/// - Parameter content: The content view. /// - Parameter content: The content view.
public init(@Meta.ViewBuilder content: () -> Body) { public init(_ axes: Set<Axis> = .vertical, @Meta.ViewBuilder content: () -> Body) {
self.content = content() self.content = content()
self.axes = axes
} }
/// Get the SwiftUI view. /// Get the SwiftUI view.
/// - Parameter properties: The widget data. /// - Parameter properties: The widget data.
/// - Returns: The SwiftUI view. /// - Returns: The SwiftUI view.
public static func view(properties: Self) -> some SwiftUI.View { public static func view(properties: Self) -> some SwiftUI.View {
SwiftUI.ScrollView { SwiftUI.ScrollView(properties.axes.swiftUI) {
MacBackendView(.mainContent) MacBackendView(.mainContent)
} }
} }