Skip to content

Commit

Permalink
Merge pull request #389 from henrikth93/henrikth93-#362-v6
Browse files Browse the repository at this point in the history
Made separate functions for key width and key padding, and adjusted t…
  • Loading branch information
andrewtavis committed Jan 13, 2024
2 parents a55f2d5 + d26d9d0 commit f8d3fd2
Show file tree
Hide file tree
Showing 3 changed files with 339 additions and 271 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
Loading

0 comments on commit f8d3fd2

Please sign in to comment.