Skip to content

Commit 51e114d

Browse files
committed
Add _AlignmentLayout
1 parent 19ced57 commit 51e114d

File tree

6 files changed

+146
-33
lines changed

6 files changed

+146
-33
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//
2+
// AlignmentLayout.swift
3+
// OpenSwiftUICore
4+
//
5+
// Status: Complete
6+
7+
package import Foundation
8+
9+
// MARK: - VAlignment [6.4.41]
10+
11+
/// An alignment in the vertical axis.
12+
@frozen
13+
public enum _VAlignment {
14+
case top
15+
case center
16+
case bottom
17+
18+
package var value: CGFloat {
19+
switch self {
20+
case .top: 0.0
21+
case .center: 0.5
22+
case .bottom: 1.0
23+
}
24+
}
25+
}
26+
27+
// MARK: - AlignmentLayout [6.4.41]
28+
29+
@frozen
30+
public struct _AlignmentLayout: UnaryLayout {
31+
public var horizontal: TextAlignment?
32+
33+
public var vertical: _VAlignment?
34+
35+
@inlinable
36+
public init(
37+
horizontal: TextAlignment? = nil,
38+
vertical: _VAlignment? = nil
39+
) {
40+
self.horizontal = horizontal
41+
self.vertical = vertical
42+
}
43+
44+
package func placement(
45+
of child: LayoutProxy,
46+
in context: PlacementContext
47+
) -> _Placement {
48+
_Placement(
49+
proposedSize: context.proposedSize,
50+
aligning: UnitPoint(x: (horizontal ?? .center).value, y: (vertical ?? .center).value),
51+
in: context.size
52+
)
53+
}
54+
55+
package func sizeThatFits(
56+
in proposedSize: _ProposedSize,
57+
context: SizeAndSpacingContext,
58+
child: LayoutProxy
59+
) -> CGSize {
60+
guard horizontal != nil,
61+
vertical != nil,
62+
let width = proposedSize.width,
63+
let height = proposedSize.height else {
64+
let childSize = child.size(in: proposedSize)
65+
let width = if horizontal != nil, let width = proposedSize.width {
66+
width
67+
} else {
68+
childSize.width
69+
}
70+
let height = if vertical != nil, let height = proposedSize.height {
71+
height
72+
} else {
73+
childSize.height
74+
}
75+
return CGSize(width: width, height: height)
76+
}
77+
return CGSize(width: width, height: height)
78+
}
79+
80+
package func spacing(
81+
in context: SizeAndSpacingContext,
82+
child: LayoutProxy
83+
) -> Spacing {
84+
if _SemanticFeature_v3.isEnabled {
85+
var spacing = child.layoutComputer.spacing()
86+
spacing.reset(
87+
AbsoluteEdge.Set(
88+
[horizontal == nil ? [] : .horizontal, vertical == nil ? [] : .vertical],
89+
layoutDirection: context.layoutDirection
90+
)
91+
)
92+
return spacing
93+
} else {
94+
return child.layoutComputer.spacing()
95+
}
96+
}
97+
98+
public typealias AnimatableData = EmptyAnimatableData
99+
100+
public typealias Body = Never
101+
102+
package typealias PlacementContextType = PlacementContext
103+
}

Sources/OpenSwiftUICore/Layout/Alignment/TextAlignment.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
// TextAlignment.swift
33
// OpenSwiftUICore
44
//
5-
// Audited for iOS 18.0
65
// Status: Complete
76

87
package import Foundation
98

9+
// MARK: - TextAlignment [6.0.87]
10+
1011
/// An alignment position for text along the horizontal axis.
1112
@frozen
1213
public enum TextAlignment: Hashable, CaseIterable {

Sources/OpenSwiftUICore/Layout/Alignment/VAlignment.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

Sources/OpenSwiftUICore/Layout/Edge/Edge.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,24 @@ public enum Edge: Int8, CaseIterable {
2323
self.rawValue = rawValue
2424
}
2525

26-
public static let top = Set(.top)
27-
public static let leading = Set(.leading)
28-
public static let bottom = Set(.bottom)
29-
public static let trailing = Set(.trailing)
26+
public static let top: Set = .init(.top) // 1
27+
28+
public static let leading: Set = .init(.leading) // 2
29+
30+
public static let bottom: Set = .init(.bottom) // 4
31+
32+
public static let trailing: Set = .init(.trailing) // 8
33+
3034
public static let all: Set = [.top, .leading, .bottom, .trailing]
31-
public static let horizontal: Set = [.leading, .trailing]
32-
public static let vertical: Set = [.top, .bottom]
35+
36+
public static let horizontal: Set = [.leading, .trailing] // 0xa
37+
38+
public static let vertical: Set = [.top, .bottom] // 0x5
3339

3440
/// Creates an instance containing just e
35-
public init(_ e: Edge) { self.init(rawValue: 1 << e.rawValue) }
41+
public init(_ e: Edge) {
42+
rawValue = 1 << e.rawValue
43+
}
3644

3745
package func contains(_ edge: Edge) -> Bool {
3846
contains(.init(edge))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// GeometryReader.swift
3+
// OpenSwiftUICore
4+
//
5+
// Status: WIP
6+
7+
extension UnaryLayout where Self.PlacementContextType == _PositionAwarePlacementContext {
8+
package static func makeViewImpl(
9+
modifier: _GraphValue<Self>,
10+
inputs: _ViewInputs,
11+
body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs
12+
) -> _ViewOutputs {
13+
preconditionFailure("TODO")
14+
}
15+
}
16+
17+
extension UnaryLayout where Self.PlacementContextType == PlacementContext {
18+
package static func makeViewImpl(
19+
modifier: _GraphValue<Self>,
20+
inputs: _ViewInputs,
21+
body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs
22+
) -> _ViewOutputs {
23+
preconditionFailure("TODO")
24+
}
25+
}

Sources/OpenSwiftUICore/Layout/PlacementContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Audited for iOS 18.0
66
// Status: Complete
7-
// ID: BA60BF7120E939C5C25B2A488163D4AC
7+
// ID: BA60BF7120E939C5C25B2A488163D4AC (SwiftUICore)
88

99
package import Foundation
1010
package import OpenGraphShims

0 commit comments

Comments
 (0)