Skip to content

Commit e1ac590

Browse files
committed
inputMethods.ts: Numeric keyboard support, albeit poor scaling
1 parent 81cef46 commit e1ac590

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

inputMethods.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
namespace microgui {
32
import AppInterface = user_interface_base.AppInterface
43
import Scene = user_interface_base.Scene
@@ -207,8 +206,8 @@ namespace microgui {
207206
["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
208207
["A", "S", "D", "F", "G", "H", "J", "K", "L", ";"],
209208
["Z", "X", "C", "V", "B", "N", "M", ",", ".", "/"],
210-
["<-", "^", " _______ ", "ENTER"]
211-
],
209+
["<-", "^", " _______ ", "ENTER"]
210+
],
212211
defaultBtnBehaviour: (btn: Button, kb: IKeyboard) => {
213212
kb.appendText(btn.state[0])
214213
},
@@ -218,6 +217,25 @@ namespace microgui {
218217
{ btnRow: 4, btnCol: 2, behaviour: (btn: Button, kb: IKeyboard) => kb.appendText(" ") }, // Spacebar
219218
{ btnRow: 4, btnCol: 3, behaviour: (btn: Button, kb: IKeyboard) => kb.nextScene() } // ENTER
220219
]
220+
},
221+
[KeyboardLayouts.NUMERIC]: {
222+
btnTexts: [
223+
["0", "1", "2", "3", "4"],
224+
["5", "6", "7", "8", "9"],
225+
["<-", "+", ".", "ENTER"]
226+
],
227+
defaultBtnBehaviour: (btn: Button, kb: IKeyboard) => {
228+
kb.appendText(btn.state[0])
229+
},
230+
specialBtnBehaviours: [
231+
{ btnRow: 2, btnCol: 0, behaviour: (btn: Button, kb: IKeyboard) => kb.deletePriorCharacters(1) }, // Backspace
232+
{ btnRow: 2, btnCol: 1, behaviour: (btn: Button, kb: IKeyboard) => kb.swapCase() }, // Change case
233+
{ btnRow: 2, btnCol: 2, behaviour: (btn: Button, kb: IKeyboard) => kb.appendText(".") }, // Spacebar
234+
{ btnRow: 2, btnCol: 3, behaviour: (btn: Button, kb: IKeyboard) => {
235+
236+
kb.nextScene()
237+
}} // ENTER
238+
]
221239
}
222240
};
223241

@@ -254,16 +272,18 @@ namespace microgui {
254272
startup(controlSetupFn: () => void) {
255273
super.startup(controlSetupFn)
256274

257-
const data = __keyboardLayout[KeyboardLayouts.QWERTY];
258-
this.btns = data.btnTexts.map(_ => [])
275+
const data = __keyboardLayout[this.keyboardLayout];
276+
this.btns = data.btnTexts.map(_ => []);
259277

260278
for (let row = 0; row < data.btnTexts.length; row++) {
261279
const bitmapWidths = data.btnTexts[row].map((txt: string) => 2 + (bitmaps.font8.charWidth * (txt.length + 1)));
262-
const totalWidth: number = bitmapWidths.reduce((total: number, w: number) => total + w, 0)
280+
const scaledWidths = bitmapWidths.map((w: number) => Screen.WIDTH / w)
281+
// const totalWidth: number = bitmapWidths.reduce((total: number, w: number) => total + w, 0)
263282

264-
let x: number = -Screen.HALF_WIDTH + (bitmapWidths[0] >> 1) + 3;
283+
let x: number = -Screen.HALF_WIDTH + (scaledWidths[0] >> 1) + 3;
265284
for (let col = 0; col < data.btnTexts[row].length; col++) {
266-
const bitmapWidth = bitmapWidths[col]
285+
// const bitmapWidth = bitmapWidths[col]
286+
const bitmapWidth = scaledWidths[col]
267287
x+= bitmapWidth >> 1
268288
this.btns[row][col] =
269289
new Button({
@@ -1003,4 +1023,3 @@ namespace microgui {
10031023
}
10041024
}
10051025
}
1006-

0 commit comments

Comments
 (0)