|
| 1 | +import Swift |
| 2 | + |
| 3 | +/// The size classes, like regular or small, that you can apply to controls |
| 4 | +/// within a view. |
| 5 | +@available(iOS 15.0, macOS 10.15, Windows 10, *) |
| 6 | +@available(tvOS, unavailable) |
| 7 | +@available(watchOS, unavailable) |
| 8 | +public enum ControlSize : String, CaseIterable, Equatable, Hashable { |
| 9 | + |
| 10 | + // MARK: - Case(s). |
| 11 | + |
| 12 | + /// A control version that is minimally sized. |
| 13 | + case mini |
| 14 | + |
| 15 | + /// A control version that is proportionally smaller size for space-constrained views. |
| 16 | + case small |
| 17 | + |
| 18 | + /// A control version that is the default size. |
| 19 | + case regular |
| 20 | + |
| 21 | + /// A control version that is prominently sized. |
| 22 | + @available(macOS 11.0, Windows 10, *) |
| 23 | + case large |
| 24 | + |
| 25 | + // MARK: - Case Interable. |
| 26 | + |
| 27 | + /// A collection of all values of this type. |
| 28 | + public static var allCases: [ControlSize] { |
| 29 | + if #available(macOS 11.0, Windows 10, *) { |
| 30 | + return [ .mini, .small, .regular, .large ] |
| 31 | + } |
| 32 | + |
| 33 | + return [ .mini, .small, .regular ] |
| 34 | + } |
| 35 | + |
| 36 | + /// A type that can represent a collection of all values of this type. |
| 37 | + public typealias AllCases = [ControlSize] |
| 38 | + |
| 39 | + // MARK: - Equatable. |
| 40 | + |
| 41 | + /// Returns a Boolean value indicating whether two values are equal. |
| 42 | + /// |
| 43 | + /// Equality is the inverse of inequality. For any values `a` and `b`, |
| 44 | + /// `a == b` implies that `a != b` is `false`. |
| 45 | + /// |
| 46 | + /// - Parameters: |
| 47 | + /// - lhs: A value to compare. |
| 48 | + /// - rhs: Another value to compare. |
| 49 | + public static func == (lhs: ControlSize, rhs: ControlSize) -> Bool { |
| 50 | + lhs.rawValue == rhs.rawValue |
| 51 | + } |
| 52 | + |
| 53 | + /// Hashes the essential components of this value by feeding them into the |
| 54 | + /// given hasher. |
| 55 | + /// |
| 56 | + /// Implement this method to conform to the `Hashable` protocol. The |
| 57 | + /// components used for hashing must be the same as the components compared |
| 58 | + /// in your type's `==` operator implementation. Call `hasher.combine(_:)` |
| 59 | + /// with each of these components. |
| 60 | + /// |
| 61 | + /// - Important: Never call `finalize()` on `hasher`. Doing so may become a |
| 62 | + /// compile-time error in the future. |
| 63 | + /// |
| 64 | + /// - Parameter hasher: The hasher to use when combining the components |
| 65 | + /// of this instance. |
| 66 | + public func hash(into hasher: inout Hasher) { |
| 67 | + hasher.combine(rawValue) |
| 68 | + } |
| 69 | +} |
0 commit comments