From 088b047b3967cfb4d0466aa7bae1557399308f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sat, 8 Apr 2023 21:02:00 +0200 Subject: [PATCH] some comments --- Core/Src/app_gui.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Core/Src/app_gui.c b/Core/Src/app_gui.c index 2756ec9..5e01d66 100644 --- a/Core/Src/app_gui.c +++ b/Core/Src/app_gui.c @@ -353,8 +353,9 @@ static void screen_menu(GuiEvent event, const char **options, menu_callback_t cb break; case GUI_EVENT_SCREEN_TICK: + // long text sliding animation if (tickNow - menu->change_time >= pdMS_TO_TICKS(500)) { - uint32_t textlen = strlen(options[menu->pos]) * 6; + const uint32_t textlen = strlen(options[menu->pos]) * 6; if (textlen >= FBW - 2) { if (textlen - menu->text_slide > FBW - 2) { menu->text_slide += 1; @@ -373,12 +374,13 @@ static void screen_menu(GuiEvent event, const char **options, menu_callback_t cb case GUI_EVENT_PAINT: for (int i = 0; i < menu->len; i++) { - bool current = menu->pos == i; - fbcolor_t color = !current; - fbpos_t y = 27 + i * 10; + // is the row currently rendered the selected row? + const bool is_selected = menu->pos == i; + const fbcolor_t color = !is_selected; // text color - black if selected, because it's inverted + const fbpos_t y = 27 + i * 10; fb_rect(0, y, FBW, 10, !color); - fb_text(1 - (current ? menu->text_slide : 0), y + 1, options[i], FONT_5X7, color); - // ensure the text doesnt escape the screen + fb_text(1 - (is_selected ? menu->text_slide : 0), y + 1, options[i], FONT_5X7, color); + // ensure the text doesn't touch the edge (looks ugly) fb_vline(FBW - 1, y, 10, !color); fb_vline(0, y, 10, !color); }