|
1 | 1 | namespace user_interface_base { |
2 | 2 | export interface INavigator { |
3 | 3 | clear: () => void |
4 | | - addButtons: (btns: Button[]) => void |
| 4 | + setBtns: (btns: Button[][]) => void |
| 5 | + addRow: (btns: Button[]) => void |
| 6 | + addCol: (btns: Button[]) => void |
5 | 7 | move: (dir: CursorDir) => Button |
6 | 8 | getCurrent: () => Button |
7 | 9 | screenToButton: (x: number, y: number) => Button |
@@ -37,10 +39,24 @@ namespace user_interface_base { |
37 | 39 | return this.row |
38 | 40 | } |
39 | 41 |
|
40 | | - public addButtons(btns: Button[]) { |
| 42 | + public setBtns(btns: Button[][]) { |
| 43 | + this.buttonGroups = btns |
| 44 | + } |
| 45 | + |
| 46 | + public addRow(btns: Button[]) { |
41 | 47 | this.buttonGroups.push(btns) |
42 | 48 | } |
43 | 49 |
|
| 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 | + } |
44 | 60 |
|
45 | 61 | /** |
46 | 62 | * Invoke .draw() on each button |
@@ -173,7 +189,7 @@ namespace user_interface_base { |
173 | 189 | } |
174 | 190 | } |
175 | 191 |
|
176 | | - public setGrid(btns: Button[][]) { |
| 192 | + public setBtns(btns: Button[][]) { |
177 | 193 | this.buttonGroups = btns |
178 | 194 | this.widths = btns.map(row => row.length) |
179 | 195 | this.height = btns.length |
@@ -284,6 +300,11 @@ namespace user_interface_base { |
284 | 300 | return !!this.deleteButton |
285 | 301 | } |
286 | 302 |
|
| 303 | + public setBtns(btns: Button[][]) { } |
| 304 | + public addRow(btns: Button[]) { } |
| 305 | + public addCol(btns: Button[]) { } |
| 306 | + |
| 307 | + |
287 | 308 | moveToIndex(index: number) { |
288 | 309 | control.assert(index < this.length, "index out of bounds") |
289 | 310 | this.row = Math.idiv(index, this.width) |
|
0 commit comments