Skip to content

Commit

Permalink
Add spaces column option
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinhenderson committed Mar 5, 2024
1 parent 08e0744 commit 655a2ed
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 17 deletions.
38 changes: 22 additions & 16 deletions DragToSpeak/Model/Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

import Foundation

enum SpacesColumn: Int {
case left
case right
case none
}

enum Layout: Int {
case alphabetical
case alphabeticalNoNumbers
Expand All @@ -17,23 +23,23 @@ enum Layout: Int {
switch self {

case .alphabetical:
return [[Cell(letter:"A"), Cell(letter: "B"), Cell(letter: "C"), Cell(letter: "D"), Cell(letter: "E"), Cell(isSpace: true, widthModifier: 0.5)],
[Cell(letter:"F"), Cell(letter: "G"), Cell(letter: "H"), Cell(letter: "I"), Cell(letter: "J"), Cell(isSpace: true, widthModifier: 0.5)],
[Cell(letter:"K"), Cell(letter: "L"), Cell(letter: "M"), Cell(letter: "N"), Cell(letter: "O"), Cell(isSpace: true, widthModifier: 0.5)],
[Cell(letter:"P"), Cell(letter: "Q"), Cell(letter: "R"), Cell(letter: "S"), Cell(letter: "T"), Cell(isSpace: true, widthModifier: 0.5)],
[Cell(letter:"U"), Cell(letter: "V"), Cell(letter: "W"), Cell(letter: "X"), Cell(letter: "Y"), Cell(isSpace: true, widthModifier: 0.5)],
[Cell(letter:"Z"), Cell(isSpace: true), Cell(word: "YES"), Cell(word: "NO"), Cell(isDelete: true), Cell(isSpace: true, widthModifier: 0.5)],
[Cell(word:"Thank you"), Cell(word: "OK"), Cell(word: "The"), Cell(word: "Please"), Cell(isFinish: true), Cell(isSpace: true, widthModifier: 0.5)],
[Cell(letter:"0"), Cell(letter: "1"), Cell(letter: "2"), Cell(letter: "3"), Cell(letter: "4"), Cell(isSpace: true, widthModifier: 0.5)],
[Cell(letter:"5"), Cell(letter: "6"), Cell(letter: "7"), Cell(letter: "8"), Cell(letter: "9"), Cell(isSpace: true, widthModifier: 0.5)]]
return [[Cell(letter:"A"), Cell(letter: "B"), Cell(letter: "C"), Cell(letter: "D"), Cell(letter: "E")],
[Cell(letter:"F"), Cell(letter: "G"), Cell(letter: "H"), Cell(letter: "I"), Cell(letter: "J")],
[Cell(letter:"K"), Cell(letter: "L"), Cell(letter: "M"), Cell(letter: "N"), Cell(letter: "O")],
[Cell(letter:"P"), Cell(letter: "Q"), Cell(letter: "R"), Cell(letter: "S"), Cell(letter: "T")],
[Cell(letter:"U"), Cell(letter: "V"), Cell(letter: "W"), Cell(letter: "X"), Cell(letter: "Y")],
[Cell(letter:"Z"), Cell(isSpace: true), Cell(word: "YES"), Cell(word: "NO"), Cell(isDelete: true)],
[Cell(word:"Thank you"), Cell(word: "OK"), Cell(word: "The"), Cell(word: "Please"), Cell(isFinish: true)],
[Cell(letter:"0"), Cell(letter: "1"), Cell(letter: "2"), Cell(letter: "3"), Cell(letter: "4")],
[Cell(letter:"5"), Cell(letter: "6"), Cell(letter: "7"), Cell(letter: "8"), Cell(letter: "9")]]
case .alphabeticalNoNumbers:
return [[Cell(letter:"A"), Cell(letter: "B"), Cell(letter: "C"), Cell(letter: "D"), Cell(letter: "E"), Cell(isSpace: true, widthModifier: 0.5)],
[Cell(letter:"F"), Cell(letter: "G"), Cell(letter: "H"), Cell(letter: "I"), Cell(letter: "J"), Cell(isSpace: true, widthModifier: 0.5)],
[Cell(letter:"K"), Cell(letter: "L"), Cell(letter: "M"), Cell(letter: "N"), Cell(letter: "O"), Cell(isSpace: true, widthModifier: 0.5)],
[Cell(letter:"P"), Cell(letter: "Q"), Cell(letter: "R"), Cell(letter: "S"), Cell(letter: "T"), Cell(isSpace: true, widthModifier: 0.5)],
[Cell(letter:"U"), Cell(letter: "V"), Cell(letter: "W"), Cell(letter: "X"), Cell(letter: "Y"), Cell(isSpace: true, widthModifier: 0.5)],
[Cell(letter:"Z"), Cell(isSpace: true), Cell(word: "YES"), Cell(word: "NO"), Cell(isDelete: true), Cell(isSpace: true, widthModifier: 0.5)],
[Cell(word:"Thank you"), Cell(word: "OK"), Cell(word: "The"), Cell(word: "Please"), Cell(isFinish: true), Cell(isSpace: true, widthModifier: 0.5)]]
return [[Cell(letter:"A"), Cell(letter: "B"), Cell(letter: "C"), Cell(letter: "D"), Cell(letter: "E")],
[Cell(letter:"F"), Cell(letter: "G"), Cell(letter: "H"), Cell(letter: "I"), Cell(letter: "J")],
[Cell(letter:"K"), Cell(letter: "L"), Cell(letter: "M"), Cell(letter: "N"), Cell(letter: "O")],
[Cell(letter:"P"), Cell(letter: "Q"), Cell(letter: "R"), Cell(letter: "S"), Cell(letter: "T")],
[Cell(letter:"U"), Cell(letter: "V"), Cell(letter: "W"), Cell(letter: "X"), Cell(letter: "Y")],
[Cell(letter:"Z"), Cell(isSpace: true), Cell(word: "YES"), Cell(word: "NO"), Cell(isDelete: true)],
[Cell(word:"Thank you"), Cell(word: "OK"), Cell(word: "The"), Cell(word: "Please"), Cell(isFinish: true)]]
case .frequency:
return [[Cell(letter:" Z"), Cell(letter: "V"), Cell(letter: "C"), Cell(letter: "H"), Cell(letter: "W"), Cell(letter: "K")],
[Cell(letter:"F"), Cell(letter: "I"), Cell(letter: "T"), Cell(letter: "A"), Cell(letter: "L"), Cell(letter: "Y")],
Expand Down
1 change: 1 addition & 0 deletions DragToSpeak/Observable/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ class AppSettings: ObservableObject {
@AppStorage("dragType") var dragType: DragType = .dwell
@AppStorage("fontSize") var fontSize: Int = 10
@AppStorage("finishOnDragEnd") var finishOnDragEnd: Bool = false
@AppStorage("spacesColumn") var spacesColumn: SpacesColumn = .none
}
26 changes: 25 additions & 1 deletion DragToSpeak/Observable/GridController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,29 @@ class GridController: ObservableObject {

var voiceEngine: VoiceEngine?
var messageController: MessageController?
var appSettings: AppSettings?

func setLayout(_ layout: Layout) {
grid = layout.grid
let spacesColumn = appSettings?.spacesColumn ?? .none

var newGrid: [[Cell]] = []

for row in layout.grid {
let spaceCell = Cell(isSpace: true, widthModifier: 0.5)

if spacesColumn == .left {
newGrid.append([spaceCell] + row)
} else if spacesColumn == .right {
newGrid.append(row + [spaceCell])
} else {
newGrid.append(row)
}

}

grid = newGrid


}

func resetCells() {
Expand Down Expand Up @@ -70,6 +90,10 @@ class GridController: ObservableObject {
self.voiceEngine = voiceEngine
}

func loadAppSettings(_ appSettings: AppSettings) {
self.appSettings = appSettings
}

func updateSize(_ size: CGSize) {
self.size = size
}
Expand Down
9 changes: 9 additions & 0 deletions DragToSpeak/Pages/SettingsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ struct SettingsPage: View {
Text("Frequency").tag(Layout.frequency)
Text("QWERTY").tag(Layout.qwerty)
}
VStack(alignment: .leading) {
Text("Insert column of spaces to side")
Picker("Spaces Column", selection: $settings.spacesColumn) {
Text("Left").tag(SpacesColumn.left)
Text("None").tag(SpacesColumn.none)
Text("Right").tag(SpacesColumn.right)
}
.pickerStyle(.segmented)
}
} footer: {
Text("The layout of the letters on the grid")
}
Expand Down
4 changes: 4 additions & 0 deletions DragToSpeak/Pages/SpellingBoardPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct SpellingBoardPage: View {
directionController.loadGridController(gridController)
directionController.loadMessageController(messageController )

gridController.loadAppSettings(settings)
gridController.setLayout(settings.layout)
gridController.loadMessageController(messageController)
gridController.loadVoiceEngine(voiceEngine)
Expand All @@ -44,6 +45,9 @@ struct SpellingBoardPage: View {
.onChange(of: settings.layout) {
gridController.setLayout(settings.layout)
}
.onChange(of: settings.spacesColumn) {
gridController.setLayout(settings.layout)
}
.environmentObject(dwellController)
.environmentObject(gridController)
.environmentObject(directionController)
Expand Down

0 comments on commit 655a2ed

Please sign in to comment.