Skip to content

Commit 9c664b9

Browse files
committedSep 20, 2022
Work on UI
1 parent 9cceeb8 commit 9c664b9

File tree

2 files changed

+49
-47
lines changed

2 files changed

+49
-47
lines changed
 

‎LayoutInspector/ContentView.swift

+17-13
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@ struct ContentView: View {
55
@State private var selectedView: String? = nil
66
@State private var generation: Int = 0
77

8+
var subject: some View {
9+
HStack {
10+
Rectangle().fill(.green)
11+
.debugLayout("green")
12+
Text("Hello world")
13+
.debugLayout("Text")
14+
Rectangle().fill(.yellow)
15+
.debugLayout("yellow")
16+
}
17+
.debugLayout("HStack")
18+
}
19+
820
var body: some View {
921
VStack {
1022
VStack(spacing: 24) {
11-
HStack(spacing: 0) {
12-
Rectangle().fill(.green)
13-
.debugLayout("green")
14-
Text("Hello world")
15-
.debugLayout("Text")
16-
Rectangle().fill(.yellow)
17-
.debugLayout("yellow")
18-
}
19-
.debugLayout("HStack")
20-
.clearConsole()
21-
.environment(\.debugLayoutSelection, selectedView)
22-
.frame(width: width, height: 80)
23-
.id(generation)
23+
subject
24+
.clearConsole()
25+
.environment(\.debugLayoutSelection, selectedView)
26+
.frame(width: width, height: 80)
27+
.id(generation)
2428

2529
LabeledContent {
2630
Slider(value: $width, in: 100...500, step: 1)

‎LayoutInspector/DebugLayout.swift

+32-34
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct DebugLayoutWrapper: ViewModifier {
1919
func body(content: Content) -> some View {
2020
let isSelected = label == selection
2121
content
22-
.border(isSelected ? Color.blue : .clear, width: 2)
22+
.border(isSelected ? Color.pink : .clear, width: 2)
2323
}
2424
}
2525

@@ -156,7 +156,7 @@ struct Selection<Value: Equatable>: PreferenceKey {
156156

157157
struct ConsoleView: View {
158158
@ObservedObject var console = Console.shared
159-
@State private var selection: String? = nil
159+
@State private var selection: String? = "Text"
160160

161161
var body: some View {
162162
ScrollView(.vertical) {
@@ -167,49 +167,47 @@ struct ConsoleView: View {
167167
.padding(.horizontal, 8)
168168

169169
Grid(alignment: .leadingFirstTextBaseline, horizontalSpacing: 0, verticalSpacing: 0) {
170+
GridRow {
171+
Text("View")
172+
Text("Proposal")
173+
Text("Response")
174+
}
175+
.font(.headline)
176+
.padding(.vertical, 4)
177+
.padding(.horizontal, 8)
178+
179+
Rectangle().fill(.secondary)
180+
.frame(height: 1)
181+
.gridCellUnsizedAxes(.horizontal)
182+
.padding(.vertical, 4)
183+
.padding(.horizontal, 8)
184+
170185
ForEach(console.log) { item in
171186
let isSelected = selection == item.label
172187
GridRow {
173188
Text(item.label)
174-
.frame(maxWidth: .infinity, alignment: .leading)
175-
.padding(.horizontal, 8)
176-
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-
}
189+
.font(.body)
190+
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
191+
192+
Text(item.proposal?.pretty ?? "")
193+
.monospacedDigit()
194+
.fixedSize()
195+
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
196+
197+
Text(item.response?.pretty ?? "")
198+
.monospacedDigit()
199+
.fixedSize()
200+
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
202201
}
203-
.padding(.vertical, 8)
202+
.font(.callout)
203+
.padding(.vertical, 4)
204+
.padding(.horizontal, 8)
204205
.foregroundColor(isSelected ? .white : nil)
205206
.background(isSelected ? Color.accentColor : .clear)
206207
.contentShape(Rectangle())
207208
.onTapGesture {
208209
selection = isSelected ? nil : item.label
209210
}
210-
211-
Divider()
212-
.gridCellUnsizedAxes(.horizontal)
213211
}
214212
}
215213
}

0 commit comments

Comments
 (0)
Please sign in to comment.