Added hide delay to context menu

This commit is contained in:
Mateusz Faderewski 2023-08-20 18:07:58 +02:00
parent de97bedc00
commit 5f6b006a1b
2 changed files with 9 additions and 2 deletions

View File

@ -40,6 +40,7 @@ void component_file_list_draw (entry_t *list, int entries, int selected);
typedef struct {
int count;
int selected;
bool hide_pending;
struct {
const char *text;
void (*action) (menu_t *menu);

View File

@ -6,6 +6,7 @@
void component_context_menu_init (component_context_menu_t *cm) {
cm->selected = -1;
cm->count = 0;
cm->hide_pending = false;
for (int i = 0; (cm->list[i].text) != NULL; i++) {
cm->count += 1;
}
@ -21,11 +22,11 @@ bool component_context_menu_process (menu_t *menu, component_context_menu_t *cm)
}
if (menu->actions.back) {
cm->selected = -1;
cm->hide_pending = true;
} else if (menu->actions.enter) {
if (cm->list[cm->selected].action) {
cm->list[cm->selected].action(menu);
cm->selected = -1;
cm->hide_pending = true;
}
} else if (menu->actions.go_up) {
cm->selected -= 1;
@ -89,4 +90,9 @@ void component_context_menu_draw (component_context_menu_t *cm) {
rdpq_paragraph_render(layout, VISIBLE_AREA_X0, VISIBLE_AREA_Y0);
rdpq_paragraph_free(layout);
if (cm->hide_pending) {
cm->hide_pending = false;
cm->selected = -1;
}
}