64 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
//
 | 
						|
//  KeyboardView.swift
 | 
						|
//  AllenWrench
 | 
						|
//
 | 
						|
//  Created by Elizabeth Cray on 1/10/25.
 | 
						|
//  Copyright © 2025 Cray. All rights reserved.
 | 
						|
//
 | 
						|
// TODO:
 | 
						|
// - if touch up outside view, close Kbd
 | 
						|
 | 
						|
import SwiftUI
 | 
						|
 | 
						|
struct KeyboardView: View {
 | 
						|
    @State var db = Database()
 | 
						|
    @State var cfg = Config()
 | 
						|
    @State var size: CGSize = .zero
 | 
						|
    var body: some View {
 | 
						|
        VStack {
 | 
						|
            HStack {
 | 
						|
                ForEach(1...4, id: \.self) { z in
 | 
						|
                    VStack {
 | 
						|
                        ForEach(1...2, id: \.self) { y in
 | 
						|
                            quarterButton(label: "\(z) \(y)")
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
            HStack {
 | 
						|
                ForEach(1...3, id: \.self) { z in
 | 
						|
                    VStack {
 | 
						|
                        ForEach(1...2, id: \.self) { y in
 | 
						|
                            quarterButton(label: "\(z) \(y)")
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                VStack {
 | 
						|
                    quarterButton(label: "RET")
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
        GeometryReader { proxy in
 | 
						|
            HStack {} // just an empty container to triggers the onAppear
 | 
						|
                .onAppear {
 | 
						|
                    size = proxy.size
 | 
						|
                }
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    func quarterButton(label: any StringProtocol) -> some View {
 | 
						|
        Button (label) {
 | 
						|
            
 | 
						|
        }
 | 
						|
        .border(cfg.highlightColor)
 | 
						|
        .frame(
 | 
						|
            width: round(size.width/4),
 | 
						|
            height: round(size.height/4)
 | 
						|
        )
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
#Preview(traits:.fixedLayout(width: 645, height: 431)) {
 | 
						|
    KeyboardView()
 | 
						|
}
 |