Skip to content

Commit 97c356e

Browse files
committed
App and Environment: shuffle & extend ContentSizeCategory
This moves the source file used for the `ContentSizeCategory` extensible enumeration. It adds some missing interfaces as well.
1 parent 369db66 commit 97c356e

File tree

2 files changed

+107
-62
lines changed

2 files changed

+107
-62
lines changed

Sources/SwiftWin32/App and Environment/Application.swift

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,113 @@
11
// Copyright © 2019 Saleem Abdulrasool <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
import class Foundation.NSNotification
5+
6+
/// Constants that indicate the preferred size of your content.
7+
public struct ContentSizeCategory: Equatable, Hashable, RawRepresentable {
8+
public typealias RawValue = String
9+
10+
public var rawValue: RawValue
11+
12+
public init(rawValue: RawValue) {
13+
self.rawValue = rawValue
14+
}
15+
}
16+
17+
extension ContentSizeCategory {
18+
// MARK - Font Sizes
19+
20+
/// An unspecified font size.
21+
public static var unspecified: ContentSizeCategory {
22+
ContentSizeCategory(rawValue: "_UICTContentSizeCategoryUnspecified")
23+
}
24+
25+
/// An extra-small font.
26+
public static var extraSmall: ContentSizeCategory {
27+
ContentSizeCategory(rawValue: "UICTContentSizeCategoryXS")
28+
}
29+
30+
/// A small font.
31+
public static var small: ContentSizeCategory {
32+
ContentSizeCategory(rawValue: "UICTContentSizeCategoryS")
33+
}
34+
35+
/// A medium-sized font.
36+
public static var medium: ContentSizeCategory {
37+
ContentSizeCategory(rawValue: "UICTContentSizeCategoryM")
38+
}
39+
40+
/// A large font.
41+
public static var large: ContentSizeCategory {
42+
ContentSizeCategory(rawValue: "UICTContentSizeCategoryL")
43+
}
44+
45+
/// An extra-large font.
46+
public static var extraLarge: ContentSizeCategory {
47+
ContentSizeCategory(rawValue: "UICTContentSizeCategoryXL")
48+
}
49+
50+
/// A font that is larger than the extra-large font but smaller than the
51+
/// largest font size available.
52+
public static var extraExtraLarge: ContentSizeCategory {
53+
ContentSizeCategory(rawValue: "UICTContentSizeCategoryXXL")
54+
}
55+
56+
/// The largest font size.
57+
public static var extraExtraExtraLarge: ContentSizeCategory {
58+
ContentSizeCategory(rawValue: "UICTContentSizeCategoryXXXL")
59+
}
60+
61+
// MARK - Accessibility Sizes
62+
63+
/// A medium font size that reflects the current accessibility settings.
64+
public static var accessibilityMedium: ContentSizeCategory {
65+
ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityM")
66+
}
67+
68+
/// A large font size that reflects the current accessibility settings.
69+
public static var accessibilityLarge: ContentSizeCategory {
70+
ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityL")
71+
}
72+
73+
/// An extra-large font size that reflects the current accessibility settings.
74+
public static var accessibilityExtraLarge: ContentSizeCategory {
75+
ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityXL")
76+
}
77+
78+
/// A font that is larger than the extra-large font but not the largest
79+
/// available, reflecting the current accessibility settings.
80+
public static var accessibilityExtraExtraLarge: ContentSizeCategory {
81+
ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityXXL")
82+
}
83+
84+
/// The largest font size that reflects the current accessibility settings.
85+
public static var accessibilityExtraExtraExtraLarge: ContentSizeCategory {
86+
ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityXXXL")
87+
}
88+
89+
// MARK - Font Size Change Notifications
90+
91+
/// A notification that posts when the user changes the preferred content size
92+
/// setting.
93+
///
94+
/// This notification is sent when the value in the
95+
/// `preferredContentSizeCategory` property changes. The `userInfo` dictionary
96+
/// of the notification contains the `newValueUserInfoKey` key, which reflects
97+
/// the new setting.
98+
public static var didChangeNotification: NSNotification.Name {
99+
NSNotification.Name(rawValue: "UIContentSizeCategoryDidChangeNotification")
100+
}
101+
102+
/// A key that reflects the new preferred content size.
103+
///
104+
/// This key's value is an `NSString` object that reflects the new value of
105+
/// the `preferredContentSizeCategory` property.
106+
public static var newValueUserInfoKey: String {
107+
"UIContentSizeCategoryNewValueUserInfoKey"
108+
}
109+
}
110+
4111
/// The centralised point of control and coordination for running applications.
5112
open class Application: Responder {
6113
internal var information: Information?

Sources/SwiftWin32/App and Environment/TraitCollection.swift

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -110,70 +110,8 @@ public enum ForceTouchCapability: Int {
110110
case unspecified
111111
case available
112112
case unavailable
113-
}
114-
115-
public struct ContentSizeCategory: Equatable, Hashable, RawRepresentable {
116-
public typealias RawValue = String
117-
118-
public var rawValue: RawValue
119-
120-
public init(rawValue: RawValue) {
121-
self.rawValue = rawValue
122-
}
123-
}
124-
125-
extension ContentSizeCategory {
126-
public static var unspecified: ContentSizeCategory {
127-
ContentSizeCategory(rawValue: "_UICTContentSizeCategoryUnspecified")
128-
}
129-
130-
public static var extraSmall: ContentSizeCategory {
131-
ContentSizeCategory(rawValue: "UICTContentSizeCategoryXS")
132-
}
133-
134-
public static var small: ContentSizeCategory {
135-
ContentSizeCategory(rawValue: "UICTContentSizeCategoryS")
136-
}
137-
138-
public static var medium: ContentSizeCategory {
139-
ContentSizeCategory(rawValue: "UICTContentSizeCategoryM")
140-
}
141-
142-
public static var large: ContentSizeCategory {
143-
ContentSizeCategory(rawValue: "UICTContentSizeCategoryL")
144-
}
145-
146-
public static var extraLarge: ContentSizeCategory {
147-
ContentSizeCategory(rawValue: "UICTContentSizeCategoryXL")
148-
}
149-
150-
public static var extraExtraLarge: ContentSizeCategory {
151-
ContentSizeCategory(rawValue: "UICTContentSizeCategoryXXL")
152-
}
153-
154-
public static var extraExtraExtraLarge: ContentSizeCategory {
155-
ContentSizeCategory(rawValue: "UICTContentSizeCategoryXXXL")
156-
}
157113

158-
public static var accessibilityMedium: ContentSizeCategory {
159-
ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityM")
160-
}
161114

162-
public static var accessibilityLarge: ContentSizeCategory {
163-
ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityL")
164-
}
165-
166-
public static var accessibilityExtraLarge: ContentSizeCategory {
167-
ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityXL")
168-
}
169-
170-
public static var accessibilityExtraExtraLarge: ContentSizeCategory {
171-
ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityXXL")
172-
}
173-
174-
public static var accessibilityExtraExtraExtraLarge: ContentSizeCategory {
175-
ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityXXXL")
176-
}
177115
}
178116

179117
private func GetCurrentColorScheme() -> UserInterfaceStyle {

0 commit comments

Comments
 (0)