Skip to content

Commit 559ecad

Browse files
committed
#218 switch conjugation state to an enum and formatting
1 parent deda389 commit 559ecad

File tree

5 files changed

+77
-62
lines changed

5 files changed

+77
-62
lines changed

Keyboards/KeyboardsBase/KeyboardViewController.swift

+58-53
Original file line numberDiff line numberDiff line change
@@ -530,42 +530,39 @@ class KeyboardViewController: UIInputViewController {
530530
}
531531
}
532532

533-
@IBOutlet var conjugateKeyTL: UIButton!
534-
@IBOutlet var conjugateKeyTR: UIButton!
535-
@IBOutlet var conjugateKeyBL: UIButton!
536-
@IBOutlet var conjugateKeyBR: UIButton!
533+
@IBOutlet var conjugateKeyTop: UIButton!
534+
@IBOutlet var conjugateKeyMiddle: UIButton!
535+
@IBOutlet var conjugateKeyBottom: UIButton!
537536

538-
/// Returns all buttons for the 2x2 conjugation display
539-
func get2x2ConjButtons() -> [UIButton] {
537+
/// Returns all buttons for the 3x1 conjugation display
538+
func get3x1ConjButtons() -> [UIButton] {
540539
let conjugationButtons: [UIButton] = [
541-
conjugateKeyTL, conjugateKeyTR, conjugateKeyBL, conjugateKeyBR
540+
conjugateKeyTop, conjugateKeyMiddle, conjugateKeyBottom
542541
]
543542

544543
return conjugationButtons
545544
}
546545

547-
@IBOutlet var conjugateLblTL: UIButton!
548-
@IBOutlet var conjugateLblTR: UIButton!
549-
@IBOutlet var conjugateLblBL: UIButton!
550-
@IBOutlet var conjugateLblBR: UIButton!
546+
@IBOutlet var conjugateLblTop: UIButton!
547+
@IBOutlet var conjugateLblMiddle: UIButton!
548+
@IBOutlet var conjugateLblBottom: UIButton!
551549

552-
/// Returns all labels for the 2x2 conjugation display.
553-
func get2x2ConjLabels() -> [UIButton] {
550+
/// Returns all labels for the 3x1 conjugation display.
551+
func get3x1ConjLabels() -> [UIButton] {
554552
let conjugationLabels: [UIButton] = [
555-
conjugateLblTL, conjugateLblTR, conjugateLblBL, conjugateLblBR
553+
conjugateLblTop, conjugateLblMiddle, conjugateLblBottom
556554
]
557555

558556
return conjugationLabels
559557
}
560558

561-
/// Sets up all buttons and labels that are associated with the 2x2 conjugation display.
562-
func setConj2x2View() {
563-
setBtn(btn: conjugateKeyTL, color: keyColor, name: "conjugateTopLeft", canCap: false, isSpecial: false)
564-
setBtn(btn: conjugateKeyTR, color: keyColor, name: "conjugateTopRight", canCap: false, isSpecial: false)
565-
setBtn(btn: conjugateKeyBL, color: keyColor, name: "conjugateBottomLeft", canCap: false, isSpecial: false)
566-
setBtn(btn: conjugateKeyBR, color: keyColor, name: "conjugateBottomRight", canCap: false, isSpecial: false)
559+
/// Sets up all buttons and labels that are associated with the 3x1 conjugation display.
560+
func setConj3x1View() {
561+
setBtn(btn: conjugateKeyTop, color: keyColor, name: "conjugateTop", canCap: false, isSpecial: false)
562+
setBtn(btn: conjugateKeyMiddle, color: keyColor, name: "conjugateMiddle", canCap: false, isSpecial: false)
563+
setBtn(btn: conjugateKeyBottom, color: keyColor, name: "conjugateBottom", canCap: false, isSpecial: false)
567564

568-
for btn in get2x2ConjButtons() {
565+
for btn in get3x1ConjButtons() {
569566
activateBtn(btn: btn)
570567
}
571568

@@ -574,45 +571,48 @@ class KeyboardViewController: UIInputViewController {
574571
if isLandscapeView {
575572
conjugationFontDivisor = 4
576573
}
577-
for btn in get2x2ConjButtons() {
574+
for btn in get3x1ConjButtons() {
578575
btn.titleLabel?.font = .systemFont(ofSize: letterKeyWidth / conjugationFontDivisor)
579576
}
580577
}
581578
}
582579

583-
@IBOutlet var conjugateKeyTop: UIButton!
584-
@IBOutlet var conjugateKeyMiddle: UIButton!
585-
@IBOutlet var conjugateKeyBottom: UIButton!
580+
@IBOutlet var conjugateKeyTL: UIButton!
581+
@IBOutlet var conjugateKeyTR: UIButton!
582+
@IBOutlet var conjugateKeyBL: UIButton!
583+
@IBOutlet var conjugateKeyBR: UIButton!
586584

587-
/// Returns all buttons for the 3x1 conjugation display
588-
func get3x1ConjButtons() -> [UIButton] {
585+
/// Returns all buttons for the 2x2 conjugation display
586+
func get2x2ConjButtons() -> [UIButton] {
589587
let conjugationButtons: [UIButton] = [
590-
conjugateKeyTop, conjugateKeyMiddle, conjugateKeyBottom
588+
conjugateKeyTL, conjugateKeyTR, conjugateKeyBL, conjugateKeyBR
591589
]
592590

593591
return conjugationButtons
594592
}
595593

596-
@IBOutlet var conjugateLblTop: UIButton!
597-
@IBOutlet var conjugateLblMiddle: UIButton!
598-
@IBOutlet var conjugateLblBottom: UIButton!
594+
@IBOutlet var conjugateLblTL: UIButton!
595+
@IBOutlet var conjugateLblTR: UIButton!
596+
@IBOutlet var conjugateLblBL: UIButton!
597+
@IBOutlet var conjugateLblBR: UIButton!
599598

600-
/// Returns all labels for the 3x1 conjugation display.
601-
func get3x1ConjLabels() -> [UIButton] {
599+
/// Returns all labels for the 2x2 conjugation display.
600+
func get2x2ConjLabels() -> [UIButton] {
602601
let conjugationLabels: [UIButton] = [
603-
conjugateLblTop, conjugateLblMiddle, conjugateLblBottom
602+
conjugateLblTL, conjugateLblTR, conjugateLblBL, conjugateLblBR
604603
]
605604

606605
return conjugationLabels
607606
}
608607

609-
/// Sets up all buttons and labels that are associated with the 3x1 conjugation display.
610-
func setConj3x1View() {
611-
setBtn(btn: conjugateKeyTop, color: keyColor, name: "conjugateTop", canCap: false, isSpecial: false)
612-
setBtn(btn: conjugateKeyMiddle, color: keyColor, name: "conjugateMiddle", canCap: false, isSpecial: false)
613-
setBtn(btn: conjugateKeyBottom, color: keyColor, name: "conjugateBottom", canCap: false, isSpecial: false)
608+
/// Sets up all buttons and labels that are associated with the 2x2 conjugation display.
609+
func setConj2x2View() {
610+
setBtn(btn: conjugateKeyTL, color: keyColor, name: "conjugateTopLeft", canCap: false, isSpecial: false)
611+
setBtn(btn: conjugateKeyTR, color: keyColor, name: "conjugateTopRight", canCap: false, isSpecial: false)
612+
setBtn(btn: conjugateKeyBL, color: keyColor, name: "conjugateBottomLeft", canCap: false, isSpecial: false)
613+
setBtn(btn: conjugateKeyBR, color: keyColor, name: "conjugateBottomRight", canCap: false, isSpecial: false)
614614

615-
for btn in get3x1ConjButtons() {
615+
for btn in get2x2ConjButtons() {
616616
activateBtn(btn: btn)
617617
}
618618

@@ -621,7 +621,7 @@ class KeyboardViewController: UIInputViewController {
621621
if isLandscapeView {
622622
conjugationFontDivisor = 4
623623
}
624-
for btn in get3x1ConjButtons() {
624+
for btn in get2x2ConjButtons() {
625625
btn.titleLabel?.font = .systemFont(ofSize: letterKeyWidth / conjugationFontDivisor)
626626
}
627627
}
@@ -716,20 +716,20 @@ class KeyboardViewController: UIInputViewController {
716716
func setConjugationBtns() {
717717
// Set the conjugation view to 2x2 for Swedish and Russian past tense.
718718
if controllerLanguage == "Swedish" {
719-
conjugateAlternateView = true
719+
conjugateDimensions = .view2x2
720720
} else if controllerLanguage == "Russian" && ruConjugationState == .past {
721-
conjugateAlternateView = true
721+
conjugateDimensions = .view2x2
722722
} else if
723723
commandState == .selectCaseConjugation
724724
&& controllerLanguage == "German"
725725
&& [.accusative, .dative, .genitive].contains(deCaseConjugationState) {
726-
conjugateAlternateView = true
726+
conjugateDimensions = .view2x2
727727
} else {
728-
conjugateAlternateView = false
728+
conjugateDimensions = .view3x2
729729
}
730730

731731
// The base conjugation view is 3x2 for first, second, and third person in singular and plural.
732-
if conjugateAlternateView == false {
732+
if conjugateDimensions == .view3x2 {
733733
setConj3x2View()
734734
} else {
735735
setConj2x2View()
@@ -755,7 +755,12 @@ class KeyboardViewController: UIInputViewController {
755755
activateBtn(btn: conjugateShiftRight)
756756

757757
// Make all labels clear and set their font for if they will be used.
758-
let allConjLabels: [UIButton] = get3x2ConjLabels() + get2x2ConjLabels()
758+
let allConjLabels: [UIButton] =
759+
get3x2ConjLabels()
760+
+ get3x1ConjLabels()
761+
+ get2x2ConjLabels()
762+
+ get1x2ConjLabels()
763+
+ get1x1ConjLabels()
759764
for lbl in allConjLabels {
760765
lbl.backgroundColor = UIColor.clear
761766
lbl.setTitleColor(specialKeyColor, for: .normal)
@@ -771,7 +776,7 @@ class KeyboardViewController: UIInputViewController {
771776
activateBtn(btn: conjugateShiftLeft)
772777
activateBtn(btn: conjugateShiftRight)
773778

774-
if conjugateAlternateView == false {
779+
if conjugateDimensions == .view3x2 {
775780
for btn in get3x2ConjButtons() {
776781
activateBtn(btn: btn)
777782
}
@@ -781,7 +786,7 @@ class KeyboardViewController: UIInputViewController {
781786
}
782787
}
783788

784-
if conjugateAlternateView == true {
789+
if conjugateDimensions == .view2x2 {
785790
for btn in get3x2ConjButtons() {
786791
deactivateBtn(btn: btn)
787792
}
@@ -801,14 +806,14 @@ class KeyboardViewController: UIInputViewController {
801806

802807
let allConjButtons: [UIButton] =
803808
get3x2ConjButtons()
804-
+ get2x2ConjButtons()
805809
+ get3x1ConjButtons()
810+
+ get2x2ConjButtons()
806811
+ get1x2ConjButtons()
807812
+ get1x1ConjButtons()
808813
let allConjLabels: [UIButton] =
809814
get3x2ConjLabels()
810-
+ get2x2ConjLabels()
811815
+ get3x1ConjLabels()
816+
+ get2x2ConjLabels()
812817
+ get1x2ConjLabels()
813818
+ get1x1ConjLabels()
814819
let allConjElements: [UIButton] = allConjButtons + allConjLabels
@@ -838,7 +843,7 @@ class KeyboardViewController: UIInputViewController {
838843
conjTPP = conjugationStateFxn() + "TPP"
839844

840845
} else if controllerLanguage == "Russian" {
841-
if conjugateAlternateView == false {
846+
if conjugateDimensions == .view3x2 {
842847
conjFPS = ruGetConjugationState() + "FPS"
843848
conjSPS = ruGetConjugationState() + "SPS"
844849
conjTPS = ruGetConjugationState() + "TPS"
@@ -899,7 +904,7 @@ class KeyboardViewController: UIInputViewController {
899904
conjugateLblBL.setTitle(" " + labelBottomLeft, for: .normal)
900905
conjugateLblBR.setTitle(" " + labelBottomRight, for: .normal)
901906

902-
if conjugateAlternateView == false {
907+
if conjugateDimensions == .view3x2 {
903908
allConjugations = [conjFPS, conjSPS, conjTPS, conjFPP, conjSPP, conjTPP]
904909
allConjugationBtns = get3x2ConjButtons()
905910
} else {

Keyboards/KeyboardsBase/ScribeFunctionality/Annotate.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func selectedWordAnnotation(_ KVC: KeyboardViewController) {
8484
}
8585
}
8686
}
87-
87+
8888
if isPrep {
8989
activateAnnotationBtn = true
9090
prepAnnotationForm = prepositions?[wordToCheck.lowercased()] as! String
@@ -98,7 +98,7 @@ func selectedWordAnnotation(_ KVC: KeyboardViewController) {
9898
}
9999
}
100100
}
101-
101+
102102
if annotationsToAssign.count > 0 {
103103
annotationState = true
104104
autoAction1Visible = false
@@ -210,7 +210,7 @@ func typedWordAnnotation(_ KVC: KeyboardViewController) {
210210
let annotationFieldWidth = KVC.translateKey.frame.width * 0.85
211211
var annotationHeight: CGFloat = 0.0
212212
annotationHeight = scribeKeyHeight
213-
213+
214214
if lastWordTyped == "Scribe" || lastWordTyped == "scribe" {
215215
// Thank the user :)
216216
annotationState = true
@@ -249,7 +249,7 @@ func typedWordAnnotation(_ KVC: KeyboardViewController) {
249249
}
250250
}
251251
}
252-
252+
253253
if isPrep {
254254
activateAnnotationBtn = true
255255
prepAnnotationForm = prepositions?[wordToCheck.lowercased()] as! String
@@ -263,7 +263,7 @@ func typedWordAnnotation(_ KVC: KeyboardViewController) {
263263
}
264264
}
265265
}
266-
266+
267267
if annotationsToAssign.count > 0 {
268268
annotationState = true
269269
autoAction1Visible = false

Keyboards/KeyboardsBase/ScribeFunctionality/CommandBar.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CommandBar: UILabel {
3737
class func instanceFromNib() -> UIView {
3838
return UINib(nibName: "Keyboard", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! UIView
3939
}
40-
40+
4141
var shadow: UIButton!
4242
var blend: UILabel!
4343

Keyboards/KeyboardsBase/ScribeFunctionality/CommandVariables.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,17 @@ var conjugatePlaceholder: String = ""
7676
var conjugatePromptAndCursor: String = ""
7777
var conjugatePromptAndPlaceholder: String = ""
7878
var conjugatePromptAndColorPlaceholder = NSMutableAttributedString()
79-
var conjugateAlternateView: Bool = false
79+
80+
/// What the view of the conjugation display to display to the user.
81+
enum ConjugateDimensions {
82+
case view3x2
83+
case view3x1
84+
case view2x2
85+
case view1x2
86+
case view1x1
87+
}
88+
89+
var conjugateDimensions: ConjugateDimensions = .view3x2
8090

8191
var allConjugations = [String]()
8292
var allConjugationBtns = [UIButton]()

Keyboards/KeyboardsBase/ScribeFunctionality/Conjugate.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func returnConjugation(keyPressed: UIButton, requestedTense: String) {
6868
// Don't change proxy if they select a conjugation that's missing.
6969
if keyPressed.titleLabel?.text == invalidCommandMsg {
7070
proxy.insertText("")
71-
} else if conjugateAlternateView == false {
71+
} else if conjugateDimensions == .view3x2 {
7272
if commandState == .selectCaseConjugation {
7373
wordToReturn = keyPressed.titleLabel?.text ?? ""
7474
proxy.insertText(wordToReturn + " ")
@@ -82,7 +82,7 @@ func returnConjugation(keyPressed: UIButton, requestedTense: String) {
8282
} else {
8383
proxy.insertText(verbs?[verbToConjugate]!["pastParticiple"] as! String + " ")
8484
}
85-
} else if conjugateAlternateView == true {
85+
} else if conjugateDimensions == .view2x2 {
8686
if commandState == .selectCaseConjugation {
8787
wordToReturn = keyPressed.titleLabel?.text ?? ""
8888
proxy.insertText(wordToReturn + " ")

0 commit comments

Comments
 (0)