Skip to content

Commit

Permalink
Made separate functions for key width and key padding, and adjusted t…
Browse files Browse the repository at this point in the history
…he layout of the expanded keyboard.

Issue scribe-org#362
  • Loading branch information
henrikth93 authored and SaurabhJamadagni committed Apr 18, 2024
1 parent fe57c21 commit e4b9f8e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 18 deletions.
6 changes: 5 additions & 1 deletion Keyboards/KeyboardsBase/InterfaceVariables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var keyWidth = CGFloat(0)
var letterKeyWidth = CGFloat(0)
var numSymKeyWidth = CGFloat(0)
var isFirstKeyboardLoad = false

var disableAccentCharacters = false;
// Constants for scaling key widths and heights.
let scalarAlternatesBtnYPad = 0.2
let scalarAlternatesBtnYPhone = 0.15
Expand All @@ -46,6 +46,10 @@ let scalarFontPhone = 0.435
let scalarLetterNumSymKeyWidth = 0.9
let scalarLetterNumSymKeyWidthLandscapeViewPad = 1.2
let scalarLetterNumSymKeyWidthLandscapeViewPhone = 1.5
var scalarSpecialKeysWidth = disableAccentCharacters ? 2.2 : 1.0
let scalarIndentKeyWidth = 1.7
let scalarShiftKeyWidth = 1.4
var scalarReturnKeyWidth = disableAccentCharacters ? 2.2 : 1.0

// Keyboard elements.
var spaceBar = String()
Expand Down
71 changes: 56 additions & 15 deletions Keyboards/KeyboardsBase/KeyboardKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,28 +253,69 @@ class KeyboardKey: UIButton {

/// Adjusts the width of a key if it's one of the special characters on the iPad keyboard.
func adjustPadKeyWidth() {
if key == "ABC" || key == "АБВ" {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true
} else if ["delete", "#+=", "shift", "selectKeyboard", SpecialKeys.indent, SpecialKeys.capsLock].contains(key) {
if (usingExpandedKeyboard)
{
scalarSpecialKeysWidth = (disableAccentCharacters && keyboardState != .symbols) ? 2.2 : 1.0
scalarReturnKeyWidth = (disableAccentCharacters && keyboardState != .symbols) ? 2.2 : 1.0
if key == "ABC" || key == "АБВ" {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true
} else if ["delete", "#+=", "selectKeyboard", SpecialKeys.capsLock].contains(key) {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * scalarSpecialKeysWidth).isActive = true //*2 scalarSpecialKeysWidth = 1
} else if [SpecialKeys.indent].contains(key) {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * scalarIndentKeyWidth).isActive = true // scalarIndentKeyWidth
} else if ["shift"].contains(key) {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * scalarShiftKeyWidth).isActive = true // scalarShiftKeyWidth
} else if ["return"].contains(key) {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true
} else if ["123", ".?123", "return", "hideKeyboard"].contains(key) {
if key == "return"
&& (controllerLanguage == "Portuguese" || controllerLanguage == "Italian" || commandState == .translate)
&& row == 1
&& DeviceType.isPad
{
widthAnchor.constraint(equalToConstant: numSymKeyWidth * scalarReturnKeyWidth).isActive = true // scalarReturnKeyWidth
}
else if ["123", ".?123", "return", "hideKeyboard"].contains(key) {
if key == "return"
&& (controllerLanguage == "Portuguese" || controllerLanguage == "Italian" || commandState == .translate)
&& row == 1
&& DeviceType.isPad
{
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1.5).isActive = true
} else {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true
}
} else if key != spaceBar && key != languageTextForSpaceBar {
widthAnchor.constraint(equalToConstant: keyWidth).isActive = true
}
}
else
{
if key == "ABC" || key == "АБВ" {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1.5).isActive = true
} else {
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true
} else if ["delete", "#+=", "shift", "selectKeyboard", SpecialKeys.indent, SpecialKeys.capsLock].contains(key) {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true
} else if ["123", ".?123", "return", "hideKeyboard"].contains(key) {
if key == "return"
&& (controllerLanguage == "Portuguese" || controllerLanguage == "Italian" || commandState == .translate)
&& row == 1
&& DeviceType.isPad
{
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1.5).isActive = true
} else {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true
}
} else if key != spaceBar && key != languageTextForSpaceBar {
widthAnchor.constraint(equalToConstant: keyWidth).isActive = true
}
} else if key != spaceBar && key != languageTextForSpaceBar {
widthAnchor.constraint(equalToConstant: keyWidth).isActive = true
}
}



/// Adjusts the width of a key if it's one of the special characters on the keyboard.
func adjustKeyWidth() {
Expand Down
12 changes: 10 additions & 2 deletions Keyboards/KeyboardsBase/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ class KeyboardViewController: UIInputViewController {
numSymKeyWidth = (UIScreen.main.bounds.width - 6) / CGFloat(symbolKeys[0].count) * scalarLetterNumSymKeyWidth
}
}

func setKeyPadding() {
let numRows = keyboard.count
for row in 0 ..< numRows {
Expand Down Expand Up @@ -1855,6 +1855,13 @@ class KeyboardViewController: UIInputViewController {
}
}

if userDefaults.bool(forKey: "svAccentCharacters") {
disableAccentCharacters = true
}
else {
disableAccentCharacters = false
}

// Actions to be done only on initial loads.
if isFirstKeyboardLoad {
shiftButtonState = .shift
Expand Down Expand Up @@ -1927,6 +1934,7 @@ class KeyboardViewController: UIInputViewController {
setCommandBtns()
setConjugationBtns()


// Clear annotation state if a keyboard state change dictates it.
if !annotationState {
annotationBtns.forEach { $0.removeFromSuperview() }
Expand Down Expand Up @@ -2084,7 +2092,7 @@ class KeyboardViewController: UIInputViewController {
}
}
}

setKeyPadding()

} else {
Expand Down

0 comments on commit e4b9f8e

Please sign in to comment.