@@ -28,10 +28,10 @@ struct DebugLayout: Layout {
28
28
29
29
func sizeThatFits( proposal: ProposedViewSize , subviews: Subviews , cache: inout ( ) ) -> CGSize {
30
30
assert ( subviews. count == 1 )
31
- log ( label, action: " P " , value : proposal . pretty )
32
- let result = subviews [ 0 ] . sizeThatFits ( proposal)
33
- log ( label, action: " ⇒ " , value : result . pretty )
34
- return result
31
+ log ( label, action: . proposal ( proposal ) )
32
+ let response = subviews [ 0 ] . sizeThatFits ( proposal)
33
+ log ( label, action: . response ( response ) )
34
+ return response
35
35
}
36
36
37
37
func placeSubviews( in bounds: CGRect , proposal: ProposedViewSize , subviews: Subviews , cache: inout ( ) ) {
@@ -91,16 +91,47 @@ final class Console: ObservableObject {
91
91
@Published var log : [ LogItem ] = [ ]
92
92
93
93
struct LogItem : Identifiable {
94
+ enum Action {
95
+ case proposal( ProposedViewSize )
96
+ case response( CGSize )
97
+ case proposalAndResponse( proposal: ProposedViewSize , response: CGSize )
98
+ }
99
+
94
100
var id : UUID = . init( )
95
101
var label : String
96
- var action : String
97
- var value : String
102
+ var action : Action
103
+
104
+ var proposal : ProposedViewSize ? {
105
+ switch action {
106
+ case . proposal( let p) : return p
107
+ case . response( _) : return nil
108
+ case . proposalAndResponse( proposal: let p, response: _) : return p
109
+ }
110
+ }
111
+
112
+ var response : CGSize ? {
113
+ switch action {
114
+ case . proposal( _) : return nil
115
+ case . response( let r) : return r
116
+ case . proposalAndResponse( proposal: _, response: let r) : return r
117
+ }
118
+ }
98
119
}
99
120
}
100
121
101
- func log( _ label: String , action: String , value : String ) {
122
+ func log( _ label: String , action: Console . LogItem . Action ) {
102
123
DispatchQueue . main. async {
103
- Console . shared. log. append ( . init( label: label, action: action, value: value) )
124
+ if var lastLogItem = Console . shared. log. last,
125
+ lastLogItem. label == label,
126
+ case . proposal( let proposal) = lastLogItem. action,
127
+ case . response( let response) = action
128
+ {
129
+ Console . shared. log. removeLast ( )
130
+ lastLogItem. action = . proposalAndResponse( proposal: proposal, response: response)
131
+ Console . shared. log. append ( lastLogItem)
132
+ } else {
133
+ Console . shared. log. append ( . init( label: label, action: action) )
134
+ }
104
135
}
105
136
}
106
137
@@ -143,13 +174,31 @@ struct ConsoleView: View {
143
174
. frame ( maxWidth: . infinity, alignment: . leading)
144
175
. padding ( . horizontal, 8 )
145
176
146
- Text ( item. action)
147
- . font ( . headline)
148
-
149
- Text ( item. value)
150
- . monospacedDigit ( )
151
- . gridColumnAlignment ( . trailing)
152
- . padding ( . horizontal, 8 )
177
+ if let proposal = item. proposal {
178
+ Text ( " P " )
179
+ . font ( . headline)
180
+
181
+ Text ( proposal. pretty)
182
+ . monospacedDigit ( )
183
+ . gridColumnAlignment ( . trailing)
184
+ . padding ( . horizontal, 8 )
185
+ } else {
186
+ Text ( " " )
187
+ Text ( " " )
188
+ }
189
+
190
+ if let response = item. response {
191
+ Text ( " ⇒ " )
192
+ . font ( . headline)
193
+
194
+ Text ( response. pretty)
195
+ . monospacedDigit ( )
196
+ . gridColumnAlignment ( . trailing)
197
+ . padding ( . horizontal, 8 )
198
+ } else {
199
+ Text ( " " )
200
+ Text ( " " )
201
+ }
153
202
}
154
203
. padding ( . vertical, 8 )
155
204
. foregroundColor ( isSelected ? . white : nil )
0 commit comments