11#include "app_config.h"
19#include "os_helpers.h"
23#include "os_io_seph_ux.h"
24#ifdef HAVE_SERIALIZED_NBGL
27#ifdef BUILD_SCREENSHOTS
28#include "json_scenario.h"
35#define NB_MAX_LETTERS 9
37#if defined(TARGET_STAX)
38#define INTER_DASHES 10
39#define SPINNER_DASH_WIDTH 22
40#define SPINNER_DASH_HEIGHT 14
41#define SPINNER_DASH_STROKE 4
42#define PROGRESS_STROKE 3
43#elif defined(TARGET_FLEX)
45#define SPINNER_DASH_WIDTH 24
46#define SPINNER_DASH_HEIGHT 16
47#define SPINNER_DASH_STROKE 4
48#define PROGRESS_STROKE 3
49#elif defined(TARGET_APEX)
51#define SPINNER_DASH_WIDTH 15
52#define SPINNER_DASH_HEIGHT 10
53#define SPINNER_DASH_STROKE 2
54#define PROGRESS_STROKE 2
75 bool computePosition);
105static bool objDrawingDisabled;
108static bool objRefreshAreaDone;
148#ifdef BUILD_SCREENSHOTS
150extern uint16_t last_nb_lines, last_nb_pages;
151extern bool last_bold_state, verbose;
170 "compute_relativePosition() without align to, parent->layout = %d, prevObj = %p\n",
175 obj->rel_x0 = obj->alignmentMarginX;
176 if (prevObj != NULL) {
177 obj->rel_y0 = prevObj->rel_y0 + prevObj->area.height + obj->alignmentMarginY;
180 obj->rel_y0 = obj->alignmentMarginY;
184 if (prevObj != NULL) {
185 obj->rel_x0 = prevObj->rel_x0 + prevObj->area.width + obj->alignmentMarginX;
188 obj->rel_x0 = obj->alignmentMarginX;
190 obj->rel_y0 = obj->alignmentMarginY;
195 if (alignToObj == NULL) {
196 alignToObj = obj->parent;
203 if (alignToObj == obj->parent) {
205 switch (obj->alignment) {
207 obj->rel_x0 = obj->alignmentMarginX;
208 obj->rel_y0 = obj->alignmentMarginY;
212 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
213 obj->rel_y0 = obj->alignmentMarginY;
217 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
218 obj->rel_y0 = obj->alignmentMarginY;
221 obj->rel_x0 = obj->alignmentMarginX;
223 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
227 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
229 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
233 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
235 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
238 obj->rel_x0 = obj->alignmentMarginX;
240 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
244 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
246 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
250 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
252 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
261 switch (obj->alignment) {
263 obj->rel_x0 = alignToObj->rel_x0 + obj->alignmentMarginX;
264 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
267 obj->rel_x0 = alignToObj->rel_x0
268 + (alignToObj->area.width - obj->area.width) / 2
269 + obj->alignmentMarginX;
270 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
273 obj->rel_x0 = alignToObj->rel_x0 + (alignToObj->area.width - obj->area.width)
274 - obj->alignmentMarginX;
275 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
279 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
280 obj->rel_y0 = alignToObj->rel_y0 + obj->alignmentMarginY;
283 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
284 obj->rel_y0 = alignToObj->rel_y0
285 + (alignToObj->area.height - obj->area.height) / 2
286 + obj->alignmentMarginY;
289 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
290 obj->rel_y0 = alignToObj->rel_y0 + (alignToObj->area.height - obj->area.height)
291 + obj->alignmentMarginY;
296 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
297 obj->rel_y0 = alignToObj->rel_y0 + obj->alignmentMarginY;
301 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
302 obj->rel_y0 = alignToObj->rel_y0
303 + (alignToObj->area.height - obj->area.height) / 2
304 + obj->alignmentMarginY;
308 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
309 obj->rel_y0 = alignToObj->rel_y0 + (alignToObj->area.height - obj->area.height)
310 + obj->alignmentMarginY;
314 obj->rel_x0 = alignToObj->rel_x0 + obj->alignmentMarginX;
316 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
319 obj->rel_x0 = alignToObj->rel_x0
320 + (alignToObj->area.width - obj->area.width) / 2
321 + obj->alignmentMarginX;
323 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
326 obj->rel_x0 = alignToObj->rel_x0 + (alignToObj->area.width - obj->area.width)
327 - obj->alignmentMarginX;
329 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
343 compute_relativePosition(obj, prevObj);
345 if (parent == NULL) {
354 obj->area.x0 = parent->obj.area.x0 + obj->rel_x0;
355 obj->area.y0 = parent->obj.area.y0 + obj->rel_y0;
357 if ((obj->area.x0 + obj->area.width) > SCREEN_WIDTH) {
359 "compute_position(), forbidden width, obj->type = %d, x0=%d, width=%d\n",
365 if ((obj->area.y0 + obj->area.height) > SCREEN_HEIGHT) {
367 "compute_position(), forbidden height, obj->type = %d, y0=%d, height=%d\n",
380 UNUSED(computePosition);
382 rectArea.backgroundColor = obj->obj.area.backgroundColor;
383 rectArea.x0 = obj->obj.area.x0;
384 rectArea.y0 = obj->obj.area.y0;
385 rectArea.width = obj->obj.area.width;
386 rectArea.height = obj->obj.area.height;
392 if (computePosition) {
393 compute_position((
nbgl_obj_t *) obj, prevObj);
396 "draw_container(), x0 = %d, y0 = %d, width = %d, height = %d\n",
400 obj->obj.area.height);
402 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
403 if (obj->forceClean) {
419 uint16_t textWidth = 0;
420 const char *text = NULL;
421#define ICON_TEXT_SPACE 12
423 if (computePosition) {
424 compute_position((
nbgl_obj_t *) obj, prevObj);
427 "draw_button(), x0 = %d, y0 = %d, width = %d, height = %d\n",
431 obj->obj.area.height);
434 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
436 if ((obj->innerColor == obj->borderColor)
437 && (obj->innerColor != obj->obj.area.backgroundColor)) {
445 if (obj->onDrawCallback != NULL) {
446 obj->text = obj->onDrawCallback(obj->token);
453 rectArea.x0 = obj->obj.area.x0;
454 rectArea.y0 = obj->obj.area.y0;
457 rectArea.y0 += (obj->obj.area.height - rectArea.height) / 2;
458 rectArea.width = obj->obj.area.width;
459 if (obj->icon != NULL) {
467#ifdef BUILD_SCREENSHOTS
468 store_string_infos(text, obj->fontId, &rectArea,
true, 1, 1,
false);
472 if (textWidth < rectArea.width) {
473 rectArea.x0 += (rectArea.width - textWidth) / 2;
476 rectArea.backgroundColor = obj->innerColor;
477 nbgl_drawText(&rectArea, text, textLen, obj->fontId, obj->foregroundColor);
480 if (obj->icon != NULL) {
481 uint16_t iconX0, iconY0;
485 iconX0 = obj->obj.area.x0
486 + (obj->obj.area.width - (textWidth + obj->icon->width +
ICON_TEXT_SPACE)) / 2;
489 iconX0 = obj->obj.area.x0 + (obj->obj.area.width - obj->icon->width) / 2;
492 "draw_button(), obj->obj.area.height = %d, obj->iconHeight = %d\n",
493 obj->obj.area.height,
495 iconY0 = obj->obj.area.y0 + (obj->obj.area.height - obj->icon->height) / 2;
497 rectArea.backgroundColor = obj->innerColor;
498 rectArea.x0 = iconX0;
499 rectArea.y0 = iconY0;
500 rectArea.width = obj->icon->width;
501 rectArea.height = obj->icon->height;
502 rectArea.bpp = obj->icon->bpp;
519 if (computePosition) {
520 compute_position((
nbgl_obj_t *) obj, prevObj);
522 LOG_DEBUG(
OBJ_LOGGER,
"draw_line(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
524 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
526 "draw_line(), backgroundColor = %d, lineColor = %d\n",
527 obj->obj.area.backgroundColor,
529 rectArea.x0 = obj->obj.area.x0;
530 rectArea.y0 = obj->obj.area.y0;
531 rectArea.backgroundColor = obj->obj.area.backgroundColor;
533 rectArea.width = obj->obj.area.width = obj->thickness;
534 rectArea.height = obj->obj.area.height;
538 rectArea.width = obj->obj.area.width;
539 rectArea.height = obj->obj.area.height = obj->thickness;
552static void draw_button(nbgl_button_t *obj, nbgl_obj_t *prevObj, bool computePosition)
554 uint16_t textWidth = 0;
555 const char *text = NULL;
556#define ICON_TEXT_SPACE 2
558 if (computePosition) {
559 compute_position((
nbgl_obj_t *) obj, prevObj);
562 "draw_button(), x0 = %d, y0 = %d, width = %d, height = %d\n",
566 obj->obj.area.height);
569 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
574 if (obj->onDrawCallback != NULL) {
575 obj->text = obj->onDrawCallback(obj->token);
582 rectArea.x0 = obj->obj.area.x0;
583 rectArea.y0 = obj->obj.area.y0;
586 rectArea.y0 += (obj->obj.area.height - rectArea.height) / 2;
587 rectArea.width = obj->obj.area.width;
588 if (obj->icon != NULL) {
597 if (textWidth < rectArea.width) {
598 rectArea.x0 += (rectArea.width - textWidth) / 2;
601 rectArea.backgroundColor = obj->innerColor;
602 nbgl_drawText(&rectArea, text, textLen, obj->fontId, obj->foregroundColor);
605 if (obj->icon != NULL) {
606 uint16_t iconX0, iconY0;
610 iconX0 = obj->obj.area.x0
611 + (obj->obj.area.width - (textWidth + obj->icon->width +
ICON_TEXT_SPACE)) / 2;
614 iconX0 = obj->obj.area.x0 + (obj->obj.area.width - obj->icon->width) / 2;
617 "draw_button(), obj->obj.area.height = %d, obj->iconHeight = %d\n",
618 obj->obj.area.height,
620 iconY0 = obj->obj.area.y0 + (obj->obj.area.height - obj->icon->height) / 2;
622 rectArea.backgroundColor = obj->innerColor;
623 rectArea.x0 = iconX0;
624 rectArea.y0 = iconY0;
625 rectArea.width = obj->icon->width;
626 rectArea.height = obj->icon->height;
627 rectArea.bpp = obj->icon->bpp;
640 if (obj->buffer == NULL) {
641 if (obj->onDrawCallback != NULL) {
642 iconDetails = obj->onDrawCallback(obj->token);
649 iconDetails = obj->buffer;
651 if (iconDetails == NULL) {
656 obj->obj.area.width = iconDetails->width;
657 obj->obj.area.height = iconDetails->height;
658 obj->obj.area.bpp = iconDetails->bpp;
659 if (computePosition) {
660 compute_position((
nbgl_obj_t *) obj, prevObj);
662 LOG_DEBUG(
OBJ_LOGGER,
"draw_image(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
664 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
666 colorMap = obj->foregroundColor;
672 colorMap = obj->foregroundColor;
684 obj->obj.area.width = SWITCH_ICON.width;
685 obj->obj.area.height = SWITCH_ICON.height;
686 if (computePosition) {
687 compute_position((
nbgl_obj_t *) obj, prevObj);
689 LOG_DEBUG(
OBJ_LOGGER,
"draw_switch(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
692 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
694 rectArea.x0 = obj->obj.area.x0;
695 rectArea.y0 = obj->obj.area.y0;
696 rectArea.width = obj->obj.area.width;
697 rectArea.height = obj->obj.area.height;
698 rectArea.backgroundColor = obj->obj.area.backgroundColor;
701#if NB_COLOR_BITS == 1
708#if NB_COLOR_BITS == 1
723 obj->obj.area.width = RADIO_WIDTH;
724 obj->obj.area.height = RADIO_HEIGHT;
725 if (computePosition) {
726 compute_position((
nbgl_obj_t *) obj, prevObj);
729 "draw_radioButton(), x0 = %d, y0 = %d, state = %d\n",
735 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
738 icon = &RADIO_OFF_ICON;
739#if NB_COLOR_BITS == 1
740 color_map = obj->activeColor;
742 color_map = obj->borderColor;
746 icon = &RADIO_ON_ICON;
747 color_map = obj->activeColor;
749 rectArea.x0 = obj->obj.area.x0;
750 rectArea.y0 = obj->obj.area.y0;
751 rectArea.width = obj->obj.area.width;
752 rectArea.height = obj->obj.area.height;
753 rectArea.backgroundColor = obj->obj.area.backgroundColor;
754 rectArea.bpp = icon->bpp;
770 uint8_t stroke = PROGRESS_STROKE;
772 uint16_t barWidth = ((obj->state * obj->obj.area.width)) / 100;
774 if (computePosition) {
775 compute_position((
nbgl_obj_t *) obj, prevObj);
778 "draw_progressBar(), x0 = %d, y0 = %d, level = %d %%\n",
782 memcpy(&barArea, &obj->obj.area,
sizeof(
nbgl_area_t));
785 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
787 if (obj->partialRedraw ==
false) {
789 if (obj->withBorder) {
793 obj->obj.area.backgroundColor,
794 obj->foregroundColor);
801 obj->previousWidth = 0;
802 if (obj->state == 0) {
807 int barDiffWith = barWidth - obj->previousWidth;
810 if (barDiffWith > 0) {
812 barArea.x0 = obj->obj.area.x0 + obj->previousWidth;
813 barArea.width = barDiffWith;
814 barColor = obj->foregroundColor;
816 else if (barDiffWith < 0) {
818 barArea.x0 = obj->obj.area.x0 + obj->previousWidth + barDiffWith;
819 barArea.width = -barDiffWith;
820 barColor = obj->obj.area.backgroundColor;
823 if (barDiffWith != 0) {
829 if (obj->partialRedraw ==
true) {
830 obj->partialRedraw =
false;
832 obj->previousWidth = barWidth;
835 extendRefreshArea(&barArea);
836 objRefreshAreaDone =
true;
841 if (computePosition) {
842 compute_position((
nbgl_obj_t *) obj, prevObj);
845 "draw_progressBar(), x0 = %d, y0 = %d, level = %d %%\n",
851 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
854 if (obj->withBorder) {
858 obj->obj.area.backgroundColor,
859 obj->foregroundColor);
865 levelWidth =
MIN((obj->obj.area.width - 2) * obj->state / 100, (obj->obj.area.width - 2));
866 if (levelWidth > 0) {
868 rectArea.width = levelWidth;
869 rectArea.height = obj->obj.area.height - 2;
870 rectArea.backgroundColor = obj->foregroundColor;
872 rectArea.x0 = obj->obj.area.x0 + 1;
873 rectArea.y0 = obj->obj.area.y0 + 1;
891 bool computePosition)
897 if (obj->nbPages < 2) {
904 obj->obj.area.height = 4;
906 if (computePosition) {
907 compute_position((
nbgl_obj_t *) obj, prevObj);
910 "draw_pageIndicator(), x0 = %d, y0 = %d, page = %d/%d\n",
917 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
919 dashWidth = (obj->obj.area.width - ((obj->nbPages - 1) * INTER_DASHES)) / obj->nbPages;
920 rectArea.x0 = obj->obj.area.x0;
921 rectArea.y0 = obj->obj.area.y0;
922 rectArea.width = dashWidth;
924 rectArea.backgroundColor = obj->obj.area.backgroundColor;
927 for (i = 0; i < obj->activePage; i++) {
930 rectArea.x0 += dashWidth + INTER_DASHES;
933 rectArea.x0 += dashWidth + INTER_DASHES;
936 for (; i < obj->nbPages; i++) {
938 rectArea.x0 += dashWidth + INTER_DASHES;
944 SPRINTF(navText,
"%d of %d", obj->activePage + 1, obj->nbPages);
950 if (computePosition) {
951 compute_position((
nbgl_obj_t *) obj, prevObj);
954 "draw_pageIndicator(), x0 = %d, y0 = %d, page = %d/%d\n",
961 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
964 rectArea.x0 = obj->obj.area.x0;
965 rectArea.y0 = obj->obj.area.y0;
966 rectArea.width = obj->obj.area.width;
967 rectArea.height = obj->obj.area.height;
968 rectArea.backgroundColor = obj->obj.area.backgroundColor;
986 uint16_t textWidth, fontHeight, lineHeight, textHeight, midHeight;
987 uint8_t line, nbLines;
991 if (computePosition) {
992 compute_position((
nbgl_obj_t *) obj, prevObj);
995 if (obj->onDrawCallback != NULL) {
996 obj->text = obj->onDrawCallback(obj->token);
1005 "draw_textArea(), wrapping = %d, x0 = %d, y0 = %d, width = %d, height = %d, text = %s\n",
1009 obj->obj.area.width,
1010 obj->obj.area.height,
1014 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1017#ifdef SCREEN_SIZE_NANO
1018 if (obj->style == INVERTED_COLORS) {
1019 obj->obj.area.backgroundColor =
WHITE;
1020 rectArea.backgroundColor =
BLACK;
1026 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1027 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1029 rectArea.x0 = obj->obj.area.x0;
1030 rectArea.y0 = obj->obj.area.y0;
1031 rectArea.width = obj->obj.area.width;
1032 rectArea.height = obj->obj.area.height;
1033#ifdef SCREEN_SIZE_NANO
1034 if (obj->style == INVERTED_COLORS) {
1047 if (obj->autoHideLongLine ==
true) {
1048#ifdef BUILD_SCREENSHOTS
1050 store_string_infos(text,
1059 if (textWidth > obj->obj.area.width) {
1060 uint16_t lineWidth, lineLen;
1064 rectArea.x0 = obj->obj.area.x0;
1065 rectArea.y0 = obj->obj.area.y0 + (obj->obj.area.height - fontHeight) / 2;
1066 rectArea.width = dotsWidth;
1070 fontId, text, obj->obj.area.width - dotsWidth, &lineLen, &lineWidth);
1071 rectArea.x0 += dotsWidth;
1072 rectArea.width = lineWidth;
1084#ifdef BUILD_SCREENSHOTS
1086 text, fontId, &obj->obj.area, obj->wrapping, last_nb_lines, last_nb_pages, last_bold_state);
1089 if ((obj->nbMaxLines > 0) && (obj->nbMaxLines < nbLines)) {
1090 nbLines = obj->nbMaxLines;
1093 textHeight = (nbLines - 1) * lineHeight + fontHeight;
1095 midHeight = (obj->obj.area.height - textHeight) / 2;
1096#ifdef SCREEN_SIZE_NANO
1097 if (obj->style == INVERTED_COLORS) {
1102 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1103 rectArea.height = fontHeight;
1105 for (line = 0; line < nbLines; line++) {
1106 uint16_t lineWidth, lineLen;
1109 fontId, text, obj->obj.area.width, &lineLen, &lineWidth, obj->wrapping);
1110 if (obj->textAlignment ==
MID_LEFT) {
1111 rectArea.x0 = obj->obj.area.x0;
1113 else if (obj->textAlignment ==
CENTER) {
1114 rectArea.x0 = obj->obj.area.x0 + (obj->obj.area.width - lineWidth) / 2;
1116 else if (obj->textAlignment ==
MID_RIGHT) {
1117 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - lineWidth;
1122 rectArea.y0 = obj->obj.area.y0 + midHeight + line * lineHeight;
1123 rectArea.width = lineWidth;
1126 "draw_textArea(), [%s] line %d, lineLen %d lineWidth = %d, obj.area.height = %d, "
1127 "textHeight = %d, nbMaxLines = %d, wrapping = %d\n",
1132 obj->obj.area.height,
1136 if ((obj->nbMaxLines == 0) || (line < (obj->nbMaxLines - 1))) {
1137 fontId =
nbgl_drawText(&rectArea, text, lineLen, fontId, obj->textColor);
1144 if ((lineWidth + dotsWidth) >= obj->obj.area.width) {
1147 nbgl_drawText(&rectArea, text, lineLen, obj->fontId, obj->textColor);
1151 rectArea.width = dotsWidth;
1152 nbgl_drawText(&rectArea,
"...", 3, obj->fontId, obj->textColor);
1154 nbgl_drawText(&rectArea, text, lineLen, fontId, obj->textColor);
1160 if (*text ==
'\n') {
1179 if (computePosition) {
1180 compute_position((
nbgl_obj_t *) obj, prevObj);
1183 obj->obj.area.y0 &= ~0x3;
1185 "draw_qrCode(), x0 = %d, y0 = %d, width = %d, height = %d, text = %s\n",
1188 obj->obj.area.width,
1189 obj->obj.area.height,
1193 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1195 rectArea.x0 = obj->obj.area.x0;
1196 rectArea.y0 = obj->obj.area.y0;
1197 rectArea.width = obj->obj.area.width;
1198 rectArea.height = obj->obj.area.height;
1199 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1200 nbgl_drawQrCode(&rectArea, obj->version, obj->text, obj->foregroundColor);
1214#ifndef HAVE_SE_TOUCH
1215 obj->obj.area.width = KEYBOARD_WIDTH;
1216 obj->obj.area.height = KEYBOARD_KEY_HEIGHT;
1219 if (computePosition) {
1220 compute_position((
nbgl_obj_t *) obj, prevObj);
1223 OBJ_LOGGER,
"draw_keyboard(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1226 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1242#ifndef HAVE_SE_TOUCH
1243 obj->obj.area.height = KEYPAD_HEIGHT;
1244 obj->obj.area.width = KEYPAD_WIDTH;
1247 if (computePosition) {
1248 compute_position((
nbgl_obj_t *) obj, prevObj);
1250 obj->obj.area.y0 &= ~0x3;
1251 LOG_DEBUG(
OBJ_LOGGER,
"draw_keypad(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1254 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1273 obj->obj.area.width = SPINNER_WIDTH;
1274 obj->obj.area.height = SPINNER_HEIGHT;
1276 if (computePosition) {
1277 compute_position((
nbgl_obj_t *) obj, prevObj);
1279 LOG_DEBUG(
OBJ_LOGGER,
"draw_spinner(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1282 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1287 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1289 if (obj->position == 0xFF) {
1291 rectArea.x0 = obj->obj.area.x0;
1292 rectArea.y0 = obj->obj.area.y0;
1293 rectArea.width = SPINNER_DASH_WIDTH;
1294 rectArea.height = SPINNER_DASH_STROKE;
1296 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1298 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 3;
1300 rectArea.x0 = obj->obj.area.x0;
1303 rectArea.x0 = obj->obj.area.x0;
1304 rectArea.y0 = obj->obj.area.y0;
1305 rectArea.width = SPINNER_DASH_STROKE;
1306 rectArea.height = SPINNER_DASH_HEIGHT;
1307 rectArea.backgroundColor = foreColor;
1309 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1311 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1313 rectArea.x0 = obj->obj.area.x0;
1318 rectArea.x0 = obj->obj.area.x0;
1319 rectArea.y0 = obj->obj.area.y0;
1320 rectArea.width = obj->obj.area.width;
1321 rectArea.height = obj->obj.area.height;
1322 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1326 rectArea.width = SPINNER_DASH_WIDTH;
1327 rectArea.height = SPINNER_DASH_STROKE;
1328 switch (obj->position) {
1330 rectArea.x0 = obj->obj.area.x0;
1331 rectArea.y0 = obj->obj.area.y0;
1334 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1335 rectArea.y0 = obj->obj.area.y0;
1338 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1339 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 3;
1342 rectArea.x0 = obj->obj.area.x0;
1343 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 3;
1351 rectArea.width = SPINNER_DASH_STROKE;
1352 rectArea.height = SPINNER_DASH_HEIGHT;
1353 rectArea.backgroundColor = foreColor;
1354 switch (obj->position) {
1356 rectArea.x0 = obj->obj.area.x0;
1357 rectArea.y0 = obj->obj.area.y0;
1360 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1361 rectArea.y0 = obj->obj.area.y0;
1364 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1365 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1368 rectArea.x0 = obj->obj.area.x0;
1369 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1390 int textLen = strlen(obj->text);
1393 if (computePosition) {
1394 compute_position((
nbgl_obj_t *) obj, prevObj);
1398 "draw_textEntry(), x0 = %d, y0 = %d, width = %d, height = %d\n",
1401 obj->obj.area.width,
1402 obj->obj.area.height);
1405 obj->obj.area.backgroundColor =
WHITE;
1406 rectArea.backgroundColor =
BLACK;
1407 rectArea.x0 = obj->obj.area.x0;
1408 rectArea.y0 = obj->obj.area.y0;
1409 rectArea.width = obj->obj.area.width;
1410 rectArea.height = obj->obj.area.height;
1414 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1419 offsetX = (obj->obj.area.width - (obj->nbChars * 10)) / 2;
1421 for (
int i = 0; i < obj->nbChars; i++) {
1423 rectArea.x0 = obj->obj.area.x0 + offsetX + (i * 10);
1424 rectArea.y0 = obj->obj.area.y0 - 2;
1426 if (textLen < obj->nbChars) {
1428 digit = obj->text[i];
1440 else if (i < (obj->nbChars - 1)) {
1441 digit = obj->text[textLen - obj->nbChars + 1 + i];
1461 if (obj->buffer == NULL) {
1464 if (computePosition) {
1465 compute_position((
nbgl_obj_t *) obj, prevObj);
1469 OBJ_LOGGER,
"draw_image_file(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1470 obj->obj.area.backgroundColor =
WHITE;
1477 if (computePosition) {
1478 compute_position((
nbgl_obj_t *) obj, prevObj);
1481 if (obj->enableMasking) {
1499 LOG_DEBUG(
OBJ_LOGGER,
"draw_object() obj->type = %d, prevObj = %p\n", obj->type, prevObj);
1500 objRefreshAreaDone =
false;
1501 if ((obj->type <
NB_OBJ_TYPES) && (draw_functions[obj->type] != NULL)) {
1502 if ((obj->type !=
SCREEN) && (obj->parent == NULL)) {
1507 func(obj, prevObj, computePosition);
1514#ifdef HAVE_SERIALIZED_NBGL
1517 if (!objRefreshAreaDone) {
1518 extendRefreshArea(&obj->area);
1536 draw_object(obj, prevObj, computePosition);
1542 OBJ_LOGGER,
"draw_obj_and_chidren(): container->children = %p\n", container->children);
1544 if (container->children != NULL) {
1545 for (i = 0; i < container->nbChildren; i++) {
1546 nbgl_obj_t *current = container->children[i];
1547 if (current != NULL) {
1549 draw_obj_and_chidren(current, prev,
true);
1550 if (current->alignTo == NULL) {
1568 x1 = refreshArea.x0 + refreshArea.width;
1569 y1 = refreshArea.y0 + refreshArea.height;
1572 if (area->x0 < refreshArea.x0) {
1574 refreshArea.x0 =
MAX(0, area->x0);
1577 if (((area->x0 + area->width) > x1) || (refreshArea.width == 0)) {
1579 x1 =
MIN(SCREEN_WIDTH, area->x0 + area->width);
1582 if (area->y0 < refreshArea.y0) {
1584 refreshArea.y0 =
MAX(0, area->y0) & ~(VERTICAL_ALIGNMENT - 1);
1587 if (((area->y0 + area->height) > y1) || (refreshArea.height == 0)) {
1589 y1 =
MIN(SCREEN_HEIGHT, area->y0 + area->height);
1591 y1 = (y1 + (VERTICAL_ALIGNMENT - 1)) & ~(VERTICAL_ALIGNMENT - 1);
1595 if (x1 > SCREEN_WIDTH) {
1597 "extendRefreshArea: Impossible area x0 = %d width %d\n",
1601 if (y1 > SCREEN_HEIGHT) {
1604 "extendRefreshArea: Impossible area y0 = %d height %d\n",
1606 refreshArea.height);
1612 refreshArea.width = x1 - refreshArea.x0;
1613 refreshArea.height = y1 - refreshArea.y0;
1616 if (area->bpp > refreshArea.bpp) {
1617 refreshArea.bpp = area->bpp;
1628 bool computePosition =
false;
1629 bool fromApp =
false;
1634 if (obj->type ==
SCREEN) {
1636 computePosition =
true;
1642 while (parent->parent != NULL) {
1643 parent = parent->parent;
1645 if (parent->type ==
SCREEN) {
1654 if ((os_sched_current_task() == TASK_BOLOS_UX) == fromApp) {
1658 if (objDrawingDisabled && fromApp) {
1661 draw_obj_and_chidren(obj, NULL, computePosition);
1681 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1687 "nbgl_refreshSpecial(), x0,y0 = [%d, %d], w,h = [%d, %d]\n",
1691 refreshArea.height);
1697 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1703 "nbgl_refreshSpecialNoPoff(), x0,y0 = [%d, %d], w,h = [%d, %d]\n",
1707 refreshArea.height);
1717 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1729#ifdef HAVE_SERIALIZED_NBGL
1732 refreshArea.x0 = SCREEN_WIDTH - 1;
1733 refreshArea.width = 0;
1734 refreshArea.y0 = SCREEN_HEIGHT - 1;
1735 refreshArea.height = 0;
1748 objDrawingDisabled =
false;
1761 objDrawingDisabled = !enable;
1783 while (parent->parent != NULL) {
1784 parent = parent->parent;
1786 if (parent->type ==
SCREEN) {
#define LOG_WARN(__logger,...)
#define LOG_DEBUG(__logger,...)
#define LOG_FATAL(__logger,...)
Middle Level API of the new BOLOS Graphical Library.
void nbgl_drawIcon(nbgl_area_t *area, nbgl_transformation_t transformation, nbgl_color_map_t color_map, const nbgl_icon_details_t *icon)
Helper function to render an icon directly from its nbgl_icon_details_t structure.
nbgl_font_id_e nbgl_drawText(const nbgl_area_t *area, const char *text, uint16_t textLen, nbgl_font_id_e fontId, color_t fontColor)
This function draws the given single-line text, with the given parameters.
void nbgl_drawRoundedBorderedRect(const nbgl_area_t *area, nbgl_radius_t radius, uint8_t stroke, color_t innerColor, color_t borderColor)
This functions draws a rounded corners rectangle with a border, with the given parameters.
void nbgl_drawQrCode(const nbgl_area_t *area, nbgl_qrcode_version_t version, const char *text, color_t backgroundColor)
Draws the given text into a V10 QR code (QR code version is fixed using qrcodegen_VERSION_MIN/qrcodeg...
void nbgl_drawRoundedRect(const nbgl_area_t *area, nbgl_radius_t radius, color_t innerColor)
This functions draws a rounded corners rectangle (without border), with the given parameters.
void nbgl_getTextMaxLenAndWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t *len, uint16_t *width, bool wrapping)
compute the max width of the first line of the given text fitting in maxWidth
uint16_t nbgl_getSingleLineTextWidth(nbgl_font_id_e fontId, const char *text)
return the max width in pixels of the given text until the first or \0 is encountered
@ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp
bool nbgl_getTextMaxLenAndWidthFromEnd(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t *len, uint16_t *width)
compute the len and width of the given text fitting in the maxWidth, starting from end of text
uint8_t nbgl_getFontHeight(nbgl_font_id_e fontId)
return the height in pixels of the font with the given font ID
uint16_t nbgl_getTextWidth(nbgl_font_id_e fontId, const char *text)
return the max width in pixels of the given text (can be multiline)
uint16_t nbgl_getTextLength(const char *text)
return the number of bytes of the given text, excluding final ' ' or '\0'
uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
compute the number of lines of the given text fitting in the given maxWidth
uint8_t nbgl_getFontLineHeight(nbgl_font_id_e fontId)
return the height in pixels of the line of font with the given font ID
uint16_t nbgl_getSingleLineTextWidthInLen(nbgl_font_id_e fontId, const char *text, uint16_t maxLen)
return the max width in pixels of the given text until the first or \0 is encountered,...
Font screen low-Level driver API, to draw elementary forms.
void nbgl_frontDrawLine(const nbgl_area_t *area, uint8_t dotStartIdx, color_t lineColor)
void nbgl_frontControlAreaMasking(uint8_t mask_index, nbgl_area_t *masked_area_or_null)
void nbgl_frontDrawImage(const nbgl_area_t *area, const uint8_t *buffer, nbgl_transformation_t transformation, nbgl_color_map_t colorMap)
void nbgl_frontDrawImageFile(const nbgl_area_t *area, const uint8_t *buffer, nbgl_color_map_t colorMap, const uint8_t *uzlib_chunk_buffer)
void nbgl_frontRefreshArea(const nbgl_area_t *area, nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
void nbgl_frontDrawRect(const nbgl_area_t *area)
void nbgl_objDraw(nbgl_obj_t *obj)
This function draws or redraws the given object and its children (recursive version)
void nbgl_refresh(void)
This functions refreshes the actual screen on display with what has changed since the last refresh.
void nbgl_refreshReset(void)
This functions resets all changes since the last refresh.
void nbgl_objAllowDrawing(bool enable)
This functions enables or disables drawing/refresh for all further calls.
void(* draw_function_t)(nbgl_obj_t *obj, nbgl_obj_t *prevObj, bool computePosition)
void nbgl_refreshSpecial(nbgl_refresh_mode_t mode)
This functions refreshes the actual screen on display with what has changed since the last refresh,...
bool nbgl_objIsUx(nbgl_obj_t *obj)
This function returns true if the object belongs to a UxScreen.
void nbgl_refreshSpecialWithPostRefresh(nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
uint8_t * nbgl_objGetRAMBuffer(void)
This function is used to get the all purpose RAM buffer.
uint8_t ramBuffer[GZLIB_UNCOMPRESSED_CHUNK]
bool nbgl_refreshIsNeeded(void)
This functions returns true if there is something to refresh.
void nbgl_objInit(void)
This functions inits all internal of nbgl objects layer.
API to draw all basic graphic objects.
struct PACKED__ nbgl_line_s nbgl_line_t
struct to represent a vertical or horizontal line
struct PACKED__ nbgl_navigation_bar_s nbgl_page_indicator_t
struct to represent a navigation bar (PAGE_INDICATOR type) There can be up to 5 page indicators,...
struct PACKED__ nbgl_radio_s nbgl_radio_t
struct to represent a radio button (RADIO_BUTTON type)
struct PACKED__ nbgl_text_area_s nbgl_text_area_t
struct to represent a text area (TEXT_AREA type)
struct PACKED__ nbgl_progress_bar_s nbgl_progress_bar_t
struct to represent a progress bar (PROGRESS_BAR type)
struct PACKED__ nbgl_keypad_s nbgl_keypad_t
struct to represent a keypad (KEYPAD type)
struct PACKED__ nbgl_mask_control_s nbgl_mask_control_t
struct PACKED__ nbgl_text_entry_s nbgl_text_entry_t
struct to represent a text entry area (TEXT_ENTRY type)
struct PACKED__ nbgl_keyboard_s nbgl_keyboard_t
struct to represent a keyboard (KEYBOARD type)
struct PACKED__ nbgl_image_s nbgl_image_t
struct to represent an image (IMAGE type)
struct PACKED__ nbgl_button_s nbgl_button_t
struct to represent a button (BUTTON type) that can contain a text and/or an icon
void nbgl_objDrawKeyboard(nbgl_keyboard_t *kbd)
This function draws a keyboard object.
#define NB_MAX_PAGES_WITH_DASHES
void nbgl_objDrawKeypad(nbgl_keypad_t *kbd)
This function draws a keypad object.
struct PACKED__ nbgl_container_s nbgl_container_t
struct to represent a container (CONTAINER type)
@ PROGRESSIVE_INDICATOR
all dashes before active page are black
struct PACKED__ nbgl_switch_s nbgl_switch_t
struct to represent a switch (size is fixed) (SWITCH type)
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
struct PACKED__ nbgl_spinner_s nbgl_spinner_t
struct to represent a "spinner", represented by the Ledger corners, in gray, with one of the corners ...
struct PACKED__ nbgl_image_file_s nbgl_image_file_t
struct to represent an image file object (IMAGE_FILE type) The source of the data is an image file wi...
struct PACKED__ nbgl_qrcode_s nbgl_qrcode_t
struct to represent a QR code (QR_CODE type), whose size is fixed
struct PACKED__ nbgl_screen_s nbgl_screen_t
struct to represent a screen (SCREEN type)
void nbgl_touchInit(bool fromUx)
Function to initialize the touch context.
nbgl_post_refresh_t
Post refresh modes.
@ POST_REFRESH_FORCE_POWER_OFF
Force screen power off after refresh.
uint8_t nbgl_color_map_t
Represents the color_map to be used for 2BPP image, or the foreground color for 1BPP image.
@ RADIUS_0_PIXELS
no radius (square angle)
@ VERTICAL
from top to bottom
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
#define GZLIB_UNCOMPRESSED_CHUNK
size of gzlib uncompression buffer in bytes
@ NO_ALIGNMENT
used when parent container layout is used
@ LEFT_TOP
on outside left
@ LEFT_BOTTOM
on outside left
@ RIGHT_TOP
on outside right
@ RIGHT_BOTTOM
on outside right
@ IMAGE
Bitmap (y and height must be multiple of 4 on Stax)
@ IMAGE_FILE
Image file (with Ledger compression)
@ TEXT_ENTRY
area for entered text, only for Nanos
@ SWITCH
Switch to turn on/off something.
@ RADIO_BUTTON
Indicator to inform whether something is on or off.
@ BUTTON
Rounded rectangle button with icon and/or text.
@ PROGRESS_BAR
horizontal bar to indicate progression of something (between 0% and 100%)
@ PAGE_INDICATOR
horizontal bar to indicate position within pages
@ LINE
Vertical or Horizontal line.
@ MASK_CONTROL
OS-specific object to enable/disable masked area.
@ CONTAINER
Empty container.
@ TEXT_AREA
Area to contain text line(s)
#define NO_TRANSFORMATION
@ NBGL_BPP_1
1 bit per pixel
@ NBGL_BPP_2
2 bits per pixel
struct PACKED__ nbgl_area_s nbgl_area_t
Represents a rectangle area of the screen.
nbgl_refresh_mode_t
different modes of refresh for nbgl_refreshSpecial()
@ FULL_COLOR_CLEAN_REFRESH
to be used for lock screen display (cleaner but longer refresh)