11#include "app_config.h"
19#include "os_helpers.h"
22#include "os_io_seph_ux.h"
23#ifdef HAVE_SERIALIZED_NBGL
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;
155 "compute_relativePosition() without align to, parent->layout = %d, prevObj = %p\n",
160 obj->rel_x0 = obj->alignmentMarginX;
161 if (prevObj != NULL) {
162 obj->rel_y0 = prevObj->rel_y0 + prevObj->area.height + obj->alignmentMarginY;
165 obj->rel_y0 = obj->alignmentMarginY;
169 if (prevObj != NULL) {
170 obj->rel_x0 = prevObj->rel_x0 + prevObj->area.width + obj->alignmentMarginX;
173 obj->rel_x0 = obj->alignmentMarginX;
175 obj->rel_y0 = obj->alignmentMarginY;
180 if (alignToObj == NULL) {
181 alignToObj = obj->parent;
188 if (alignToObj == obj->parent) {
190 switch (obj->alignment) {
192 obj->rel_x0 = obj->alignmentMarginX;
193 obj->rel_y0 = obj->alignmentMarginY;
197 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
198 obj->rel_y0 = obj->alignmentMarginY;
202 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
203 obj->rel_y0 = obj->alignmentMarginY;
206 obj->rel_x0 = obj->alignmentMarginX;
208 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
212 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
214 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
218 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
220 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
223 obj->rel_x0 = obj->alignmentMarginX;
225 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
229 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
231 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
235 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
237 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
246 switch (obj->alignment) {
248 obj->rel_x0 = alignToObj->rel_x0 + obj->alignmentMarginX;
249 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
252 obj->rel_x0 = alignToObj->rel_x0
253 + (alignToObj->area.width - obj->area.width) / 2
254 + obj->alignmentMarginX;
255 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
258 obj->rel_x0 = alignToObj->rel_x0 + (alignToObj->area.width - obj->area.width)
259 - obj->alignmentMarginX;
260 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
264 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
265 obj->rel_y0 = alignToObj->rel_y0 + obj->alignmentMarginY;
268 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
269 obj->rel_y0 = alignToObj->rel_y0
270 + (alignToObj->area.height - obj->area.height) / 2
271 + obj->alignmentMarginY;
274 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
275 obj->rel_y0 = alignToObj->rel_y0 + (alignToObj->area.height - obj->area.height)
276 + obj->alignmentMarginY;
281 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
282 obj->rel_y0 = alignToObj->rel_y0 + obj->alignmentMarginY;
286 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
287 obj->rel_y0 = alignToObj->rel_y0
288 + (alignToObj->area.height - obj->area.height) / 2
289 + obj->alignmentMarginY;
293 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
294 obj->rel_y0 = alignToObj->rel_y0 + (alignToObj->area.height - obj->area.height)
295 + obj->alignmentMarginY;
299 obj->rel_x0 = alignToObj->rel_x0 + obj->alignmentMarginX;
301 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
304 obj->rel_x0 = alignToObj->rel_x0
305 + (alignToObj->area.width - obj->area.width) / 2
306 + obj->alignmentMarginX;
308 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
311 obj->rel_x0 = alignToObj->rel_x0 + (alignToObj->area.width - obj->area.width)
312 - obj->alignmentMarginX;
314 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
328 compute_relativePosition(obj, prevObj);
330 if (parent == NULL) {
339 obj->area.x0 = parent->obj.area.x0 + obj->rel_x0;
340 obj->area.y0 = parent->obj.area.y0 + obj->rel_y0;
342 if ((obj->area.x0 + obj->area.width) > SCREEN_WIDTH) {
344 "compute_position(), forbidden width, obj->type = %d, x0=%d, width=%d\n",
350 if ((obj->area.y0 + obj->area.height) > SCREEN_HEIGHT) {
352 "compute_position(), forbidden height, obj->type = %d, y0=%d, height=%d\n",
365 UNUSED(computePosition);
367 rectArea.backgroundColor = obj->obj.area.backgroundColor;
368 rectArea.x0 = obj->obj.area.x0;
369 rectArea.y0 = obj->obj.area.y0;
370 rectArea.width = obj->obj.area.width;
371 rectArea.height = obj->obj.area.height;
377 if (computePosition) {
378 compute_position((
nbgl_obj_t *) obj, prevObj);
381 "draw_container(), x0 = %d, y0 = %d, width = %d, height = %d\n",
385 obj->obj.area.height);
387 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
388 if (obj->forceClean) {
404 uint16_t textWidth = 0;
405 const char *text = NULL;
406#define ICON_TEXT_SPACE 12
408 if (computePosition) {
409 compute_position((
nbgl_obj_t *) obj, prevObj);
412 "draw_button(), x0 = %d, y0 = %d, width = %d, height = %d\n",
416 obj->obj.area.height);
419 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
421 if ((obj->innerColor == obj->borderColor)
422 && (obj->innerColor != obj->obj.area.backgroundColor)) {
427 (
nbgl_area_t *) obj, obj->radius, 2, obj->innerColor, obj->borderColor);
430 if (obj->onDrawCallback != NULL) {
431 obj->text = obj->onDrawCallback(obj->token);
438 rectArea.x0 = obj->obj.area.x0;
439 rectArea.y0 = obj->obj.area.y0;
442 rectArea.y0 += (obj->obj.area.height - rectArea.height) / 2;
443 rectArea.width = obj->obj.area.width;
444 if (obj->icon != NULL) {
452#ifdef BUILD_SCREENSHOTS
453 store_string_infos(text, obj->fontId, &rectArea,
true, 1, 1,
false);
457 if (textWidth < rectArea.width) {
458 rectArea.x0 += (rectArea.width - textWidth) / 2;
461 rectArea.backgroundColor = obj->innerColor;
462 nbgl_drawText(&rectArea, text, textLen, obj->fontId, obj->foregroundColor);
465 if (obj->icon != NULL) {
466 uint16_t iconX0, iconY0;
470 iconX0 = obj->obj.area.x0
471 + (obj->obj.area.width - (textWidth + obj->icon->width +
ICON_TEXT_SPACE)) / 2;
474 iconX0 = obj->obj.area.x0 + (obj->obj.area.width - obj->icon->width) / 2;
477 "draw_button(), obj->obj.area.height = %d, obj->iconHeight = %d\n",
478 obj->obj.area.height,
480 iconY0 = obj->obj.area.y0 + (obj->obj.area.height - obj->icon->height) / 2;
482 rectArea.backgroundColor = obj->innerColor;
483 rectArea.x0 = iconX0;
484 rectArea.y0 = iconY0;
485 rectArea.width = obj->icon->width;
486 rectArea.height = obj->icon->height;
487 rectArea.bpp = obj->icon->bpp;
504 if (computePosition) {
505 compute_position((
nbgl_obj_t *) obj, prevObj);
507 LOG_DEBUG(
OBJ_LOGGER,
"draw_line(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
509 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
511 "draw_line(), backgroundColor = %d, lineColor = %d\n",
512 obj->obj.area.backgroundColor,
514 rectArea.x0 = obj->obj.area.x0;
515 rectArea.y0 = obj->obj.area.y0;
517 rectArea.width = obj->obj.area.width = obj->thickness;
518 rectArea.backgroundColor = obj->lineColor;
519 rectArea.height = obj->obj.area.height;
524 if (obj->thickness == 1) {
525 mask = 0x1 << (obj->offset & 0x3);
527 else if (obj->thickness == 2) {
528 mask = 0x3 << ((obj->offset < 3) ? obj->offset : 2);
530 else if (obj->thickness == 3) {
531 mask = 0x7 << (obj->offset & 0x1);
533 else if (obj->thickness == 4) {
540 rectArea.width = obj->obj.area.width;
541 rectArea.height = obj->obj.area.height = VERTICAL_ALIGNMENT;
542 rectArea.backgroundColor = obj->obj.area.backgroundColor;
555static void draw_button(nbgl_button_t *obj, nbgl_obj_t *prevObj, bool computePosition)
557 uint16_t textWidth = 0;
558 const char *text = NULL;
559#define ICON_TEXT_SPACE 2
561 if (computePosition) {
562 compute_position((
nbgl_obj_t *) obj, prevObj);
565 "draw_button(), x0 = %d, y0 = %d, width = %d, height = %d\n",
569 obj->obj.area.height);
572 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
577 if (obj->onDrawCallback != NULL) {
578 obj->text = obj->onDrawCallback(obj->token);
585 rectArea.x0 = obj->obj.area.x0;
586 rectArea.y0 = obj->obj.area.y0;
589 rectArea.y0 += (obj->obj.area.height - rectArea.height) / 2;
590 rectArea.width = obj->obj.area.width;
591 if (obj->icon != NULL) {
600 if (textWidth < rectArea.width) {
601 rectArea.x0 += (rectArea.width - textWidth) / 2;
604 rectArea.backgroundColor = obj->innerColor;
605 nbgl_drawText(&rectArea, text, textLen, obj->fontId, obj->foregroundColor);
608 if (obj->icon != NULL) {
609 uint16_t iconX0, iconY0;
613 iconX0 = obj->obj.area.x0
614 + (obj->obj.area.width - (textWidth + obj->icon->width +
ICON_TEXT_SPACE)) / 2;
617 iconX0 = obj->obj.area.x0 + (obj->obj.area.width - obj->icon->width) / 2;
620 "draw_button(), obj->obj.area.height = %d, obj->iconHeight = %d\n",
621 obj->obj.area.height,
623 iconY0 = obj->obj.area.y0 + (obj->obj.area.height - obj->icon->height) / 2;
625 rectArea.backgroundColor = obj->innerColor;
626 rectArea.x0 = iconX0;
627 rectArea.y0 = iconY0;
628 rectArea.width = obj->icon->width;
629 rectArea.height = obj->icon->height;
630 rectArea.bpp = obj->icon->bpp;
643 if (obj->buffer == NULL) {
644 if (obj->onDrawCallback != NULL) {
645 iconDetails = obj->onDrawCallback(obj->token);
652 iconDetails = obj->buffer;
654 if (iconDetails == NULL) {
659 obj->obj.area.width = iconDetails->width;
660 obj->obj.area.height = iconDetails->height;
661 obj->obj.area.bpp = iconDetails->bpp;
662 if (computePosition) {
663 compute_position((
nbgl_obj_t *) obj, prevObj);
665 LOG_DEBUG(
OBJ_LOGGER,
"draw_image(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
667 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
669 colorMap = obj->foregroundColor;
675 colorMap = obj->foregroundColor;
687 obj->obj.area.width = C_switch_60_40.width;
688 obj->obj.area.height = C_switch_60_40.height;
689 if (computePosition) {
690 compute_position((
nbgl_obj_t *) obj, prevObj);
692 LOG_DEBUG(
OBJ_LOGGER,
"draw_switch(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
695 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
697 rectArea.x0 = obj->obj.area.x0;
698 rectArea.y0 = obj->obj.area.y0;
699 rectArea.width = obj->obj.area.width;
700 rectArea.height = obj->obj.area.height;
701 rectArea.backgroundColor = obj->obj.area.backgroundColor;
718 obj->obj.area.width = RADIO_WIDTH;
719 obj->obj.area.height = RADIO_HEIGHT;
720 if (computePosition) {
721 compute_position((
nbgl_obj_t *) obj, prevObj);
724 "draw_radioButton(), x0 = %d, y0 = %d, state = %d\n",
730 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
733 icon = &RADIO_OFF_ICON;
734 color_map = obj->borderColor;
737 icon = &RADIO_ON_ICON;
738 color_map = obj->activeColor;
740 rectArea.x0 = obj->obj.area.x0;
741 rectArea.y0 = obj->obj.area.y0;
742 rectArea.width = obj->obj.area.width;
743 rectArea.height = obj->obj.area.height;
744 rectArea.backgroundColor = obj->obj.area.backgroundColor;
745 rectArea.bpp = icon->bpp;
763 if (computePosition) {
764 compute_position((
nbgl_obj_t *) obj, prevObj);
767 obj->obj.area.y0 &= ~(VERTICAL_ALIGNMENT - 1);
769 "draw_progressBar(), x0 = %d, y0 = %d, level = %d %%\n",
775 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
777 if (obj->partialRedraw ==
false) {
779 if (obj->withBorder) {
783 obj->obj.area.backgroundColor,
784 obj->foregroundColor);
791 obj->previousWidth = 0;
795 uint16_t barWidth = ((obj->state * obj->obj.area.width)) / 100;
796 int barDiffWith = barWidth - obj->previousWidth;
798 memcpy(&barArea, &obj->obj.area,
sizeof(
nbgl_area_t));
800 if (barDiffWith > 0) {
802 barArea.x0 = obj->obj.area.x0 + obj->previousWidth;
803 barArea.width = barDiffWith;
804 barColor = obj->foregroundColor;
806 else if (barDiffWith < 0) {
808 barArea.x0 = obj->obj.area.x0 + obj->previousWidth + barDiffWith;
809 barArea.width = -barDiffWith;
810 barColor = obj->obj.area.backgroundColor;
813 if (barDiffWith != 0) {
819 if (obj->partialRedraw ==
true) {
820 obj->partialRedraw =
false;
822 obj->previousWidth = barWidth;
824 extendRefreshArea(&barArea);
825 objRefreshAreaDone =
true;
830 if (computePosition) {
831 compute_position((
nbgl_obj_t *) obj, prevObj);
834 "draw_progressBar(), x0 = %d, y0 = %d, level = %d %%\n",
840 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
843 if (obj->withBorder) {
847 obj->obj.area.backgroundColor,
848 obj->foregroundColor);
854 levelWidth =
MIN((obj->obj.area.width - 2) * obj->state / 100, (obj->obj.area.width - 2));
855 if (levelWidth > 0) {
857 rectArea.width = levelWidth;
858 rectArea.height = obj->obj.area.height - 2;
859 rectArea.backgroundColor = obj->foregroundColor;
861 rectArea.x0 = obj->obj.area.x0 + 1;
862 rectArea.y0 = obj->obj.area.y0 + 1;
880 bool computePosition)
886 if (obj->nbPages < 2) {
893 obj->obj.area.height = 4;
895 if (computePosition) {
896 compute_position((
nbgl_obj_t *) obj, prevObj);
899 "draw_pageIndicator(), x0 = %d, y0 = %d, page = %d/%d\n",
906 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
908 dashWidth = (obj->obj.area.width - ((obj->nbPages - 1) * INTER_DASHES)) / obj->nbPages;
909 rectArea.x0 = obj->obj.area.x0;
910 rectArea.y0 = obj->obj.area.y0;
911 rectArea.width = dashWidth;
912 rectArea.height = obj->obj.area.height;
913 rectArea.backgroundColor = obj->obj.area.backgroundColor;
916 for (i = 0; i < obj->activePage; i++) {
919 rectArea.x0 += dashWidth + INTER_DASHES;
922 rectArea.x0 += dashWidth + INTER_DASHES;
925 for (; i < obj->nbPages; i++) {
927 rectArea.x0 += dashWidth + INTER_DASHES;
933 SPRINTF(navText,
"%d of %d", obj->activePage + 1, obj->nbPages);
939 if (computePosition) {
940 compute_position((
nbgl_obj_t *) obj, prevObj);
943 "draw_pageIndicator(), x0 = %d, y0 = %d, page = %d/%d\n",
950 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
953 rectArea.x0 = obj->obj.area.x0;
954 rectArea.y0 = obj->obj.area.y0;
955 rectArea.width = obj->obj.area.width;
956 rectArea.height = obj->obj.area.height;
957 rectArea.backgroundColor = obj->obj.area.backgroundColor;
975 uint16_t textWidth, fontHeight, lineHeight, textHeight, midHeight;
976 uint8_t line, nbLines;
980 if (computePosition) {
981 compute_position((
nbgl_obj_t *) obj, prevObj);
984 if (obj->onDrawCallback != NULL) {
985 obj->text = obj->onDrawCallback(obj->token);
994 "draw_textArea(), wrapping = %d, x0 = %d, y0 = %d, width = %d, height = %d, text = %s\n",
999 obj->obj.area.height,
1003 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1006#ifdef SCREEN_SIZE_NANO
1007 if (obj->style == INVERTED_COLORS) {
1008 obj->obj.area.backgroundColor =
WHITE;
1009 rectArea.backgroundColor =
BLACK;
1015 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1016 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1018 rectArea.x0 = obj->obj.area.x0;
1019 rectArea.y0 = obj->obj.area.y0;
1020 rectArea.width = obj->obj.area.width;
1021 rectArea.height = obj->obj.area.height;
1022#ifdef SCREEN_SIZE_NANO
1023 if (obj->style == INVERTED_COLORS) {
1036 if (obj->autoHideLongLine ==
true) {
1037#ifdef BUILD_SCREENSHOTS
1039 store_string_infos(text,
1048 if (textWidth > obj->obj.area.width) {
1049 uint16_t lineWidth, lineLen;
1053 rectArea.x0 = obj->obj.area.x0;
1054 rectArea.y0 = obj->obj.area.y0 + (obj->obj.area.height - fontHeight) / 2;
1055 rectArea.width = dotsWidth;
1059 fontId, text, obj->obj.area.width - dotsWidth, &lineLen, &lineWidth);
1060 rectArea.x0 += dotsWidth;
1061 rectArea.width = lineWidth;
1073#ifdef BUILD_SCREENSHOTS
1075 text, fontId, &obj->obj.area, obj->wrapping, last_nb_lines, last_nb_pages, last_bold_state);
1078 if ((obj->nbMaxLines > 0) && (obj->nbMaxLines < nbLines)) {
1079 nbLines = obj->nbMaxLines;
1082 textHeight = (nbLines - 1) * lineHeight + fontHeight;
1084 midHeight = (obj->obj.area.height - textHeight) / 2;
1085#ifdef SCREEN_SIZE_NANO
1086 if (obj->style == INVERTED_COLORS) {
1091 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1092 rectArea.height = fontHeight;
1094 for (line = 0; line < nbLines; line++) {
1095 uint16_t lineWidth, lineLen;
1098 fontId, text, obj->obj.area.width, &lineLen, &lineWidth, obj->wrapping);
1099 if (obj->textAlignment ==
MID_LEFT) {
1100 rectArea.x0 = obj->obj.area.x0;
1102 else if (obj->textAlignment ==
CENTER) {
1103 rectArea.x0 = obj->obj.area.x0 + (obj->obj.area.width - lineWidth) / 2;
1105 else if (obj->textAlignment ==
MID_RIGHT) {
1106 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - lineWidth;
1111 rectArea.y0 = obj->obj.area.y0 + midHeight + line * lineHeight;
1112 rectArea.width = lineWidth;
1115 "draw_textArea(), [%s] line %d, lineLen %d lineWidth = %d, obj.area.height = %d, "
1116 "textHeight = %d, nbMaxLines = %d, wrapping = %d\n",
1121 obj->obj.area.height,
1125 if ((obj->nbMaxLines == 0) || (line < (obj->nbMaxLines - 1))) {
1126 fontId =
nbgl_drawText(&rectArea, text, lineLen, fontId, obj->textColor);
1133 if ((lineWidth + dotsWidth) >= obj->obj.area.width) {
1136 nbgl_drawText(&rectArea, text, lineLen, obj->fontId, obj->textColor);
1140 rectArea.width = dotsWidth;
1141 nbgl_drawText(&rectArea,
"...", 3, obj->fontId, obj->textColor);
1143 nbgl_drawText(&rectArea, text, lineLen, fontId, obj->textColor);
1149 if (*text ==
'\n') {
1168 if (computePosition) {
1169 compute_position((
nbgl_obj_t *) obj, prevObj);
1172 obj->obj.area.y0 &= ~0x3;
1174 "draw_qrCode(), x0 = %d, y0 = %d, width = %d, height = %d, text = %s\n",
1177 obj->obj.area.width,
1178 obj->obj.area.height,
1182 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1184 rectArea.x0 = obj->obj.area.x0;
1185 rectArea.y0 = obj->obj.area.y0;
1186 rectArea.width = obj->obj.area.width;
1187 rectArea.height = obj->obj.area.height;
1188 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1189 nbgl_drawQrCode(&rectArea, obj->version, obj->text, obj->foregroundColor);
1203#ifndef HAVE_SE_TOUCH
1204 obj->obj.area.width = KEYBOARD_WIDTH;
1205 obj->obj.area.height = KEYBOARD_KEY_HEIGHT;
1208 if (computePosition) {
1209 compute_position((
nbgl_obj_t *) obj, prevObj);
1212 OBJ_LOGGER,
"draw_keyboard(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1215 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1231#ifndef HAVE_SE_TOUCH
1232 obj->obj.area.height = KEYPAD_HEIGHT;
1233 obj->obj.area.width = KEYPAD_WIDTH;
1236 if (computePosition) {
1237 compute_position((
nbgl_obj_t *) obj, prevObj);
1239 obj->obj.area.y0 &= ~0x3;
1240 LOG_DEBUG(
OBJ_LOGGER,
"draw_keypad(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1243 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1262 obj->obj.area.width = SPINNER_WIDTH;
1263 obj->obj.area.height = SPINNER_HEIGHT;
1265 if (computePosition) {
1266 compute_position((
nbgl_obj_t *) obj, prevObj);
1268 obj->obj.area.y0 &= ~0x3;
1269 LOG_DEBUG(
OBJ_LOGGER,
"draw_spinner(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1272 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1277 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1279 if (obj->position == 0xFF) {
1281 rectArea.x0 = obj->obj.area.x0;
1282 rectArea.y0 = obj->obj.area.y0;
1283 rectArea.width = 20;
1284 rectArea.height = 4;
1286 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1288 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 4;
1290 rectArea.x0 = obj->obj.area.x0;
1293 rectArea.x0 = obj->obj.area.x0;
1294 rectArea.y0 = obj->obj.area.y0;
1296 rectArea.height = 12;
1297 rectArea.backgroundColor = foreColor;
1299 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1301 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1303 rectArea.x0 = obj->obj.area.x0;
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;
1313 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1317 rectArea.width = 20;
1318 rectArea.height = 4;
1319 switch (obj->position) {
1321 rectArea.x0 = obj->obj.area.x0;
1322 rectArea.y0 = obj->obj.area.y0;
1326 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1327 rectArea.y0 = obj->obj.area.y0;
1331 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1332 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 4;
1336 rectArea.x0 = obj->obj.area.x0;
1337 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 4;
1347 rectArea.height = 12;
1348 rectArea.backgroundColor = foreColor;
1349 switch (obj->position) {
1351 rectArea.x0 = obj->obj.area.x0;
1352 rectArea.y0 = obj->obj.area.y0;
1355 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1356 rectArea.y0 = obj->obj.area.y0;
1359 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1360 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1363 rectArea.x0 = obj->obj.area.x0;
1364 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1385 int textLen = strlen(obj->text);
1388 if (computePosition) {
1389 compute_position((
nbgl_obj_t *) obj, prevObj);
1393 "draw_textEntry(), x0 = %d, y0 = %d, width = %d, height = %d\n",
1396 obj->obj.area.width,
1397 obj->obj.area.height);
1400 obj->obj.area.backgroundColor =
WHITE;
1401 rectArea.backgroundColor =
BLACK;
1402 rectArea.x0 = obj->obj.area.x0;
1403 rectArea.y0 = obj->obj.area.y0;
1404 rectArea.width = obj->obj.area.width;
1405 rectArea.height = obj->obj.area.height;
1409 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1414 offsetX = (obj->obj.area.width - (obj->nbChars * 10)) / 2;
1416 for (
int i = 0; i < obj->nbChars; i++) {
1418 rectArea.x0 = obj->obj.area.x0 + offsetX + (i * 10);
1419 rectArea.y0 = obj->obj.area.y0 - 2;
1421 if (textLen < obj->nbChars) {
1423 digit = obj->text[i];
1435 else if (i < (obj->nbChars - 1)) {
1436 digit = obj->text[textLen - obj->nbChars + 1 + i];
1456 if (obj->buffer == NULL) {
1459 if (computePosition) {
1460 compute_position((
nbgl_obj_t *) obj, prevObj);
1464 OBJ_LOGGER,
"draw_image_file(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1465 obj->obj.area.backgroundColor =
WHITE;
1472 if (computePosition) {
1473 compute_position((
nbgl_obj_t *) obj, prevObj);
1476 if (obj->enableMasking) {
1494 LOG_DEBUG(
OBJ_LOGGER,
"draw_object() obj->type = %d, prevObj = %p\n", obj->type, prevObj);
1495 objRefreshAreaDone =
false;
1496 if ((obj->type <
NB_OBJ_TYPES) && (draw_functions[obj->type] != NULL)) {
1497 if ((obj->type !=
SCREEN) && (obj->parent == NULL)) {
1502 func(obj, prevObj, computePosition);
1509#ifdef HAVE_SERIALIZED_NBGL
1512 if (!objRefreshAreaDone) {
1513 extendRefreshArea(&obj->area);
1531 draw_object(obj, prevObj, computePosition);
1537 OBJ_LOGGER,
"draw_obj_and_chidren(): container->children = %p\n", container->children);
1539 if (container->children != NULL) {
1540 for (i = 0; i < container->nbChildren; i++) {
1541 nbgl_obj_t *current = container->children[i];
1542 if (current != NULL) {
1544 draw_obj_and_chidren(current, prev,
true);
1545 if (current->alignTo == NULL) {
1563 x1 = refreshArea.x0 + refreshArea.width;
1564 y1 = refreshArea.y0 + refreshArea.height;
1567 if (area->x0 < refreshArea.x0) {
1569 refreshArea.x0 =
MAX(0, area->x0);
1572 if (((area->x0 + area->width) > x1) || (refreshArea.width == 0)) {
1574 x1 =
MIN(SCREEN_WIDTH, area->x0 + area->width);
1577 if (area->y0 < refreshArea.y0) {
1579 refreshArea.y0 =
MAX(0, area->y0) & ~(VERTICAL_ALIGNMENT - 1);
1582 if (((area->y0 + area->height) > y1) || (refreshArea.height == 0)) {
1584 y1 =
MIN(SCREEN_HEIGHT, area->y0 + area->height);
1586 y1 = (y1 + (VERTICAL_ALIGNMENT - 1)) & ~(VERTICAL_ALIGNMENT - 1);
1590 if (x1 > SCREEN_WIDTH) {
1592 "extendRefreshArea: Impossible area x0 = %d width %d\n",
1596 if (y1 > SCREEN_HEIGHT) {
1599 "extendRefreshArea: Impossible area y0 = %d height %d\n",
1601 refreshArea.height);
1607 refreshArea.width = x1 - refreshArea.x0;
1608 refreshArea.height = y1 - refreshArea.y0;
1611 if (area->bpp > refreshArea.bpp) {
1612 refreshArea.bpp = area->bpp;
1623 bool computePosition =
false;
1629 if (obj->type ==
SCREEN) {
1631 computePosition =
true;
1637 while (parent->parent != NULL) {
1638 parent = parent->parent;
1640 if (parent->type ==
SCREEN) {
1649 if (objDrawingDisabled && fromApp) {
1652 draw_obj_and_chidren(obj, NULL, computePosition);
1672 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1678 "nbgl_refreshSpecial(), x0,y0 = [%d, %d], w,h = [%d, %d]\n",
1682 refreshArea.height);
1688 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1694 "nbgl_refreshSpecialNoPoff(), x0,y0 = [%d, %d], w,h = [%d, %d]\n",
1698 refreshArea.height);
1708 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1720#ifdef HAVE_SERIALIZED_NBGL
1723 refreshArea.x0 = SCREEN_WIDTH - 1;
1724 refreshArea.width = 0;
1725 refreshArea.y0 = SCREEN_HEIGHT - 1;
1726 refreshArea.height = 0;
1739 objDrawingDisabled =
false;
1752 objDrawingDisabled = !enable;
1774 while (parent->parent != NULL) {
1775 parent = parent->parent;
1777 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.
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)