- Sistema de menus operatiu, falta ficar-los tots

- Afegit .tap del Fernando Martín. Investigar perqué falla.
This commit is contained in:
2024-12-03 22:09:52 +01:00
parent 2ebe1916a4
commit 486bd648d3
10 changed files with 103 additions and 15 deletions

View File

@@ -27,6 +27,7 @@ namespace ui
std::vector<option_t> options;
};
void(*exit_callback)(void) = nullptr;
std::vector<menu_t> menus;
int visible_menu = -1;
int menu_x = 0;
@@ -41,10 +42,11 @@ namespace ui
int mx, my;
Uint32 mb = SDL_GetMouseState(&mx, &my);
mx=mx/CHR_W; my=my/CHR_H;
ui::printrect(0, 0, 59, 1, COLOR_BLACK);
int w;
ui::printrect(0, 0, 320, 1, COLOR_BLACK);
int opt_pos=1;
int index=0;
for (auto menu : menus)
for (auto &menu : menus)
{
const int text_size = (menu.label.size()+2);
uint8_t text_color = COLOR_WHITE;
@@ -62,10 +64,10 @@ namespace ui
if (visible_menu!=-1)
{
opt_pos=2;
menu_t m = menus[visible_menu];
menu_t &m = menus[visible_menu];
ui::printrect(menu_x, 1, 22, m.options.size()+2, COLOR_BLACK);
ui::box(menu_x, 1, 22, m.options.size()+2, COLOR_WHITE);
for (auto option : m.options)
for (auto &option : m.options)
{
if (option.type!=OPTION_TYPE_SEPARATOR)
{
@@ -75,6 +77,12 @@ namespace ui
{
ui::printrect(menu_x+1, opt_pos, 20, 1, COLOR_DARK_BLUE);
text_color = COLOR_WHITE;
if (ui::getClicked())
{
if (option.callback) option.value = option.callback(option.value);
if (exit_callback) exit_callback();
return;
}
}
ui::printtxt(menu_x+1, opt_pos, option.label.c_str(), text_color);
@@ -89,6 +97,11 @@ namespace ui
}
}
void setexitcallback(void(*callback)(void))
{
exit_callback = callback;
}
const int addsubmenu(const char *label)
{
menu_t m;