Skip to content

Commit

Permalink
Add basic path support (#102)
Browse files Browse the repository at this point in the history
* Update Package.swift

* Add basic path support
  • Loading branch information
Kyle-Ye authored Aug 28, 2024
1 parent 0f91969 commit e5b5ce4
Show file tree
Hide file tree
Showing 10 changed files with 550 additions and 82 deletions.
37 changes: 16 additions & 21 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ let systemFrameworkSearchFlag = isXcodeEnv ? "-iframework" : "-Fsystem"

let releaseVersion = Context.environment["OPENSWIFTUI_TARGET_RELEASE"].flatMap { Int($0) } ?? 2021
let platforms: [SupportedPlatform] = switch releaseVersion {
case 2023:
case 2024:
#if swift(>=6.0)
[
.iOS(.v18),
.macOS(.v15),
.macCatalyst(.v18),
.tvOS(.v18),
.watchOS(.v10),
.visionOS(.v2),
]
#else // FIXME: Remove when we bump to Swift 6.0
[
.iOS(.v17),
.macOS(.v14),
Expand All @@ -34,14 +44,7 @@ case 2023:
.watchOS(.v9),
.visionOS(.v1),
]
case 2022:
[
.iOS(.v16),
.macOS(.v13),
.macCatalyst(.v16),
.tvOS(.v16),
.watchOS(.v8),
]
#endif
case 2021:
[
.iOS(.v15),
Expand All @@ -67,18 +70,10 @@ var sharedSwiftSettings: [SwiftSetting] = [
.define("OPENSWIFTUI_RELEASE_\(releaseVersion)"),
]

switch releaseVersion {
case 2023:
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2023_API"))
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2022_API"))
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2021_API"))
case 2022:
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2022_API"))
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2021_API"))
case 2021:
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_2021_API"))
default:
break
if releaseVersion >= 2021 {
for year in 2021 ... releaseVersion {
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_\(year)_API"))
}
}

let warningsAsErrorsCondition = envEnable("OPENSWIFTUI_WERROR", default: isXcodeEnv && development)
Expand Down
12 changes: 12 additions & 0 deletions Sources/COpenSwiftUI/Overlay/CoreGraphics/__CGPathParseString.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// __CGPathParseString.m
// COpenSwiftUI

#include "__CGPathParseString.h"

#if OPENSWIFTUI_TARGET_OS_DARWIN
BOOL __CGPathParseString(CGMutablePathRef path, const char *utf8CString) {
// TODO
return NO;
}
#endif
4 changes: 1 addition & 3 deletions Sources/COpenSwiftUI/dyld_Private.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//
// dyld_Private.c
//
//
//
// COpenSwiftUI

#include "dyld_Private.h"

Expand Down
24 changes: 24 additions & 0 deletions Sources/COpenSwiftUI/include/__CGPathParseString.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// __CGPathParseString.m
// COpenSwiftUI

#ifndef __CGPathParseString_h
#define __CGPathParseString_h

#include "OpenSwiftUIBase.h"

#if OPENSWIFTUI_TARGET_OS_DARWIN

#include <Foundation/Foundation.h>
#include <CoreGraphics/CoreGraphics.h>

OPENSWIFTUI_ASSUME_NONNULL_BEGIN

OPENSWIFTUI_EXPORT
BOOL __CGPathParseString(CGMutablePathRef path, const char *utf8CString);

OPENSWIFTUI_ASSUME_NONNULL_END

#endif

#endif /* __CGPathParseString_h */
19 changes: 19 additions & 0 deletions Sources/OpenSwiftUI/Core/Data/UnsafeAtomicLazy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// UnsafeAtomicLazy.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Status: WIP

struct UnsafeAtomicLazy<Data>: Destroyable {
@UnsafeLockedPointer
var cache: Data?

func read(_ block: () -> Data) -> Data {
fatalError("TODO") // StrokedPath.boundingRect
}

func destroy() {
_cache.destroy()
}
}
58 changes: 0 additions & 58 deletions Sources/OpenSwiftUI/View/Shape/Path.swift

This file was deleted.

31 changes: 31 additions & 0 deletions Sources/OpenSwiftUI/View/Shape/Path/FixedRoundedRect.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// FixedRoundedRect.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Status: WIP

import Foundation

@usableFromInline
struct FixedRoundedRect: Equatable {
var rect: CGRect
var cornerSize: CGSize
var style: RoundedCornerStyle

func contains(_ roundedRect: FixedRoundedRect) -> Bool {
guard rect.insetBy(dx: -0.001, dy: -0.001).contains(roundedRect.rect) else {
return false
}
guard !(cornerSize.width <= roundedRect.cornerSize.width && cornerSize.height <= roundedRect.cornerSize.height) else {
return true
}
let minCornerWidth = min(abs(rect.size.width) / 2, cornerSize.width)
let minCornerHeight = min(abs(rect.size.height) / 2, cornerSize.height)
let factor = 0.292893 // 1 - cos(45 * Double.pi / 180)
return rect.insetBy(dx: minCornerWidth * factor, dy: minCornerHeight * factor).contains(roundedRect.rect)
}

func distance(to point: CGPoint) -> CGFloat {
fatalError("TODO")
}
}
Loading

0 comments on commit e5b5ce4

Please sign in to comment.