Keys. Did barely anything this evening.
This commit is contained in:
parent
c754be2c9d
commit
021ea4bba9
24
src/main.cpp
24
src/main.cpp
@ -1,5 +1,6 @@
|
||||
#include <ti/screen.h>
|
||||
#include <ti/getcsc.h>
|
||||
#include <ti/getkey.h>
|
||||
#include <stdlib.h>
|
||||
#include "main.h"
|
||||
|
||||
@ -40,6 +41,7 @@ int main(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char* list_symbols = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
int display_list(const list_item* list, const list_config& config)
|
||||
{
|
||||
size_t item_count = 0;
|
||||
@ -52,12 +54,32 @@ int display_list(const list_item* list, const list_config& config)
|
||||
if (item_count == 0) return -1; // No list to display.
|
||||
|
||||
uint8_t max_on_screen = MIN(config.end_row - config.start_row, 10 - config.start_row) + 1;
|
||||
uint24_t offset = 0;
|
||||
|
||||
uint24_t index = 0,
|
||||
offset = 0;
|
||||
|
||||
_render:
|
||||
for (size_t i = 0, j = offset; i < max_on_screen && j < item_count; i++, j++)
|
||||
{
|
||||
// TODO: print prefix
|
||||
os_SetCursorPos(config.start_row + i, 0);
|
||||
os_PutStrLine(list[j].display_name);
|
||||
}
|
||||
|
||||
uint16_t key = os_GetKey();
|
||||
switch (key)
|
||||
{
|
||||
case k_Up:
|
||||
if (index > 0) index--;
|
||||
if (index <= offset) offset = index;
|
||||
break;
|
||||
|
||||
case k_Down:
|
||||
if (index < item_count) index++;
|
||||
if (index >= offset) offset = index;
|
||||
break;
|
||||
}
|
||||
goto _render;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user