Skip to content

Commit 5b5f39f

Browse files
Add progress bar computation multiple of eight
1 parent 08ff25a commit 5b5f39f

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

lib_nbgl/include/nbgl_obj.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ extern "C" {
101101
#define PROGRESSBAR_WIDTH 120
102102
#define PROGRESSBAR_HEIGHT 12
103103
#if defined(TARGET_STAX)
104-
#define PROGRESSBAR_ALIGNMENT_MARGIN_Y 24
104+
#define PROGRESSBAR_ALIGNMENT_MARGIN_Y 28
105105
#elif defined(TARGET_FLEX)
106106
#define PROGRESSBAR_ALIGNMENT_MARGIN_Y 32
107107
#endif // TARGETS

lib_nbgl/src/nbgl_layout.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,7 @@ int nbgl_layoutAddProgressBar(nbgl_layout_t *layout,
21852185
nbgl_container_t *container;
21862186
nbgl_text_area_t *textArea;
21872187
nbgl_progress_bar_t *progress;
2188+
uint16_t height_nearest_multiple_of_8 = 0;
21882189

21892190
LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddProgressBar():\n");
21902191
if (layout == NULL) {
@@ -2194,7 +2195,7 @@ int nbgl_layoutAddProgressBar(nbgl_layout_t *layout,
21942195
// First Create Container :
21952196
container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
21962197
// progressbar + text + subText
2197-
container->nbChildren = 3;
2198+
container->nbChildren = (subText != NULL) ? 3 : 2;
21982199
container->children = nbgl_containerPoolGet(container->nbChildren, layoutInt->layer);
21992200

22002201
container->obj.area.width = AVAILABLE_WIDTH;
@@ -2214,15 +2215,20 @@ int nbgl_layoutAddProgressBar(nbgl_layout_t *layout,
22142215
// set this new progressbar as child of the container
22152216
container->children[0] = (nbgl_obj_t *) progress;
22162217

2218+
// The height of containers must be a multiple of eight :
2219+
height_nearest_multiple_of_8 = PROGRESSBAR_HEIGHT + 4;
2220+
if (height_nearest_multiple_of_8 % 8 != 0) {
2221+
height_nearest_multiple_of_8 += 8 - (height_nearest_multiple_of_8 % 8);
2222+
}
22172223
// update container height
2218-
container->obj.area.height += PROGRESSBAR_HEIGHT;
2224+
container->obj.area.height += (height_nearest_multiple_of_8);
22192225

22202226
// create text area
22212227
textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
22222228
textArea->textColor = BLACK;
22232229
textArea->text = PIC(text);
22242230
textArea->textAlignment = CENTER;
2225-
textArea->fontId = (subText != NULL) ? LARGE_MEDIUM_FONT : SMALL_REGULAR_FONT;
2231+
textArea->fontId = LARGE_MEDIUM_FONT;
22262232
textArea->wrapping = true;
22272233
textArea->obj.alignmentMarginY = BAR_TEXT_MARGIN;
22282234
textArea->obj.alignTo = (nbgl_obj_t *) progress;
@@ -2232,8 +2238,13 @@ int nbgl_layoutAddProgressBar(nbgl_layout_t *layout,
22322238
textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
22332239
textArea->style = NO_STYLE;
22342240

2241+
// The height of containers must be a multiple of eight :
2242+
height_nearest_multiple_of_8 = (textArea->obj.alignmentMarginY + textArea->obj.area.height) + 4;
2243+
if (height_nearest_multiple_of_8 % 8 != 0) {
2244+
height_nearest_multiple_of_8 += 8 - (height_nearest_multiple_of_8 % 8);
2245+
}
22352246
// update container height
2236-
container->obj.area.height += textArea->obj.alignmentMarginY + textArea->obj.area.height;
2247+
container->obj.area.height += (height_nearest_multiple_of_8);
22372248

22382249
// set this text as child of the container
22392250
container->children[1] = (nbgl_obj_t *) textArea;
@@ -2257,9 +2268,14 @@ int nbgl_layoutAddProgressBar(nbgl_layout_t *layout,
22572268
subTextArea->wrapping);
22582269
subTextArea->style = NO_STYLE;
22592270

2271+
// The height of containers must be a multiple of eight :
2272+
height_nearest_multiple_of_8
2273+
= (subTextArea->obj.alignmentMarginY + subTextArea->obj.area.height) + 4;
2274+
if (height_nearest_multiple_of_8 % 8 != 0) {
2275+
height_nearest_multiple_of_8 += 8 - (height_nearest_multiple_of_8 % 8);
2276+
}
22602277
// update container height
2261-
container->obj.area.height
2262-
+= subTextArea->obj.alignmentMarginY + subTextArea->obj.area.height;
2278+
container->obj.area.height += (height_nearest_multiple_of_8);
22632279

22642280
// set thissub-text as child of the container
22652281
container->children[2] = (nbgl_obj_t *) subTextArea;

0 commit comments

Comments
 (0)