Skip to content

Commit 24a4deb

Browse files
Improve progress bar in NBGL
1 parent 5b5f39f commit 24a4deb

File tree

2 files changed

+18
-36
lines changed

2 files changed

+18
-36
lines changed

lib_nbgl/include/nbgl_obj.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,6 @@ extern "C" {
9797
#define SPINNER_HEIGHT 48
9898
#endif // TARGETS
9999

100-
// width & height for progress bar
101-
#define PROGRESSBAR_WIDTH 120
102-
#define PROGRESSBAR_HEIGHT 12
103-
#if defined(TARGET_STAX)
104-
#define PROGRESSBAR_ALIGNMENT_MARGIN_Y 28
105-
#elif defined(TARGET_FLEX)
106-
#define PROGRESSBAR_ALIGNMENT_MARGIN_Y 32
107-
#endif // TARGETS
108-
109100
// width & height for radio button
110101
#if defined(TARGET_STAX)
111102
#define RADIO_WIDTH 32

lib_nbgl/src/nbgl_layout.c

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#define SPINNER_INTER_TEXTS_MARGIN 20
6262
#define BAR_TEXT_MARGIN 24
6363
#define BAR_INTER_TEXTS_MARGIN 16
64+
#define PROGRESSBAR_ALIGNMENT_MARGIN_Y 28
6465
#elif defined(TARGET_FLEX)
6566
#define RADIO_CHOICE_HEIGHT 92
6667
#define FOOTER_HEIGHT 80
@@ -83,10 +84,15 @@
8384
#define SPINNER_INTER_TEXTS_MARGIN 16
8485
#define BAR_TEXT_MARGIN 24
8586
#define BAR_INTER_TEXTS_MARGIN 16
87+
#define PROGRESSBAR_ALIGNMENT_MARGIN_Y 32
8688
#else // TARGETS
8789
#error Undefined target
8890
#endif // TARGETS
8991

92+
// width & height for progress bar
93+
#define PROGRESSBAR_WIDTH 120
94+
#define PROGRESSBAR_HEIGHT 12
95+
9096
// refresh period of the spinner, in ms
9197
#define SPINNER_REFRESH_PERIOD 400
9298

@@ -2185,7 +2191,6 @@ int nbgl_layoutAddProgressBar(nbgl_layout_t *layout,
21852191
nbgl_container_t *container;
21862192
nbgl_text_area_t *textArea;
21872193
nbgl_progress_bar_t *progress;
2188-
uint16_t height_nearest_multiple_of_8 = 0;
21892194

21902195
LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddProgressBar():\n");
21912196
if (layout == NULL) {
@@ -2204,24 +2209,18 @@ int nbgl_layoutAddProgressBar(nbgl_layout_t *layout,
22042209

22052210
// Create progressbar
22062211
progress = (nbgl_progress_bar_t *) nbgl_objPoolGet(PROGRESS_BAR, layoutInt->layer);
2207-
progress->foregroundColor = BLACK;
2208-
progress->withBorder = true;
2209-
progress->state = percentage;
2210-
progress->obj.area.width = PROGRESSBAR_WIDTH;
2211-
progress->obj.area.height = PROGRESSBAR_HEIGHT;
2212-
progress->obj.alignment = TOP_MIDDLE;
2213-
progress->obj.alignmentMarginY = PROGRESSBAR_ALIGNMENT_MARGIN_Y;
2212+
progress->foregroundColor = BLACK;
2213+
progress->withBorder = true;
2214+
progress->state = percentage;
2215+
progress->obj.area.width = PROGRESSBAR_WIDTH;
2216+
progress->obj.area.height = PROGRESSBAR_HEIGHT;
2217+
progress->obj.alignment = TOP_MIDDLE;
22142218

22152219
// set this new progressbar as child of the container
22162220
container->children[0] = (nbgl_obj_t *) progress;
22172221

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-
}
22232222
// update container height
2224-
container->obj.area.height += (height_nearest_multiple_of_8);
2223+
container->obj.area.height = progress->obj.alignmentMarginY + progress->obj.area.height;
22252224

22262225
// create text area
22272226
textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
@@ -2238,13 +2237,8 @@ int nbgl_layoutAddProgressBar(nbgl_layout_t *layout,
22382237
textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
22392238
textArea->style = NO_STYLE;
22402239

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-
}
22462240
// update container height
2247-
container->obj.area.height += (height_nearest_multiple_of_8);
2241+
container->obj.area.height += textArea->obj.alignmentMarginY + textArea->obj.area.height;
22482242

22492243
// set this text as child of the container
22502244
container->children[1] = (nbgl_obj_t *) textArea;
@@ -2268,18 +2262,15 @@ int nbgl_layoutAddProgressBar(nbgl_layout_t *layout,
22682262
subTextArea->wrapping);
22692263
subTextArea->style = NO_STYLE;
22702264

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-
}
22772265
// update container height
2278-
container->obj.area.height += (height_nearest_multiple_of_8);
2266+
container->obj.area.height
2267+
+= subTextArea->obj.alignmentMarginY + subTextArea->obj.area.height;
22792268

22802269
// set thissub-text as child of the container
22812270
container->children[2] = (nbgl_obj_t *) subTextArea;
22822271
}
2272+
// The height of containers must be a multiple of eight
2273+
container->obj.area.height = (container->obj.area.height + 7) & 0xFFF8;
22832274

22842275
layoutAddObject(layoutInt, (nbgl_obj_t *) container);
22852276

0 commit comments

Comments
 (0)