Skip to content

Commit 979026b

Browse files
committed
Separate inspector
1 parent 4e1a4ea commit 979026b

File tree

1 file changed

+47
-51
lines changed

1 file changed

+47
-51
lines changed

LayoutInspector/ContentView.swift

+47-51
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,61 @@ import SwiftUI
22
import DebugLayout
33

44
struct ContentView: View {
5-
@State private var width: CGFloat = 300
6-
@State private var height: CGFloat = 100
7-
@State private var selectedView: String? = nil
8-
@State private var generation: Int = 0
9-
10-
// MARK: - Edit here
11-
12-
/// The view tree whose layout you want to inspect. Add `.debugLayout()` calls at
13-
/// each point where you want to inspect the layout algorithm, i.e. what sizes are
14-
/// being proposed and returned. We call these **inspection points**.
15-
///
16-
/// ## Suggested examples
17-
///
18-
/// ### Padding
19-
///
20-
/// var subject: some View {
21-
/// Text("Hello world")
22-
/// .debugLayout("Text")
23-
/// .padding(10)
24-
/// .debugLayout("padding")
25-
/// .border(Color.green)
26-
/// .debugLayout("border")
27-
/// }
28-
///
29-
/// ### Stacks
30-
///
31-
/// var subject: some View {
32-
/// HStack(spacing: 10) {
33-
/// Rectangle().fill(.green)
34-
/// .debugLayout("green")
35-
/// Text("Hello world")
36-
/// .debugLayout("Text")
37-
/// Rectangle().fill(.yellow)
38-
/// .debugLayout("yellow")
39-
/// }
40-
/// .debugLayout("HStack")
41-
/// }
42-
///
43-
/// ### fixedSize
44-
///
45-
/// var subject: some View {
46-
/// Text("Lorem ipsum dolor sit amet")
47-
/// .debugLayout("Text")
48-
/// .fixedSize()
49-
/// .debugLayout("fixedSize")
50-
/// .frame(width: 100)
51-
/// .debugLayout("frame")
52-
/// .border(Color.green)
53-
/// }
54-
var subject: some View {
5+
var suggestedExamplePadding: some View {
556
Text("Hello world")
567
.debugLayout("Text")
578
.padding(10)
589
.debugLayout("padding")
5910
.border(Color.green)
6011
.debugLayout("border")
12+
13+
}
14+
15+
var hstack: some View {
16+
HStack(spacing: 10) {
17+
Rectangle().fill(.green)
18+
.debugLayout("green")
19+
Text("Hello world")
20+
.debugLayout("Text")
21+
Rectangle().fill(.yellow)
22+
.debugLayout("yellow")
23+
}
24+
.debugLayout("HStack")
6125
}
6226

63-
// MARK: Edit end
27+
var fixedSize: some View {
28+
Text("Lorem ipsum dolor sit amet")
29+
.debugLayout("Text")
30+
.fixedSize()
31+
.debugLayout("fixedSize")
32+
.frame(width: 100)
33+
.debugLayout("frame")
34+
.border(Color.green)
35+
}
36+
37+
var body: some View {
38+
Inspector {
39+
hstack
40+
}
41+
}
42+
}
43+
44+
struct Inspector<Subject: View>: View {
45+
46+
/// The view tree whose layout you want to inspect. Add `.debugLayout()` calls at
47+
/// each point where you want to inspect the layout algorithm, i.e. what sizes are
48+
/// being proposed and returned. We call these **inspection points**.
49+
@ViewBuilder var subject: Subject
50+
51+
init(@ViewBuilder subject: () -> Subject) {
52+
self.subject = subject()
53+
}
54+
55+
@State private var width: CGFloat = 300
56+
@State private var height: CGFloat = 100
57+
@State private var selectedView: String? = nil
58+
@State private var generation: Int = 0
59+
6460

6561
var body: some View {
6662
VStack {

0 commit comments

Comments
 (0)