@@ -2,65 +2,61 @@ import SwiftUI
2
2
import DebugLayout
3
3
4
4
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 {
55
6
Text ( " Hello world " )
56
7
. debugLayout ( " Text " )
57
8
. padding ( 10 )
58
9
. debugLayout ( " padding " )
59
10
. border ( Color . green)
60
11
. 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 " )
61
25
}
62
26
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
+
64
60
65
61
var body : some View {
66
62
VStack {
0 commit comments