@@ -62,7 +62,7 @@ struct ClearDebugLayoutLog: Layout {
62
62
public final class LogStore : ObservableObject {
63
63
public static let shared : LogStore = . init( )
64
64
65
- @Published var log : [ LogEntry ] = [ ]
65
+ @Published public var log : [ LogEntry ] = [ ]
66
66
var viewLabels : Set < String > = [ ]
67
67
68
68
func registerViewLabelAndWarnIfNotUnique( _ label: String , file: StaticString , line: UInt ) {
@@ -76,36 +76,6 @@ public final class LogStore: ObservableObject {
76
76
}
77
77
}
78
78
79
- @available ( macOS 13 . 0 , iOS 16 . 0 , tvOS 16 . 0 , watchOS 9 . 0 , * )
80
- struct LogEntry : Identifiable {
81
- enum Step {
82
- case proposal( ProposedViewSize )
83
- case response( CGSize )
84
- case proposalAndResponse( proposal: ProposedViewSize , response: CGSize )
85
- }
86
-
87
- var id : UUID = . init( )
88
- var label : String
89
- var step : Step
90
- var indent : Int
91
-
92
- var proposal : ProposedViewSize ? {
93
- switch step {
94
- case . proposal( let p) : return p
95
- case . response( _) : return nil
96
- case . proposalAndResponse( proposal: let p, response: _) : return p
97
- }
98
- }
99
-
100
- var response : CGSize ? {
101
- switch step {
102
- case . proposal( _) : return nil
103
- case . response( let r) : return r
104
- case . proposalAndResponse( proposal: _, response: let r) : return r
105
- }
106
- }
107
- }
108
-
109
79
@available ( macOS 13 . 0 , iOS 16 . 0 , tvOS 16 . 0 , watchOS 9 . 0 , * )
110
80
struct DebugLayoutSelectedViewID : EnvironmentKey {
111
81
static var defaultValue : String ? { nil }
@@ -118,99 +88,3 @@ extension EnvironmentValues {
118
88
set { self [ DebugLayoutSelectedViewID . self] = newValue }
119
89
}
120
90
}
121
-
122
- @available ( macOS 13 . 0 , iOS 16 . 0 , tvOS 16 . 0 , watchOS 9 . 0 , * )
123
- public struct DebugLayoutLogView : View {
124
- @Binding var selection : String ?
125
- @ObservedObject var logStore : LogStore
126
-
127
- private static let tableRowHorizontalPadding : CGFloat = 8
128
- private static let tableRowVerticalPadding : CGFloat = 4
129
-
130
- public init ( selection: Binding < String ? > ? = nil , logStore: LogStore = LogStore . shared) {
131
- if let binding = selection {
132
- self . _selection = binding
133
- } else {
134
- var nirvana : String ? = nil
135
- self . _selection = Binding ( get: { nirvana } , set: { nirvana = $0 } )
136
- }
137
- self . _logStore = ObservedObject ( wrappedValue: logStore)
138
- }
139
-
140
- public var body : some View {
141
- ScrollView ( . vertical) {
142
- Grid ( alignment: . leadingFirstTextBaseline, horizontalSpacing: 0 , verticalSpacing: 0 ) {
143
- // Table header row
144
- GridRow {
145
- Text ( " View " )
146
- Text ( " Proposal " )
147
- Text ( " Response " )
148
- }
149
- . font ( . headline)
150
- . padding ( . vertical, Self . tableRowVerticalPadding)
151
- . padding ( . horizontal, Self . tableRowHorizontalPadding)
152
-
153
- // Table header separator line
154
- Rectangle ( ) . fill ( . secondary)
155
- . frame ( height: 1 )
156
- . gridCellUnsizedAxes ( . horizontal)
157
- . padding ( . vertical, Self . tableRowVerticalPadding)
158
- . padding ( . horizontal, Self . tableRowHorizontalPadding)
159
-
160
- // Table rows
161
- ForEach ( logStore. log) { item in
162
- let isSelected = selection == item. label
163
- GridRow {
164
- HStack ( spacing: 0 ) {
165
- indentation ( level: item. indent)
166
- Text ( item. label)
167
- . font ( . body)
168
- }
169
- . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . leading)
170
-
171
- Text ( item. proposal? . pretty ?? " … " )
172
- . monospacedDigit ( )
173
- . fixedSize ( )
174
- . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . leading)
175
-
176
- Text ( item. response? . pretty ?? " … " )
177
- . monospacedDigit ( )
178
- . fixedSize ( )
179
- . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . leading)
180
- }
181
- . font ( . callout)
182
- . padding ( . vertical, Self . tableRowVerticalPadding)
183
- . padding ( . horizontal, Self . tableRowHorizontalPadding)
184
- . foregroundColor ( isSelected ? . white : nil )
185
- . background ( isSelected ? Color . accentColor : . clear)
186
- . contentShape ( Rectangle ( ) )
187
- . onTapGesture {
188
- selection = isSelected ? nil : item. label
189
- }
190
- }
191
- }
192
- . padding ( . vertical, 8 )
193
- }
194
- . background {
195
- #if os(macOS)
196
- Color ( white: 0.8 )
197
- #else
198
- Color ( uiColor: . secondarySystemBackground)
199
- #endif
200
- }
201
- }
202
-
203
- private func indentation( level: Int ) -> some View {
204
- ForEach ( 0 ..< level, id: \. self) { _ in
205
- Color . clear
206
- . frame ( width: 16 )
207
- . overlay ( alignment: . leading) {
208
- Rectangle ( )
209
- . frame ( width: 1 )
210
- . padding ( . leading, 4 )
211
- // Compensate for cell padding, we want continuous vertical lines.
212
- . padding ( . vertical, - Self. tableRowVerticalPadding)
213
- }
214
- }
215
- }
216
- }
0 commit comments