11 #include "app_config.h"
19 #include "os_helpers.h"
22 #ifdef HAVE_SERIALIZED_NBGL
24 #include "os_io_seproxyhal.h"
26 #ifdef BUILD_SCREENSHOTS
27 #include "json_scenario.h"
34 #define NB_MAX_LETTERS 9
54 bool computePosition);
84 static bool objDrawingDisabled;
87 static bool objRefreshAreaDone;
114 #ifndef HAVE_SE_TOUCH
127 #ifdef BUILD_SCREENSHOTS
132 extern uint16_t last_nb_lines, last_nb_pages;
133 extern bool last_bold_state, verbose;
153 "compute_relativePosition() without align to, parent->layout = %d, prevObj = %p\n",
158 obj->rel_x0 = obj->alignmentMarginX;
159 if (prevObj != NULL) {
160 obj->rel_y0 = prevObj->rel_y0 + prevObj->area.height + obj->alignmentMarginY;
163 obj->rel_y0 = obj->alignmentMarginY;
167 if (prevObj != NULL) {
168 obj->rel_x0 = prevObj->rel_x0 + prevObj->area.width + obj->alignmentMarginX;
171 obj->rel_x0 = obj->alignmentMarginX;
173 obj->rel_y0 = obj->alignmentMarginY;
178 if (alignToObj == NULL) {
179 alignToObj = obj->parent;
186 if (alignToObj == obj->parent) {
188 switch (obj->alignment) {
190 obj->rel_x0 = obj->alignmentMarginX;
191 obj->rel_y0 = obj->alignmentMarginY;
195 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
196 obj->rel_y0 = obj->alignmentMarginY;
200 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
201 obj->rel_y0 = obj->alignmentMarginY;
204 obj->rel_x0 = obj->alignmentMarginX;
206 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
210 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
212 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
216 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
218 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
221 obj->rel_x0 = obj->alignmentMarginX;
223 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
227 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
229 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
233 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
235 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
244 switch (obj->alignment) {
246 obj->rel_x0 = alignToObj->rel_x0 + obj->alignmentMarginX;
247 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
250 obj->rel_x0 = alignToObj->rel_x0
251 + (alignToObj->area.width - obj->area.width) / 2
252 + obj->alignmentMarginX;
253 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
256 obj->rel_x0 = alignToObj->rel_x0 + (alignToObj->area.width - obj->area.width)
257 - obj->alignmentMarginX;
258 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
262 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
263 obj->rel_y0 = alignToObj->rel_y0 + obj->alignmentMarginY;
266 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
267 obj->rel_y0 = alignToObj->rel_y0
268 + (alignToObj->area.height - obj->area.height) / 2
269 + obj->alignmentMarginY;
272 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
273 obj->rel_y0 = alignToObj->rel_y0 + (alignToObj->area.height - obj->area.height)
274 + obj->alignmentMarginY;
279 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
280 obj->rel_y0 = alignToObj->rel_y0 + obj->alignmentMarginY;
284 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
285 obj->rel_y0 = alignToObj->rel_y0
286 + (alignToObj->area.height - obj->area.height) / 2
287 + obj->alignmentMarginY;
291 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
292 obj->rel_y0 = alignToObj->rel_y0 + (alignToObj->area.height - obj->area.height)
293 + obj->alignmentMarginY;
297 obj->rel_x0 = alignToObj->rel_x0 + obj->alignmentMarginX;
299 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
302 obj->rel_x0 = alignToObj->rel_x0
303 + (alignToObj->area.width - obj->area.width) / 2
304 + obj->alignmentMarginX;
306 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
309 obj->rel_x0 = alignToObj->rel_x0 + (alignToObj->area.width - obj->area.width)
310 - obj->alignmentMarginX;
312 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
326 compute_relativePosition(obj, prevObj);
328 if (parent == NULL) {
337 obj->area.x0 = parent->obj.area.x0 + obj->rel_x0;
338 obj->area.y0 = parent->obj.area.y0 + obj->rel_y0;
342 "compute_position(), forbidden width, obj->type = %d, x0=%d, width=%d\n",
350 "compute_position(), forbidden height, obj->type = %d, y0=%d, height=%d\n",
363 UNUSED(computePosition);
365 rectArea.backgroundColor = obj->obj.area.backgroundColor;
366 rectArea.x0 = obj->obj.area.x0;
367 rectArea.y0 = obj->obj.area.y0;
368 rectArea.width = obj->obj.area.width;
369 rectArea.height = obj->obj.area.height;
375 if (computePosition) {
376 compute_position((
nbgl_obj_t *) obj, prevObj);
379 "draw_container(), x0 = %d, y0 = %d, width = %d, height = %d\n",
383 obj->obj.area.height);
385 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
386 if (obj->forceClean) {
403 const char *text = NULL;
404 #define ICON_TEXT_SPACE 12
406 if (computePosition) {
407 compute_position((
nbgl_obj_t *) obj, prevObj);
410 "draw_button(), x0 = %d, y0 = %d, width = %d, height = %d\n",
414 obj->obj.area.height);
417 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
419 if ((obj->innerColor == obj->borderColor)
420 && (obj->innerColor != obj->obj.area.backgroundColor)) {
425 (
nbgl_area_t *) obj, obj->radius, 2, obj->innerColor, obj->borderColor);
428 if (obj->onDrawCallback != NULL) {
429 obj->text = obj->onDrawCallback(obj->token);
436 rectArea.x0 = obj->obj.area.x0;
437 rectArea.y0 = obj->obj.area.y0;
440 rectArea.y0 += (obj->obj.area.height - rectArea.height) / 2;
441 rectArea.width = obj->obj.area.width;
442 if (obj->icon != NULL) {
450 #ifdef BUILD_SCREENSHOTS
451 store_string_infos(text, obj->fontId, &rectArea,
true, 1, 1,
false);
455 if (textWidth < rectArea.width) {
456 rectArea.x0 += (rectArea.width - textWidth) / 2;
459 rectArea.backgroundColor = obj->innerColor;
460 nbgl_drawText(&rectArea, text, textLen, obj->fontId, obj->foregroundColor);
463 if (obj->icon != NULL) {
468 iconX0 = obj->obj.area.x0
469 + (obj->obj.area.width - (textWidth + obj->icon->width +
ICON_TEXT_SPACE)) / 2;
472 iconX0 = obj->obj.area.x0 + (obj->obj.area.width - obj->icon->width) / 2;
475 "draw_button(), obj->obj.area.height = %d, obj->iconHeight = %d\n",
476 obj->obj.area.height,
478 iconY0 = obj->obj.area.y0 + (obj->obj.area.height - obj->icon->height) / 2;
480 rectArea.backgroundColor = obj->innerColor;
481 rectArea.x0 = iconX0;
482 rectArea.y0 = iconY0;
483 rectArea.width = obj->icon->width;
484 rectArea.height = obj->icon->height;
485 rectArea.bpp = obj->icon->bpp;
502 if (computePosition) {
503 compute_position((
nbgl_obj_t *) obj, prevObj);
505 LOG_DEBUG(
OBJ_LOGGER,
"draw_line(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
507 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
509 "draw_line(), backgroundColor = %d, lineColor = %d\n",
510 obj->obj.area.backgroundColor,
512 rectArea.x0 = obj->obj.area.x0;
513 rectArea.y0 = obj->obj.area.y0;
515 rectArea.width = obj->obj.area.width = obj->thickness;
516 rectArea.backgroundColor = obj->lineColor;
517 rectArea.height = obj->obj.area.height;
522 if (obj->thickness == 1) {
523 mask = 0x1 << (obj->offset & 0x3);
525 else if (obj->thickness == 2) {
526 mask = 0x3 << ((obj->offset < 3) ? obj->offset : 2);
528 else if (obj->thickness == 3) {
529 mask = 0x7 << (obj->offset & 0x1);
531 else if (obj->thickness == 4) {
538 rectArea.width = obj->obj.area.width;
539 rectArea.height = obj->obj.area.height = 4;
540 rectArea.backgroundColor = obj->obj.area.backgroundColor;
552 if (obj->buffer == NULL) {
553 if (obj->onDrawCallback != NULL) {
554 iconDetails = obj->onDrawCallback(obj->token);
561 iconDetails = obj->buffer;
563 if (iconDetails == NULL) {
568 obj->obj.area.width = iconDetails->width;
569 obj->obj.area.height = iconDetails->height;
570 obj->obj.area.bpp = iconDetails->bpp;
571 if (computePosition) {
572 compute_position((
nbgl_obj_t *) obj, prevObj);
574 LOG_DEBUG(
OBJ_LOGGER,
"draw_image(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
576 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
578 colorMap = obj->foregroundColor;
584 colorMap = obj->foregroundColor;
596 obj->obj.area.width = C_switch_60_40.width;
597 obj->obj.area.height = C_switch_60_40.height;
598 if (computePosition) {
599 compute_position((
nbgl_obj_t *) obj, prevObj);
601 LOG_DEBUG(
OBJ_LOGGER,
"draw_switch(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
604 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
606 rectArea.x0 = obj->obj.area.x0;
607 rectArea.y0 = obj->obj.area.y0;
608 rectArea.width = obj->obj.area.width;
609 rectArea.height = obj->obj.area.height;
610 rectArea.backgroundColor = obj->obj.area.backgroundColor;
629 if (computePosition) {
630 compute_position((
nbgl_obj_t *) obj, prevObj);
633 "draw_radioButton(), x0 = %d, y0 = %d, state = %d\n",
639 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
643 color_map = obj->borderColor;
647 color_map = obj->activeColor;
649 rectArea.x0 = obj->obj.area.x0;
650 rectArea.y0 = obj->obj.area.y0;
651 rectArea.width = obj->obj.area.width;
652 rectArea.height = obj->obj.area.height;
653 rectArea.backgroundColor = obj->obj.area.backgroundColor;
654 rectArea.bpp = icon->bpp;
672 if (computePosition) {
673 compute_position((
nbgl_obj_t *) obj, prevObj);
676 "draw_progressBar(), x0 = %d, y0 = %d, level = %d %%\n",
682 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
684 if (obj->partialRedraw ==
false) {
686 if (obj->withBorder) {
690 obj->obj.area.backgroundColor,
691 obj->foregroundColor);
698 obj->previousWidth = 0;
702 uint16_t barWidth = ((obj->state * obj->obj.area.width)) / 100;
703 int barDiffWith = barWidth - obj->previousWidth;
705 memcpy(&barArea, &obj->obj.area,
sizeof(
nbgl_area_t));
707 if (barDiffWith >= 0) {
709 barArea.x0 = obj->obj.area.x0 + obj->previousWidth;
710 barArea.width = barDiffWith;
711 barColor = obj->foregroundColor;
715 barArea.x0 = obj->obj.area.x0 + obj->previousWidth + barDiffWith;
716 barArea.width = -barDiffWith;
717 barColor = obj->obj.area.backgroundColor;
720 if (barDiffWith != 0) {
726 if (obj->partialRedraw ==
true) {
727 obj->partialRedraw =
false;
729 obj->previousWidth = barWidth;
731 extendRefreshArea(&barArea);
732 objRefreshAreaDone =
true;
737 if (computePosition) {
738 compute_position((
nbgl_obj_t *) obj, prevObj);
741 "draw_progressBar(), x0 = %d, y0 = %d, level = %d %%\n",
747 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
750 if (obj->withBorder) {
754 obj->obj.area.backgroundColor,
755 obj->foregroundColor);
761 levelWidth =
MIN((obj->obj.area.width - 2) * obj->state / 100, (obj->obj.area.width - 2));
762 if (levelWidth > 0) {
764 rectArea.width = levelWidth;
765 rectArea.height = obj->obj.area.height - 2;
766 rectArea.backgroundColor = obj->foregroundColor;
768 rectArea.x0 = obj->obj.area.x0 + 1;
769 rectArea.y0 = obj->obj.area.y0 + 1;
787 bool computePosition)
793 if (obj->nbPages < 2) {
800 #define INTER_DASHES 10
802 #define INTER_DASHES 8
805 obj->obj.area.height = 4;
807 if (computePosition) {
808 compute_position((
nbgl_obj_t *) obj, prevObj);
811 "draw_pageIndicator(), x0 = %d, y0 = %d, page = %d/%d\n",
818 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
820 dashWidth = (obj->obj.area.width - ((obj->nbPages - 1) *
INTER_DASHES)) / obj->nbPages;
821 rectArea.x0 = obj->obj.area.x0;
822 rectArea.y0 = obj->obj.area.y0;
823 rectArea.width = dashWidth;
824 rectArea.height = obj->obj.area.height;
825 rectArea.backgroundColor = obj->obj.area.backgroundColor;
828 for (i = 0; i < obj->activePage; i++) {
837 for (; i < obj->nbPages; i++) {
845 SPRINTF(navText,
"%d of %d", obj->activePage + 1, obj->nbPages);
851 if (computePosition) {
852 compute_position((
nbgl_obj_t *) obj, prevObj);
855 "draw_pageIndicator(), x0 = %d, y0 = %d, page = %d/%d\n",
862 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
865 rectArea.x0 = obj->obj.area.x0;
866 rectArea.y0 = obj->obj.area.y0;
867 rectArea.width = obj->obj.area.width;
868 rectArea.height = obj->obj.area.height;
869 rectArea.backgroundColor = obj->obj.area.backgroundColor;
887 uint16_t textWidth, fontHeight, lineHeight, textHeight, midHeight;
892 if (computePosition) {
893 compute_position((
nbgl_obj_t *) obj, prevObj);
896 if (obj->onDrawCallback != NULL) {
897 obj->text = obj->onDrawCallback(obj->token);
906 "draw_textArea(), wrapping = %d, x0 = %d, y0 = %d, width = %d, height = %d, text = %s\n",
911 obj->obj.area.height,
915 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
918 #ifdef SCREEN_SIZE_NANO
919 if (obj->style == INVERTED_COLORS) {
920 obj->obj.area.backgroundColor =
WHITE;
921 rectArea.backgroundColor =
BLACK;
927 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
928 rectArea.backgroundColor = obj->obj.area.backgroundColor;
930 rectArea.x0 = obj->obj.area.x0;
931 rectArea.y0 = obj->obj.area.y0;
932 rectArea.width = obj->obj.area.width;
933 rectArea.height = obj->obj.area.height;
934 #ifdef SCREEN_SIZE_NANO
935 if (obj->style == INVERTED_COLORS) {
948 if (obj->autoHideLongLine ==
true) {
949 #ifdef BUILD_SCREENSHOTS
951 store_string_infos(text,
960 if (textWidth > obj->obj.area.width) {
965 rectArea.x0 = obj->obj.area.x0;
966 rectArea.y0 = obj->obj.area.y0 + (obj->obj.area.height - fontHeight) / 2;
967 rectArea.width = dotsWidth;
971 fontId, text, obj->obj.area.width - dotsWidth, &lineLen, &lineWidth);
972 rectArea.x0 += dotsWidth;
973 rectArea.width = lineWidth;
985 #ifdef BUILD_SCREENSHOTS
987 text, fontId, &obj->obj.area, obj->wrapping, last_nb_lines, last_nb_pages, last_bold_state);
990 if ((obj->nbMaxLines > 0) && (obj->nbMaxLines < nbLines)) {
991 nbLines = obj->nbMaxLines;
994 textHeight = (nbLines - 1) * lineHeight + fontHeight;
996 midHeight = (obj->obj.area.height - textHeight) / 2;
997 #ifdef SCREEN_SIZE_NANO
998 if (obj->style == INVERTED_COLORS) {
1003 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1004 rectArea.height = fontHeight;
1006 for (line = 0; line < nbLines; line++) {
1010 fontId, text, obj->obj.area.width, &lineLen, &lineWidth, obj->wrapping);
1011 if (obj->textAlignment ==
MID_LEFT) {
1012 rectArea.x0 = obj->obj.area.x0;
1014 else if (obj->textAlignment ==
CENTER) {
1015 rectArea.x0 = obj->obj.area.x0 + (obj->obj.area.width - lineWidth) / 2;
1017 else if (obj->textAlignment ==
MID_RIGHT) {
1018 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - lineWidth;
1023 rectArea.y0 = obj->obj.area.y0 + midHeight + line * lineHeight;
1024 rectArea.width = lineWidth;
1027 "draw_textArea(), %s line %d, lineLen %d lineWidth = %d, obj.area.height = %d, "
1028 "textHeight = %d, nbMaxLines = %d, wrapping = %d\n",
1033 obj->obj.area.height,
1037 if ((obj->nbMaxLines == 0) || (line < (obj->nbMaxLines - 1))) {
1038 fontId =
nbgl_drawText(&rectArea, text, lineLen, fontId, obj->textColor);
1041 #ifdef HAVE_SE_TOUCH
1044 nbgl_drawText(&rectArea, text, lineLen - 3, obj->fontId, obj->textColor);
1048 nbgl_drawText(&rectArea,
"...", 3, obj->fontId, obj->textColor);
1050 nbgl_drawText(&rectArea, text, lineLen, fontId, obj->textColor);
1056 if (*text ==
'\n') {
1075 if (computePosition) {
1076 compute_position((
nbgl_obj_t *) obj, prevObj);
1079 obj->obj.area.y0 &= ~0x3;
1081 "draw_qrCode(), x0 = %d, y0 = %d, width = %d, height = %d, text = %s\n",
1084 obj->obj.area.width,
1085 obj->obj.area.height,
1089 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1091 rectArea.x0 = obj->obj.area.x0;
1092 rectArea.y0 = obj->obj.area.y0;
1093 rectArea.width = obj->obj.area.width;
1094 rectArea.height = obj->obj.area.height;
1095 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1096 nbgl_drawQrCode(&rectArea, obj->version, obj->text, obj->foregroundColor);
1100 #ifdef NBGL_KEYBOARD
1110 #ifndef HAVE_SE_TOUCH
1111 obj->obj.area.width = KEYBOARD_WIDTH;
1115 if (computePosition) {
1116 compute_position((
nbgl_obj_t *) obj, prevObj);
1119 OBJ_LOGGER,
"draw_keyboard(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1122 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1138 #ifndef HAVE_SE_TOUCH
1139 obj->obj.area.height = KEYPAD_HEIGHT;
1140 obj->obj.area.width = KEYPAD_WIDTH;
1143 if (computePosition) {
1144 compute_position((
nbgl_obj_t *) obj, prevObj);
1146 obj->obj.area.y0 &= ~0x3;
1147 LOG_DEBUG(
OBJ_LOGGER,
"draw_keypad(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1150 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1156 #ifdef HAVE_SE_TOUCH
1172 if (computePosition) {
1173 compute_position((
nbgl_obj_t *) obj, prevObj);
1175 obj->obj.area.y0 &= ~0x3;
1176 LOG_DEBUG(
OBJ_LOGGER,
"draw_spinner(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1179 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1184 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1186 if (obj->position == 0xFF) {
1188 rectArea.x0 = obj->obj.area.x0;
1189 rectArea.y0 = obj->obj.area.y0;
1190 rectArea.width = 20;
1191 rectArea.height = 4;
1193 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1195 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 4;
1197 rectArea.x0 = obj->obj.area.x0;
1200 rectArea.x0 = obj->obj.area.x0;
1201 rectArea.y0 = obj->obj.area.y0;
1203 rectArea.height = 12;
1204 rectArea.backgroundColor = foreColor;
1206 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1208 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1210 rectArea.x0 = obj->obj.area.x0;
1216 rectArea.x0 = obj->obj.area.x0;
1217 rectArea.y0 = obj->obj.area.y0;
1218 rectArea.width = obj->obj.area.width;
1219 rectArea.height = obj->obj.area.height;
1220 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1224 rectArea.width = 20;
1225 rectArea.height = 4;
1226 switch (obj->position) {
1228 rectArea.x0 = obj->obj.area.x0;
1229 rectArea.y0 = obj->obj.area.y0;
1233 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1234 rectArea.y0 = obj->obj.area.y0;
1238 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1239 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 4;
1243 rectArea.x0 = obj->obj.area.x0;
1244 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 4;
1254 rectArea.height = 12;
1255 rectArea.backgroundColor = foreColor;
1256 switch (obj->position) {
1258 rectArea.x0 = obj->obj.area.x0;
1259 rectArea.y0 = obj->obj.area.y0;
1262 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1263 rectArea.y0 = obj->obj.area.y0;
1266 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1267 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1270 rectArea.x0 = obj->obj.area.x0;
1271 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1292 int textLen = strlen(obj->text);
1295 if (computePosition) {
1296 compute_position((
nbgl_obj_t *) obj, prevObj);
1300 "draw_textEntry(), x0 = %d, y0 = %d, width = %d, height = %d\n",
1303 obj->obj.area.width,
1304 obj->obj.area.height);
1307 obj->obj.area.backgroundColor =
WHITE;
1308 rectArea.backgroundColor =
BLACK;
1309 rectArea.x0 = obj->obj.area.x0;
1310 rectArea.y0 = obj->obj.area.y0;
1311 rectArea.width = obj->obj.area.width;
1312 rectArea.height = obj->obj.area.height;
1316 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1321 offsetX = (obj->obj.area.width - (obj->nbChars * 10)) / 2;
1323 for (
int i = 0; i < obj->nbChars; i++) {
1325 rectArea.x0 = obj->obj.area.x0 + offsetX + (i * 10);
1326 rectArea.y0 = obj->obj.area.y0 - 2;
1328 if (textLen < obj->nbChars) {
1330 digit = obj->text[i];
1342 else if (i < (obj->nbChars - 1)) {
1343 digit = obj->text[textLen - obj->nbChars + 1 + i];
1363 if (obj->buffer == NULL) {
1366 if (computePosition) {
1367 compute_position((
nbgl_obj_t *) obj, prevObj);
1371 OBJ_LOGGER,
"draw_image_file(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1372 obj->obj.area.backgroundColor =
WHITE;
1379 if (computePosition) {
1380 compute_position((
nbgl_obj_t *) obj, prevObj);
1383 if (obj->enableMasking) {
1401 LOG_DEBUG(
OBJ_LOGGER,
"draw_object() obj->type = %d, prevObj = %p\n", obj->type, prevObj);
1402 objRefreshAreaDone =
false;
1403 if ((obj->type <
NB_OBJ_TYPES) && (draw_functions[obj->type] != NULL)) {
1405 func(obj, prevObj, computePosition);
1412 #ifdef HAVE_SERIALIZED_NBGL
1415 if (!objRefreshAreaDone) {
1416 extendRefreshArea(&obj->area);
1434 draw_object(obj, prevObj, computePosition);
1440 OBJ_LOGGER,
"draw_obj_and_chidren(): container->children = %p\n", container->children);
1442 if (container->children != NULL) {
1443 for (i = 0; i < container->nbChildren; i++) {
1444 nbgl_obj_t *current = container->children[i];
1445 if (current != NULL) {
1447 draw_obj_and_chidren(current, prev,
true);
1448 if (current->alignTo == NULL) {
1466 x1 = refreshArea.x0 + refreshArea.width;
1467 y1 = refreshArea.y0 + refreshArea.height;
1470 if (area->x0 < refreshArea.x0) {
1472 refreshArea.x0 =
MAX(0, area->x0);
1475 if (((area->x0 + area->width) > x1) || (refreshArea.width == 0)) {
1480 if (area->y0 < refreshArea.y0) {
1482 refreshArea.y0 =
MAX(0, area->y0);
1485 if (((area->y0 + area->height) > y1) || (refreshArea.height == 0)) {
1493 "extendRefreshArea: Impossible area x0 = %d width %d\n",
1498 #ifdef HAVE_SE_TOUCH
1500 "extendRefreshArea: Impossible area y0 = %d height %d\n",
1502 refreshArea.height);
1508 refreshArea.width = x1 - refreshArea.x0;
1509 refreshArea.height = y1 - refreshArea.y0;
1512 if (area->bpp > refreshArea.bpp) {
1513 refreshArea.bpp = area->bpp;
1524 bool computePosition =
false;
1530 if (obj->type ==
SCREEN) {
1532 computePosition =
true;
1538 while (parent->parent != NULL) {
1539 parent = parent->parent;
1541 if (parent->type ==
SCREEN) {
1550 if (objDrawingDisabled && fromApp) {
1553 draw_obj_and_chidren(obj, NULL, computePosition);
1573 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1579 "nbgl_refreshSpecial(), x0,y0 = [%d, %d], w,h = [%d, %d]\n",
1583 refreshArea.height);
1589 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1595 "nbgl_refreshSpecialNoPoff(), x0,y0 = [%d, %d], w,h = [%d, %d]\n",
1599 refreshArea.height);
1609 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1621 #ifdef HAVE_SERIALIZED_NBGL
1625 refreshArea.width = 0;
1627 refreshArea.height = 0;
1640 objDrawingDisabled =
false;
1641 #ifdef HAVE_SE_TOUCH
1653 objDrawingDisabled = !enable;
1675 while (parent->parent != NULL) {
1676 parent = parent->parent;
1678 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_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_frontDrawHorizontalLine(const nbgl_area_t *area, uint8_t mask, color_t lineColor)
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.
uint8_t * nbgl_objGetRAMBuffer(void)
This function is used to get the all purpose RAM buffer.
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.
const char * get_ux_loc_string(uint32_t index)
void nbgl_refreshSpecialWithPostRefresh(nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
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 KEYBOARD_KEY_HEIGHT
#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)
BOLOS_UX_LOC_STRINGS UX_LOC_STRINGS_INDEX