diff --git a/lib_nbgl/include/nbgl_obj.h b/lib_nbgl/include/nbgl_obj.h index fd40786de..75f0c516b 100644 --- a/lib_nbgl/include/nbgl_obj.h +++ b/lib_nbgl/include/nbgl_obj.h @@ -350,7 +350,7 @@ typedef struct PACKED__ nbgl_progress_bar_s { nbgl_obj_t obj; // common part bool withBorder; ///< if set to true, a border in black surround the whole object uint8_t state; ///< state of the progress, in % (from 0 to 100). - uint8_t previousState; ///< previous state of the progress, in % (from 0 to 100). + bool partialRedraw; ///< set to true to redraw only partially the object (update state). uint16_t previousWidth; color_t foregroundColor; ///< color of the inner progress bar and border (if applicable) } nbgl_progress_bar_t; diff --git a/lib_nbgl/src/nbgl_layout.c b/lib_nbgl/src/nbgl_layout.c index c0f9caeeb..179716f86 100644 --- a/lib_nbgl/src/nbgl_layout.c +++ b/lib_nbgl/src/nbgl_layout.c @@ -334,7 +334,7 @@ static void longTouchCallback(nbgl_obj_t *obj, // Update progress bar state if (new_state != progressBar->state) { - progressBar->previousState = progressBar->state; + progressBar->partialRedraw = true; progressBar->state = new_state; nbgl_objDraw((nbgl_obj_t *) progressBar); @@ -355,7 +355,8 @@ static void longTouchCallback(nbgl_obj_t *obj, else if ((eventType == TOUCH_RELEASED) || (eventType == OUT_OF_TOUCH) || (eventType == SWIPED_LEFT) || (eventType == SWIPED_RIGHT)) { nbgl_wait_pipeline(); - progressBar->state = 0; + progressBar->partialRedraw = true; + progressBar->state = 0; nbgl_objDraw((nbgl_obj_t *) progressBar); nbgl_refreshSpecialWithPostRefresh(BLACK_AND_WHITE_REFRESH, POST_REFRESH_FORCE_POWER_OFF); } diff --git a/lib_nbgl/src/nbgl_obj.c b/lib_nbgl/src/nbgl_obj.c index c9973ceae..6a4f445e5 100644 --- a/lib_nbgl/src/nbgl_obj.c +++ b/lib_nbgl/src/nbgl_obj.c @@ -666,8 +666,6 @@ static void draw_progressBar(nbgl_progress_bar_t *obj, nbgl_obj_t *prevObj, bool { #ifdef HAVE_SE_TOUCH -#define UNTRACKED_PREVIOUS_STATE 255 - uint8_t stroke = 3; // 3 pixels for border if (computePosition) { @@ -682,13 +680,7 @@ static void draw_progressBar(nbgl_progress_bar_t *obj, nbgl_obj_t *prevObj, bool // inherit background from parent obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor; - // `obj->previousState` variable allows to control whether if - // - The progress bar is fully redrawn whatever the progress bar state (`obj->previousState == - // 0`). - // - The progress bar is partially drawn from previous draw - // (`obj->previousState > 0 and <= 100`). `obj->previousState` is set by the caller before each - // progress bar redraw. The progress bar state is reset otherwise. - if (obj->previousState == 0) { + if (obj->partialRedraw == false) { // Case of progress bar full draw if (obj->withBorder) { nbgl_drawRoundedBorderedRect((nbgl_area_t *) obj, @@ -701,11 +693,9 @@ static void draw_progressBar(nbgl_progress_bar_t *obj, nbgl_obj_t *prevObj, bool nbgl_drawRoundedRect( (nbgl_area_t *) obj, RADIUS_0_PIXELS, obj->obj.area.backgroundColor); } + // also reset previous width to be sure to clean up everything + obj->previousWidth = 0; } - else if (obj->previousState == UNTRACKED_PREVIOUS_STATE) { - obj->state = 0; - } - // Setup bar draw nbgl_area_t barArea; uint16_t barWidth = ((obj->state * obj->obj.area.width)) / 100; @@ -730,12 +720,12 @@ static void draw_progressBar(nbgl_progress_bar_t *obj, nbgl_obj_t *prevObj, bool nbgl_drawRoundedRect((nbgl_area_t *) &barArea, RADIUS_0_PIXELS, barColor); } - // reset previous state to be sure that in case of full redraw of the screen we redraw the + // reset partialRedraw to be sure that in case of full redraw of the screen we redraw the // full bar - if (obj->previousState) { - obj->previousState = UNTRACKED_PREVIOUS_STATE; - obj->previousWidth = barWidth; + if (obj->partialRedraw == true) { + obj->partialRedraw = false; } + obj->previousWidth = barWidth; extendRefreshArea(&barArea); objRefreshAreaDone = true; diff --git a/lib_nbgl/src/nbgl_screen.c b/lib_nbgl/src/nbgl_screen.c index 4aef1d0a5..ba07911b4 100644 --- a/lib_nbgl/src/nbgl_screen.c +++ b/lib_nbgl/src/nbgl_screen.c @@ -10,6 +10,7 @@ #include "nbgl_front.h" #include "nbgl_screen.h" #include "nbgl_debug.h" +#include "nbgl_touch.h" #include "os_pic.h" #include "os_io.h" #include "os_task.h" @@ -363,7 +364,13 @@ int nbgl_screenPush(nbgl_obj_t ***elements, // update previous topOfStack topOfStack->next = &screenStack[screenIndex]; screenStack[screenIndex].previous = topOfStack; - // new top of stack +#ifdef HAVE_SE_TOUCH + nbgl_touchStatePosition_t touchStatePosition = {.state = RELEASED, .x = 0, .y = 0}; + // make a fake touch release for the current top-of-stack to avoid issue + // (for example in long-touch press) + nbgl_touchHandler(&touchStatePosition, 0); +#endif // HAVE_SE_TOUCH + // new top of stack topOfStack = &screenStack[screenIndex]; topOfStack->next = NULL; break;