From eeb19cb9294a1ff91c9d9eae254c7c1856fecfc8 Mon Sep 17 00:00:00 2001 From: Elizabeth Cray Date: Wed, 15 Jan 2025 00:45:28 -0500 Subject: [PATCH] End-Of-Session: Created keyboard grid array --- .../xcschemes/xcschememanagement.plist | 2 +- AllenWrench/Database.swift | 8 ---- awkbd/KeyboardView.swift | 46 +++++++++++++++---- awkbd/KeyboardViewController.swift | 6 ++- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/AllenWrench.xcodeproj/xcuserdata/liz.xcuserdatad/xcschemes/xcschememanagement.plist b/AllenWrench.xcodeproj/xcuserdata/liz.xcuserdatad/xcschemes/xcschememanagement.plist index 022477b..e9a264e 100644 --- a/AllenWrench.xcodeproj/xcuserdata/liz.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/AllenWrench.xcodeproj/xcuserdata/liz.xcuserdatad/xcschemes/xcschememanagement.plist @@ -12,7 +12,7 @@ awkbd.xcscheme_^#shared#^_ orderHint - 1 + 0 diff --git a/AllenWrench/Database.swift b/AllenWrench/Database.swift index 31865e4..4e91e36 100644 --- a/AllenWrench/Database.swift +++ b/AllenWrench/Database.swift @@ -8,14 +8,6 @@ import Foundation -//struct Database { -// var groups: [String] -// var phrases: [Phrase] -// var phrasesByGroup(group: String): [Phrase] = { -// -// } -//} - class Database { // TODO: if empty, save+return default phrases var phrases: [Phrase] { diff --git a/awkbd/KeyboardView.swift b/awkbd/KeyboardView.swift index 01d1772..dc612cf 100644 --- a/awkbd/KeyboardView.swift +++ b/awkbd/KeyboardView.swift @@ -7,26 +7,54 @@ // // 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 { - ScrollView { - VStack { - ForEach(db.groups) { group in - Text(group.name) - .foregroundColor(cfg.highlightColor) - HStack { - ForEach(group.phrases) { phrase in - Text(phrase.string) + VStack { + HStack { + ForEach(1...4, id: \.self) { z in + VStack { + ForEach(1...2, id: \.self) { y in + quarterButton(label: "\(z) \(y)") } } } - Button("Clear") { db.groups[1].name = NSUUID().uuidString} + } + 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) + ) } } diff --git a/awkbd/KeyboardViewController.swift b/awkbd/KeyboardViewController.swift index 29b67d7..94eedcb 100644 --- a/awkbd/KeyboardViewController.swift +++ b/awkbd/KeyboardViewController.swift @@ -20,9 +20,9 @@ class KeyboardViewController: UIInputViewController { override func viewDidLoad() { super.viewDidLoad() - let hostController = UIHostingController(rootView: KeyboardView()) hostController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] + hostController.sizingOptions = [.intrinsicContentSize] self.view.addSubview(hostController.view) addChild(hostController) @@ -64,5 +64,9 @@ class KeyboardViewController: UIInputViewController { } self.nextKeyboardButton.setTitleColor(textColor, for: []) } + + func sendText(text: String) { + textDocumentProxy.insertText(text) + } }