Skip to content

Commit a2d6ddf

Browse files
committed
SwiftWin32: further adopt static libraries on 5.7+
Swift 5.7.0 enables static libraries for non-standard library cases. Use this to extract the CoreGraphics interfaces out of the primary library.
1 parent e648af7 commit a2d6ddf

File tree

59 files changed

+266
-32
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+266
-32
lines changed

Examples/Calculator/Calculator.swift

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import SwiftWin32
55
import Foundation
66

7+
#if swift(>=5.7)
8+
import CoreGraphics
9+
#endif
10+
711
private extension View {
812
func addSubviews(_ views: [View]) {
913
_ = views.map { self.addSubview($0) }

Examples/UICatalog/UICatalog.swift

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import func WinSDK.MessageBoxW
88
import let WinSDK.MB_OK
99
import struct WinSDK.UINT
1010

11+
#if swift(>=5.7)
12+
import CoreGraphics
13+
#endif
14+
1115
private extension Label {
1216
convenience init(frame: Rect, title: String) {
1317
self.init(frame: frame)

Package.swift

+9-2
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,24 @@ let SwiftWin32: Package =
2727
targets: [
2828
.target(name: "CoreAnimation",
2929
path: "Sources/SwiftWin32/CoreAnimation"),
30+
.target(name: "CoreGraphics",
31+
path: "Sources/SwiftWin32/CoreGraphics"),
3032
.target(name: "SwiftWin32",
3133
dependencies: [
3234
"CoreAnimation",
35+
"CoreGraphics",
3336
.product(name: "Logging", package: "swift-log"),
3437
.product(name: "OrderedCollections",
3538
package: "swift-collections"),
3639
.product(name: "cassowary", package: "cassowary"),
3740
.product(name: "SwiftCOM", package: "swift-com"),
3841
],
3942
path: "Sources/SwiftWin32",
40-
exclude: ["CoreAnimation", "CMakeLists.txt"],
43+
exclude: [
44+
"CoreAnimation",
45+
"CoreGraphics",
46+
"CMakeLists.txt"
47+
],
4148
swiftSettings: [
4249
.enableExperimentalFeature("AccessLevelOnImport"),
4350
],
@@ -76,7 +83,7 @@ let SwiftWin32: Package =
7683
]),
7784
.target(name: "TestUtilities", path: "Tests/Utilities"),
7885
.testTarget(name: "AutoLayoutTests", dependencies: ["SwiftWin32"]),
79-
.testTarget(name: "CoreGraphicsTests", dependencies: ["SwiftWin32"]),
86+
.testTarget(name: "CoreGraphicsTests", dependencies: ["CoreGraphics"]),
8087
.testTarget(name: "SupportTests", dependencies: ["SwiftWin32"]),
8188
.testTarget(name: "UICoreTests",
8289
dependencies: ["SwiftWin32", "TestUtilities"])

[email protected]

+9-2
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,24 @@ let SwiftWin32: Package =
2727
targets: [
2828
.target(name: "CoreAnimation",
2929
path: "Sources/SwiftWin32/CoreAnimation"),
30+
.target(name: "CoreGraphics",
31+
path: "Sources/SwiftWin32/CoreGraphics"),
3032
.target(name: "SwiftWin32",
3133
dependencies: [
3234
"CoreAnimation",
35+
"CoreGraphics",
3336
.product(name: "Logging", package: "swift-log"),
3437
.product(name: "OrderedCollections",
3538
package: "swift-collections"),
3639
.product(name: "cassowary", package: "cassowary"),
3740
.product(name: "SwiftCOM", package: "swift-com"),
3841
],
3942
path: "Sources/SwiftWin32",
40-
exclude: ["CoreAnimation", "CMakeLists.txt"],
43+
exclude: [
44+
"CoreAnimation",
45+
"CoreGraphics",
46+
"CMakeLists.txt",
47+
],
4148
linkerSettings: [
4249
.linkedLibrary("User32"),
4350
.linkedLibrary("ComCtl32"),
@@ -73,7 +80,7 @@ let SwiftWin32: Package =
7380
]),
7481
.target(name: "TestUtilities", path: "Tests/Utilities"),
7582
.testTarget(name: "AutoLayoutTests", dependencies: ["SwiftWin32"]),
76-
.testTarget(name: "CoreGraphicsTests", dependencies: ["SwiftWin32"]),
83+
.testTarget(name: "CoreGraphicsTests", dependencies: ["CoreGraphics"]),
7784
.testTarget(name: "SupportTests", dependencies: ["SwiftWin32"]),
7885
.testTarget(name: "UICoreTests",
7986
dependencies: ["SwiftWin32", "TestUtilities"])

Sources/SwiftWin32/Animation and Haptics/Property-Based Animations/CubicTimingParameters.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright © 2021 Saleem Abdulrasool <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
#if swift(>=5.7)
5+
import CoreGraphics
6+
#endif
7+
48
/// The timing information for animations in the form of a cubic Bézier curve.
59
public class CubicTimingParameters {
610
// MARK - Initializing a Cubic Timing Parameters Object

Sources/SwiftWin32/Animation and Haptics/Property-Based Animations/SpringTimingParameters.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright © 2021 Saleem Abdulrasool <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
#if swift(>=5.7)
5+
import CoreGraphics
6+
#endif
7+
48
/// The timing information for animations that mimics the behavior of a spring.
59
public class SpringTimingParameters {
610
// MARK - Initializing a Spring Timing Parameters Object

Sources/SwiftWin32/Animation and Haptics/View Controller Transitions/ViewControllerTransitionCoordinatorContext.swift

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
import struct Foundation.TimeInterval
55

6+
#if swift(>=5.7)
7+
import CoreGraphics
8+
#endif
9+
610
/// Modal presentation styles available when presenting view controllers.
711
public enum ModalPresentationStyle: Int {
812
/// The default presentation style chosen by the system.

Sources/SwiftWin32/Animation and Haptics/ViewControllerContextTransitioning.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright © 2021 Saleem Abdulrasool <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
#if swift(>=5.7)
5+
import CoreGraphics
6+
#endif
7+
48
/// The keys you use to identify the view controllers involved in a transition.
59
public struct TransitionContextViewControllerKey: Equatable, Hashable, RawRepresentable {
610
public typealias RawValue = String

Sources/SwiftWin32/Appearance Customization/Configurations/ListContentConfiguration.swift

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
import class Foundation.NSAttributedString
55

6+
#if swift(>=5.7)
7+
import CoreGraphics
8+
#endif
9+
610
extension ListContentConfiguration {
711
/// Properties that affect the list content configuration's image.
812
public struct ImageProperties {

Sources/SwiftWin32/AutoLayout/LayoutGuide.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright © 2020 Saleem Abdulrasool <[email protected]>.
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
#if swift(>=5.7)
5+
import CoreGraphics
6+
#endif
7+
48
public class LayoutGuide {
59
// MARK - Working with Layout Guides
610

Sources/SwiftWin32/CMakeLists.txt

+16-6
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,6 @@ target_sources(SwiftWin32 PRIVATE
134134
"Windows and Screens/CoordinateSpace.swift"
135135
"Windows and Screens/Screen.swift"
136136
"Windows and Screens/Window.swift")
137-
target_sources(SwiftWin32 PRIVATE
138-
CG/AffineTransform.swift
139-
CG/Point.swift
140-
CG/Rect.swift
141-
CG/Size.swift
142-
CG/Vector.swift)
143137
target_sources(SwiftWin32 PRIVATE
144138
Platform/BatteryMonitor.swift
145139
Platform/Error.swift
@@ -164,11 +158,26 @@ target_sources(SwiftWin32 PRIVATE
164158
if(CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.7.0)
165159
target_sources(SwiftWin32 PRIVATE
166160
CoreAnimation/Transform3D.swift)
161+
target_sources(SwiftWin32 PRIVATE
162+
CoreGraphics/AffineTransform.swift
163+
CoreGraphics/Point.swift
164+
CoreGraphics/Rect.swift
165+
CoreGraphics/Size.swift
166+
CoreGraphics/Vector.swift)
167167
else()
168168
add_library(CoreAnimation STATIC
169169
CoreAnimation/Transform3D.swift)
170170
target_link_libraries(SwiftWin32 PRIVATE
171171
CoreAnimation)
172+
173+
add_library(CoreGraphics STATIC
174+
CoreGraphics/AffineTransform.swift
175+
CoreGraphics/Point.swift
176+
CoreGraphics/Rect.swift
177+
CoreGraphics/Size.swift
178+
CoreGraphics/Vector.swift)
179+
target_link_libraries(SwiftWin32 PRIVATE
180+
CoreGraphics)
172181
endif()
173182
target_link_libraries(SwiftWin32 PUBLIC
174183
ComCtl32
@@ -188,5 +197,6 @@ set_target_properties(SwiftWin32 PROPERTIES
188197

189198
if(CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 5.7.0)
190199
_install_target(CoreAnimation)
200+
_install_target(CoreGraphics)
191201
endif()
192202
_install_target(SwiftWin32)
File renamed without changes.

Sources/SwiftWin32/CG/Rect.swift Sources/SwiftWin32/CoreGraphics/Rect.swift

-14
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,3 @@ extension Rect: CustomDebugStringConvertible {
275275
return "Rect(origin: \(origin), size: \(size))"
276276
}
277277
}
278-
279-
extension Rect {
280-
internal func scaled(for dpi: UINT, style: WindowStyle) -> Rect {
281-
let scale: Double = Double(dpi) / Double(USER_DEFAULT_SCREEN_DPI)
282-
283-
var r: RECT =
284-
RECT(from: self.applying(AffineTransform(scaleX: scale, y: scale)))
285-
if !AdjustWindowRectExForDpi(&r, style.base, false, style.extended, dpi) {
286-
log.warning("AdjustWindowRectExForDpi: \(Error(win32: GetLastError()))")
287-
}
288-
289-
return Rect(from: r)
290-
}
291-
}
File renamed without changes.

Sources/SwiftWin32/Focus-Based Navigation/FocusItem.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright © 2020 Saleem Abdulrasool <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
#if swift(>=5.7)
5+
import CoreGraphics
6+
#endif
7+
48
/// An object that can become focused.
59
public protocol FocusItem: FocusEnvironment {
610
// MARK - Determining Focusability

Sources/SwiftWin32/Focus-Based Navigation/FocusItemContainer.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright © 2020 Saleem Abdulrasool <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
#if swift(>=5.7)
5+
import CoreGraphics
6+
#endif
7+
48
/// The container responsible for providing geometric context to focus items
59
/// within a given focus environment.
610
public protocol FocusItemContainer {

Sources/SwiftWin32/Focus-Based Navigation/FocusMovementHint.swift

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#if swift(>=5.7)
55
import CoreAnimation
6+
import CoreGraphics
67
#endif
78

89
/// Provides movement hint information for the focused item.

Sources/SwiftWin32/Images and PDF/Image.swift

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import WinSDK
55
import SwiftCOM
66

7+
#if swift(>=5.7)
8+
import CoreGraphics
9+
#endif
10+
711
private let WICImagingFactory: SwiftCOM.IWICImagingFactory? =
812
try? IWICImagingFactory.CreateInstance(class: CLSID_WICImagingFactory)
913

Sources/SwiftWin32/Menus and Shortcuts/ContextMenuInteraction.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright © 2020 Saleem Abdulrasool <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
#if swift(>=5.7)
5+
import CoreGraphics
6+
#endif
7+
48
extension ContextMenuInteraction {
59
/// Constants that describe the appearance of the menu.
610
public enum Appearance: Int {

Sources/SwiftWin32/Menus and Shortcuts/ContextMenuInteractionDelegate.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright © 2020 Saleem Abdulrasool <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
#if swift(>=5.7)
5+
import CoreGraphics
6+
#endif
7+
48
/// The methods for providing the set of actions to perform on your content,
59
/// and for customizing the preview of that content.
610
public protocol ContextMenuInteractionDelegate: AnyObject {

Sources/SwiftWin32/Menus and Shortcuts/PreviewTarget.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright © 2020 Saleem Abdulrasool <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
#if swift(>=5.7)
5+
import CoreGraphics
6+
#endif
7+
48
/// An object that specifies the container view to use for animations.
59
public class PreviewTarget {
610
/// Creating a Preview Target Object

Sources/SwiftWin32/Menus and Shortcuts/TargetedPreview.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright © 2020 Saleem Abdulrasool <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
#if swift(>=5.7)
5+
import CoreGraphics
6+
#endif
7+
48
public class TargetedPreview {
59
/// Creting a Targeted Preview Object
610

Sources/SwiftWin32/Pointer Interactions/PointerRegion.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright © 2020 Saleem Abdulrasool <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
#if swift(>=5.7)
5+
import CoreGraphics
6+
#endif
7+
48
public class PointerRegion {
59
// MARK - Configuring a Region
610

Sources/SwiftWin32/Pointer Interactions/PointerRegionRequest.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright © 2020 Saleem Abdulrasool <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
#if swift(>=5.7)
5+
import CoreGraphics
6+
#endif
7+
48
/// An object to describe the pointer's location in the interaction's view.
59
public class PointerRegionRequest {
610
// MARK - Inspecting the Region Request

Sources/SwiftWin32/Pointer Interactions/PointerStyle.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright © 2020 Saleem Abdulrasool <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
#if swift(>=5.7)
5+
import CoreGraphics
6+
#endif
7+
48
extension PointerEffect {
59
/// An effect that defines how to apply a tint to a view during a pointer
610
/// interaction.

Sources/SwiftWin32/Support/Point+UIExtensions.swift

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// SPDX-License-Identifier: BSD-3-Clause
33

44
import WinSDK
5+
#if swift(>=5.7)
6+
import CoreGraphics
7+
#endif
58

69
extension Point {
710
internal init(from: POINT) {

Sources/SwiftWin32/Support/Rect+UIExtensions.swift

+20-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
// SPDX-License-Identifier: BSD-3-Clause
33

44
import WinSDK
5+
#if swift(>=5.7)
6+
import CoreGraphics
7+
#endif
58

69
extension Rect {
710
internal init(from: RECT) {
8-
self.origin = Point(x: from.left, y: from.top)
9-
self.size = Size(width: from.right - from.left,
10-
height: from.bottom - from.top)
11+
self.init(origin: Point(x: from.left, y: from.top),
12+
size: Size(width: from.right - from.left,
13+
height: from.bottom - from.top))
1114
}
1215
}
1316

@@ -25,3 +28,17 @@ extension Rect {
2528
Point(x: self.midX, y: self.midY)
2629
}
2730
}
31+
32+
extension Rect {
33+
internal func scaled(for dpi: UINT, style: WindowStyle) -> Rect {
34+
let scale: Double = Double(dpi) / Double(USER_DEFAULT_SCREEN_DPI)
35+
36+
var r: RECT =
37+
RECT(from: self.applying(AffineTransform(scaleX: scale, y: scale)))
38+
if !AdjustWindowRectExForDpi(&r, style.base, false, style.extended, dpi) {
39+
log.warning("AdjustWindowRectExForDpi: \(Error(win32: GetLastError()))")
40+
}
41+
42+
return Rect(from: r)
43+
}
44+
}

Sources/SwiftWin32/Support/Size+UIExtensions.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright © 2020 Saleem Abdulrasool <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
#if swift(>=5.7)
5+
import CoreGraphics
6+
#endif
7+
48
extension Size {
59
internal init<Integer: FixedWidthInteger>(width: Integer, height: Integer) {
610
self.init(width: Int(width), height: Int(height))

0 commit comments

Comments
 (0)