Skip to content

Commit a8baed0

Browse files
committed
Rename startDebugLayout() to inspectLayout() and debugLayout() to layoutStep()
1 parent 60b5f30 commit a8baed0

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

DemoApp/ContentView.swift

+19-16
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,45 @@ import SwiftUI
33

44
struct ContentView: View {
55
var body: some View {
6-
Inspector {
7-
/// The view tree whose layout you want to inspect. Add `.debugLayout()` calls at
8-
/// each point where you want to inspect the layout algorithm, i.e. what sizes are
9-
/// being proposed and returned. We call these **inspection points**.
10-
hStackExample
6+
/// The view tree whose layout you want to inspect. Add `.layoutStep()`
7+
/// calls at each point where you want to inspect the layout algorithm,
8+
/// i.e. what sizes are being proposed and returned. We call these
9+
/// **inspection points**.
10+
VStack {
11+
Inspector {
12+
hStackExample
13+
}
1114
}
1215
}
1316

1417
var paddingExample: some View {
1518
Text("Hello world")
16-
.debugLayout("Text")
19+
.layoutStep("Text")
1720
.padding(10)
18-
.debugLayout("padding")
21+
.layoutStep("padding")
1922
.border(Color.green)
20-
.debugLayout("border")
23+
.layoutStep("border")
2124
}
2225

2326
var hStackExample: some View {
2427
HStack(spacing: 10) {
2528
Rectangle().fill(.green)
26-
.debugLayout("green")
29+
.layoutStep("green")
2730
Text("Hello world")
28-
.debugLayout("Text")
31+
.layoutStep("Text")
2932
Rectangle().fill(.yellow)
30-
.debugLayout("yellow")
33+
.layoutStep("yellow")
3134
}
32-
.debugLayout("HStack")
35+
.layoutStep("HStack")
3336
}
3437

3538
var fixedSizeExample: some View {
3639
Text("Lorem ipsum dolor sit amet")
37-
.debugLayout("Text")
40+
.layoutStep("Text")
3841
.fixedSize()
39-
.debugLayout("fixedSize")
42+
.layoutStep("fixedSize")
4043
.frame(width: 100)
41-
.debugLayout("frame")
44+
.layoutStep("frame")
4245
.border(Color.green)
4346
}
4447
}
@@ -59,7 +62,7 @@ struct Inspector<Subject: View>: View {
5962
VStack {
6063
VStack {
6164
subject
62-
.startDebugLayout(selection: selectedView)
65+
.inspectLayout(selection: selectedView)
6366
.id(generation)
6467
.frame(width: roundedWidth, height: roundedHeight)
6568
.overlay {

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ Layout Inspector consists of:
4040

4141
## Requirements
4242

43-
iOS 16.0 or macOS 13.0 (requires the `Layout` protocol).
43+
iOS 16.0 or macOS 13.0 (because it requires the `Layout` protocol).
4444

4545
## Instructions
4646

4747
1. `import LayoutInspector`
48-
49-
2. Add `.debugLayout()` at each point in a view tree where you want to inspect
50-
the layout algorithm (what sizes are being proposed and returned).
51-
52-
3. At the top of the view tree you want to inspect, add `.startDebugLayout()`.
5348

54-
See the README of the demo app for a complete example.
49+
2. At the top of the view tree you want to inspect, insert `.inspectLayout()`.
50+
51+
3. Insert `.layoutStep("View label")` at each point in a view tree where you
52+
want to inspect the layout algorithm (what sizes are being proposed and
53+
returned). This is necessary to inject the helper "views" that observe the
54+
layout process.
5555

5656
## Acknowledgements
5757

Sources/LayoutInspector/DebugLayout.swift

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import SwiftUI
22

33
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
44
extension View {
5-
/// Start debugging the layout algorithm for this subtree.
6-
///
7-
/// This clears the debug layout log.
8-
public func startDebugLayout(selection: String? = nil) -> some View {
5+
/// Inspect the layout for this subtree.
6+
public func inspectLayout(selection: String? = nil) -> some View {
97
ClearDebugLayoutLog {
108
self
119
}
@@ -14,7 +12,7 @@ extension View {
1412

1513
/// Monitor the layout proposals and responses for this view and add them
1614
/// to the log.
17-
public func debugLayout(
15+
public func layoutStep(
1816
_ label: String,
1917
file: StaticString = #fileID,
2018
line: UInt = #line

Sources/LayoutInspector/DebugLayoutImpl.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public final class LogStore: ObservableObject {
136136
func registerViewLabelAndWarnIfNotUnique(_ label: String, file: StaticString, line: UInt) {
137137
DispatchQueue.main.async {
138138
if self.viewLabels.contains(label) {
139-
let message: StaticString = "Duplicate view label '%s' detected. Use unique labels in debugLayout() calls"
139+
let message: StaticString = "Duplicate view label '%s' detected. Use unique labels in layoutStep() calls"
140140
runtimeWarning(message, [label], file: file, line: line)
141141
}
142142
self.viewLabels.insert(label)

0 commit comments

Comments
 (0)