Edge.swift 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. /// Indicates a specific edge of a rectangle.
  2. public enum Edge: Int8, CaseIterable, Hashable, Sendable {
  3. /// The top edge.
  4. case top
  5. /// The bottom edge.
  6. case bottom
  7. /// The leading edge (the left edge in left to right layouts).
  8. case leading
  9. /// The trailing edge (the right edge in left to right layouts).
  10. case trailing
  11. /// An efficient set of Edges.
  12. public struct Set: OptionSet, Hashable, Sendable {
  13. public let rawValue: Int8
  14. public init(rawValue: Int8) {
  15. self.rawValue = rawValue
  16. }
  17. public init(_ edge: Edge) {
  18. self.rawValue = 1 << edge.rawValue
  19. }
  20. public static let top = Set(.top)
  21. public static let bottom = Set(.bottom)
  22. public static let leading = Set(.leading)
  23. public static let trailing = Set(.trailing)
  24. public static let horizontal: Set = [.leading, .trailing]
  25. public static let vertical: Set = [.bottom, .top]
  26. public static let all: Set = [.horizontal, .vertical]
  27. }
  28. }