Skip to content

Commit

Permalink
#112 dynamically resize app and keyboard texts and characters
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis committed Jan 31, 2022
1 parent 7a5b87a commit 0796059
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Starting Monday the 24th of January, the entire design of Scribe was reworked to
### 🐞 Bug Fixes

- The keyboard colors should not switch randomly between light and dark mode now.
- Removed an additional character from the Spanish iPad keyboard's special keys.

### ⚖️ Legal

Expand Down
2 changes: 1 addition & 1 deletion Keyboards/KeyboardsBase/InterfaceVariables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public class SpanishKeyboardConstants {
]

static let symbolKeysPad = [
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "*", "delete"],
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "delete"],
["", "£", "¥", "^", "[", "]", "{", "}", "", "", "return"],
["123", "§", "|", "~", "", "\\", "<", ">", "¡", "¿", "123"],
["ABC", "selectKeyboard", "space", "ABC", "hideKeyboard"] // "undoArrow"
Expand Down
83 changes: 53 additions & 30 deletions Keyboards/KeyboardsBase/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ class KeyboardViewController: UIInputViewController {

/// Sets the keyboard layouts given the chosen keyboard and device type.
func setKeyboardLayouts() {
if switchInput {
// Always start in letters with a new keyboard.
keyboardState = .letters
}

if controllerLanguage == "French" {
if switchInput {
setENKeyboardLayout()
Expand Down Expand Up @@ -176,7 +171,7 @@ class KeyboardViewController: UIInputViewController {
/// - The delete key is made slightly larger.
func styleIconBtn(btn: UIButton, color: UIColor, iconName: String) {
btn.setTitle("", for: .normal)
let btnsThatAreSlightlyLarger = ["delete.left", "chevron.left", "chevron.right", "shift", "shift.fill", "capslock.fill"]
var btnsThatAreSlightlyLarger = ["delete.left", "chevron.left", "chevron.right", "shift", "shift.fill", "capslock.fill"]
var selectKeyboardIconConfig = UIImage.SymbolConfiguration(pointSize: letterButtonWidth / 1.75, weight: .light, scale: .medium)
if btnsThatAreSlightlyLarger.contains(iconName) {
selectKeyboardIconConfig = UIImage.SymbolConfiguration(pointSize: letterButtonWidth / 1.55, weight: .light, scale: .medium)
Expand All @@ -188,6 +183,7 @@ class KeyboardViewController: UIInputViewController {
}
}
if DeviceType.isPad {
btnsThatAreSlightlyLarger.append("globe")
if isLandscapeView == true {
selectKeyboardIconConfig = UIImage.SymbolConfiguration(pointSize: letterButtonWidth / 3.75, weight: .light, scale: .medium)
if btnsThatAreSlightlyLarger.contains(iconName) {
Expand Down Expand Up @@ -290,7 +286,11 @@ class KeyboardViewController: UIInputViewController {
previewBar.layer.borderColor = previewBarBorderColor
previewBar.layer.borderWidth = 1.0
previewBar.textAlignment = NSTextAlignment.left
previewBar.font = .systemFont(ofSize: annotationHeight * 0.7)
if DeviceType.isPhone {
previewBar.font = .systemFont(ofSize: annotationHeight * 0.7)
} else if DeviceType.isPad {
previewBar.font = .systemFont(ofSize: annotationHeight * 0.85)
}
previewBarShadow.isUserInteractionEnabled = false

if DeviceType.isPhone {
Expand All @@ -307,8 +307,9 @@ class KeyboardViewController: UIInputViewController {
CommandBackground.isUserInteractionEnabled = false
}

// The button used to display Scribe commands.
// The button used to display Scribe commands and its shadow.
@IBOutlet var scribeBtn: UIButton!
@IBOutlet var scribeBtnShadow: UIButton!

/// Assigns the icon and sets up the Scribe button.
func setScribeBtn() {
Expand All @@ -326,23 +327,27 @@ class KeyboardViewController: UIInputViewController {
}
}
setBtn(btn: scribeBtn, color: commandKeyColor, name: "Scribe", canCapitalize: false, isSpecial: false)
scribeBtnShadow.isUserInteractionEnabled = false
scribeBtn.layer.borderColor = previewBarBorderColor
scribeBtn.layer.borderWidth = 1.0
scribeBtn.contentMode = .center
scribeBtn.imageView?.contentMode = .scaleAspectFit
scribeBtnShadow.isUserInteractionEnabled = false
}

/// Changes the Scribe key to an escape key.
func scribeBtnToEscape() {
scribeBtn.setTitle("", for: .normal)
let selectKeyboardIconConfig = UIImage.SymbolConfiguration(pointSize: annotationHeight * 0.75, weight: .light, scale: .medium)
var selectKeyboardIconConfig = UIImage.SymbolConfiguration(pointSize: annotationHeight * 0.75, weight: .light, scale: .medium)
if DeviceType.isPad {
selectKeyboardIconConfig = UIImage.SymbolConfiguration(pointSize: annotationHeight * 1.1, weight: .light, scale: .medium)
}
scribeBtn.setImage(UIImage(systemName: "xmark", withConfiguration: selectKeyboardIconConfig), for: .normal)
scribeBtn.tintColor = keyCharColor
}

// Shadow elements for the Scribe button and preview bar.
// Shadow elements for preview bar.
@IBOutlet var previewBarShadow: UIButton!
@IBOutlet var previewBarBlend: UILabel!
@IBOutlet var scribeBtnShadow: UIButton!

// Buttons used to trigger Scribe command functionality.
@IBOutlet var translateBtn: UIButton!
Expand Down Expand Up @@ -1012,9 +1017,15 @@ class KeyboardViewController: UIInputViewController {
styleBtn(btn: conjugateBtn, title: conjugateBtnLbl, radius: commandKeyCornerRadius)
styleBtn(btn: pluralBtn, title: pluralBtnLbl, radius: commandKeyCornerRadius)

translateBtn.titleLabel?.font = .systemFont(ofSize: annotationHeight * 0.65)
conjugateBtn.titleLabel?.font = .systemFont(ofSize: annotationHeight * 0.65)
pluralBtn.titleLabel?.font = .systemFont(ofSize: annotationHeight * 0.65)
if DeviceType.isPhone {
translateBtn.titleLabel?.font = .systemFont(ofSize: annotationHeight * 0.65)
conjugateBtn.titleLabel?.font = .systemFont(ofSize: annotationHeight * 0.65)
pluralBtn.titleLabel?.font = .systemFont(ofSize: annotationHeight * 0.65)
} else if DeviceType.isPad {
translateBtn.titleLabel?.font = .systemFont(ofSize: annotationHeight * 0.9)
conjugateBtn.titleLabel?.font = .systemFont(ofSize: annotationHeight * 0.9)
pluralBtn.titleLabel?.font = .systemFont(ofSize: annotationHeight * 0.9)
}

} else {
if previewState == true {
Expand Down Expand Up @@ -1428,9 +1439,17 @@ class KeyboardViewController: UIInputViewController {

if annotation == "PL" {
// Make text smaller to fit the annotation.
elem.font = .systemFont(ofSize: annotationHeight * 0.60)
if DeviceType.isPhone {
elem.font = .systemFont(ofSize: annotationHeight * 0.6)
} else if DeviceType.isPad {
elem.font = .systemFont(ofSize: annotationHeight * 0.8)
}
} else {
elem.font = .systemFont(ofSize: annotationHeight * 0.70)
if DeviceType.isPhone {
elem.font = .systemFont(ofSize: annotationHeight * 0.70)
} else if DeviceType.isPad {
elem.font = .systemFont(ofSize: annotationHeight * 0.95)
}
}

if annotation == "F" {
Expand Down Expand Up @@ -1464,7 +1483,11 @@ class KeyboardViewController: UIInputViewController {
annotationToDisplay = "Инс"
}
}
elem.font = .systemFont(ofSize: annotationHeight * 0.65)
if DeviceType.isPhone {
elem.font = .systemFont(ofSize: annotationHeight * 0.65)
} else if DeviceType.isPad {
elem.font = .systemFont(ofSize: annotationHeight * 0.85)
}
elem.backgroundColor = keyCharColor
}
elem.text = annotationToDisplay
Expand Down Expand Up @@ -1494,7 +1517,11 @@ class KeyboardViewController: UIInputViewController {
nounAnnotationsToDisplay = 0

// Make preview bar font larger for annotation.
previewBar.font = .systemFont(ofSize: annotationHeight * 0.8)
if DeviceType.isPhone {
previewBar.font = .systemFont(ofSize: annotationHeight * 0.8)
} else if DeviceType.isPad {
previewBar.font = .systemFont(ofSize: annotationHeight)
}

let nounForm = nouns?[wordToCheck]?["form"] as? String
if nounForm == "" {
Expand Down Expand Up @@ -1593,7 +1620,11 @@ class KeyboardViewController: UIInputViewController {
if isPreposition {
prepAnnotationState = true
// Make preview bar font larger for annotation.
previewBar.font = .systemFont(ofSize: annotationHeight * 0.8)
if DeviceType.isPhone {
previewBar.font = .systemFont(ofSize: annotationHeight * 0.8)
} else if DeviceType.isPad {
previewBar.font = .systemFont(ofSize: annotationHeight)
}
previewBar.textColor = keyCharColor

// Initialize an array of display elements and count how many will be changed.
Expand Down Expand Up @@ -1737,6 +1768,8 @@ class KeyboardViewController: UIInputViewController {
previewState = true
getTranslation = true
switchInput = true
// Always start in letters with a new keyboard.
keyboardState = .letters
loadKeys()
previewBar.text = translatePromptAndCursor

Expand Down Expand Up @@ -2027,16 +2060,6 @@ class KeyboardViewController: UIInputViewController {
/// - sender: the key that was pressed.
@objc func keyTouchDown(_ sender: UIButton) {
sender.backgroundColor = keyPressedColor

// Scribe key annotation.
let senderKey = sender.layer.value(forKey: "original") as? String
if senderKey == "Scribe" {
sender.alpha = 0.5
// Bring sender's opacity back up to fully opaque
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
sender.alpha = 1.0
}
}
}

/// Defines events that occur given multiple presses of a single key.
Expand Down
5 changes: 4 additions & 1 deletion Scribe/Base.lproj/AppScreen.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@
<rect key="frame" x="18.666666666666657" y="686.33333333333337" width="337.66666666666674" height="55"/>
<color key="backgroundColor" systemColor="systemTealColor"/>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="2QI-f0-YLj" userLabel="SwitchView">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" hasAttributedTitle="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2QI-f0-YLj" userLabel="SwitchView">
<rect key="frame" x="18.666666666666657" y="686.33333333333337" width="337.66666666666674" height="55"/>
<color key="backgroundColor" systemColor="systemYellowColor"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal">
<attributedString key="attributedTitle"/>
</state>
</button>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="privacyDownArrow" translatesAutoresizingMaskIntoConstraints="NO" id="uAP-y9-G5O" userLabel="PrivacyScroll">
<rect key="frame" x="165" y="643.33333333333337" width="45" height="29.666666666666629"/>
Expand Down
27 changes: 22 additions & 5 deletions Scribe/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ class ViewController: UIViewController {
setUI()
}

/// Includes a call to set the UI for the app screen.
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
setUI()
}

/// Includes a call to set the UI for the app screen.
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
setUI()
}

// Lock the device into portrait mode to avoid resizing issues.
var orientations = UIInterfaceOrientationMask.portrait
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
Expand All @@ -104,9 +116,9 @@ class ViewController: UIViewController {
/// Sets the font size for the text in the app screen and corresponding UIImage icons.
func setFontSize() {
if UIDevice.current.userInterfaceIdiom == .phone {
fontSize = UIScreen.main.bounds.width / 30
fontSize = UIScreen.main.bounds.height / 65
} else if UIDevice.current.userInterfaceIdiom == .pad {
fontSize = UIScreen.main.bounds.width / 45
fontSize = UIScreen.main.bounds.height / 60
}
}

Expand Down Expand Up @@ -144,14 +156,14 @@ class ViewController: UIViewController {
let switchViewColor = UIColor(red: 241.0/255.0, green: 204.0/255.0, blue: 131.0/255.0, alpha: 1.0)
/// Sets the functionality of the button that switches between installation instructions and the privacy policy.
func setSwitchViewBtn() {
switchView.titleLabel?.font = .systemFont(ofSize: switchView.frame.height * 0.35)
if displayPrivacyPolicy == false {
switchView.setTitle("View Privacy Policy", for: .normal)
} else if displayPrivacyPolicy == true {
switchView.setTitle("View Installation", for: .normal)
}
switchView.contentHorizontalAlignment = UIControl.ContentHorizontalAlignment.center
switchView.setTitleColor(UIColor.keyCharColorLight, for: .normal)
switchView.titleLabel?.font = .systemFont(ofSize: fontSize * 1.5)

switchView.clipsToBounds = true
switchView.backgroundColor = switchViewColor
Expand Down Expand Up @@ -207,8 +219,13 @@ class ViewController: UIViewController {
var settingsSymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.2, weight: .medium, scale: .medium)
var privacySymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.25, weight: .medium, scale: .medium)
if UIDevice.current.userInterfaceIdiom == .pad {
settingsSymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.15, weight: .medium, scale: .medium)
privacySymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.2, weight: .medium, scale: .medium)
if UIScreen.main.bounds.height < UIScreen.main.bounds.width {
settingsSymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.05, weight: .medium, scale: .medium)
privacySymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.15, weight: .medium, scale: .medium)
} else {
settingsSymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.15, weight: .medium, scale: .medium)
privacySymbolConfig = UIImage.SymbolConfiguration(pointSize: fontSize * 0.2, weight: .medium, scale: .medium)
}
}
let settingsSymbol = UIImage(systemName: "gear", withConfiguration: settingsSymbolConfig)
let privacySymbol = UIImage(systemName: "lock.shield", withConfiguration: privacySymbolConfig)
Expand Down

0 comments on commit 0796059

Please sign in to comment.