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 18, 2024
1 parent 73b6dbb commit 656d3c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 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 @@ -330,7 +330,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 @@ -351,7 +351,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

0 comments on commit 656d3c3

Please sign in to comment.