@@ -25,41 +25,77 @@ struct ResizableAndDraggableFrame: ViewModifier {
25
25
. padding ( . top, Self . titleBarHeight)
26
26
. overlay {
27
27
ZStack ( alignment: . top) {
28
- Rectangle ( )
29
- . frame ( height: Self . titleBarHeight)
30
- . foregroundStyle ( . tertiary)
31
- . draggable ( point: $frame. origin, coordinateSpace: coordinateSpace)
32
-
33
- let resizeHandle = ResizeHandle ( )
34
- . fill ( . secondary)
35
- . frame ( width: 20 , height: 20 )
36
- resizeHandle
37
- . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . topLeading)
38
- . draggable ( point: $frame. topLeading, coordinateSpace: coordinateSpace)
39
- resizeHandle
40
- . rotationEffect ( . degrees( 90 ) )
41
- . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . topTrailing)
42
- . draggable ( point: $frame. topTrailing, coordinateSpace: coordinateSpace)
43
- resizeHandle
44
- . rotationEffect ( . degrees( - 90 ) )
45
- . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . bottomLeading)
46
- . draggable ( point: $frame. bottomLeading, coordinateSpace: coordinateSpace)
47
- resizeHandle
48
- . rotationEffect ( . degrees( 180 ) )
49
- . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . bottomTrailing)
50
- . draggable ( point: $frame. bottomTrailing, coordinateSpace: coordinateSpace)
28
+ titleBar
29
+ resizeHandles
51
30
}
52
31
}
53
32
}
33
+
34
+ @ViewBuilder private var titleBar : some View {
35
+ Rectangle ( )
36
+ . frame ( height: Self . titleBarHeight)
37
+ . foregroundStyle ( . ultraThinMaterial)
38
+ . overlay {
39
+ Text ( " Layout Inspector " )
40
+ . font ( . footnote)
41
+ }
42
+ . overlay ( alignment: . bottom) {
43
+ Rectangle ( )
44
+ . foregroundStyle ( . quaternary)
45
+ . frame ( height: 1 )
46
+ }
47
+ . draggable ( point: $frame. origin, coordinateSpace: coordinateSpace)
48
+ . help ( " Move " )
49
+ }
50
+
51
+ @ViewBuilder private var resizeHandles : some View {
52
+ let resizeHandle = TriangleStripes ( )
53
+ . fill ( Color ( white: 0.5 ) . opacity ( 0.5 ) )
54
+ . frame ( width: 15 , height: 15 )
55
+ . frame ( width: Self . titleBarHeight, height: Self . titleBarHeight, alignment: . topLeading)
56
+ . contentShape ( Rectangle ( ) )
57
+ . help ( " Resize " )
58
+ resizeHandle
59
+ . draggable ( point: $frame. topLeading, coordinateSpace: coordinateSpace)
60
+ . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . topLeading)
61
+ resizeHandle
62
+ . rotationEffect ( . degrees( 90 ) )
63
+ . draggable ( point: $frame. topTrailing, coordinateSpace: coordinateSpace)
64
+ . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . topTrailing)
65
+ resizeHandle
66
+ . rotationEffect ( . degrees( - 90 ) )
67
+ . draggable ( point: $frame. bottomLeading, coordinateSpace: coordinateSpace)
68
+ . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . bottomLeading)
69
+ resizeHandle
70
+ . rotationEffect ( . degrees( 180 ) )
71
+ . draggable ( point: $frame. bottomTrailing, coordinateSpace: coordinateSpace)
72
+ . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . bottomTrailing)
73
+ }
54
74
}
55
75
56
- struct ResizeHandle : Shape {
76
+ struct TriangleStripes : Shape {
57
77
func path( in rect: CGRect ) -> Path {
78
+ let stripeCount = 4
79
+ let spacing : CGFloat = 0.15 // in unit points
80
+ let stripeWidth = ( 1 - CGFloat( stripeCount - 1 ) * spacing) / CGFloat( stripeCount)
81
+
58
82
var path = Path ( )
83
+ // First stripe is special
59
84
path. move ( to: rect. topLeading)
60
- path. addLine ( to: rect. topTrailing )
61
- path. addLine ( to: rect. bottomLeading )
85
+ path. addLine ( to: rect. unitPoint ( . init ( x : stripeWidth , y : 0 ) ) )
86
+ path. addLine ( to: rect. unitPoint ( . init ( x : 0 , y : stripeWidth ) ) )
62
87
path. closeSubpath ( )
88
+
89
+ for stripe in 1 ..< stripeCount {
90
+ let start = CGFloat ( stripe) * ( stripeWidth + spacing)
91
+ let end = start + stripeWidth
92
+ path. move ( to: rect. unitPoint ( . init( x: start, y: 0 ) ) )
93
+ path. addLine ( to: rect. unitPoint ( . init( x: end, y: 0 ) ) )
94
+ path. addLine ( to: rect. unitPoint ( . init( x: 0 , y: end) ) )
95
+ path. addLine ( to: rect. unitPoint ( . init( x: 0 , y: start) ) )
96
+ path. closeSubpath ( )
97
+ }
98
+
63
99
return path
64
100
}
65
101
}
0 commit comments