|
| 1 | +// |
| 2 | +// Direction.swift |
| 3 | +// OpenSwiftUICore |
| 4 | +// |
| 5 | +// Status: Complete |
| 6 | + |
| 7 | +// MARK: - HorizontalDirection [6.4.41] |
| 8 | + |
| 9 | +/// A direction on the horizontal axis. |
| 10 | +@frozen |
| 11 | +public enum HorizontalDirection: Int8, CaseIterable, Codable { |
| 12 | + /// The leading direction. |
| 13 | + case leading |
| 14 | + |
| 15 | + /// The trailing direction. |
| 16 | + case trailing |
| 17 | + |
| 18 | + /// An efficient set of horizontal directions. |
| 19 | + @frozen |
| 20 | + public struct Set: OptionSet, Equatable, Hashable { |
| 21 | + public let rawValue: Int8 |
| 22 | + |
| 23 | + public init(rawValue: Int8) { |
| 24 | + self.rawValue = rawValue |
| 25 | + } |
| 26 | + |
| 27 | + /// A set containing only the leading horizontal direction. |
| 28 | + public static let leading: HorizontalDirection.Set = .init(.leading) |
| 29 | + |
| 30 | + /// A set containing only the trailing horizontal direction. |
| 31 | + public static let trailing: HorizontalDirection.Set = .init(.trailing) |
| 32 | + |
| 33 | + /// A set containing the leading and trailing horizontal directions. |
| 34 | + public static let all: HorizontalDirection.Set = [.leading, .trailing] |
| 35 | + |
| 36 | + /// Creates a set of directions containing only the specified direction. |
| 37 | + public init(_ direction: HorizontalDirection) { |
| 38 | + rawValue = 1 << direction.rawValue |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +// MARK: - VerticalDirection [6.4.41] |
| 44 | + |
| 45 | +/// A direction on the vertical axis. |
| 46 | +@frozen |
| 47 | +public enum VerticalDirection: Int8, CaseIterable, Codable { |
| 48 | + /// The upward direction. |
| 49 | + case up |
| 50 | + |
| 51 | + /// The downward direction. |
| 52 | + case down |
| 53 | + |
| 54 | + /// An efficient set of vertical directions. |
| 55 | + @frozen |
| 56 | + public struct Set: OptionSet { |
| 57 | + public let rawValue: Int8 |
| 58 | + |
| 59 | + public init(rawValue: Int8) { |
| 60 | + self.rawValue = rawValue |
| 61 | + } |
| 62 | + |
| 63 | + /// A set containing only the upward vertical direction. |
| 64 | + public static let up: VerticalDirection.Set = .init(.up) |
| 65 | + |
| 66 | + /// A set containing only the downward vertical direction. |
| 67 | + public static let down: VerticalDirection.Set = .init(.down) |
| 68 | + |
| 69 | + /// A set containing the upward and downward vertical directions. |
| 70 | + public static let all: VerticalDirection.Set = [.up, .down] |
| 71 | + |
| 72 | + /// Creates a set of directions containing only the specified direction. |
| 73 | + public init(_ direction: VerticalDirection) { |
| 74 | + rawValue = 1 << direction.rawValue |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments