Skip to content

Commit f2af426

Browse files
committed
inputMethods.ts: Keyboard now accepts values ending with a decimal; converts to .0
1 parent a930313 commit f2af426

2 files changed

Lines changed: 39 additions & 40 deletions

File tree

inputMethods.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ namespace microgui {
221221
type KeyboardBtnFn = (btn: Button, kb: IKeyboard) => void;
222222
type SpecialBtnData = { btnRow: number, btnCol: number, behaviour: KeyboardBtnFn };
223223
type KeyboardLayoutData = {
224-
btnTexts: (string | Bitmap)[][],
225-
defaultBtnBehaviour: KeyboardBtnFn,
226-
specialBtnBehaviours: SpecialBtnData[]
224+
btnTexts: (string | Bitmap)[][],
225+
defaultBtnBehaviour: KeyboardBtnFn,
226+
specialBtnBehaviours: SpecialBtnData[]
227227
};
228228

229229
const __kbBehaviourNumericDefault: KeyboardBtnFn = (btn: Button, kb: IKeyboard) => { // Default Behaviour: Prevent leading zeroes
@@ -271,13 +271,13 @@ namespace microgui {
271271
kb.appendText(".")
272272
} // END OF: Decimal point
273273

274+
// These are legal: 0. -0. they both just become 0
274275
const __kbBehaviourNumericEnter: KeyboardBtnFn = (btn: Button, kb: IKeyboard) => { // Enter
275276
const txt = kb.getText();
276277
const len = txt.length;
277278
const lenRule = txt[len - 1] != "-";
278-
const noDecimalEnding = txt[len - 1] != "."; // Illegal: 0. , -0. , -10. Okay: -0.00.. and 0.000 (becomes 0 later)
279279

280-
if (len > 0 && lenRule && noDecimalEnding) { // Last rule could be removed, casting "1." to number is valid.
280+
if (len > 0 && lenRule) {
281281
// Turn -0 and -0.000... into 0 before returning
282282
const txtAsNum: number = +txt;
283283
if (txtAsNum == 0 || txtAsNum == -0)
@@ -288,7 +288,7 @@ namespace microgui {
288288
}
289289
} // END OF: ENTER
290290

291-
function __keyboardLayout(layout: KeyboardLayouts, del = false): KeyboardLayoutData {
291+
function __keyboardLayout(layout: KeyboardLayouts, del = false): KeyboardLayoutData {
292292
switch (layout) {
293293
case KeyboardLayouts.QWERTY: {
294294
const ret: KeyboardLayoutData = {
@@ -310,8 +310,8 @@ namespace microgui {
310310
]
311311
}
312312
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() })
313+
ret.btnTexts[4].insertAt(0, btn_delete)
314+
ret.specialBtnBehaviours.push({ btnRow: 4, btnCol: 0, behaviour: (b: Button, kb: IKeyboard) => kb.deleteFn() })
315315
}
316316
return ret
317317
}
@@ -321,11 +321,11 @@ namespace microgui {
321321
* E.g: prevents two decimal places, - only at start, etc
322322
*/
323323
case KeyboardLayouts.NUMERIC_POSITIVE_INTEGER:
324-
case KeyboardLayouts.NUMERIC: {
324+
case KeyboardLayouts.NUMERIC: {
325325
const ret: KeyboardLayoutData = {
326326
btnTexts: [
327327
["1", "2", "3", "<-"],
328-
["4", "5", "6" ],
328+
["4", "5", "6"],
329329
["7", "8", "9", "0", "ENTER"]
330330
],
331331
defaultBtnBehaviour: __kbBehaviourNumericDefault,
@@ -344,7 +344,7 @@ namespace microgui {
344344
}
345345
if (del) {
346346
ret.btnTexts[0].push(btn_delete)
347-
ret.specialBtnBehaviours.push({ btnRow: 0, btnCol: 4, behaviour: (b: Button, kb: IKeyboard) => kb.deleteFn() })
347+
ret.specialBtnBehaviours.push({ btnRow: 0, btnCol: 4, behaviour: (b: Button, kb: IKeyboard) => kb.deleteFn() })
348348
}
349349
return ret
350350
}
@@ -534,7 +534,6 @@ namespace microgui {
534534

535535
const specialBtnData: SpecialBtnData[] = __keyboardLayout(this.keyboardLayout, this.passedDeleteFn !== undefined).specialBtnBehaviours;
536536
const specialBtnRows: number[] = specialBtnData.map((sbd: SpecialBtnData) => sbd.btnRow);
537-
const specialBtnCols: number[] = specialBtnData.map((sbd: SpecialBtnData) => sbd.btnCol);
538537

539538
const isSpecialBtn = (row: number, col: number): boolean => {
540539
return (specialBtnRows.indexOf(row) != -1) && (specialBtnRows.indexOf(col) != -1);

pxt.json

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
{
2-
"name": "MicroGUI",
3-
"version": "0.0.39",
4-
"description": "",
5-
"dependencies": {
6-
"core": "*",
7-
"radio": "*",
8-
"microphone": "*",
9-
"datalogger": "*",
10-
"user-interface-base": "github:microbit-apps/user-interface-base#v0.0.33"
11-
},
12-
"files": [
13-
"app.ts",
14-
"analytics.ts",
15-
"inputMethods.ts",
16-
"graphableFunction.ts",
17-
"guiComponents.ts"
18-
],
19-
"testFiles": [
20-
"test.ts"
21-
],
22-
"targetVersions": {
23-
"target": "7.1.15",
24-
"targetId": "microbit"
25-
},
26-
"supportedTargets": [
27-
"microbit"
28-
],
29-
"preferredEditor": "blocksprj"
2+
"name": "MicroGUI",
3+
"version": "0.0.39",
4+
"description": "",
5+
"dependencies": {
6+
"core": "*",
7+
"radio": "*",
8+
"microphone": "*",
9+
"datalogger": "*",
10+
"user-interface-base": "github:microbit-apps/user-interface-base#v0.0.33"
11+
},
12+
"files": [
13+
"app.ts",
14+
"analytics.ts",
15+
"inputMethods.ts",
16+
"graphableFunction.ts",
17+
"guiComponents.ts"
18+
],
19+
"testFiles": [
20+
"test.ts"
21+
],
22+
"targetVersions": {
23+
"target": "7.1.15",
24+
"targetId": "microbit"
25+
},
26+
"supportedTargets": [
27+
"microbit"
28+
],
29+
"preferredEditor": "blocksprj"
3030
}

0 commit comments

Comments
 (0)