From 39035cf2ae6af6250b22b83258ec72412283f4fa Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Wed, 16 Jun 2021 23:53:31 +0100 Subject: [PATCH 1/3] Use `CGFloat`, `CGPoint`, `CGRect` from Foundation --- .../Modifiers/Effects/ClipEffect.swift | 4 +- .../Modifiers/Effects/GeometryEffect.swift | 4 +- .../Modifiers/Effects/RotationEffect.swift | 6 +- .../Modifiers/FlexFrameLayout.swift | 4 +- .../TokamakCore/Modifiers/FrameLayout.swift | 4 +- .../TokamakCore/Modifiers/PaddingLayout.swift | 4 +- .../TokamakCore/Modifiers/ShadowLayout.swift | 16 ++++++ .../Modifiers/StyleModifiers.swift | 4 +- Sources/TokamakCore/PreviewProvider.swift | 4 +- Sources/TokamakCore/Shapes/Ellipse.swift | 4 +- .../TokamakCore/Shapes/FixedRoundedRect.swift | 4 +- .../TokamakCore/Shapes/ModifiedShapes.swift | 6 +- Sources/TokamakCore/Shapes/Path.swift | 11 +--- Sources/TokamakCore/Shapes/Rectangle.swift | 4 +- Sources/TokamakCore/Shapes/Shape.swift | 4 +- .../TokamakCore/Shapes/ShapeModifiers.swift | 4 +- Sources/TokamakCore/Shapes/StrokeStyle.swift | 4 +- Sources/TokamakCore/Shapes/TrimmedPath.swift | 4 +- Sources/TokamakCore/Stubs/CGStubs.swift | 57 ++----------------- Sources/TokamakCore/Tokens/Edge.swift | 4 +- Sources/TokamakCore/Tokens/Font.swift | 4 +- Sources/TokamakCore/Tokens/GridItem.swift | 4 +- Sources/TokamakCore/Tokens/UnitPoint.swift | 5 +- .../Views/Containers/Section.swift | 4 +- .../Views/Layout/GeometryReader.swift | 4 +- Sources/TokamakCore/Views/Layout/HStack.swift | 4 +- .../TokamakCore/Views/Layout/LazyHGrid.swift | 4 +- .../TokamakCore/Views/Layout/LazyVGrid.swift | 4 +- Sources/TokamakCore/Views/Layout/VStack.swift | 4 +- Sources/TokamakCore/Views/Layout/ZStack.swift | 4 +- .../TokamakCore/Views/Spacers/Spacer.swift | 4 +- Sources/TokamakCore/Views/Text/Text.swift | 4 +- Sources/TokamakDOM/Core.swift | 5 +- .../Views/Layout/GeometryReader.swift | 3 +- Sources/TokamakDemo/PathDemo.swift | 3 +- Sources/TokamakDemo/TextDemo.swift | 4 +- Sources/TokamakStaticHTML/Core.swift | 5 +- .../Modifiers/LayoutModifiers.swift | 3 +- Sources/TokamakStaticHTML/Shapes/Path.swift | 4 +- .../Views/Spacers/Spacer.swift | 3 +- .../TokamakStaticHTML/Views/Text/Text.swift | 3 +- 41 files changed, 130 insertions(+), 108 deletions(-) diff --git a/Sources/TokamakCore/Modifiers/Effects/ClipEffect.swift b/Sources/TokamakCore/Modifiers/Effects/ClipEffect.swift index 3e8848844..239a1ffbf 100644 --- a/Sources/TokamakCore/Modifiers/Effects/ClipEffect.swift +++ b/Sources/TokamakCore/Modifiers/Effects/ClipEffect.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 06/29/2020. // +import Foundation + public struct _ClipEffect: ViewModifier where ClipShape: Shape { public var shape: ClipShape public var style: FillStyle diff --git a/Sources/TokamakCore/Modifiers/Effects/GeometryEffect.swift b/Sources/TokamakCore/Modifiers/Effects/GeometryEffect.swift index f37893edc..bdd09731d 100644 --- a/Sources/TokamakCore/Modifiers/Effects/GeometryEffect.swift +++ b/Sources/TokamakCore/Modifiers/Effects/GeometryEffect.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 7/3/20. // +import Foundation + // FIXME: Make `Animatable` public protocol GeometryEffect: ViewModifier { func effectValue(size: CGSize) -> ProjectionTransform diff --git a/Sources/TokamakCore/Modifiers/Effects/RotationEffect.swift b/Sources/TokamakCore/Modifiers/Effects/RotationEffect.swift index 6bcfb317c..812b046b0 100644 --- a/Sources/TokamakCore/Modifiers/Effects/RotationEffect.swift +++ b/Sources/TokamakCore/Modifiers/Effects/RotationEffect.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 7/3/20. // +import Foundation + public struct _RotationEffect: GeometryEffect { public var angle: Angle public var anchor: UnitPoint @@ -25,7 +27,7 @@ public struct _RotationEffect: GeometryEffect { } public func effectValue(size: CGSize) -> ProjectionTransform { - .init(CGAffineTransform.identity.rotated(by: angle.radians)) + .init(CGAffineTransform.identity.rotated(by: CGFloat(angle.radians))) } public func body(content: Content) -> some View { diff --git a/Sources/TokamakCore/Modifiers/FlexFrameLayout.swift b/Sources/TokamakCore/Modifiers/FlexFrameLayout.swift index 24b6f62a8..7858e290c 100644 --- a/Sources/TokamakCore/Modifiers/FlexFrameLayout.swift +++ b/Sources/TokamakCore/Modifiers/FlexFrameLayout.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation + public struct _FlexFrameLayout: ViewModifier { public let minWidth: CGFloat? public let idealWidth: CGFloat? diff --git a/Sources/TokamakCore/Modifiers/FrameLayout.swift b/Sources/TokamakCore/Modifiers/FrameLayout.swift index a786a2bf3..bbbc6ebb9 100644 --- a/Sources/TokamakCore/Modifiers/FrameLayout.swift +++ b/Sources/TokamakCore/Modifiers/FrameLayout.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation + public struct _FrameLayout: ViewModifier { public let width: CGFloat? public let height: CGFloat? diff --git a/Sources/TokamakCore/Modifiers/PaddingLayout.swift b/Sources/TokamakCore/Modifiers/PaddingLayout.swift index 8bed5bdc3..3334d8c29 100644 --- a/Sources/TokamakCore/Modifiers/PaddingLayout.swift +++ b/Sources/TokamakCore/Modifiers/PaddingLayout.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation + public struct _PaddingLayout: ViewModifier { public var edges: Edge.Set public var insets: EdgeInsets? diff --git a/Sources/TokamakCore/Modifiers/ShadowLayout.swift b/Sources/TokamakCore/Modifiers/ShadowLayout.swift index b1de3ea34..991da8ae8 100644 --- a/Sources/TokamakCore/Modifiers/ShadowLayout.swift +++ b/Sources/TokamakCore/Modifiers/ShadowLayout.swift @@ -1,3 +1,19 @@ +// Copyright 2021 Tokamak contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation + public struct _ShadowLayout: ViewModifier, EnvironmentReader { public var color: Color public var radius: CGFloat diff --git a/Sources/TokamakCore/Modifiers/StyleModifiers.swift b/Sources/TokamakCore/Modifiers/StyleModifiers.swift index a7f734110..b9d49758b 100644 --- a/Sources/TokamakCore/Modifiers/StyleModifiers.swift +++ b/Sources/TokamakCore/Modifiers/StyleModifiers.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 6/29/20. // +import Foundation + public struct _BackgroundModifier: ViewModifier, EnvironmentReader where Background: View { diff --git a/Sources/TokamakCore/PreviewProvider.swift b/Sources/TokamakCore/PreviewProvider.swift index 758172282..171b4bb41 100644 --- a/Sources/TokamakCore/PreviewProvider.swift +++ b/Sources/TokamakCore/PreviewProvider.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation + /// This protocol has no functionality currently, and is only provided for compatibility purposes. public protocol PreviewProvider { associatedtype Previews: View diff --git a/Sources/TokamakCore/Shapes/Ellipse.swift b/Sources/TokamakCore/Shapes/Ellipse.swift index ad61c20d7..4566b0816 100644 --- a/Sources/TokamakCore/Shapes/Ellipse.swift +++ b/Sources/TokamakCore/Shapes/Ellipse.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 6/29/20. // +import Foundation + public struct Ellipse: Shape { public func path(in rect: CGRect) -> Path { .init(storage: .ellipse(rect), sizing: .flexible) diff --git a/Sources/TokamakCore/Shapes/FixedRoundedRect.swift b/Sources/TokamakCore/Shapes/FixedRoundedRect.swift index 5e7b2c266..78f2f9d42 100644 --- a/Sources/TokamakCore/Shapes/FixedRoundedRect.swift +++ b/Sources/TokamakCore/Shapes/FixedRoundedRect.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 7/22/20. // +import Foundation + public struct FixedRoundedRect: Equatable { public let rect: CGRect public let cornerSize: CGSize? diff --git a/Sources/TokamakCore/Shapes/ModifiedShapes.swift b/Sources/TokamakCore/Shapes/ModifiedShapes.swift index 19317e987..485ac3283 100644 --- a/Sources/TokamakCore/Shapes/ModifiedShapes.swift +++ b/Sources/TokamakCore/Shapes/ModifiedShapes.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 06/28/2020. // +import Foundation + public struct _StrokedShape: Shape where S: Shape { @Environment(\.self) public var environment public var shape: S @@ -106,7 +108,7 @@ public struct RotatedShape: Shape where Content: Shape { public func path(in rect: CGRect) -> Path { shape .path(in: rect) - .applying(.init(rotationAngle: angle.radians)) + .applying(.init(rotationAngle: CGFloat(angle.radians))) } } diff --git a/Sources/TokamakCore/Shapes/Path.swift b/Sources/TokamakCore/Shapes/Path.swift index 20010b6e6..0a847af9e 100644 --- a/Sources/TokamakCore/Shapes/Path.swift +++ b/Sources/TokamakCore/Shapes/Path.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,13 +15,7 @@ // Created by Carson Katri on 06/28/2020. // -#if canImport(Darwin) -import Darwin -#elseif canImport(Glibc) -import Glibc -#elseif os(WASI) -import WASILibc -#endif +import Foundation /// The outline of a 2D shape. public struct Path: Equatable, LosslessStringConvertible { @@ -610,6 +604,7 @@ private func getArc( clockwise: clockwise ) } else { + let angle = CGFloat(angle) let endPoint = CGPoint( x: (radius * cos(angle)) + center.x, y: (radius * sin(angle)) + center.y diff --git a/Sources/TokamakCore/Shapes/Rectangle.swift b/Sources/TokamakCore/Shapes/Rectangle.swift index e849f929c..d7b74d168 100644 --- a/Sources/TokamakCore/Shapes/Rectangle.swift +++ b/Sources/TokamakCore/Shapes/Rectangle.swift @@ -1,4 +1,4 @@ -// Copyright 2018-2020 Tokamak contributors +// Copyright 2018-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation + public struct Rectangle: Shape { public func path(in rect: CGRect) -> Path { .init(storage: .rect(rect), sizing: .flexible) diff --git a/Sources/TokamakCore/Shapes/Shape.swift b/Sources/TokamakCore/Shapes/Shape.swift index 7b7bcb8e4..2b3c055c3 100644 --- a/Sources/TokamakCore/Shapes/Shape.swift +++ b/Sources/TokamakCore/Shapes/Shape.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 06/28/2020. // +import Foundation + public protocol Shape: View { func path(in rect: CGRect) -> Path } diff --git a/Sources/TokamakCore/Shapes/ShapeModifiers.swift b/Sources/TokamakCore/Shapes/ShapeModifiers.swift index 6a363a263..d5765e64a 100644 --- a/Sources/TokamakCore/Shapes/ShapeModifiers.swift +++ b/Sources/TokamakCore/Shapes/ShapeModifiers.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 6/29/20. // +import Foundation + public extension InsettableShape { func strokeBorder( _ content: S, diff --git a/Sources/TokamakCore/Shapes/StrokeStyle.swift b/Sources/TokamakCore/Shapes/StrokeStyle.swift index 236baeab6..d67a3c5e1 100644 --- a/Sources/TokamakCore/Shapes/StrokeStyle.swift +++ b/Sources/TokamakCore/Shapes/StrokeStyle.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 7/22/20. // +import Foundation + public struct StrokeStyle: Equatable { public var lineWidth: CGFloat public var lineCap: CGLineCap diff --git a/Sources/TokamakCore/Shapes/TrimmedPath.swift b/Sources/TokamakCore/Shapes/TrimmedPath.swift index fc74ffed7..1fcdb47c7 100644 --- a/Sources/TokamakCore/Shapes/TrimmedPath.swift +++ b/Sources/TokamakCore/Shapes/TrimmedPath.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 7/22/20. // +import Foundation + public struct TrimmedPath: Equatable { public let path: Path public let from: CGFloat diff --git a/Sources/TokamakCore/Stubs/CGStubs.swift b/Sources/TokamakCore/Stubs/CGStubs.swift index a67a28745..d84bb94a6 100644 --- a/Sources/TokamakCore/Stubs/CGStubs.swift +++ b/Sources/TokamakCore/Stubs/CGStubs.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,31 +15,12 @@ // Created by Max Desiatov on 08/04/2020. // -#if canImport(Glibc) -import Glibc -#elseif canImport(Darwin) -import Darwin -#elseif os(WASI) -import WASILibc -#endif - -public typealias CGFloat = Double -public struct CGPoint: Equatable { - public var x: CGFloat - public var y: CGFloat - - public init(x: CGFloat, y: CGFloat) { - self.x = x - self.y = y - } - - public static var zero: Self { - .init(x: 0, y: 0) - } +import Foundation +extension CGPoint { func rotate(_ angle: Angle, around origin: Self) -> Self { - let cosAngle = cos(angle.radians) - let sinAngle = sin(angle.radians) + let cosAngle = CGFloat(cos(angle.radians)) + let sinAngle = CGFloat(sin(angle.radians)) return .init( x: cosAngle * (x - origin.x) - sinAngle * (y - origin.y) + origin.x, y: sinAngle * (x - origin.x) + cosAngle * (y - origin.y) + origin.y @@ -54,34 +35,6 @@ public struct CGPoint: Equatable { } } -public struct CGSize: Equatable { - public var width: CGFloat - public var height: CGFloat - - public init(width: CGFloat, height: CGFloat) { - self.width = width - self.height = height - } - - public static var zero: Self { - .init(width: 0, height: 0) - } -} - -public struct CGRect: Equatable { - public var origin: CGPoint - public var size: CGSize - - public init(origin: CGPoint, size: CGSize) { - self.origin = origin - self.size = size - } - - public static var zero: Self { - .init(origin: .zero, size: .zero) - } -} - public enum CGLineCap { /// A line with a squared-off end. Extends to the endpoint of the Path. case butt diff --git a/Sources/TokamakCore/Tokens/Edge.swift b/Sources/TokamakCore/Tokens/Edge.swift index 9eb39ea64..09dadf73d 100644 --- a/Sources/TokamakCore/Tokens/Edge.swift +++ b/Sources/TokamakCore/Tokens/Edge.swift @@ -1,4 +1,4 @@ -// Copyright 2018-2020 Tokamak contributors +// Copyright 2018-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation + public enum Edge: Int8, CaseIterable { case top, leading, bottom, trailing diff --git a/Sources/TokamakCore/Tokens/Font.swift b/Sources/TokamakCore/Tokens/Font.swift index 3ea487f20..c0378b9be 100644 --- a/Sources/TokamakCore/Tokens/Font.swift +++ b/Sources/TokamakCore/Tokens/Font.swift @@ -1,4 +1,4 @@ -// Copyright 2018-2020 Tokamak contributors +// Copyright 2018-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation + /// Override `TokamakCore`'s default `Font` resolvers with a Renderer-specific one. /// You can override a specific font box /// (such as `_SystemFontBox`, or all boxes with `AnyFontBox`). diff --git a/Sources/TokamakCore/Tokens/GridItem.swift b/Sources/TokamakCore/Tokens/GridItem.swift index 78b3440c8..51227d9d9 100644 --- a/Sources/TokamakCore/Tokens/GridItem.swift +++ b/Sources/TokamakCore/Tokens/GridItem.swift @@ -1,4 +1,4 @@ -// Copyright 2019-2020 Tokamak contributors +// Copyright 2019-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 7/13/20. // +import Foundation + public struct GridItem { public enum Size { case fixed(CGFloat) diff --git a/Sources/TokamakCore/Tokens/UnitPoint.swift b/Sources/TokamakCore/Tokens/UnitPoint.swift index cbdc0f440..676390094 100644 --- a/Sources/TokamakCore/Tokens/UnitPoint.swift +++ b/Sources/TokamakCore/Tokens/UnitPoint.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -11,11 +11,12 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - // // Created by Carson Katri on 6/28/20. // +import Foundation + public struct UnitPoint: Hashable { public var x: CGFloat public var y: CGFloat diff --git a/Sources/TokamakCore/Views/Containers/Section.swift b/Sources/TokamakCore/Views/Containers/Section.swift index 4f5c2eba9..7d02dc620 100644 --- a/Sources/TokamakCore/Views/Containers/Section.swift +++ b/Sources/TokamakCore/Views/Containers/Section.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 7/5/20. // +import Foundation + protocol SectionView { func listRow(_ style: ListStyle) -> AnyView } diff --git a/Sources/TokamakCore/Views/Layout/GeometryReader.swift b/Sources/TokamakCore/Views/Layout/GeometryReader.swift index e3e04610c..35091bf38 100644 --- a/Sources/TokamakCore/Views/Layout/GeometryReader.swift +++ b/Sources/TokamakCore/Views/Layout/GeometryReader.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation + public struct GeometryProxy { public let size: CGSize } diff --git a/Sources/TokamakCore/Views/Layout/HStack.swift b/Sources/TokamakCore/Views/Layout/HStack.swift index 2b68b0521..1978734fb 100644 --- a/Sources/TokamakCore/Views/Layout/HStack.swift +++ b/Sources/TokamakCore/Views/Layout/HStack.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Max Desiatov on 08/04/2020. // +import Foundation + /// An alignment position along the vertical axis. public enum VerticalAlignment: Equatable { case top diff --git a/Sources/TokamakCore/Views/Layout/LazyHGrid.swift b/Sources/TokamakCore/Views/Layout/LazyHGrid.swift index 72a7663f4..5291c05d5 100644 --- a/Sources/TokamakCore/Views/Layout/LazyHGrid.swift +++ b/Sources/TokamakCore/Views/Layout/LazyHGrid.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 7/13/20. // +import Foundation + public struct LazyHGrid: _PrimitiveView where Content: View { let rows: [GridItem] let alignment: VerticalAlignment diff --git a/Sources/TokamakCore/Views/Layout/LazyVGrid.swift b/Sources/TokamakCore/Views/Layout/LazyVGrid.swift index 0d286c6b4..2f9555af8 100644 --- a/Sources/TokamakCore/Views/Layout/LazyVGrid.swift +++ b/Sources/TokamakCore/Views/Layout/LazyVGrid.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 7/13/20. // +import Foundation + public struct LazyVGrid: _PrimitiveView where Content: View { let columns: [GridItem] let alignment: HorizontalAlignment diff --git a/Sources/TokamakCore/Views/Layout/VStack.swift b/Sources/TokamakCore/Views/Layout/VStack.swift index f26fcdaf3..ff61d3470 100644 --- a/Sources/TokamakCore/Views/Layout/VStack.swift +++ b/Sources/TokamakCore/Views/Layout/VStack.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation + /// An alignment position along the horizontal axis. public enum HorizontalAlignment: Equatable { case leading diff --git a/Sources/TokamakCore/Views/Layout/ZStack.swift b/Sources/TokamakCore/Views/Layout/ZStack.swift index 4c63f134c..e12709fbc 100644 --- a/Sources/TokamakCore/Views/Layout/ZStack.swift +++ b/Sources/TokamakCore/Views/Layout/ZStack.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation + /// An alignment in both axes. public struct Alignment: Equatable { public var horizontal: HorizontalAlignment diff --git a/Sources/TokamakCore/Views/Spacers/Spacer.swift b/Sources/TokamakCore/Views/Spacers/Spacer.swift index 1217ca245..2695d5d1c 100644 --- a/Sources/TokamakCore/Views/Spacers/Spacer.swift +++ b/Sources/TokamakCore/Views/Spacers/Spacer.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Carson Katri on 06/29/2020. // +import Foundation + /// A `View` that fills the major axis of its parent stack. /// /// HStack { diff --git a/Sources/TokamakCore/Views/Text/Text.swift b/Sources/TokamakCore/Views/Text/Text.swift index eb7ce8bbf..6ec6b2ae7 100644 --- a/Sources/TokamakCore/Views/Text/Text.swift +++ b/Sources/TokamakCore/Views/Text/Text.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ // Created by Max Desiatov on 08/04/2020. // +import Foundation + /// A view that displays one or more lines of read-only text. /// /// You can choose a font using the `font(_:)` view modifier. diff --git a/Sources/TokamakDOM/Core.swift b/Sources/TokamakDOM/Core.swift index 11f1682a3..6d24cfa3f 100644 --- a/Sources/TokamakDOM/Core.swift +++ b/Sources/TokamakDOM/Core.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -87,9 +87,6 @@ public typealias Font = TokamakCore.Font public typealias Angle = TokamakCore.Angle public typealias CGAffineTransform = TokamakCore.CGAffineTransform -public typealias CGPoint = TokamakCore.CGPoint -public typealias CGRect = TokamakCore.CGRect -public typealias CGSize = TokamakCore.CGSize public typealias UnitPoint = TokamakCore.UnitPoint public typealias Edge = TokamakCore.Edge diff --git a/Sources/TokamakDOM/Views/Layout/GeometryReader.swift b/Sources/TokamakDOM/Views/Layout/GeometryReader.swift index f78cf6f96..c6b9b1aa8 100644 --- a/Sources/TokamakDOM/Views/Layout/GeometryReader.swift +++ b/Sources/TokamakDOM/Views/Layout/GeometryReader.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation import JavaScriptKit @_spi(TokamakCore) import TokamakCore import TokamakStaticHTML diff --git a/Sources/TokamakDemo/PathDemo.swift b/Sources/TokamakDemo/PathDemo.swift index cc35f08fb..4e633aaa9 100644 --- a/Sources/TokamakDemo/PathDemo.swift +++ b/Sources/TokamakDemo/PathDemo.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation import TokamakShim struct Star: Shape { diff --git a/Sources/TokamakDemo/TextDemo.swift b/Sources/TokamakDemo/TextDemo.swift index 2d1441371..cbbc513be 100644 --- a/Sources/TokamakDemo/TextDemo.swift +++ b/Sources/TokamakDemo/TextDemo.swift @@ -39,8 +39,8 @@ struct TextDemo: View { .heavy, .black, ], id: \.self) { weight in - Text("a") - .fontWeight(weight) + Text("a") + .fontWeight(weight) } } VStack { diff --git a/Sources/TokamakStaticHTML/Core.swift b/Sources/TokamakStaticHTML/Core.swift index 7a90b2a9e..13eb99a96 100644 --- a/Sources/TokamakStaticHTML/Core.swift +++ b/Sources/TokamakStaticHTML/Core.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -49,9 +49,6 @@ public typealias Color = TokamakCore.Color public typealias Font = TokamakCore.Font public typealias CGAffineTransform = TokamakCore.CGAffineTransform -public typealias CGPoint = TokamakCore.CGPoint -public typealias CGRect = TokamakCore.CGRect -public typealias CGSize = TokamakCore.CGSize // MARK: Views diff --git a/Sources/TokamakStaticHTML/Modifiers/LayoutModifiers.swift b/Sources/TokamakStaticHTML/Modifiers/LayoutModifiers.swift index 527d24cf8..7e385c217 100644 --- a/Sources/TokamakStaticHTML/Modifiers/LayoutModifiers.swift +++ b/Sources/TokamakStaticHTML/Modifiers/LayoutModifiers.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation import TokamakCore private extension DOMViewModifier { diff --git a/Sources/TokamakStaticHTML/Shapes/Path.swift b/Sources/TokamakStaticHTML/Shapes/Path.swift index 8e69b0432..470ddffc7 100644 --- a/Sources/TokamakStaticHTML/Shapes/Path.swift +++ b/Sources/TokamakStaticHTML/Shapes/Path.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,6 +14,8 @@ // // Created by Carson Katri on 6/29/20. // + +import Foundation import TokamakCore extension StrokeStyle { diff --git a/Sources/TokamakStaticHTML/Views/Spacers/Spacer.swift b/Sources/TokamakStaticHTML/Views/Spacers/Spacer.swift index daeafa227..ce3f1d6aa 100644 --- a/Sources/TokamakStaticHTML/Views/Spacers/Spacer.swift +++ b/Sources/TokamakStaticHTML/Views/Spacers/Spacer.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation import TokamakCore public enum SpacerContainerAxis { diff --git a/Sources/TokamakStaticHTML/Views/Text/Text.swift b/Sources/TokamakStaticHTML/Views/Text/Text.swift index e0f186975..93283ec75 100644 --- a/Sources/TokamakStaticHTML/Views/Text/Text.swift +++ b/Sources/TokamakStaticHTML/Views/Text/Text.swift @@ -1,4 +1,4 @@ -// Copyright 2020 Tokamak contributors +// Copyright 2020-2021 Tokamak contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +import Foundation import TokamakCore extension Font.Design: CustomStringConvertible { From 0163117a4d972d3217d2bcadde5a24b901415e93 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 17 Jun 2021 11:05:15 +0100 Subject: [PATCH 2/3] Fix GTK build --- Sources/TokamakCore/Stubs/CGStubs.swift | 21 ++++++++++------ Sources/TokamakGTK/Core.swift | 5 ++-- Sources/TokamakGTK/Shapes/Shape.swift | 33 +++++++++++++++++++------ Sources/TokamakGTK/Views/Stack.swift | 2 +- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/Sources/TokamakCore/Stubs/CGStubs.swift b/Sources/TokamakCore/Stubs/CGStubs.swift index d84bb94a6..a62edf452 100644 --- a/Sources/TokamakCore/Stubs/CGStubs.swift +++ b/Sources/TokamakCore/Stubs/CGStubs.swift @@ -35,6 +35,17 @@ extension CGPoint { } } +public extension CGAffineTransform { + /// Transform the point into the transform's coordinate system. + func transform(point: CGPoint) -> CGPoint { + CGPoint( + x: (a * point.x) + (c * point.y) + tx, + y: (b * point.x) + (d * point.y) + ty + ) + } +} + +#if !canImport(CoreGraphics) public enum CGLineCap { /// A line with a squared-off end. Extends to the endpoint of the Path. case butt @@ -127,14 +138,6 @@ public struct CGAffineTransform: Equatable { ) } - /// Transform the point into the transform's coordinate system. - public func transform(point: CGPoint) -> CGPoint { - CGPoint( - x: (a * point.x) + (c * point.y) + tx, - y: (b * point.x) + (d * point.y) + ty - ) - } - /// Returns an affine transformation matrix constructed by combining two existing affine /// transforms. /// - Parameters: @@ -203,3 +206,5 @@ public struct CGAffineTransform: Equatable { self == Self.identity } } + +#endif diff --git a/Sources/TokamakGTK/Core.swift b/Sources/TokamakGTK/Core.swift index fba29544e..e1992bab5 100644 --- a/Sources/TokamakGTK/Core.swift +++ b/Sources/TokamakGTK/Core.swift @@ -78,10 +78,9 @@ public typealias RoundedRectangle = TokamakCore.RoundedRectangle public typealias Color = TokamakCore.Color public typealias Font = TokamakCore.Font +#if !canImport(CoreGraphics) public typealias CGAffineTransform = TokamakCore.CGAffineTransform -public typealias CGPoint = TokamakCore.CGPoint -public typealias CGRect = TokamakCore.CGRect -public typealias CGSize = TokamakCore.CGSize +#endif // MARK: Views diff --git a/Sources/TokamakGTK/Shapes/Shape.swift b/Sources/TokamakGTK/Shapes/Shape.swift index ae00a5bf4..4b8708047 100644 --- a/Sources/TokamakGTK/Shapes/Shape.swift +++ b/Sources/TokamakGTK/Shapes/Shape.swift @@ -17,6 +17,7 @@ import CGDK import CGTK +import Foundation import TokamakCore func createPath(from elements: [Path.Element], in cr: OpaquePointer) { @@ -25,12 +26,12 @@ func createPath(from elements: [Path.Element], in cr: OpaquePointer) { for element in elements { switch element { case let .move(to: p): - cairo_move_to(cr, p.x, p.y) + cairo_move_to(cr, Double(p.x), Double(p.y)) current = p start = p case let .line(to: p): - cairo_line_to(cr, p.x, p.y) + cairo_line_to(cr, Double(p.x), Double(p.y)) current = p case .closeSubpath: @@ -38,13 +39,29 @@ func createPath(from elements: [Path.Element], in cr: OpaquePointer) { current = start case let .curve(to: p, control1: c1, control2: c2): - cairo_curve_to(cr, c1.x, c1.y, c2.x, c2.y, p.x, p.y) + cairo_curve_to( + cr, + Double(c1.x), + Double(c1.y), + Double(c2.x), + Double(c2.y), + Double(p.x), + Double(p.y) + ) current = p case let .quadCurve(to: p, control: c): let c1 = CGPoint(x: (current.x + 2 * c.x) / 3, y: (current.y + 2 * c.y) / 3) let c2 = CGPoint(x: (p.x + 2 * c.x) / 3, y: (p.y + 2 * c.y) / 3) - cairo_curve_to(cr, c1.x, c1.y, c2.x, c2.y, p.x, p.y) + cairo_curve_to( + cr, + Double(c1.x), + Double(c1.y), + Double(c2.x), + Double(c2.y), + Double(p.x), + Double(p.y) + ) current = p } } @@ -87,12 +104,12 @@ extension _ShapeView: GTKPrimitive { stroke = true let style = strokedPath.style - cairo_set_line_width(cr, style.lineWidth) + cairo_set_line_width(cr, Double(style.lineWidth)) cairo_set_line_join(cr, style.lineJoin.cairo) cairo_set_line_cap(cr, style.lineCap.cairo) - cairo_set_miter_limit(cr, style.miterLimit) - cairo_set_dash(cr, style.dash, Int32(style.dash.count), style.dashPhase) - + cairo_set_miter_limit(cr, Double(style.miterLimit)) + let dash = style.dash.map(Double.init) + cairo_set_dash(cr, dash, Int32(dash.count), Double(style.dashPhase)) } else { elements = path.elements stroke = false diff --git a/Sources/TokamakGTK/Views/Stack.swift b/Sources/TokamakGTK/Views/Stack.swift index b9b3f9d4b..176c55b5a 100644 --- a/Sources/TokamakGTK/Views/Stack.swift +++ b/Sources/TokamakGTK/Views/Stack.swift @@ -26,7 +26,7 @@ protocol StackProtocol { struct Box: View, ParentView, AnyWidget, StackProtocol { let content: Content let orientation: GtkOrientation - let spacing: TokamakCore.CGFloat + let spacing: CGFloat let alignment: Alignment let expand = true From 6ad4edcca31ad77675c057171e93b201f764510f Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 17 Jun 2021 11:10:24 +0100 Subject: [PATCH 3/3] Fix macOS build --- Sources/TokamakDOM/Core.swift | 5 ++++- Sources/TokamakStaticHTML/Core.swift | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/TokamakDOM/Core.swift b/Sources/TokamakDOM/Core.swift index 6d24cfa3f..02332d5e0 100644 --- a/Sources/TokamakDOM/Core.swift +++ b/Sources/TokamakDOM/Core.swift @@ -85,8 +85,11 @@ public typealias RoundedRectangle = TokamakCore.RoundedRectangle public typealias Color = TokamakCore.Color public typealias Font = TokamakCore.Font -public typealias Angle = TokamakCore.Angle +#if !canImport(CoreGraphics) public typealias CGAffineTransform = TokamakCore.CGAffineTransform +#endif + +public typealias Angle = TokamakCore.Angle public typealias UnitPoint = TokamakCore.UnitPoint public typealias Edge = TokamakCore.Edge diff --git a/Sources/TokamakStaticHTML/Core.swift b/Sources/TokamakStaticHTML/Core.swift index 13eb99a96..2b8d56348 100644 --- a/Sources/TokamakStaticHTML/Core.swift +++ b/Sources/TokamakStaticHTML/Core.swift @@ -48,7 +48,9 @@ public typealias RoundedRectangle = TokamakCore.RoundedRectangle public typealias Color = TokamakCore.Color public typealias Font = TokamakCore.Font +#if !canImport(CoreGraphics) public typealias CGAffineTransform = TokamakCore.CGAffineTransform +#endif // MARK: Views