Skip to content

Commit

Permalink
Merge pull request #386 from henrikth93/henrikth93-#379-keyboardviewc…
Browse files Browse the repository at this point in the history
…ontroller

Refactoring keyboardviewcontroller #379
  • Loading branch information
andrewtavis authored Dec 3, 2023
2 parents d2e4c67 + 6b372ee commit 9aec558
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 31 deletions.
21 changes: 21 additions & 0 deletions Keyboards/KeyboardsBase/InterfaceVariables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ var letterKeyWidth = CGFloat(0)
var numSymKeyWidth = CGFloat(0)
var isFirstKeyboardLoad = false

//Constants for scaling key widths and heights
let keyCornerRadiusScalarLandscapeViewPhone = 9.0
let comamndKeyCornerRadiusScalarLandscapeViewPhone = 5.0
let keyCornerRadiusScalarPhone = 6.0
let commandKeyCornerRadiusScalarPhone = 3.0
let keyCornerRadiusScalarLandscapeViewPad = 12.0
let commandKeyCornerRadiusScalarLandscapeViewPad = 7.5
let keyCornerRadiusScalarPad = 9.0
let commandKeyCornerRadiusScalarPad = 5.0
let fontScalarPhone = 0.435
let fontScalarPad = 0.475
let emojiKeyFontScalar = 0.475
let letterNumSymKeyWidthScalar = 0.9
let letterNumSymKeyWidthScalarLandscapeViewPhone = 1.5
let letterNumSymKeyWidthScalarLandscapeViewPad = 1.2
let alternatesBtnYScalarPhone = 0.15
let alternatesBtnYScalarPad = 0.2
let commandKeyHeightScalarPhone = 0.435
let commandKeyHeightScalarPad = 0.475

// Keyboard elements.
var spaceBar = String()
var language = String()
Expand Down Expand Up @@ -195,3 +215,4 @@ var keyPopChar = UILabel()
var keyHoldPopChar = UILabel()
var keyPopLayer = CAShapeLayer()
var keyHoldPopLayer = CAShapeLayer()

64 changes: 33 additions & 31 deletions Keyboards/KeyboardsBase/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,9 @@ class KeyboardViewController: UIInputViewController {
radius: commandKeyCornerRadius
)
if DeviceType.isPhone {
pluralKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.435)
pluralKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * fontScalarPhone)
} else if DeviceType.isPad {
pluralKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.475)
pluralKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * fontScalarPad)
}
activateBtn(btn: pluralKey)

Expand All @@ -735,11 +735,11 @@ class KeyboardViewController: UIInputViewController {
styleBtn(btn: phoneEmojiKey1, title: emojisToDisplayArray[1], radius: commandKeyCornerRadius)

if DeviceType.isPhone {
phoneEmojiKey0.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.435)
phoneEmojiKey1.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.435)
phoneEmojiKey0.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * fontScalarPhone)
phoneEmojiKey1.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * fontScalarPhone)
} else if DeviceType.isPad {
phoneEmojiKey0.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.475)
phoneEmojiKey1.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.475)
phoneEmojiKey0.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * fontScalarPad)
phoneEmojiKey1.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * fontScalarPad)
}

activateBtn(btn: phoneEmojiKey0)
Expand All @@ -754,9 +754,9 @@ class KeyboardViewController: UIInputViewController {
styleBtn(btn: padEmojiKey1, title: emojisToDisplayArray[1], radius: commandKeyCornerRadius)
styleBtn(btn: padEmojiKey2, title: emojisToDisplayArray[2], radius: commandKeyCornerRadius)

padEmojiKey0.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.475)
padEmojiKey1.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.475)
padEmojiKey2.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.475)
padEmojiKey0.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * emojiKeyFontScalar)
padEmojiKey1.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * emojiKeyFontScalar)
padEmojiKey2.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * emojiKeyFontScalar)

