Skip to content

Commit 0200b6f

Browse files
committed
navigator.ts: addition of addCol, addRow, setBtns as interface methods
1 parent 724b237 commit 0200b6f

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

navigator.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
namespace user_interface_base {
22
export interface INavigator {
33
clear: () => void
4-
addButtons: (btns: Button[]) => void
4+
setBtns: (btns: Button[][]) => void
5+
addRow: (btns: Button[]) => void
6+
addCol: (btns: Button[]) => void
57
move: (dir: CursorDir) => Button
68
getCurrent: () => Button
79
screenToButton: (x: number, y: number) => Button
@@ -37,10 +39,24 @@ namespace user_interface_base {
3739
return this.row
3840
}
3941

40-
public addButtons(btns: Button[]) {
42+
public setBtns(btns: Button[][]) {
43+
this.buttonGroups = btns
44+
}
45+
46+
public addRow(btns: Button[]) {
4147
this.buttonGroups.push(btns)
4248
}
4349

50+
/**
51+
* Append a col during runtime.
52+
* Does not need to be the same size as the grid height
53+
* @param btns
54+
*/
55+
public addCol(btns: Button[]) {
56+
for (let i = 0; i < btns.length; i++) {
57+
this.buttonGroups[i].push(btns[i]);
58+
}
59+
}
4460

4561
/**
4662
* Invoke .draw() on each button
@@ -173,7 +189,7 @@ namespace user_interface_base {
173189
}
174190
}
175191

176-
public setGrid(btns: Button[][]) {
192+
public setBtns(btns: Button[][]) {
177193
this.buttonGroups = btns
178194
this.widths = btns.map(row => row.length)
179195
this.height = btns.length
@@ -284,6 +300,11 @@ namespace user_interface_base {
284300
return !!this.deleteButton
285301
}
286302

303+
public setBtns(btns: Button[][]) { }
304+
public addRow(btns: Button[]) { }
305+
public addCol(btns: Button[]) { }
306+
307+
287308
moveToIndex(index: number) {
288309
control.assert(index < this.length, "index out of bounds")
289310
this.row = Math.idiv(index, this.width)

0 commit comments

Comments
 (0)