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
36#if defined(TARGET_STAX)
37#define INTER_DASHES 10
38#elif defined(TARGET_FLEX)
60 bool computePosition);
90static bool objDrawingDisabled;
93static bool objRefreshAreaDone;
133#ifdef BUILD_SCREENSHOTS
135extern uint16_t last_nb_lines, last_nb_pages;
136extern bool last_bold_state, verbose;
156 "compute_relativePosition() without align to, parent->layout = %d, prevObj = %p\n",
161 obj->rel_x0 = obj->alignmentMarginX;
162 if (prevObj != NULL) {
163 obj->rel_y0 = prevObj->rel_y0 + prevObj->area.height + obj->alignmentMarginY;
166 obj->rel_y0 = obj->alignmentMarginY;
170 if (prevObj != NULL) {
171 obj->rel_x0 = prevObj->rel_x0 + prevObj->area.width + obj->alignmentMarginX;
174 obj->rel_x0 = obj->alignmentMarginX;
176 obj->rel_y0 = obj->alignmentMarginY;
181 if (alignToObj == NULL) {
182 alignToObj = obj->parent;
189 if (alignToObj == obj->parent) {
191 switch (obj->alignment) {
193 obj->rel_x0 = obj->alignmentMarginX;
194 obj->rel_y0 = obj->alignmentMarginY;
198 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
199 obj->rel_y0 = obj->alignmentMarginY;
203 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
204 obj->rel_y0 = obj->alignmentMarginY;
207 obj->rel_x0 = obj->alignmentMarginX;
209 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
213 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
215 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
219 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
221 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
224 obj->rel_x0 = obj->alignmentMarginX;
226 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
230 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
232 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
236 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
238 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
247 switch (obj->alignment) {
249 obj->rel_x0 = alignToObj->rel_x0 + obj->alignmentMarginX;
250 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
253 obj->rel_x0 = alignToObj->rel_x0
254 + (alignToObj->area.width - obj->area.width) / 2
255 + obj->alignmentMarginX;
256 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
259 obj->rel_x0 = alignToObj->rel_x0 + (alignToObj->area.width - obj->area.width)
260 - obj->alignmentMarginX;
261 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
265 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
266 obj->rel_y0 = alignToObj->rel_y0 + obj->alignmentMarginY;
269 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
270 obj->rel_y0 = alignToObj->rel_y0
271 + (alignToObj->area.height - obj->area.height) / 2
272 + obj->alignmentMarginY;
275 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
276 obj->rel_y0 = alignToObj->rel_y0 + (alignToObj->area.height - obj->area.height)
277 + obj->alignmentMarginY;
282 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
283 obj->rel_y0 = alignToObj->rel_y0 + obj->alignmentMarginY;
287 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
288 obj->rel_y0 = alignToObj->rel_y0
289 + (alignToObj->area.height - obj->area.height) / 2
290 + obj->alignmentMarginY;
294 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
295 obj->rel_y0 = alignToObj->rel_y0 + (alignToObj->area.height - obj->area.height)
296 + obj->alignmentMarginY;
300 obj->rel_x0 = alignToObj->rel_x0 + obj->alignmentMarginX;
302 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
305 obj->rel_x0 = alignToObj->rel_x0
306 + (alignToObj->area.width - obj->area.width) / 2
307 + obj->alignmentMarginX;
309 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
312 obj->rel_x0 = alignToObj->rel_x0 + (alignToObj->area.width - obj->area.width)
313 - obj->alignmentMarginX;
315 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
329 compute_relativePosition(obj, prevObj);
331 if (parent == NULL) {
340 obj->area.x0 = parent->obj.area.x0 + obj->rel_x0;
341 obj->area.y0 = parent->obj.area.y0 + obj->rel_y0;
343 if ((obj->area.x0 + obj->area.width) > SCREEN_WIDTH) {
345 "compute_position(), forbidden width, obj->type = %d, x0=%d, width=%d\n",
351 if ((obj->area.y0 + obj->area.height) > SCREEN_HEIGHT) {
353 "compute_position(), forbidden height, obj->type = %d, y0=%d, height=%d\n",
366 UNUSED(computePosition);
368 rectArea.backgroundColor = obj->obj.area.backgroundColor;
369 rectArea.x0 = obj->obj.area.x0;
370 rectArea.y0 = obj->obj.area.y0;
371 rectArea.width = obj->obj.area.width;
372 rectArea.height = obj->obj.area.height;
378 if (computePosition) {
379 compute_position((
nbgl_obj_t *) obj, prevObj);
382 "draw_container(), x0 = %d, y0 = %d, width = %d, height = %d\n",
386 obj->obj.area.height);
388 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
389 if (obj->forceClean) {
406 const char *text = NULL;
407#define ICON_TEXT_SPACE 12
409 if (computePosition) {
410 compute_position((
nbgl_obj_t *) obj, prevObj);
413 "draw_button(), x0 = %d, y0 = %d, width = %d, height = %d\n",
417 obj->obj.area.height);
420 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
422 if ((obj->innerColor == obj->borderColor)
423 && (obj->innerColor != obj->obj.area.backgroundColor)) {
428 (
nbgl_area_t *) obj, obj->radius, 2, obj->innerColor, obj->borderColor);
431 if (obj->onDrawCallback != NULL) {
432 obj->text = obj->onDrawCallback(obj->token);
439 rectArea.x0 = obj->obj.area.x0;
440 rectArea.y0 = obj->obj.area.y0;
443 rectArea.y0 += (obj->obj.area.height - rectArea.height) / 2;
444 rectArea.width = obj->obj.area.width;
445 if (obj->icon != NULL) {
453#ifdef BUILD_SCREENSHOTS
454 store_string_infos(text, obj->fontId, &rectArea,
true, 1, 1,
false);
458 if (textWidth < rectArea.width) {
459 rectArea.x0 += (rectArea.width - textWidth) / 2;
462 rectArea.backgroundColor = obj->innerColor;
463 nbgl_drawText(&rectArea, text, textLen, obj->fontId, obj->foregroundColor);
466 if (obj->icon != NULL) {
471 iconX0 = obj->obj.area.x0
472 + (obj->obj.area.width - (textWidth + obj->icon->width +
ICON_TEXT_SPACE)) / 2;
475 iconX0 = obj->obj.area.x0 + (obj->obj.area.width - obj->icon->width) / 2;
478 "draw_button(), obj->obj.area.height = %d, obj->iconHeight = %d\n",
479 obj->obj.area.height,
481 iconY0 = obj->obj.area.y0 + (obj->obj.area.height - obj->icon->height) / 2;
483 rectArea.backgroundColor = obj->innerColor;
484 rectArea.x0 = iconX0;
485 rectArea.y0 = iconY0;
486 rectArea.width = obj->icon->width;
487 rectArea.height = obj->icon->height;
488 rectArea.bpp = obj->icon->bpp;
505 if (computePosition) {
506 compute_position((
nbgl_obj_t *) obj, prevObj);
508 LOG_DEBUG(
OBJ_LOGGER,
"draw_line(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
510 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
512 "draw_line(), backgroundColor = %d, lineColor = %d\n",
513 obj->obj.area.backgroundColor,
515 rectArea.x0 = obj->obj.area.x0;
516 rectArea.y0 = obj->obj.area.y0;
518 rectArea.width = obj->obj.area.width = obj->thickness;
519 rectArea.backgroundColor = obj->lineColor;
520 rectArea.height = obj->obj.area.height;
525 if (obj->thickness == 1) {
526 mask = 0x1 << (obj->offset & 0x3);
528 else if (obj->thickness == 2) {
529 mask = 0x3 << ((obj->offset < 3) ? obj->offset : 2);
531 else if (obj->thickness == 3) {
532 mask = 0x7 << (obj->offset & 0x1);
534 else if (obj->thickness == 4) {
541 rectArea.width = obj->obj.area.width;
542 rectArea.height = obj->obj.area.height = VERTICAL_ALIGNMENT;
543 rectArea.backgroundColor = obj->obj.area.backgroundColor;
556static void draw_button(nbgl_button_t *obj, nbgl_obj_t *prevObj, bool computePosition)
559 const char *text = NULL;
560#define ICON_TEXT_SPACE 2
562 if (computePosition) {
563 compute_position((
nbgl_obj_t *) obj, prevObj);
566 "draw_button(), x0 = %d, y0 = %d, width = %d, height = %d\n",
570 obj->obj.area.height);
573 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
578 if (obj->onDrawCallback != NULL) {
579 obj->text = obj->onDrawCallback(obj->token);
586 rectArea.x0 = obj->obj.area.x0;
587 rectArea.y0 = obj->obj.area.y0;
590 rectArea.y0 += (obj->obj.area.height - rectArea.height) / 2;
591 rectArea.width = obj->obj.area.width;
592 if (obj->icon != NULL) {
601 if (textWidth < rectArea.width) {
602 rectArea.x0 += (rectArea.width - textWidth) / 2;
605 rectArea.backgroundColor = obj->innerColor;
606 nbgl_drawText(&rectArea, text, textLen, obj->fontId, obj->foregroundColor);
609 if (obj->icon != NULL) {
614 iconX0 = obj->obj.area.x0
615 + (obj->obj.area.width - (textWidth + obj->icon->width +
ICON_TEXT_SPACE)) / 2;
618 iconX0 = obj->obj.area.x0 + (obj->obj.area.width - obj->icon->width) / 2;
621 "draw_button(), obj->obj.area.height = %d, obj->iconHeight = %d\n",
622 obj->obj.area.height,
624 iconY0 = obj->obj.area.y0 + (obj->obj.area.height - obj->icon->height) / 2;
626 rectArea.backgroundColor = obj->innerColor;
627 rectArea.x0 = iconX0;
628 rectArea.y0 = iconY0;
629 rectArea.width = obj->icon->width;
630 rectArea.height = obj->icon->height;
631 rectArea.bpp = obj->icon->bpp;
644 if (obj->buffer == NULL) {
645 if (obj->onDrawCallback != NULL) {
646 iconDetails = obj->onDrawCallback(obj->token);
653 iconDetails = obj->buffer;
655 if (iconDetails == NULL) {
660 obj->obj.area.width = iconDetails->width;
661 obj->obj.area.height = iconDetails->height;
662 obj->obj.area.bpp = iconDetails->bpp;
663 if (computePosition) {
664 compute_position((
nbgl_obj_t *) obj, prevObj);
666 LOG_DEBUG(
OBJ_LOGGER,
"draw_image(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
668 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
670 colorMap = obj->foregroundColor;
676 colorMap = obj->foregroundColor;
688 obj->obj.area.width = C_switch_60_40.width;
689 obj->obj.area.height = C_switch_60_40.height;
690 if (computePosition) {
691 compute_position((
nbgl_obj_t *) obj, prevObj);
693 LOG_DEBUG(
OBJ_LOGGER,
"draw_switch(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
696 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
698 rectArea.x0 = obj->obj.area.x0;
699 rectArea.y0 = obj->obj.area.y0;
700 rectArea.width = obj->obj.area.width;
701 rectArea.height = obj->obj.area.height;
702 rectArea.backgroundColor = obj->obj.area.backgroundColor;
719 obj->obj.area.width = RADIO_WIDTH;
720 obj->obj.area.height = RADIO_HEIGHT;
721 if (computePosition) {
722 compute_position((
nbgl_obj_t *) obj, prevObj);
725 "draw_radioButton(), x0 = %d, y0 = %d, state = %d\n",
731 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
734 icon = &RADIO_OFF_ICON;
735 color_map = obj->borderColor;
738 icon = &RADIO_ON_ICON;
739 color_map = obj->activeColor;
741 rectArea.x0 = obj->obj.area.x0;
742 rectArea.y0 = obj->obj.area.y0;
743 rectArea.width = obj->obj.area.width;
744 rectArea.height = obj->obj.area.height;
745 rectArea.backgroundColor = obj->obj.area.backgroundColor;
746 rectArea.bpp = icon->bpp;
764 if (computePosition) {
765 compute_position((
nbgl_obj_t *) obj, prevObj);
768 obj->obj.area.y0 &= ~(VERTICAL_ALIGNMENT - 1);
770 "draw_progressBar(), x0 = %d, y0 = %d, level = %d %%\n",
776 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
778 if (obj->partialRedraw ==
false) {
780 if (obj->withBorder) {
784 obj->obj.area.backgroundColor,
785 obj->foregroundColor);
792 obj->previousWidth = 0;
796 uint16_t barWidth = ((obj->state * obj->obj.area.width)) / 100;
797 int barDiffWith = barWidth - obj->previousWidth;
799 memcpy(&barArea, &obj->obj.area,
sizeof(
nbgl_area_t));
801 if (barDiffWith > 0) {
803 barArea.x0 = obj->obj.area.x0 + obj->previousWidth;
804 barArea.width = barDiffWith;
805 barColor = obj->foregroundColor;
807 else if (barDiffWith < 0) {
809 barArea.x0 = obj->obj.area.x0 + obj->previousWidth + barDiffWith;
810 barArea.width = -barDiffWith;
811 barColor = obj->obj.area.backgroundColor;
814 if (barDiffWith != 0) {
820 if (obj->partialRedraw ==
true) {
821 obj->partialRedraw =
false;
823 obj->previousWidth = barWidth;
825 extendRefreshArea(&barArea);
826 objRefreshAreaDone =
true;
831 if (computePosition) {
832 compute_position((
nbgl_obj_t *) obj, prevObj);
835 "draw_progressBar(), x0 = %d, y0 = %d, level = %d %%\n",
841 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
844 if (obj->withBorder) {
848 obj->obj.area.backgroundColor,
849 obj->foregroundColor);
855 levelWidth =
MIN((obj->obj.area.width - 2) * obj->state / 100, (obj->obj.area.width - 2));
856 if (levelWidth > 0) {
858 rectArea.width = levelWidth;
859 rectArea.height = obj->obj.area.height - 2;
860 rectArea.backgroundColor = obj->foregroundColor;
862 rectArea.x0 = obj->obj.area.x0 + 1;
863 rectArea.y0 = obj->obj.area.y0 + 1;
881 bool computePosition)
887 if (obj->nbPages < 2) {
894 obj->obj.area.height = 4;
896 if (computePosition) {
897 compute_position((
nbgl_obj_t *) obj, prevObj);
900 "draw_pageIndicator(), x0 = %d, y0 = %d, page = %d/%d\n",
907 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
909 dashWidth = (obj->obj.area.width - ((obj->nbPages - 1) * INTER_DASHES)) / obj->nbPages;
910 rectArea.x0 = obj->obj.area.x0;
911 rectArea.y0 = obj->obj.area.y0;
912 rectArea.width = dashWidth;
913 rectArea.height = obj->obj.area.height;
914 rectArea.backgroundColor = obj->obj.area.backgroundColor;
917 for (i = 0; i < obj->activePage; i++) {
920 rectArea.x0 += dashWidth + INTER_DASHES;
923 rectArea.x0 += dashWidth + INTER_DASHES;
926 for (; i < obj->nbPages; i++) {
928 rectArea.x0 += dashWidth + INTER_DASHES;
934 SPRINTF(navText,
"%d of %d", obj->activePage + 1, obj->nbPages);
940 if (computePosition) {
941 compute_position((
nbgl_obj_t *) obj, prevObj);
944 "draw_pageIndicator(), x0 = %d, y0 = %d, page = %d/%d\n",
951 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
954 rectArea.x0 = obj->obj.area.x0;
955 rectArea.y0 = obj->obj.area.y0;
956 rectArea.width = obj->obj.area.width;
957 rectArea.height = obj->obj.area.height;
958 rectArea.backgroundColor = obj->obj.area.backgroundColor;
976 uint16_t textWidth, fontHeight, lineHeight, textHeight, midHeight;
981 if (computePosition) {
982 compute_position((
nbgl_obj_t *) obj, prevObj);
985 if (obj->onDrawCallback != NULL) {
986 obj->text = obj->onDrawCallback(obj->token);
995 "draw_textArea(), wrapping = %d, x0 = %d, y0 = %d, width = %d, height = %d, text = %s\n",
1000 obj->obj.area.height,
1004 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1007#ifdef SCREEN_SIZE_NANO
1008 if (obj->style == INVERTED_COLORS) {
1009 obj->obj.area.backgroundColor =
WHITE;
1010 rectArea.backgroundColor =
BLACK;
1016 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1017 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1019 rectArea.x0 = obj->obj.area.x0;
1020 rectArea.y0 = obj->obj.area.y0;
1021 rectArea.width = obj->obj.area.width;
1022 rectArea.height = obj->obj.area.height;
1023#ifdef SCREEN_SIZE_NANO
1024 if (obj->style == INVERTED_COLORS) {
1037 if (obj->autoHideLongLine ==
true) {
1038#ifdef BUILD_SCREENSHOTS
1040 store_string_infos(text,
1049 if (textWidth > obj->obj.area.width) {
1054 rectArea.x0 = obj->obj.area.x0;
1055 rectArea.y0 = obj->obj.area.y0 + (obj->obj.area.height - fontHeight) / 2;
1056 rectArea.width = dotsWidth;
1060 fontId, text, obj->obj.area.width - dotsWidth, &lineLen, &lineWidth);
1061 rectArea.x0 += dotsWidth;
1062 rectArea.width = lineWidth;
1074#ifdef BUILD_SCREENSHOTS
1076 text, fontId, &obj->obj.area, obj->wrapping, last_nb_lines, last_nb_pages, last_bold_state);
1079 if ((obj->nbMaxLines > 0) && (obj->nbMaxLines < nbLines)) {
1080 nbLines = obj->nbMaxLines;
1083 textHeight = (nbLines - 1) * lineHeight + fontHeight;
1085 midHeight = (obj->obj.area.height - textHeight) / 2;
1086#ifdef SCREEN_SIZE_NANO
1087 if (obj->style == INVERTED_COLORS) {
1092 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1093 rectArea.height = fontHeight;
1095 for (line = 0; line < nbLines; line++) {
1099 fontId, text, obj->obj.area.width, &lineLen, &lineWidth, obj->wrapping);
1100 if (obj->textAlignment ==
MID_LEFT) {
1101 rectArea.x0 = obj->obj.area.x0;
1103 else if (obj->textAlignment ==
CENTER) {
1104 rectArea.x0 = obj->obj.area.x0 + (obj->obj.area.width - lineWidth) / 2;
1106 else if (obj->textAlignment ==
MID_RIGHT) {
1107 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - lineWidth;
1112 rectArea.y0 = obj->obj.area.y0 + midHeight + line * lineHeight;
1113 rectArea.width = lineWidth;
1116 "draw_textArea(), [%s] line %d, lineLen %d lineWidth = %d, obj.area.height = %d, "
1117 "textHeight = %d, nbMaxLines = %d, wrapping = %d\n",
1122 obj->obj.area.height,
1126 if ((obj->nbMaxLines == 0) || (line < (obj->nbMaxLines - 1))) {
1127 fontId =
nbgl_drawText(&rectArea, text, lineLen, fontId, obj->textColor);
1134 if ((lineWidth + dotsWidth) >= obj->obj.area.width) {
1137 nbgl_drawText(&rectArea, text, lineLen, obj->fontId, obj->textColor);
1141 rectArea.width = dotsWidth;
1142 nbgl_drawText(&rectArea,
"...", 3, obj->fontId, obj->textColor);
1144 nbgl_drawText(&rectArea, text, lineLen, fontId, obj->textColor);
1150 if (*text ==
'\n') {
1169 if (computePosition) {
1170 compute_position((
nbgl_obj_t *) obj, prevObj);
1173 obj->obj.area.y0 &= ~0x3;
1175 "draw_qrCode(), x0 = %d, y0 = %d, width = %d, height = %d, text = %s\n",
1178 obj->obj.area.width,
1179 obj->obj.area.height,
1183 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1185 rectArea.x0 = obj->obj.area.x0;
1186 rectArea.y0 = obj->obj.area.y0;
1187 rectArea.width = obj->obj.area.width;
1188 rectArea.height = obj->obj.area.height;
1189 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1190 nbgl_drawQrCode(&rectArea, obj->version, obj->text, obj->foregroundColor);
1204#ifndef HAVE_SE_TOUCH
1205 obj->obj.area.width = KEYBOARD_WIDTH;
1206 obj->obj.area.height = KEYBOARD_KEY_HEIGHT;
1209 if (computePosition) {
1210 compute_position((
nbgl_obj_t *) obj, prevObj);
1213 OBJ_LOGGER,
"draw_keyboard(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1216 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1232#ifndef HAVE_SE_TOUCH
1233 obj->obj.area.height = KEYPAD_HEIGHT;
1234 obj->obj.area.width = KEYPAD_WIDTH;
1237 if (computePosition) {
1238 compute_position((
nbgl_obj_t *) obj, prevObj);
1240 obj->obj.area.y0 &= ~0x3;
1241 LOG_DEBUG(
OBJ_LOGGER,
"draw_keypad(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1244 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1263 obj->obj.area.width = SPINNER_WIDTH;
1264 obj->obj.area.height = SPINNER_HEIGHT;
1266 if (computePosition) {
1267 compute_position((
nbgl_obj_t *) obj, prevObj);
1269 obj->obj.area.y0 &= ~0x3;
1270 LOG_DEBUG(
OBJ_LOGGER,
"draw_spinner(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1273 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1278 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1280 if (obj->position == 0xFF) {
1282 rectArea.x0 = obj->obj.area.x0;
1283 rectArea.y0 = obj->obj.area.y0;
1284 rectArea.width = 20;
1285 rectArea.height = 4;
1287 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1289 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 4;
1291 rectArea.x0 = obj->obj.area.x0;
1294 rectArea.x0 = obj->obj.area.x0;
1295 rectArea.y0 = obj->obj.area.y0;
1297 rectArea.height = 12;
1298 rectArea.backgroundColor = foreColor;
1300 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1302 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1304 rectArea.x0 = obj->obj.area.x0;
1310 rectArea.x0 = obj->obj.area.x0;
1311 rectArea.y0 = obj->obj.area.y0;
1312 rectArea.width = obj->obj.area.width;
1313 rectArea.height = obj->obj.area.height;
1314 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1318 rectArea.width = 20;
1319 rectArea.height = 4;
1320 switch (obj->position) {
1322 rectArea.x0 = obj->obj.area.x0;
1323 rectArea.y0 = obj->obj.area.y0;
1327 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1328 rectArea.y0 = obj->obj.area.y0;
1332 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1333 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 4;
1337 rectArea.x0 = obj->obj.area.x0;
1338 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 4;
1348 rectArea.height = 12;
1349 rectArea.backgroundColor = foreColor;
1350 switch (obj->position) {
1352 rectArea.x0 = obj->obj.area.x0;
1353 rectArea.y0 = obj->obj.area.y0;
1356 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
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 + obj->obj.area.height - rectArea.height;
1364 rectArea.x0 = obj->obj.area.x0;
1365 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1386 int textLen = strlen(obj->text);
1389 if (computePosition) {
1390 compute_position((
nbgl_obj_t *) obj, prevObj);
1394 "draw_textEntry(), x0 = %d, y0 = %d, width = %d, height = %d\n",
1397 obj->obj.area.width,
1398 obj->obj.area.height);
1401 obj->obj.area.backgroundColor =
WHITE;
1402 rectArea.backgroundColor =
BLACK;
1403 rectArea.x0 = obj->obj.area.x0;
1404 rectArea.y0 = obj->obj.area.y0;
1405 rectArea.width = obj->obj.area.width;
1406 rectArea.height = obj->obj.area.height;
1410 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1415 offsetX = (obj->obj.area.width - (obj->nbChars * 10)) / 2;
1417 for (
int i = 0; i < obj->nbChars; i++) {
1419 rectArea.x0 = obj->obj.area.x0 + offsetX + (i * 10);
1420 rectArea.y0 = obj->obj.area.y0 - 2;
1422 if (textLen < obj->nbChars) {
1424 digit = obj->text[i];
1436 else if (i < (obj->nbChars - 1)) {
1437 digit = obj->text[textLen - obj->nbChars + 1 + i];
1457 if (obj->buffer == NULL) {
1460 if (computePosition) {
1461 compute_position((
nbgl_obj_t *) obj, prevObj);
1465 OBJ_LOGGER,
"draw_image_file(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1466 obj->obj.area.backgroundColor =
WHITE;
1473 if (computePosition) {
1474 compute_position((
nbgl_obj_t *) obj, prevObj);
1477 if (obj->enableMasking) {
1495 LOG_DEBUG(
OBJ_LOGGER,
"draw_object() obj->type = %d, prevObj = %p\n", obj->type, prevObj);
1496 objRefreshAreaDone =
false;
1497 if ((obj->type <
NB_OBJ_TYPES) && (draw_functions[obj->type] != NULL)) {
1498 if ((obj->type !=
SCREEN) && (obj->parent == NULL)) {
1503 func(obj, prevObj, computePosition);
1510#ifdef HAVE_SERIALIZED_NBGL
1513 if (!objRefreshAreaDone) {
1514 extendRefreshArea(&obj->area);
1532 draw_object(obj, prevObj, computePosition);
1538 OBJ_LOGGER,
"draw_obj_and_chidren(): container->children = %p\n", container->children);
1540 if (container->children != NULL) {
1541 for (i = 0; i < container->nbChildren; i++) {
1542 nbgl_obj_t *current = container->children[i];
1543 if (current != NULL) {
1545 draw_obj_and_chidren(current, prev,
true);
1546 if (current->alignTo == NULL) {
1564 x1 = refreshArea.x0 + refreshArea.width;
1565 y1 = refreshArea.y0 + refreshArea.height;
1568 if (area->x0 < refreshArea.x0) {
1570 refreshArea.x0 =
MAX(0, area->x0);
1573 if (((area->x0 + area->width) > x1) || (refreshArea.width == 0)) {
1575 x1 =
MIN(SCREEN_WIDTH, area->x0 + area->width);
1578 if (area->y0 < refreshArea.y0) {
1580 refreshArea.y0 =
MAX(0, area->y0) & ~(VERTICAL_ALIGNMENT - 1);
1583 if (((area->y0 + area->height) > y1) || (refreshArea.height == 0)) {
1585 y1 =
MIN(SCREEN_HEIGHT, area->y0 + area->height);
1587 y1 = (y1 + (VERTICAL_ALIGNMENT - 1)) & ~(VERTICAL_ALIGNMENT - 1);
1591 if (x1 > SCREEN_WIDTH) {
1593 "extendRefreshArea: Impossible area x0 = %d width %d\n",
1597 if (y1 > SCREEN_HEIGHT) {
1600 "extendRefreshArea: Impossible area y0 = %d height %d\n",
1602 refreshArea.height);
1608 refreshArea.width = x1 - refreshArea.x0;
1609 refreshArea.height = y1 - refreshArea.y0;
1612 if (area->bpp > refreshArea.bpp) {
1613 refreshArea.bpp = area->bpp;
1624 bool computePosition =
false;
1630 if (obj->type ==
SCREEN) {
1632 computePosition =
true;
1638 while (parent->parent != NULL) {
1639 parent = parent->parent;
1641 if (parent->type ==
SCREEN) {
1650 if (objDrawingDisabled && fromApp) {
1653 draw_obj_and_chidren(obj, NULL, computePosition);
1673 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1679 "nbgl_refreshSpecial(), x0,y0 = [%d, %d], w,h = [%d, %d]\n",
1683 refreshArea.height);
1689 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1695 "nbgl_refreshSpecialNoPoff(), x0,y0 = [%d, %d], w,h = [%d, %d]\n",
1699 refreshArea.height);
1709 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1721#ifdef HAVE_SERIALIZED_NBGL
1724 refreshArea.x0 = SCREEN_WIDTH - 1;
1725 refreshArea.width = 0;
1726 refreshArea.y0 = SCREEN_HEIGHT - 1;
1727 refreshArea.height = 0;
1740 objDrawingDisabled =
false;
1753 objDrawingDisabled = !enable;
1775 while (parent->parent != NULL) {
1776 parent = parent->parent;
1778 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.
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 * 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)