Skip to content

Commit

Permalink
SwiftWin32: further adopt static libraries on 5.7+
Browse files Browse the repository at this point in the history
Swift 5.7.0 enables static libraries for non-standard library
cases.  Use this to extract the CoreGraphics interfaces out of the
primary library.
  • Loading branch information
compnerd committed Dec 25, 2023
1 parent e648af7 commit 1118fef
Show file tree
Hide file tree
Showing 57 changed files with 257 additions and 33 deletions.
4 changes: 4 additions & 0 deletions Examples/Calculator/Calculator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import SwiftWin32
import Foundation

#if swift(>=5.7)
import CoreGraphics
#endif

private extension View {
func addSubviews(_ views: [View]) {
_ = views.map { self.addSubview($0) }
Expand Down
4 changes: 4 additions & 0 deletions Examples/UICatalog/UICatalog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import func WinSDK.MessageBoxW
import let WinSDK.MB_OK
import struct WinSDK.UINT

#if swift(>=5.7)
import CoreGraphics
#endif

private extension Label {
convenience init(frame: Rect, title: String) {
self.init(frame: frame)
Expand Down
11 changes: 9 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,24 @@ let SwiftWin32: Package =
targets: [
.target(name: "CoreAnimation",
path: "Sources/SwiftWin32/CoreAnimation"),
.target(name: "CoreGraphics",
path: "Sources/SwiftWin32/CoreGraphics"),
.target(name: "SwiftWin32",
dependencies: [
"CoreAnimation",
"CoreGraphics",
.product(name: "Logging", package: "swift-log"),
.product(name: "OrderedCollections",
package: "swift-collections"),
.product(name: "cassowary", package: "cassowary"),
.product(name: "SwiftCOM", package: "swift-com"),
],
path: "Sources/SwiftWin32",
exclude: ["CoreAnimation", "CMakeLists.txt"],
exclude: [
"CoreAnimation",
"CoreGraphics",
"CMakeLists.txt"
],
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport"),
],
Expand Down Expand Up @@ -76,7 +83,7 @@ let SwiftWin32: Package =
]),
.target(name: "TestUtilities", path: "Tests/Utilities"),
.testTarget(name: "AutoLayoutTests", dependencies: ["SwiftWin32"]),
.testTarget(name: "CoreGraphicsTests", dependencies: ["SwiftWin32"]),
.testTarget(name: "CoreGraphicsTests", dependencies: ["CoreGraphics"]),
.testTarget(name: "SupportTests", dependencies: ["SwiftWin32"]),
.testTarget(name: "UICoreTests",
dependencies: ["SwiftWin32", "TestUtilities"])
Expand Down
11 changes: 9 additions & 2 deletions Package@swift-5.7.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,24 @@ let SwiftWin32: Package =
targets: [
.target(name: "CoreAnimation",
path: "Sources/SwiftWin32/CoreAnimation"),
.target(name: "CoreGraphics",
path: "Sources/SwiftWin32/CoreGraphics"),
.target(name: "SwiftWin32",
dependencies: [
"CoreAnimation",
"CoreGraphics",
.product(name: "Logging", package: "swift-log"),
.product(name: "OrderedCollections",
package: "swift-collections"),
.product(name: "cassowary", package: "cassowary"),
.product(name: "SwiftCOM", package: "swift-com"),
],
path: "Sources/SwiftWin32",
exclude: ["CoreAnimation", "CMakeLists.txt"],
exclude: [
"CoreAnimation",
"CoreGraphics",
"CMakeLists.txt",
],
linkerSettings: [
.linkedLibrary("User32"),
.linkedLibrary("ComCtl32"),
Expand Down Expand Up @@ -73,7 +80,7 @@ let SwiftWin32: Package =
]),
.target(name: "TestUtilities", path: "Tests/Utilities"),
.testTarget(name: "AutoLayoutTests", dependencies: ["SwiftWin32"]),
.testTarget(name: "CoreGraphicsTests", dependencies: ["SwiftWin32"]),
.testTarget(name: "CoreGraphicsTests", dependencies: ["CoreGraphics"]),
.testTarget(name: "SupportTests", dependencies: ["SwiftWin32"]),
.testTarget(name: "UICoreTests",
dependencies: ["SwiftWin32", "TestUtilities"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3-Clause

#if swift(>=5.7)
import CoreGraphics
#endif

/// The timing information for animations in the form of a cubic Bézier curve.
public class CubicTimingParameters {
// MARK - Initializing a Cubic Timing Parameters Object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3-Clause

#if swift(>=5.7)
import CoreGraphics
#endif

/// The timing information for animations that mimics the behavior of a spring.
public class SpringTimingParameters {
// MARK - Initializing a Spring Timing Parameters Object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

import struct Foundation.TimeInterval

#if swift(>=5.7)
import CoreGraphics
#endif

/// Modal presentation styles available when presenting view controllers.
public enum ModalPresentationStyle: Int {
/// The default presentation style chosen by the system.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3-Clause

#if swift(>=5.7)
import CoreGraphics
#endif

/// The keys you use to identify the view controllers involved in a transition.
public struct TransitionContextViewControllerKey: Equatable, Hashable, RawRepresentable {
public typealias RawValue = String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

import class Foundation.NSAttributedString

#if swift(>=5.7)
import CoreGraphics
#endif

extension ListContentConfiguration {
/// Properties that affect the list content configuration's image.
public struct ImageProperties {
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftWin32/AutoLayout/LayoutGuide.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright © 2020 Saleem Abdulrasool <compnerd@compnerd.org>.
// SPDX-License-Identifier: BSD-3-Clause

#if swift(>=5.7)
import CoreGraphics
#endif

public class LayoutGuide {
// MARK - Working with Layout Guides

Expand Down
22 changes: 16 additions & 6 deletions Sources/SwiftWin32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ target_sources(SwiftWin32 PRIVATE
"Windows and Screens/CoordinateSpace.swift"
"Windows and Screens/Screen.swift"
"Windows and Screens/Window.swift")
target_sources(SwiftWin32 PRIVATE
CG/AffineTransform.swift
CG/Point.swift
CG/Rect.swift
CG/Size.swift
CG/Vector.swift)
target_sources(SwiftWin32 PRIVATE
Platform/BatteryMonitor.swift
Platform/Error.swift
Expand All @@ -164,11 +158,26 @@ target_sources(SwiftWin32 PRIVATE
if(CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.7.0)
target_sources(SwiftWin32 PRIVATE
CoreAnimation/Transform3D.swift)
target_sources(SwiftWin32 PRIVATE
CoreGraphics/AffineTransform.swift
CoreGraphics/Point.swift
CoreGraphics/Rect.swift
CoreGraphics/Size.swift
CoreGraphics/Vector.swift)
else()
add_library(CoreAnimation STATIC
CoreAnimation/Transform3D.swift)
target_link_libraries(SwiftWin32 PRIVATE
CoreAnimation)

add_library(CoreGraphics STATIC
CoreGraphics/AffineTransform.swift
CoreGraphics/Point.swift
CoreGraphics/Rect.swift
CoreGraphics/Size.swift
CoreGraphics/Vector.swift)
target_link_libraries(SwiftWin32 PRIVATE
CoreGraphics)
endif()
target_link_libraries(SwiftWin32 PUBLIC
ComCtl32
Expand All @@ -188,5 +197,6 @@ set_target_properties(SwiftWin32 PROPERTIES

if(CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 5.7.0)
_install_target(CoreAnimation)
_install_target(CoreGraphics)
endif()
_install_target(SwiftWin32)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,3 @@ extension Rect: CustomDebugStringConvertible {
return "Rect(origin: \(origin), size: \(size))"
}
}

extension Rect {
internal func scaled(for dpi: UINT, style: WindowStyle) -> Rect {
let scale: Double = Double(dpi) / Double(USER_DEFAULT_SCREEN_DPI)

var r: RECT =
RECT(from: self.applying(AffineTransform(scaleX: scale, y: scale)))
if !AdjustWindowRectExForDpi(&r, style.base, false, style.extended, dpi) {
log.warning("AdjustWindowRectExForDpi: \(Error(win32: GetLastError()))")
}

return Rect(from: r)
}
}
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions Sources/SwiftWin32/Focus-Based Navigation/FocusItem.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright © 2020 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3-Clause

#if swift(>=5.7)
import CoreGraphics
#endif

/// An object that can become focused.
public protocol FocusItem: FocusEnvironment {
// MARK - Determining Focusability
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright © 2020 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3-Clause

#if swift(>=5.7)
import CoreGraphics
#endif

/// The container responsible for providing geometric context to focus items
/// within a given focus environment.
public protocol FocusItemContainer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#if swift(>=5.7)
import CoreAnimation
import CoreGraphics
#endif

/// Provides movement hint information for the focused item.
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftWin32/Images and PDF/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import WinSDK
import SwiftCOM

#if swift(>=5.7)
import CoreGraphics
#endif

private let WICImagingFactory: SwiftCOM.IWICImagingFactory? =
try? IWICImagingFactory.CreateInstance(class: CLSID_WICImagingFactory)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright © 2020 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3-Clause

#if swift(>=5.7)
import CoreGraphics
#endif

extension ContextMenuInteraction {
/// Constants that describe the appearance of the menu.
public enum Appearance: Int {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright © 2020 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3-Clause

#if swift(>=5.7)
import CoreGraphics
#endif

/// The methods for providing the set of actions to perform on your content,
/// and for customizing the preview of that content.
public protocol ContextMenuInteractionDelegate: AnyObject {
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftWin32/Menus and Shortcuts/PreviewTarget.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright © 2020 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3-Clause

#if swift(>=5.7)
import CoreGraphics
#endif

/// An object that specifies the container view to use for animations.
public class PreviewTarget {
/// Creating a Preview Target Object
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftWin32/Menus and Shortcuts/TargetedPreview.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright © 2020 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3-Clause

#if swift(>=5.7)
import CoreGraphics
#endif

public class TargetedPreview {
/// Creting a Targeted Preview Object

Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftWin32/Pointer Interactions/PointerRegion.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright © 2020 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3-Clause

#if swift(>=5.7)
import CoreGraphics
#endif

public class PointerRegion {
// MARK - Configuring a Region

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright © 2020 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3-Clause

#if swift(>=5.7)
import CoreGraphics
#endif

/// An object to describe the pointer's location in the interaction's view.
public class PointerRegionRequest {
// MARK - Inspecting the Region Request
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftWin32/Pointer Interactions/PointerStyle.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright © 2020 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3-Clause

#if swift(>=5.7)
import CoreGraphics
#endif

extension PointerEffect {
/// An effect that defines how to apply a tint to a view during a pointer
/// interaction.
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftWin32/Support/Point+UIExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// SPDX-License-Identifier: BSD-3-Clause

import WinSDK
#if swift(>=5.7)
import CoreGraphics
#endif

extension Point {
internal init(from: POINT) {
Expand Down
23 changes: 20 additions & 3 deletions Sources/SwiftWin32/Support/Rect+UIExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
// SPDX-License-Identifier: BSD-3-Clause

import WinSDK
#if swift(>=5.7)
import CoreGraphics
#endif

extension Rect {
internal init(from: RECT) {
self.origin = Point(x: from.left, y: from.top)
self.size = Size(width: from.right - from.left,
height: from.bottom - from.top)
self.init(origin: Point(x: from.left, y: from.top),
size: Size(width: from.right - from.left,
height: from.bottom - from.top))
}
}

Expand All @@ -25,3 +28,17 @@ extension Rect {
Point(x: self.midX, y: self.midY)
}
}

extension Rect {
internal func scaled(for dpi: UINT, style: WindowStyle) -> Rect {
let scale: Double = Double(dpi) / Double(USER_DEFAULT_SCREEN_DPI)

var r: RECT =
RECT(from: self.applying(AffineTransform(scaleX: scale, y: scale)))
if !AdjustWindowRectExForDpi(&r, style.base, false, style.extended, dpi) {
log.warning("AdjustWindowRectExForDpi: \(Error(win32: GetLastError()))")
}

return Rect(from: r)
}
}
4 changes: 4 additions & 0 deletions Sources/SwiftWin32/Support/Size+UIExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright © 2020 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3-Clause

#if swift(>=5.7)
import CoreGraphics
#endif

extension Size {
internal init<Integer: FixedWidthInteger>(width: Integer, height: Integer) {
self.init(width: Int(width), height: Int(height))
Expand Down
Loading

0 comments on commit 1118fef

Please sign in to comment.