Skip to content

Commit c684817

Browse files
committed
add delete button to qwerty
1 parent f7fc63f commit c684817

1 file changed

Lines changed: 17 additions & 28 deletions

File tree

inputMethods.ts

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ namespace microgui {
203203
export enum KeyboardLayouts {
204204
QWERTY,
205205
NUMERIC,
206-
NUMERIC_POSITIVE_ONLY,
206+
NUMERIC_POSITIVE_INTEGER,
207207
}
208208

209209
interface IKeyboard {
@@ -261,7 +261,7 @@ namespace microgui {
261261
} // END OF: Minus symbol: Toggle "-" at the start.
262262

263263

264-
const __kbBehaviourNumericDeimcal: KeyboardBtnFn = (btn: Button, kb: IKeyboard) => { // Decimal point
264+
const __kbBehaviourNumericDecimal: KeyboardBtnFn = (btn: Button, kb: IKeyboard) => { // Decimal point
265265
const txt = kb.getText();
266266
const len = txt.length;
267267
const decimalAlreadyPresent = txt.includes(".")
@@ -309,53 +309,42 @@ namespace microgui {
309309
{ btnRow: 4, btnCol: 3, behaviour: (btn: Button, kb: IKeyboard) => kb.nextScene() } // ENTER
310310
]
311311
}
312+
if (del) {
313+
ret.btnTexts[4].insertAt(0,btn_delete)
314+
ret.specialBtnBehaviours.push({ btnRow: 4, btnCol: 0, behaviour: (b: Button, kb: IKeyboard) => kb.deleteFn() })
315+
}
312316
return ret
313317
}
314318

315319
/**
316320
* Ensures that the user inputs result in a valid number.
317321
* E.g: prevents two decimal places, - only at start, etc
318322
*/
323+
case KeyboardLayouts.NUMERIC_POSITIVE_INTEGER:
319324
case KeyboardLayouts.NUMERIC: {
320325
const ret: KeyboardLayoutData = {
321326
btnTexts: [
322327
["1", "2", "3", "<-"],
323-
["4", "5", "6", ".", "-"],
328+
["4", "5", "6" ],
324329
["7", "8", "9", "0", "ENTER"]
325330
],
326331
defaultBtnBehaviour: __kbBehaviourNumericDefault,
327332
specialBtnBehaviours: [
328333
{ btnRow: 0, btnCol: 3, behaviour: (btn: Button, kb: IKeyboard) => kb.deletePriorCharacters(1) }, // Backspace
329-
{ btnRow: 1, btnCol: 4, behaviour: (b: Button, kb: IKeyboard) => __kbBehaviourNumericMinus(b, kb) },
330-
{ btnRow: 1, btnCol: 3, behaviour: (b: Button, kb: IKeyboard) => __kbBehaviourNumericDeimcal(b, kb) },
331334
{ btnRow: 2, btnCol: 4, behaviour: (b: Button, kb: IKeyboard) => __kbBehaviourNumericEnter(b, kb) }
332335
]
333336
}
337+
if (layout == KeyboardLayouts.NUMERIC) {
338+
ret.btnTexts[1].push(".")
339+
ret.btnTexts[1].push("-")
340+
ret.specialBtnBehaviours.push(
341+
{ btnRow: 1, btnCol: 4, behaviour: (b: Button, kb: IKeyboard) => __kbBehaviourNumericMinus(b, kb) })
342+
ret.specialBtnBehaviours.push(
343+
{ btnRow: 1, btnCol: 3, behaviour: (b: Button, kb: IKeyboard) => __kbBehaviourNumericDecimal(b, kb) })
344+
}
334345
if (del) {
335346
ret.btnTexts[0].push(btn_delete)
336-
ret.specialBtnBehaviours.insertAt(1,
337-
{ btnRow: 0, btnCol: 4, behaviour: (b: Button, kb: IKeyboard) => kb.deleteFn() }) // btn_delete
338-
}
339-
return ret
340-
}
341-
342-
/**
343-
* Ensures that the user inputs result in a valid number.
344-
* E.g: prevents two decimal places, - only at start, etc
345-
*/
346-
case KeyboardLayouts.NUMERIC_POSITIVE_ONLY: {
347-
const ret: KeyboardLayoutData = {
348-
btnTexts: [
349-
["1", "2", "3", "<-"],
350-
["4", "5", "6", "."],
351-
["7", "8", "9", "0", "ENTER"]
352-
],
353-
defaultBtnBehaviour: __kbBehaviourNumericDefault,
354-
specialBtnBehaviours: [
355-
{ btnRow: 0, btnCol: 3, behaviour: (b: Button, kb: IKeyboard) => kb.deletePriorCharacters(1) }, // Backspace
356-
{ btnRow: 1, btnCol: 3, behaviour: (b: Button, kb: IKeyboard) => __kbBehaviourNumericDeimcal(b, kb) }, // Decimal point
357-
{ btnRow: 2, btnCol: 4, behaviour: (b: Button, kb: IKeyboard) => __kbBehaviourNumericEnter(b, kb) } // Enter
358-
]
347+
ret.specialBtnBehaviours.push({ btnRow: 0, btnCol: 4, behaviour: (b: Button, kb: IKeyboard) => kb.deleteFn() })
359348
}
360349
return ret
361350
}

0 commit comments

Comments
 (0)