activateBtn(btn: padEmojiKey0)
activateBtn(btn: padEmojiKey1)
Expand Down Expand Up @@ -1633,15 +1633,15 @@ class KeyboardViewController: UIInputViewController {
// keyWidth determined per keyboard by the top row.
if isLandscapeView {
if DeviceType.isPhone {
letterKeyWidth = (UIScreen.main.bounds.height - 5) / CGFloat(letterKeys[0].count) * 1.5
numSymKeyWidth = (UIScreen.main.bounds.height - 5) / CGFloat(numberKeys[0].count) * 1.5
letterKeyWidth = (UIScreen.main.bounds.height - 5) / CGFloat(letterKeys[0].count) * letterNumSymKeyWidthScalarLandscapeViewPhone
numSymKeyWidth = (UIScreen.main.bounds.height - 5) / CGFloat(numberKeys[0].count) * letterNumSymKeyWidthScalarLandscapeViewPhone
} else if DeviceType.isPad {
letterKeyWidth = (UIScreen.main.bounds.height - 5) / CGFloat(letterKeys[0].count) * 1.2
numSymKeyWidth = (UIScreen.main.bounds.height - 5) / CGFloat(numberKeys[0].count) * 1.2
letterKeyWidth = (UIScreen.main.bounds.height - 5) / CGFloat(letterKeys[0].count) * letterNumSymKeyWidthScalarLandscapeViewPad
numSymKeyWidth = (UIScreen.main.bounds.height - 5) / CGFloat(numberKeys[0].count) * letterNumSymKeyWidthScalarLandscapeViewPad
}
} else {
letterKeyWidth = (UIScreen.main.bounds.width - 6) / CGFloat(letterKeys[0].count) * 0.9
numSymKeyWidth = (UIScreen.main.bounds.width - 6) / CGFloat(symbolKeys[0].count) * 0.9
letterKeyWidth = (UIScreen.main.bounds.width - 6) / CGFloat(letterKeys[0].count) * letterNumSymKeyWidthScalar
numSymKeyWidth = (UIScreen.main.bounds.width - 6) / CGFloat(symbolKeys[0].count) * letterNumSymKeyWidthScalar
}

// Derive keyboard given current states and set widths.
Expand All @@ -1661,22 +1661,24 @@ class KeyboardViewController: UIInputViewController {
keyWidth = numSymKeyWidth
}



// Derive corner radii.
if DeviceType.isPhone {
if isLandscapeView {
keyCornerRadius = keyWidth / 9
commandKeyCornerRadius = keyWidth / 5
keyCornerRadius = keyWidth / keyCornerRadiusScalarLandscapeViewPhone
commandKeyCornerRadius = keyWidth / comamndKeyCornerRadiusScalarLandscapeViewPhone
} else {
keyCornerRadius = keyWidth / 6
commandKeyCornerRadius = keyWidth / 3
keyCornerRadius = keyWidth / keyCornerRadiusScalarPhone
commandKeyCornerRadius = keyWidth / commandKeyCornerRadiusScalarPhone
}
} else if DeviceType.isPad {
if isLandscapeView {
keyCornerRadius = keyWidth / 12
commandKeyCornerRadius = keyWidth / 7.5
keyCornerRadius = keyWidth / keyCornerRadiusScalarLandscapeViewPad
commandKeyCornerRadius = keyWidth / commandKeyCornerRadiusScalarLandscapeViewPad
} else {
keyCornerRadius = keyWidth / 9
commandKeyCornerRadius = keyWidth / 5
keyCornerRadius = keyWidth / keyCornerRadiusScalarPad
commandKeyCornerRadius = keyWidth / commandKeyCornerRadiusScalarPad
}
}

Expand Down Expand Up @@ -1711,13 +1713,13 @@ class KeyboardViewController: UIInputViewController {
deactivateConjugationDisplay()

if DeviceType.isPhone {
translateKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.435)
conjugateKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.435)
pluralKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.435)
translateKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * commandKeyHeightScalarPhone)
conjugateKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * commandKeyHeightScalarPhone)
pluralKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * commandKeyHeightScalarPhone)
} else if DeviceType.isPad {
translateKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.475)
conjugateKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.475)
pluralKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * 0.475)
translateKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * commandKeyHeightScalarPad)
conjugateKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * commandKeyHeightScalarPad)
pluralKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * commandKeyHeightScalarPad)
}

if commandState == .selectCommand {
Expand Down Expand Up @@ -2818,9 +2820,9 @@ class KeyboardViewController: UIInputViewController {
genAlternatesView(key: key)

alternateBtnStartX = 5.0
var alternatesBtnY = key.frame.height * 0.15
var alternatesBtnY = key.frame.height * alternatesBtnYScalarPhone
if DeviceType.isPad {
alternatesBtnY = key.frame.height * 0.2
alternatesBtnY = key.frame.height * alternatesBtnYScalarPad
}
for char in alternateKeys {
let alternateKey = KeyboardKey(
Expand Down

0 comments on commit 9aec558

Please sign in to comment.