Add support for horizontal scroll views
This commit is contained in:
parent
3c2cc8cb48
commit
cccf048d67
18
Sources/Core/Model/Enumerations/Axis.swift
Normal file
18
Sources/Core/Model/Enumerations/Axis.swift
Normal 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
|
||||||
|
|
||||||
|
}
|
||||||
@ -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:
|
||||||
|
[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user