mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-25 06:13:14 +03:00
GUI: Fix array out of bounds in menu exit (#3604)
* GUI: Fix array out of bounds in menu exit * Gui: fix incorrect empty menu handling * Gui: add missing item check in menu ok handling * Gui: remove dead code from menu module Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
286fd796e7
commit
9bef2aaec6
@ -44,25 +44,19 @@ static void menu_draw_callback(Canvas* canvas, void* _model) {
|
|||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
shift_position = (0 + position + items_count - 1) % items_count;
|
shift_position = (0 + position + items_count - 1) % items_count;
|
||||||
item = MenuItemArray_get(model->items, shift_position);
|
item = MenuItemArray_get(model->items, shift_position);
|
||||||
if(item->icon) {
|
canvas_draw_icon_animation(canvas, 4, 3, item->icon);
|
||||||
canvas_draw_icon_animation(canvas, 4, 3, item->icon);
|
|
||||||
}
|
|
||||||
canvas_draw_str(canvas, 22, 14, item->label);
|
canvas_draw_str(canvas, 22, 14, item->label);
|
||||||
// Second line main
|
// Second line main
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
shift_position = (1 + position + items_count - 1) % items_count;
|
shift_position = (1 + position + items_count - 1) % items_count;
|
||||||
item = MenuItemArray_get(model->items, shift_position);
|
item = MenuItemArray_get(model->items, shift_position);
|
||||||
if(item->icon) {
|
canvas_draw_icon_animation(canvas, 4, 25, item->icon);
|
||||||
canvas_draw_icon_animation(canvas, 4, 25, item->icon);
|
|
||||||
}
|
|
||||||
canvas_draw_str(canvas, 22, 36, item->label);
|
canvas_draw_str(canvas, 22, 36, item->label);
|
||||||
// Third line
|
// Third line
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
shift_position = (2 + position + items_count - 1) % items_count;
|
shift_position = (2 + position + items_count - 1) % items_count;
|
||||||
item = MenuItemArray_get(model->items, shift_position);
|
item = MenuItemArray_get(model->items, shift_position);
|
||||||
if(item->icon) {
|
canvas_draw_icon_animation(canvas, 4, 47, item->icon);
|
||||||
canvas_draw_icon_animation(canvas, 4, 47, item->icon);
|
|
||||||
}
|
|
||||||
canvas_draw_str(canvas, 22, 58, item->label);
|
canvas_draw_str(canvas, 22, 58, item->label);
|
||||||
// Frame and scrollbar
|
// Frame and scrollbar
|
||||||
elements_frame(canvas, 0, 21, 128 - 5, 21);
|
elements_frame(canvas, 0, 21, 128 - 5, 21);
|
||||||
@ -107,8 +101,8 @@ static void menu_enter(void* context) {
|
|||||||
menu->view,
|
menu->view,
|
||||||
MenuModel * model,
|
MenuModel * model,
|
||||||
{
|
{
|
||||||
MenuItem* item = MenuItemArray_get(model->items, model->position);
|
if(MenuItemArray_size(model->items)) {
|
||||||
if(item && item->icon) {
|
MenuItem* item = MenuItemArray_get(model->items, model->position);
|
||||||
icon_animation_start(item->icon);
|
icon_animation_start(item->icon);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -121,8 +115,8 @@ static void menu_exit(void* context) {
|
|||||||
menu->view,
|
menu->view,
|
||||||
MenuModel * model,
|
MenuModel * model,
|
||||||
{
|
{
|
||||||
MenuItem* item = MenuItemArray_get(model->items, model->position);
|
if(MenuItemArray_size(model->items)) {
|
||||||
if(item && item->icon) {
|
MenuItem* item = MenuItemArray_get(model->items, model->position);
|
||||||
icon_animation_stop(item->icon);
|
icon_animation_stop(item->icon);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -230,19 +224,17 @@ static void menu_process_up(Menu* menu) {
|
|||||||
menu->view,
|
menu->view,
|
||||||
MenuModel * model,
|
MenuModel * model,
|
||||||
{
|
{
|
||||||
MenuItem* item = MenuItemArray_get(model->items, model->position);
|
if(MenuItemArray_size(model->items)) {
|
||||||
if(item && item->icon) {
|
MenuItem* item = MenuItemArray_get(model->items, model->position);
|
||||||
icon_animation_stop(item->icon);
|
icon_animation_stop(item->icon);
|
||||||
}
|
|
||||||
|
|
||||||
if(model->position > 0) {
|
if(model->position > 0) {
|
||||||
model->position--;
|
model->position--;
|
||||||
} else {
|
} else {
|
||||||
model->position = MenuItemArray_size(model->items) - 1;
|
model->position = MenuItemArray_size(model->items) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
item = MenuItemArray_get(model->items, model->position);
|
item = MenuItemArray_get(model->items, model->position);
|
||||||
if(item && item->icon) {
|
|
||||||
icon_animation_start(item->icon);
|
icon_animation_start(item->icon);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -254,19 +246,17 @@ static void menu_process_down(Menu* menu) {
|
|||||||
menu->view,
|
menu->view,
|
||||||
MenuModel * model,
|
MenuModel * model,
|
||||||
{
|
{
|
||||||
MenuItem* item = MenuItemArray_get(model->items, model->position);
|
if(MenuItemArray_size(model->items)) {
|
||||||
if(item && item->icon) {
|
MenuItem* item = MenuItemArray_get(model->items, model->position);
|
||||||
icon_animation_stop(item->icon);
|
icon_animation_stop(item->icon);
|
||||||
}
|
|
||||||
|
|
||||||
if(model->position < MenuItemArray_size(model->items) - 1) {
|
if(model->position < MenuItemArray_size(model->items) - 1) {
|
||||||
model->position++;
|
model->position++;
|
||||||
} else {
|
} else {
|
||||||
model->position = 0;
|
model->position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
item = MenuItemArray_get(model->items, model->position);
|
item = MenuItemArray_get(model->items, model->position);
|
||||||
if(item && item->icon) {
|
|
||||||
icon_animation_start(item->icon);
|
icon_animation_start(item->icon);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -279,7 +269,7 @@ static void menu_process_ok(Menu* menu) {
|
|||||||
menu->view,
|
menu->view,
|
||||||
MenuModel * model,
|
MenuModel * model,
|
||||||
{
|
{
|
||||||
if(model->position < MenuItemArray_size(model->items)) {
|
if(MenuItemArray_size(model->items)) {
|
||||||
item = MenuItemArray_get(model->items, model->position);
|
item = MenuItemArray_get(model->items, model->position);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user