forked from ole/swiftui-layout-inspector
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLogEntry.swift
116 lines (111 loc) · 3.09 KB
/
LogEntry.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import SwiftUI
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
public struct LogEntry: Identifiable {
public enum Step {
case proposal(ProposedViewSize)
case response(CGSize)
case proposalAndResponse(proposal: ProposedViewSize, response: CGSize)
}
public var id: UUID = .init()
public var label: String
public var step: Step
public var indent: Int
public var proposal: ProposedViewSize? {
switch step {
case .proposal(let p): return p
case .response(_): return nil
case .proposalAndResponse(proposal: let p, response: _): return p
}
}
public var response: CGSize? {
switch step {
case .proposal(_): return nil
case .response(let r): return r
case .proposalAndResponse(proposal: _, response: let r): return r
}
}
}
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
let sampleLogEntries: [LogEntry] = [
.init(
label: "HStack",
step: .proposal(.init(width: 300, height: 100)),
indent: 0
),
.init(
label: "Text",
step: .proposalAndResponse(
proposal: .init(width: 0, height: 100),
response: .init(width: 0, height: 86.3)),
indent: 1
),
.init(
label: "Text",
step: .proposalAndResponse(
proposal: .init(width: .infinity, height: 100),
response: .init(width: 85.3, height: 20.3)
),
indent: 1
),
.init(
label: "green",
step: .proposalAndResponse(
proposal: .init(width: 0, height: 100),
response: .init(width: 0, height: 100)
),
indent: 1
),
.init(
label: "green",
step: .proposalAndResponse(
proposal: .init(width: .infinity, height: 100),
response: .init(width: CGFloat.infinity, height: 100)
),
indent: 1
),
.init(
label: "yellow",
step: .proposalAndResponse(
proposal: .init(width: 0, height: 100),
response: .init(width: 0, height: 100)
),
indent: 1
),
.init(
label: "yellow",
step: .proposalAndResponse(
proposal: .init(width: .infinity, height: 100),
response: .init(width: CGFloat.infinity, height: 100)
),
indent: 1
),
.init(
label: "Text",
step: .proposalAndResponse(
proposal: .init(width: 93.3, height: 100),
response: .init(width: 85.3, height: 20.3)
),
indent: 1
),
.init(
label: "green",
step: .proposalAndResponse(
proposal: .init(width: 97.3, height: 100),
response: .init(width: 97.3, height: 100)
),
indent: 1
),
.init(
label: "yellow",
step: .proposalAndResponse(
proposal: .init(width: 97.3, height: 100),
response: .init(width: 97.3, height: 100)
),
indent: 1
),
.init(
label: "HStack",
step: .response(.init(width: 300, height: 100)),
indent: 0
),
]