Skip to content

Commit 121ea93

Browse files
committedSep 23, 2022
Add suggestions for view trees to inspect
1 parent bed0d01 commit 121ea93

File tree

2 files changed

+54
-10
lines changed

2 files changed

+54
-10
lines changed
 

‎LayoutInspector/ContentView.swift

+49-6
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,61 @@ struct ContentView: View {
66
@State private var selectedView: String? = nil
77
@State private var generation: Int = 0
88

9+
// MARK: - Edit here
10+
11+
/// The view tree whose layout you want to inspect. Add `.debugLayout()` calls at
12+
/// each point where you want to inspect the layout algorithm, i.e. what sizes are
13+
/// being proposed and returned. We call these **inspection points**.
14+
///
15+
/// ## Suggested examples
16+
///
17+
/// ### Padding
18+
///
19+
/// var subject: some View {
20+
/// Text("Hello world")
21+
/// .debugLayout("Text")
22+
/// .padding(10)
23+
/// .debugLayout("padding")
24+
/// .border(Color.green)
25+
/// .debugLayout("border")
26+
/// }
27+
///
28+
/// ### Stacks
29+
///
30+
/// var subject: some View {
31+
/// HStack(spacing: 10) {
32+
/// Rectangle().fill(.green)
33+
/// .debugLayout("green")
34+
/// Text("Hello world")
35+
/// .debugLayout("Text")
36+
/// Rectangle().fill(.yellow)
37+
/// .debugLayout("yellow")
38+
/// }
39+
/// .debugLayout("HStack")
40+
/// }
41+
///
42+
/// ### fixedSize
43+
///
44+
/// var subject: some View {
45+
/// Text("Lorem ipsum dolor sit amet")
46+
/// .debugLayout("Text")
47+
/// .fixedSize()
48+
/// .debugLayout("fixedSize")
49+
/// .frame(width: 100)
50+
/// .debugLayout("frame")
51+
/// .border(Color.green)
52+
/// }
953
var subject: some View {
1054
Text("Hello world")
1155
.debugLayout("Text")
12-
.padding()
56+
.padding(10)
1357
.debugLayout("padding")
14-
.background {
15-
Color.yellow
16-
.debugLayout("yellow")
17-
}
18-
.debugLayout("background")
58+
.border(Color.green)
59+
.debugLayout("border")
1960
}
2061

62+
// MARK: Edit end
63+
2164
var body: some View {
2265
VStack {
2366
VStack {

‎README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ iOS 16.0 or macOS 13.0 (requires the `Layout` protocol).
1616
1. Edit the `subject: some View` property in `ContentView`. It should contain
1717
the view tree you want to inspect.
1818

19-
2. Add `.debugLayout()` to each view in the view tree whose layout algorithm
20-
you want to inspect.
19+
2. Add `.debugLayout()` at each point in the view tree where you want to inspect
20+
the layout algorithm (what sizes are being proposed and returned).
2121

22-
Example of a `subject` property with a few `debugLayout` inspection points:
22+
Example of a `subject` property with a few inspection points:
2323

2424
```swift
2525
var subject: some View {
2626
Text("Hello world")
2727
.debugLayout("Text")
28-
.padding()
28+
.padding(10)
2929
.debugLayout("padding")
3030
.background {
3131
Color.yellow
@@ -41,6 +41,7 @@ iOS 16.0 or macOS 13.0 (requires the `Layout` protocol).
4141
- The table on the bottom displays the sizes that are being proposed at each
4242
inspection point in the subject view ("Proposal", and the resulting view
4343
sizes ("Response").
44+
- You can tap/click items in the grid to highlight the respective view.
4445
- You can use the sliders to modify the size proposed to the subject view.
4546
- Some views cache certain layout information. Press "Reset layout cache"
4647
after modifying the sliders to reset the caches.

0 commit comments

Comments
 (0)