Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring keyboardviewcontroller #379 #386

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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