Skip to content

Add Direction #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions Sources/OpenSwiftUICore/Layout/Direction/Direction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// Direction.swift
// OpenSwiftUICore
//
// Status: Complete

// MARK: - HorizontalDirection [6.4.41]

/// A direction on the horizontal axis.
@frozen
public enum HorizontalDirection: Int8, CaseIterable, Codable {
/// The leading direction.
case leading

/// The trailing direction.
case trailing

/// An efficient set of horizontal directions.
@frozen
public struct Set: OptionSet, Equatable, Hashable {
public let rawValue: Int8

public init(rawValue: Int8) {
self.rawValue = rawValue
}

/// A set containing only the leading horizontal direction.
public static let leading: HorizontalDirection.Set = .init(.leading)

/// A set containing only the trailing horizontal direction.
public static let trailing: HorizontalDirection.Set = .init(.trailing)

/// A set containing the leading and trailing horizontal directions.
public static let all: HorizontalDirection.Set = [.leading, .trailing]

/// Creates a set of directions containing only the specified direction.
public init(_ direction: HorizontalDirection) {
rawValue = 1 << direction.rawValue
}
}
}

// MARK: - VerticalDirection [6.4.41]

/// A direction on the vertical axis.
@frozen
public enum VerticalDirection: Int8, CaseIterable, Codable {
/// The upward direction.
case up

/// The downward direction.
case down

/// An efficient set of vertical directions.
@frozen
public struct Set: OptionSet {
public let rawValue: Int8

public init(rawValue: Int8) {
self.rawValue = rawValue
}

/// A set containing only the upward vertical direction.
public static let up: VerticalDirection.Set = .init(.up)

/// A set containing only the downward vertical direction.
public static let down: VerticalDirection.Set = .init(.down)

/// A set containing the upward and downward vertical directions.
public static let all: VerticalDirection.Set = [.up, .down]

/// Creates a set of directions containing only the specified direction.
public init(_ direction: VerticalDirection) {
rawValue = 1 << direction.rawValue
}
}
}