11import SwiftUI
22
3+ let editKeyCornerRadius : CGFloat = 8
4+ let editKeyGap : CGFloat = 8
5+
36struct EditView : View {
47 @Environment ( \. colorScheme) var colorScheme
58 let totalWidth : CGFloat
@@ -12,136 +15,111 @@ struct EditView: View {
1215
1316 ZStack {
1417 button (
15- image: " arrowtriangle.left.fill " , shrink: 15 ,
16- background: getNormalBackground ( colorScheme) ,
17- foreground: getNormalForeground ( colorScheme) ,
18- shadow: getShadow ( colorScheme) ,
18+ image: " arrowtriangle.left.fill " , shrink: 15 , normal: true ,
1919 index: 0 , width: width, height: height * 3
2020 ) {
2121 client. keyPressed ( " " , " ArrowLeft " )
2222 }
2323 button (
24- image: " arrowtriangle.up.fill " , shrink: 15 ,
25- background: getNormalBackground ( colorScheme) ,
26- foreground: getNormalForeground ( colorScheme) ,
27- shadow: getShadow ( colorScheme) ,
24+ image: " arrowtriangle.up.fill " , shrink: 15 , normal: true ,
2825 index: 1 , width: width, height: height * 1.5
2926 ) {
3027 client. keyPressed ( " " , " ArrowUp " )
3128 }
3229 button (
33- image: " arrowtriangle.right.fill " , shrink: 15 ,
34- background: getNormalBackground ( colorScheme) ,
35- foreground: getNormalForeground ( colorScheme) ,
36- shadow: getShadow ( colorScheme) ,
30+ image: " arrowtriangle.right.fill " , shrink: 15 , normal: true ,
3731 index: 2 , width: width, height: height * 3
3832 ) {
3933 client. keyPressed ( " " , " ArrowRight " )
4034 }
4135 button (
42- image: " scissors " , shrink: 10 ,
43- background: getFunctionBackground ( colorScheme) ,
44- foreground: getNormalForeground ( colorScheme) ,
45- shadow: getShadow ( colorScheme) ,
36+ image: " scissors " , shrink: 10 , normal: false ,
4637 index: 3 , width: width, height: height
4738 ) {
4839 client. cut ( )
4940 }
5041 button (
51- image: " doc.on.doc " , shrink: 10 ,
52- background: getFunctionBackground ( colorScheme) ,
53- foreground: getNormalForeground ( colorScheme) ,
54- shadow: getShadow ( colorScheme) ,
42+ image: " doc.on.doc " , shrink: 10 , normal: false ,
5543 index: 7 , width: width, height: height
5644 ) {
5745 client. copy ( )
5846 }
5947 button (
60- image: " arrowtriangle.down.fill " , shrink: 15 ,
61- background: getNormalBackground ( colorScheme) ,
62- foreground: getNormalForeground ( colorScheme) ,
63- shadow: getShadow ( colorScheme) ,
48+ image: " arrowtriangle.down.fill " , shrink: 15 , normal: true ,
6449 index: 5 , width: width, height: height * 1.5
6550 ) {
6651 client. keyPressed ( " " , " ArrowDown " )
6752 }
6853 button (
69- image: " doc.on.clipboard " , shrink: 10 ,
70- background: getFunctionBackground ( colorScheme) ,
71- foreground: getNormalForeground ( colorScheme) ,
72- shadow: getShadow ( colorScheme) ,
54+ image: " doc.on.clipboard " , shrink: 10 , normal: false ,
7355 index: 11 , width: width, height: height
7456 ) {
7557 client. paste ( )
7658 }
7759 button (
78- image: " arrow.left.to.line " , shrink: 15 ,
79- background: getNormalBackground ( colorScheme) ,
80- foreground: getNormalForeground ( colorScheme) ,
81- shadow: getShadow ( colorScheme) ,
60+ image: " arrow.left.to.line " , shrink: 15 , normal: true ,
8261 index: 12 , width: width * 1.5 , height: height
8362 ) {
8463 client. keyPressed ( " " , " Home " )
8564 }
8665 button (
87- image: " arrow.right.to.line " , shrink: 15 ,
88- background: getNormalBackground ( colorScheme) ,
89- foreground: getNormalForeground ( colorScheme) ,
90- shadow: getShadow ( colorScheme) ,
66+ image: " arrow.right.to.line " , shrink: 15 , normal: true ,
9167 index: 13 , width: width * 1.5 , height: height
9268 ) {
9369 client. keyPressed ( " " , " End " )
9470 }
9571 button (
96- image: " delete.left " , shrink: 10 ,
97- background: getFunctionBackground ( colorScheme) ,
98- foreground: getNormalForeground ( colorScheme) ,
99- shadow: getShadow ( colorScheme) ,
72+ image: " delete.left " , shrink: 10 , normal: false ,
10073 index: 15 , width: width, height: height
101- ) {
102- client. keyPressed ( " " , " Backspace " )
103- }
74+ ) { }
10475 }
10576 }
10677 }
10778
10879 private func position( _ index: Int , _ width: CGFloat , _ height: CGFloat ) -> CGPoint {
10980 let row = index / 4
11081 let col = index % 4
111- return CGPoint ( x: ( CGFloat ( col) + 0.5 ) * width, y: ( CGFloat ( row) + 0.5 ) * height)
82+ return CGPoint ( x: CGFloat ( col) * width, y: CGFloat ( row) * height)
11283 }
11384
11485 private func button(
115- image: String , shrink: CGFloat , background : Color , foreground : Color , shadow : Color ,
86+ image: String , shrink: CGFloat , normal : Bool ,
11687 index: Int , width: CGFloat , height: CGFloat , action: @escaping ( ) -> Void
11788 ) -> some View {
118- let w = width - 8
119- let h = height - 8
120- let r : CGFloat = 8
121- return Button {
122- action ( )
123- } label: {
124- VStack {
125- let symbol = Image ( systemName: image)
126- . resizable ( )
127- . aspectRatio ( contentMode: . fit)
128- . foregroundColor ( foreground)
129- let size = keyboardHeight / shrink
130- if image == " arrowtriangle.up.fill " || image == " arrowtriangle.down.fill " {
131- symbol. frame ( width: size)
132- } else {
133- symbol. frame ( height: size)
134- }
135- } . frame ( width: w, height: h)
136- . background ( background)
137- . foregroundColor ( . black)
138- . cornerRadius ( r)
139- } . buttonStyle ( PlainButtonStyle ( ) )
140- . shadow ( color: shadow, radius: 0 , x: 0 , y: 1 )
141- . frame ( width: w, height: h)
142- . overlay (
143- RoundedRectangle ( cornerRadius: r)
144- . stroke ( Color . clear, lineWidth: 1 )
145- ) . position ( position ( index, width, height) )
89+ let background = normal ? getNormalBackground ( colorScheme) : getFunctionBackground ( colorScheme)
90+ let pressedBackground =
91+ normal ? getFunctionBackground ( colorScheme) : getNormalBackground ( colorScheme)
92+ let foreground = getNormalForeground ( colorScheme)
93+ let p = position ( index, width, height)
94+ let size = keyboardHeight / shrink
95+ let useWidth = image == " arrowtriangle.up.fill " || image == " arrowtriangle.down.fill "
96+ let symbol = Image ( systemName: image)
97+ . resizable ( )
98+ . aspectRatio ( contentMode: . fit)
99+ . condition ( useWidth) {
100+ $0. frame ( width: size)
101+ }
102+ . condition ( !useWidth) {
103+ $0. frame ( height: size)
104+ }
105+ if image == " delete.left " {
106+ return AnyView (
107+ BackspaceView (
108+ x: p. x, y: p. y, width: width, height: height, hMargin: editKeyGap, vMargin: editKeyGap,
109+ radius: editKeyCornerRadius) )
110+ }
111+ return AnyView (
112+ symbol. keyProperties (
113+ x: p. x, y: p. y, width: width, height: height, hMargin: editKeyGap, vMargin: editKeyGap,
114+ radius: editKeyCornerRadius,
115+ background: background,
116+ pressedBackground: pressedBackground,
117+ foreground: foreground,
118+ shadow: getShadow ( colorScheme) ,
119+ action: GestureAction (
120+ onTap: {
121+ action ( )
122+ } ) )
123+ )
146124 }
147125}
0 commit comments