diff --git a/Sources/OpenSwiftUICore/Layout/Alignment/AlignmentLayout.swift b/Sources/OpenSwiftUICore/Layout/Alignment/AlignmentLayout.swift new file mode 100644 index 00000000..dd7f58bd --- /dev/null +++ b/Sources/OpenSwiftUICore/Layout/Alignment/AlignmentLayout.swift @@ -0,0 +1,103 @@ +// +// AlignmentLayout.swift +// OpenSwiftUICore +// +// Status: Complete + +package import Foundation + +// MARK: - VAlignment [6.4.41] + +/// An alignment in the vertical axis. +@frozen +public enum _VAlignment { + case top + case center + case bottom + + package var value: CGFloat { + switch self { + case .top: 0.0 + case .center: 0.5 + case .bottom: 1.0 + } + } +} + +// MARK: - AlignmentLayout [6.4.41] + +@frozen +public struct _AlignmentLayout: UnaryLayout { + public var horizontal: TextAlignment? + + public var vertical: _VAlignment? + + @inlinable + public init( + horizontal: TextAlignment? = nil, + vertical: _VAlignment? = nil + ) { + self.horizontal = horizontal + self.vertical = vertical + } + + package func placement( + of child: LayoutProxy, + in context: PlacementContext + ) -> _Placement { + _Placement( + proposedSize: context.proposedSize, + aligning: UnitPoint(x: (horizontal ?? .center).value, y: (vertical ?? .center).value), + in: context.size + ) + } + + package func sizeThatFits( + in proposedSize: _ProposedSize, + context: SizeAndSpacingContext, + child: LayoutProxy + ) -> CGSize { + guard horizontal != nil, + vertical != nil, + let width = proposedSize.width, + let height = proposedSize.height else { + let childSize = child.size(in: proposedSize) + let width = if horizontal != nil, let width = proposedSize.width { + width + } else { + childSize.width + } + let height = if vertical != nil, let height = proposedSize.height { + height + } else { + childSize.height + } + return CGSize(width: width, height: height) + } + return CGSize(width: width, height: height) + } + + package func spacing( + in context: SizeAndSpacingContext, + child: LayoutProxy + ) -> Spacing { + if _SemanticFeature_v3.isEnabled { + var spacing = child.layoutComputer.spacing() + spacing.reset( + AbsoluteEdge.Set( + [horizontal == nil ? [] : .horizontal, vertical == nil ? [] : .vertical], + layoutDirection: context.layoutDirection + ) + ) + return spacing + } else { + return child.layoutComputer.spacing() + } + } + + public typealias AnimatableData = EmptyAnimatableData + + public typealias Body = Never + + package typealias PlacementContextType = PlacementContext +} diff --git a/Sources/OpenSwiftUICore/Layout/Alignment/TextAlignment.swift b/Sources/OpenSwiftUICore/Layout/Alignment/TextAlignment.swift index 53ae2ac0..af570669 100644 --- a/Sources/OpenSwiftUICore/Layout/Alignment/TextAlignment.swift +++ b/Sources/OpenSwiftUICore/Layout/Alignment/TextAlignment.swift @@ -2,11 +2,12 @@ // TextAlignment.swift // OpenSwiftUICore // -// Audited for iOS 18.0 // Status: Complete package import Foundation +// MARK: - TextAlignment [6.0.87] + /// An alignment position for text along the horizontal axis. @frozen public enum TextAlignment: Hashable, CaseIterable { diff --git a/Sources/OpenSwiftUICore/Layout/Alignment/VAlignment.swift b/Sources/OpenSwiftUICore/Layout/Alignment/VAlignment.swift deleted file mode 100644 index 63fbfd68..00000000 --- a/Sources/OpenSwiftUICore/Layout/Alignment/VAlignment.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// VAlignment.swift -// OpenSwiftUICore -// -// Audited for iOS 18.0 -// Status: Complete - -package import Foundation - -/// An alignment in the vertical axis. -@frozen -public enum _VAlignment { - case top - case center - case bottom - - package var value: CGFloat { - switch self { - case .top: 0.0 - case .center: 0.5 - case .bottom: 1.0 - } - } -} diff --git a/Sources/OpenSwiftUICore/Layout/Edge/Edge.swift b/Sources/OpenSwiftUICore/Layout/Edge/Edge.swift index 050bdbf5..23ae5197 100644 --- a/Sources/OpenSwiftUICore/Layout/Edge/Edge.swift +++ b/Sources/OpenSwiftUICore/Layout/Edge/Edge.swift @@ -23,16 +23,24 @@ public enum Edge: Int8, CaseIterable { self.rawValue = rawValue } - public static let top = Set(.top) - public static let leading = Set(.leading) - public static let bottom = Set(.bottom) - public static let trailing = Set(.trailing) + public static let top: Set = .init(.top) // 1 + + public static let leading: Set = .init(.leading) // 2 + + public static let bottom: Set = .init(.bottom) // 4 + + public static let trailing: Set = .init(.trailing) // 8 + public static let all: Set = [.top, .leading, .bottom, .trailing] - public static let horizontal: Set = [.leading, .trailing] - public static let vertical: Set = [.top, .bottom] + + public static let horizontal: Set = [.leading, .trailing] // 0xa + + public static let vertical: Set = [.top, .bottom] // 0x5 /// Creates an instance containing just e - public init(_ e: Edge) { self.init(rawValue: 1 << e.rawValue) } + public init(_ e: Edge) { + rawValue = 1 << e.rawValue + } package func contains(_ edge: Edge) -> Bool { contains(.init(edge)) diff --git a/Sources/OpenSwiftUICore/Layout/GeometryReader.swift b/Sources/OpenSwiftUICore/Layout/GeometryReader.swift new file mode 100644 index 00000000..a0e4187e --- /dev/null +++ b/Sources/OpenSwiftUICore/Layout/GeometryReader.swift @@ -0,0 +1,25 @@ +// +// GeometryReader.swift +// OpenSwiftUICore +// +// Status: WIP + +extension UnaryLayout where Self.PlacementContextType == _PositionAwarePlacementContext { + package static func makeViewImpl( + modifier: _GraphValue, + inputs: _ViewInputs, + body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs + ) -> _ViewOutputs { + preconditionFailure("TODO") + } +} + +extension UnaryLayout where Self.PlacementContextType == PlacementContext { + package static func makeViewImpl( + modifier: _GraphValue, + inputs: _ViewInputs, + body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs + ) -> _ViewOutputs { + preconditionFailure("TODO") + } +} diff --git a/Sources/OpenSwiftUICore/Layout/PlacementContext.swift b/Sources/OpenSwiftUICore/Layout/PlacementContext.swift index 25f0aca6..2fae9911 100644 --- a/Sources/OpenSwiftUICore/Layout/PlacementContext.swift +++ b/Sources/OpenSwiftUICore/Layout/PlacementContext.swift @@ -4,7 +4,7 @@ // // Audited for iOS 18.0 // Status: Complete -// ID: BA60BF7120E939C5C25B2A488163D4AC +// ID: BA60BF7120E939C5C25B2A488163D4AC (SwiftUICore) package import Foundation package import OpenGraphShims