[Menu] Add captions and seperators

Additionally, skip selection of them to retain flow and maintain auto scroll.
This commit is contained in:
Kostas Missos
2018-05-25 00:33:11 +03:00
committed by nwert
parent 03729bddd5
commit 997e250c43
3 changed files with 64 additions and 13 deletions

View File

@@ -41,6 +41,7 @@ void tui_pbar(gfx_con_t *con, int x, int y, u32 val)
void *tui_do_menu(gfx_con_t *con, menu_t *menu)
{
int idx = 0, cnt;
int prev_idx = 0;
gfx_clear(con->gfx_ctxt, 0xFF1B1B1B);
@@ -50,6 +51,31 @@ void *tui_do_menu(gfx_con_t *con, menu_t *menu)
gfx_con_setpos(con, menu->x, menu->y);
gfx_printf(con, "[%s]\n\n", menu->caption);
// Skip caption or seperator lines selection
while (menu->ents[idx].type == MENT_CAPTION ||
menu->ents[idx].type == MENT_CHGLINE)
{
if (prev_idx <= idx || (!idx && prev_idx == cnt - 1))
{
idx++;
if (idx > (cnt - 1))
{
idx = 0;
prev_idx = 0;
}
}
else
{
idx--;
if (idx < 0)
{
idx = cnt - 1;
prev_idx = cnt;
}
}
}
prev_idx = idx;
// Draw the menu
for (cnt = 0; menu->ents[cnt].type != MENT_END; cnt++)
{
@@ -57,11 +83,13 @@ void *tui_do_menu(gfx_con_t *con, menu_t *menu)
gfx_con_setcol(con, 0xFF1B1B1B, 1, 0xFFCCCCCC);
else
gfx_con_setcol(con, 0xFFCCCCCC, 1, 0xFF1B1B1B);
con->x += 8;
gfx_printf(con, "%s", menu->ents[cnt].caption);
if (cnt != idx && menu->ents[cnt].type == MENT_CAPTION)
gfx_printf(con, "%k %s", menu->ents[cnt].color, menu->ents[cnt].caption);
else
gfx_printf(con, " %s", menu->ents[cnt].caption);
if(menu->ents[cnt].type == MENT_MENU)
gfx_printf(con, "%k...", 0xFFEE9900);
gfx_putc(con, '\n');
gfx_printf(con, " \n");
}
gfx_con_setcol(con, 0xFFCCCCCC, 1, 0xFF1B1B1B);
gfx_putc(con, '\n');
@@ -93,6 +121,8 @@ void *tui_do_menu(gfx_con_t *con, menu_t *menu)
case MENT_BACK:
return NULL;
break;
default:
break;
}
gfx_clear(con->gfx_ctxt, 0xFF1B1B1B);
}