Skip to content

Commit

Permalink
Fix Progress Bar issue in long-press when releasing
Browse files Browse the repository at this point in the history
  • Loading branch information
nroggeman-ledger committed Sep 19, 2024
1 parent 766b9c1 commit f19d087
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib_nbgl/include/nbgl_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions lib_nbgl/src/nbgl_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
24 changes: 7 additions & 17 deletions lib_nbgl/src/nbgl_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion lib_nbgl/src/nbgl_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f19d087

Please sign in to comment.