From 9de91a15b9d09794da8150750981871a959ad620 Mon Sep 17 00:00:00 2001 From: Vasyl Demianov Date: Sun, 30 Jun 2024 17:47:50 +0000 Subject: [PATCH] Increase number of possible elements on a page, minor safety checks. --- .vscode/launch.json | 15 +++++++++++++++ src/ui/page_common.h | 2 +- src/ui/ui_main_menu.c | 11 ++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..e2612507 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "HDZGOGGLE emulator", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build_emu/HDZGOGGLE", + "cwd": "${workspaceFolder}" + } + ] +} diff --git a/src/ui/page_common.h b/src/ui/page_common.h index 975a6ef7..c52f7e63 100644 --- a/src/ui/page_common.h +++ b/src/ui/page_common.h @@ -74,7 +74,7 @@ extern "C" { #define RIGHT_BUTTON_IMG "right_button.png" #define ALERT_IMG "alert.png" -#define MAX_PANELS 9 +#define MAX_PANELS 10 #define FLAG_SELECTABLE LV_OBJ_FLAG_USER_1 #define STATE_DISABLED LV_STATE_USER_1 diff --git a/src/ui/ui_main_menu.c b/src/ui/ui_main_menu.c index 2c50c3f3..cc7da7a1 100644 --- a/src/ui/ui_main_menu.c +++ b/src/ui/ui_main_menu.c @@ -1,5 +1,6 @@ #include "ui/ui_main_menu.h" +#include #include #include @@ -100,8 +101,12 @@ void submenu_enter(void) { if (pp->p_arr.max) { // if we have selectable entries, select the first selectable one - for (pp->p_arr.cur = 0; !lv_obj_has_flag(pp->p_arr.panel[pp->p_arr.cur], FLAG_SELECTABLE); ++pp->p_arr.cur); - set_select_item(&pp->p_arr, pp->p_arr.cur); + for (pp->p_arr.cur = 0; pp->p_arr.cur < pp->p_arr.max && !lv_obj_has_flag(pp->p_arr.panel[pp->p_arr.cur], FLAG_SELECTABLE); ++pp->p_arr.cur); + if (pp->p_arr.cur == pp->p_arr.max) { + pp->p_arr.cur = 0; + } else { + set_select_item(&pp->p_arr, pp->p_arr.cur); + } } if (pp->enter) { @@ -264,7 +269,7 @@ void main_menu_show(bool is_show) { static void main_menu_create_entry(lv_obj_t *menu, lv_obj_t *section, page_pack_t *pp) { LOGD("creating main menu entry %s", pp->name); - + assert(pp->p_arr.max <= MAX_PANELS); pp->page = pp->create(menu, &pp->p_arr); lv_obj_t *cont = lv_menu_cont_create(section);