11#include "app_config.h"
19#include "os_helpers.h"
23#include "os_io_seph_ux.h"
24#ifdef HAVE_SERIALIZED_NBGL
27#ifdef BUILD_SCREENSHOTS
28#include "json_scenario.h"
35#define NB_MAX_LETTERS 9
37#if defined(TARGET_STAX)
38#define INTER_DASHES 10
39#define SPINNER_DASH_WIDTH 22
40#define SPINNER_DASH_HEIGHT 14
41#define SPINNER_DASH_STROKE 4
42#define PROGRESS_STROKE 3
43#elif defined(TARGET_FLEX)
45#define SPINNER_DASH_WIDTH 24
46#define SPINNER_DASH_HEIGHT 16
47#define SPINNER_DASH_STROKE 4
48#define PROGRESS_STROKE 3
49#elif defined(TARGET_APEX)
51#define SPINNER_DASH_WIDTH 15
52#define SPINNER_DASH_HEIGHT 10
53#define SPINNER_DASH_STROKE 2
54#define PROGRESS_STROKE 2
75 bool computePosition);
105static bool objDrawingDisabled;
108static bool objRefreshAreaDone;
148#ifdef BUILD_SCREENSHOTS
150extern uint16_t last_nb_lines, last_nb_pages;
151extern bool last_bold_state, verbose;
170 "compute_relativePosition() without align to, parent->layout = %d, prevObj = %p\n",
175 obj->rel_x0 = obj->alignmentMarginX;
176 if (prevObj != NULL) {
177 obj->rel_y0 = prevObj->rel_y0 + prevObj->area.height + obj->alignmentMarginY;
180 obj->rel_y0 = obj->alignmentMarginY;
184 if (prevObj != NULL) {
185 obj->rel_x0 = prevObj->rel_x0 + prevObj->area.width + obj->alignmentMarginX;
188 obj->rel_x0 = obj->alignmentMarginX;
190 obj->rel_y0 = obj->alignmentMarginY;
195 if (alignToObj == NULL) {
196 alignToObj = obj->parent;
203 if (alignToObj == obj->parent) {
205 switch (obj->alignment) {
207 obj->rel_x0 = obj->alignmentMarginX;
208 obj->rel_y0 = obj->alignmentMarginY;
212 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
213 obj->rel_y0 = obj->alignmentMarginY;
217 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
218 obj->rel_y0 = obj->alignmentMarginY;
221 obj->rel_x0 = obj->alignmentMarginX;
223 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
227 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
229 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
233 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
235 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
238 obj->rel_x0 = obj->alignmentMarginX;
240 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
244 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
246 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
250 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
252 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
261 switch (obj->alignment) {
263 obj->rel_x0 = alignToObj->rel_x0 + obj->alignmentMarginX;
264 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
267 obj->rel_x0 = alignToObj->rel_x0
268 + (alignToObj->area.width - obj->area.width) / 2
269 + obj->alignmentMarginX;
270 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
273 obj->rel_x0 = alignToObj->rel_x0 + (alignToObj->area.width - obj->area.width)
274 - obj->alignmentMarginX;
275 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
279 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
280 obj->rel_y0 = alignToObj->rel_y0 + obj->alignmentMarginY;
283 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
284 obj->rel_y0 = alignToObj->rel_y0
285 + (alignToObj->area.height - obj->area.height) / 2
286 + obj->alignmentMarginY;
289 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
290 obj->rel_y0 = alignToObj->rel_y0 + (alignToObj->area.height - obj->area.height)
291 + obj->alignmentMarginY;
296 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
297 obj->rel_y0 = alignToObj->rel_y0 + obj->alignmentMarginY;
301 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
302 obj->rel_y0 = alignToObj->rel_y0
303 + (alignToObj->area.height - obj->area.height) / 2
304 + obj->alignmentMarginY;
308 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
309 obj->rel_y0 = alignToObj->rel_y0 + (alignToObj->area.height - obj->area.height)
310 + obj->alignmentMarginY;
314 obj->rel_x0 = alignToObj->rel_x0 + obj->alignmentMarginX;
316 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
319 obj->rel_x0 = alignToObj->rel_x0
320 + (alignToObj->area.width - obj->area.width) / 2
321 + obj->alignmentMarginX;
323 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
326 obj->rel_x0 = alignToObj->rel_x0 + (alignToObj->area.width - obj->area.width)
327 - obj->alignmentMarginX;
329 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
343 compute_relativePosition(obj, prevObj);
345 if (parent == NULL) {
354 obj->area.x0 = parent->obj.area.x0 + obj->rel_x0;
355 obj->area.y0 = parent->obj.area.y0 + obj->rel_y0;
357 if ((obj->area.x0 + obj->area.width) > SCREEN_WIDTH) {
358#ifdef BUILD_SCREENSHOTS
359 obj->area.width = SCREEN_WIDTH - obj->area.x0;
361 if (!obj->area.width) {
367 "compute_position(), forbidden width, obj->type = %d, x0=%d, width=%d\n",
374 if ((obj->area.y0 + obj->area.height) > SCREEN_HEIGHT) {
375#ifdef BUILD_SCREENSHOTS
376 obj->area.height = SCREEN_HEIGHT - obj->area.y0;
378 if (!obj->area.height) {
379 obj->area.height = 1;
384 "compute_position(), forbidden height, obj->type = %d, y0=%d, height=%d\n",
398 UNUSED(computePosition);
400 rectArea.backgroundColor = obj->obj.area.backgroundColor;
401 rectArea.x0 = obj->obj.area.x0;
402 rectArea.y0 = obj->obj.area.y0;
403 rectArea.width = obj->obj.area.width;
404 rectArea.height = obj->obj.area.height;
410 if (computePosition) {
411 compute_position((
nbgl_obj_t *) obj, prevObj);
414 "draw_container(), x0 = %d, y0 = %d, width = %d, height = %d\n",
418 obj->obj.area.height);
420 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
421 if (obj->forceClean) {
437 uint16_t textWidth = 0;
438 const char *text = NULL;
439#define ICON_TEXT_SPACE 12
441 if (computePosition) {
442 compute_position((
nbgl_obj_t *) obj, prevObj);
445 "draw_button(), x0 = %d, y0 = %d, width = %d, height = %d\n",
449 obj->obj.area.height);
452 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
454 if ((obj->innerColor == obj->borderColor)
455 && (obj->innerColor != obj->obj.area.backgroundColor)) {
474 if (obj->onDrawCallback != NULL) {
475 obj->text = obj->onDrawCallback(obj->token);
482 rectArea.x0 = obj->obj.area.x0;
483 rectArea.y0 = obj->obj.area.y0;
486 rectArea.y0 += (obj->obj.area.height - rectArea.height) / 2;
487 rectArea.width = obj->obj.area.width;
488 if (obj->icon != NULL) {
496#ifdef BUILD_SCREENSHOTS
497 store_string_infos(text, obj->fontId, &rectArea,
true, 1, 1,
false);
501 if (textWidth < rectArea.width) {
502 rectArea.x0 += (rectArea.width - textWidth) / 2;
505 rectArea.backgroundColor = obj->innerColor;
506 nbgl_drawText(&rectArea, text, textLen, obj->fontId, obj->foregroundColor);
509 if (obj->icon != NULL) {
510 uint16_t iconX0, iconY0;
514 iconX0 = obj->obj.area.x0
515 + (obj->obj.area.width - (textWidth + obj->icon->width +
ICON_TEXT_SPACE)) / 2;
518 iconX0 = obj->obj.area.x0 + (obj->obj.area.width - obj->icon->width) / 2;
521 "draw_button(), obj->obj.area.height = %d, obj->iconHeight = %d\n",
522 obj->obj.area.height,
524 iconY0 = obj->obj.area.y0 + (obj->obj.area.height - obj->icon->height) / 2;
526 rectArea.backgroundColor = obj->innerColor;
527 rectArea.x0 = iconX0;
528 rectArea.y0 = iconY0;
529 rectArea.width = obj->icon->width;
530 rectArea.height = obj->icon->height;
531 rectArea.bpp = obj->icon->bpp;
548 if (computePosition) {
549 compute_position((
nbgl_obj_t *) obj, prevObj);
551 LOG_DEBUG(
OBJ_LOGGER,
"draw_line(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
553 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
555 "draw_line(), backgroundColor = %d, lineColor = %d\n",
556 obj->obj.area.backgroundColor,
558 rectArea.x0 = obj->obj.area.x0;
559 rectArea.y0 = obj->obj.area.y0;
560 rectArea.backgroundColor = obj->obj.area.backgroundColor;
562 rectArea.width = obj->obj.area.width = obj->thickness;
563 rectArea.height = obj->obj.area.height;
567 rectArea.width = obj->obj.area.width;
568 rectArea.height = obj->obj.area.height = obj->thickness;
581static void draw_button(nbgl_button_t *obj, nbgl_obj_t *prevObj, bool computePosition)
583 uint16_t textWidth = 0;
584 const char *text = NULL;
585#define ICON_TEXT_SPACE 2
587 if (computePosition) {
588 compute_position((
nbgl_obj_t *) obj, prevObj);
591 "draw_button(), x0 = %d, y0 = %d, width = %d, height = %d\n",
595 obj->obj.area.height);
598 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
603 if (obj->onDrawCallback != NULL) {
604 obj->text = obj->onDrawCallback(obj->token);
611 rectArea.x0 = obj->obj.area.x0;
612 rectArea.y0 = obj->obj.area.y0;
615 rectArea.y0 += (obj->obj.area.height - rectArea.height) / 2;
616 rectArea.width = obj->obj.area.width;
617 if (obj->icon != NULL) {
626 if (textWidth < rectArea.width) {
627 rectArea.x0 += (rectArea.width - textWidth) / 2;
630 rectArea.backgroundColor = obj->innerColor;
631 nbgl_drawText(&rectArea, text, textLen, obj->fontId, obj->foregroundColor);
634 if (obj->icon != NULL) {
635 uint16_t iconX0, iconY0;
639 iconX0 = obj->obj.area.x0
640 + (obj->obj.area.width - (textWidth + obj->icon->width +
ICON_TEXT_SPACE)) / 2;
643 iconX0 = obj->obj.area.x0 + (obj->obj.area.width - obj->icon->width) / 2;
646 "draw_button(), obj->obj.area.height = %d, obj->iconHeight = %d\n",
647 obj->obj.area.height,
649 iconY0 = obj->obj.area.y0 + (obj->obj.area.height - obj->icon->height) / 2;
651 rectArea.backgroundColor = obj->innerColor;
652 rectArea.x0 = iconX0;
653 rectArea.y0 = iconY0;
654 rectArea.width = obj->icon->width;
655 rectArea.height = obj->icon->height;
656 rectArea.bpp = obj->icon->bpp;
669 if (obj->buffer == NULL) {
670 if (obj->onDrawCallback != NULL) {
671 iconDetails = obj->onDrawCallback(obj->token);
678 iconDetails = obj->buffer;
680 if (iconDetails == NULL) {
685 obj->obj.area.width = iconDetails->width;
686 obj->obj.area.height = iconDetails->height;
687 obj->obj.area.bpp = iconDetails->bpp;
688 if (computePosition) {
689 compute_position((
nbgl_obj_t *) obj, prevObj);
691 LOG_DEBUG(
OBJ_LOGGER,
"draw_image(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
693 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
695 colorMap = obj->foregroundColor;
701 colorMap = obj->foregroundColor;
713 obj->obj.area.width = SWITCH_ICON.width;
714 obj->obj.area.height = SWITCH_ICON.height;
715 if (computePosition) {
716 compute_position((
nbgl_obj_t *) obj, prevObj);
718 LOG_DEBUG(
OBJ_LOGGER,
"draw_switch(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
721 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
723 rectArea.x0 = obj->obj.area.x0;
724 rectArea.y0 = obj->obj.area.y0;
725 rectArea.width = obj->obj.area.width;
726 rectArea.height = obj->obj.area.height;
727 rectArea.backgroundColor = obj->obj.area.backgroundColor;
730#if NB_COLOR_BITS == 1
737#if NB_COLOR_BITS == 1
752 obj->obj.area.width = RADIO_WIDTH;
753 obj->obj.area.height = RADIO_HEIGHT;
754 if (computePosition) {
755 compute_position((
nbgl_obj_t *) obj, prevObj);
758 "draw_radioButton(), x0 = %d, y0 = %d, state = %d\n",
764 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
767 icon = &RADIO_OFF_ICON;
768#if NB_COLOR_BITS == 1
769 color_map = obj->activeColor;
771 color_map = obj->borderColor;
775 icon = &RADIO_ON_ICON;
776 color_map = obj->activeColor;
778 rectArea.x0 = obj->obj.area.x0;
779 rectArea.y0 = obj->obj.area.y0;
780 rectArea.width = obj->obj.area.width;
781 rectArea.height = obj->obj.area.height;
782 rectArea.backgroundColor = obj->obj.area.backgroundColor;
783 rectArea.bpp = icon->bpp;
799 uint8_t stroke = PROGRESS_STROKE;
801 uint16_t barWidth = ((obj->state * obj->obj.area.width)) / 100;
803 if (computePosition) {
804 compute_position((
nbgl_obj_t *) obj, prevObj);
807 "draw_progressBar(), x0 = %d, y0 = %d, level = %d %%\n",
811 memcpy(&barArea, &obj->obj.area,
sizeof(
nbgl_area_t));
814 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
816 if (obj->partialRedraw ==
false) {
818 if (obj->withBorder) {
822 obj->obj.area.backgroundColor,
823 obj->foregroundColor);
830 obj->previousWidth = 0;
831 if (obj->state == 0) {
836 int barDiffWith = barWidth - obj->previousWidth;
839 if (barDiffWith > 0) {
841 barArea.x0 = obj->obj.area.x0 + obj->previousWidth;
842 barArea.width = barDiffWith;
843 barColor = obj->foregroundColor;
845 else if (barDiffWith < 0) {
847 barArea.x0 = obj->obj.area.x0 + obj->previousWidth + barDiffWith;
848 barArea.width = -barDiffWith;
849 barColor = obj->obj.area.backgroundColor;
852 if (barDiffWith != 0) {
858 if (obj->partialRedraw ==
true) {
859 obj->partialRedraw =
false;
861 obj->previousWidth = barWidth;
864 extendRefreshArea(&barArea);
865 objRefreshAreaDone =
true;
870 if (computePosition) {
871 compute_position((
nbgl_obj_t *) obj, prevObj);
874 "draw_progressBar(), x0 = %d, y0 = %d, level = %d %%\n",
880 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
883 if (obj->withBorder) {
887 obj->obj.area.backgroundColor,
888 obj->foregroundColor);
894 levelWidth =
MIN((obj->obj.area.width - 2) * obj->state / 100, (obj->obj.area.width - 2));
895 if (levelWidth > 0) {
897 rectArea.width = levelWidth;
898 rectArea.height = obj->obj.area.height - 2;
899 rectArea.backgroundColor = obj->foregroundColor;
901 rectArea.x0 = obj->obj.area.x0 + 1;
902 rectArea.y0 = obj->obj.area.y0 + 1;
920 bool computePosition)
926 if (obj->nbPages < 2) {
933 obj->obj.area.height = 4;
935 if (computePosition) {
936 compute_position((
nbgl_obj_t *) obj, prevObj);
939 "draw_pageIndicator(), x0 = %d, y0 = %d, page = %d/%d\n",
946 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
948 dashWidth = (obj->obj.area.width - ((obj->nbPages - 1) * INTER_DASHES)) / obj->nbPages;
949 rectArea.x0 = obj->obj.area.x0;
950 rectArea.y0 = obj->obj.area.y0;
951 rectArea.width = dashWidth;
953 rectArea.backgroundColor = obj->obj.area.backgroundColor;
956 for (i = 0; i < obj->activePage; i++) {
959 rectArea.x0 += dashWidth + INTER_DASHES;
962 rectArea.x0 += dashWidth + INTER_DASHES;
965 for (; i < obj->nbPages; i++) {
967 rectArea.x0 += dashWidth + INTER_DASHES;
973 SPRINTF(navText,
"%d of %d", obj->activePage + 1, obj->nbPages);
979 if (computePosition) {
980 compute_position((
nbgl_obj_t *) obj, prevObj);
983 "draw_pageIndicator(), x0 = %d, y0 = %d, page = %d/%d\n",
990 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
993 rectArea.x0 = obj->obj.area.x0;
994 rectArea.y0 = obj->obj.area.y0;
995 rectArea.width = obj->obj.area.width;
996 rectArea.height = obj->obj.area.height;
997 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1015 uint16_t textWidth, fontHeight, lineHeight, textHeight, midHeight;
1016 uint8_t line, nbLines;
1020 if (computePosition) {
1021 compute_position((
nbgl_obj_t *) obj, prevObj);
1024 if (obj->onDrawCallback != NULL) {
1025 obj->text = obj->onDrawCallback(obj->token);
1034 "draw_textArea(), wrapping = %d, x0 = %d, y0 = %d, width = %d, height = %d, text = %s\n",
1038 obj->obj.area.width,
1039 obj->obj.area.height,
1043 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1046#ifdef SCREEN_SIZE_NANO
1047 if (obj->style == INVERTED_COLORS) {
1048 obj->obj.area.backgroundColor =
WHITE;
1049 rectArea.backgroundColor =
BLACK;
1055 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1056 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1058 rectArea.x0 = obj->obj.area.x0;
1059 rectArea.y0 = obj->obj.area.y0;
1060 rectArea.width = obj->obj.area.width;
1061 rectArea.height = obj->obj.area.height;
1062#ifdef SCREEN_SIZE_NANO
1063 if (obj->style == INVERTED_COLORS) {
1076 if (obj->autoHideLongLine ==
true) {
1077#ifdef BUILD_SCREENSHOTS
1079 store_string_infos(text,
1088 if (textWidth > obj->obj.area.width) {
1089 uint16_t lineWidth, lineLen;
1093 rectArea.x0 = obj->obj.area.x0;
1094 rectArea.y0 = obj->obj.area.y0 + (obj->obj.area.height - fontHeight) / 2;
1095 rectArea.width = dotsWidth;
1099 fontId, text, obj->obj.area.width - dotsWidth, &lineLen, &lineWidth);
1100 rectArea.x0 += dotsWidth;
1101 rectArea.width = lineWidth;
1113#ifdef BUILD_SCREENSHOTS
1115 text, fontId, &obj->obj.area, obj->wrapping, last_nb_lines, last_nb_pages, last_bold_state);
1118 if ((obj->nbMaxLines > 0) && (obj->nbMaxLines < nbLines)) {
1119 nbLines = obj->nbMaxLines;
1122 textHeight = (nbLines - 1) * lineHeight + fontHeight;
1124 midHeight = (obj->obj.area.height - textHeight) / 2;
1125#ifdef SCREEN_SIZE_NANO
1126 if (obj->style == INVERTED_COLORS) {
1131 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1132 rectArea.height = fontHeight;
1134 for (line = 0; line < nbLines; line++) {
1135 uint16_t lineWidth, lineLen;
1138 fontId, text, obj->obj.area.width, &lineLen, &lineWidth, obj->wrapping);
1139 if (obj->textAlignment ==
MID_LEFT) {
1140 rectArea.x0 = obj->obj.area.x0;
1142 else if (obj->textAlignment ==
CENTER) {
1143 rectArea.x0 = obj->obj.area.x0 + (obj->obj.area.width - lineWidth) / 2;
1145 else if (obj->textAlignment ==
MID_RIGHT) {
1146 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - lineWidth;
1151 rectArea.y0 = obj->obj.area.y0 + midHeight + line * lineHeight;
1152 rectArea.width = lineWidth;
1155 "draw_textArea(), [%s] line %d, lineLen %d lineWidth = %d, obj.area.height = %d, "
1156 "textHeight = %d, nbMaxLines = %d, wrapping = %d\n",
1161 obj->obj.area.height,
1165 if ((obj->nbMaxLines == 0) || (line < (obj->nbMaxLines - 1))) {
1166 fontId =
nbgl_drawText(&rectArea, text, lineLen, fontId, obj->textColor);
1173 if ((lineWidth + dotsWidth) >= obj->obj.area.width) {
1176 nbgl_drawText(&rectArea, text, lineLen, obj->fontId, obj->textColor);
1180 rectArea.width = dotsWidth;
1181 nbgl_drawText(&rectArea,
"...", 3, obj->fontId, obj->textColor);
1183 nbgl_drawText(&rectArea, text, lineLen, fontId, obj->textColor);
1189 if (*text ==
'\n') {
1208 if (computePosition) {
1209 compute_position((
nbgl_obj_t *) obj, prevObj);
1212 obj->obj.area.y0 &= ~0x3;
1214 "draw_qrCode(), x0 = %d, y0 = %d, width = %d, height = %d, text = %s\n",
1217 obj->obj.area.width,
1218 obj->obj.area.height,
1222 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1224 rectArea.x0 = obj->obj.area.x0;
1225 rectArea.y0 = obj->obj.area.y0;
1226 rectArea.width = obj->obj.area.width;
1227 rectArea.height = obj->obj.area.height;
1228 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1229 nbgl_drawQrCode(&rectArea, obj->version, obj->text, obj->foregroundColor);
1243#ifndef HAVE_SE_TOUCH
1244 obj->obj.area.width = KEYBOARD_WIDTH;
1245 obj->obj.area.height = KEYBOARD_KEY_HEIGHT;
1248 if (computePosition) {
1249 compute_position((
nbgl_obj_t *) obj, prevObj);
1252 OBJ_LOGGER,
"draw_keyboard(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1255 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1271#ifndef HAVE_SE_TOUCH
1272 obj->obj.area.height = KEYPAD_HEIGHT;
1273 obj->obj.area.width = KEYPAD_WIDTH;
1276 if (computePosition) {
1277 compute_position((
nbgl_obj_t *) obj, prevObj);
1279 obj->obj.area.y0 &= ~0x3;
1280 LOG_DEBUG(
OBJ_LOGGER,
"draw_keypad(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1283 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1302 obj->obj.area.width = SPINNER_WIDTH;
1303 obj->obj.area.height = SPINNER_HEIGHT;
1305 if (computePosition) {
1306 compute_position((
nbgl_obj_t *) obj, prevObj);
1308 LOG_DEBUG(
OBJ_LOGGER,
"draw_spinner(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1311 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1316 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1318 if (obj->position == 0xFF) {
1320 rectArea.x0 = obj->obj.area.x0;
1321 rectArea.y0 = obj->obj.area.y0;
1322 rectArea.width = SPINNER_DASH_WIDTH;
1323 rectArea.height = SPINNER_DASH_STROKE;
1325 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1327 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1329 rectArea.x0 = obj->obj.area.x0;
1332 rectArea.x0 = obj->obj.area.x0;
1333 rectArea.y0 = obj->obj.area.y0;
1334 rectArea.width = SPINNER_DASH_STROKE;
1335 rectArea.height = SPINNER_DASH_HEIGHT;
1337 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1339 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1341 rectArea.x0 = obj->obj.area.x0;
1346 rectArea.x0 = obj->obj.area.x0;
1347 rectArea.y0 = obj->obj.area.y0;
1348 rectArea.width = obj->obj.area.width;
1349 rectArea.height = obj->obj.area.height;
1350 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1354 rectArea.width = SPINNER_DASH_WIDTH;
1355 rectArea.height = SPINNER_DASH_STROKE;
1356 switch (obj->position) {
1358 rectArea.x0 = obj->obj.area.x0;
1359 rectArea.y0 = obj->obj.area.y0;
1362 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1363 rectArea.y0 = obj->obj.area.y0;
1366 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1367 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 3;
1370 rectArea.x0 = obj->obj.area.x0;
1371 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 3;
1379 rectArea.width = SPINNER_DASH_STROKE;
1380 rectArea.height = SPINNER_DASH_HEIGHT;
1381 rectArea.backgroundColor = foreColor;
1382 switch (obj->position) {
1384 rectArea.x0 = obj->obj.area.x0;
1385 rectArea.y0 = obj->obj.area.y0;
1388 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1389 rectArea.y0 = obj->obj.area.y0;
1392 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1393 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1396 rectArea.x0 = obj->obj.area.x0;
1397 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1418 int textLen = strlen(obj->text);
1421 if (computePosition) {
1422 compute_position((
nbgl_obj_t *) obj, prevObj);
1426 "draw_textEntry(), x0 = %d, y0 = %d, width = %d, height = %d\n",
1429 obj->obj.area.width,
1430 obj->obj.area.height);
1433 obj->obj.area.backgroundColor =
WHITE;
1434 rectArea.backgroundColor =
BLACK;
1435 rectArea.x0 = obj->obj.area.x0;
1436 rectArea.y0 = obj->obj.area.y0;
1437 rectArea.width = obj->obj.area.width;
1438 rectArea.height = obj->obj.area.height;
1442 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1447 offsetX = (obj->obj.area.width - (obj->nbChars * 10)) / 2;
1449 for (
int i = 0; i < obj->nbChars; i++) {
1451 rectArea.x0 = obj->obj.area.x0 + offsetX + (i * 10);
1452 rectArea.y0 = obj->obj.area.y0 - 2;
1454 if (textLen < obj->nbChars) {
1456 digit = obj->text[i];
1468 else if (i < (obj->nbChars - 1)) {
1469 digit = obj->text[textLen - obj->nbChars + 1 + i];
1489 if (obj->buffer == NULL) {
1492 if (computePosition) {
1493 compute_position((
nbgl_obj_t *) obj, prevObj);
1497 OBJ_LOGGER,
"draw_image_file(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1498 obj->obj.area.backgroundColor =
WHITE;
1505 if (computePosition) {
1506 compute_position((
nbgl_obj_t *) obj, prevObj);
1509 if (obj->enableMasking) {
1527 LOG_DEBUG(
OBJ_LOGGER,
"draw_object() obj->type = %d, prevObj = %p\n", obj->type, prevObj);
1528 objRefreshAreaDone =
false;
1529 if ((obj->type <
NB_OBJ_TYPES) && (draw_functions[obj->type] != NULL)) {
1530 if ((obj->type !=
SCREEN) && (obj->parent == NULL)) {
1535 func(obj, prevObj, computePosition);
1542#ifdef HAVE_SERIALIZED_NBGL
1545 if (!objRefreshAreaDone) {
1546 extendRefreshArea(&obj->area);
1564 draw_object(obj, prevObj, computePosition);
1570 OBJ_LOGGER,
"draw_obj_and_chidren(): container->children = %p\n", container->children);
1572 if (container->children != NULL) {
1573 for (i = 0; i < container->nbChildren; i++) {
1574 nbgl_obj_t *current = container->children[i];
1575 if (current != NULL) {
1577 draw_obj_and_chidren(current, prev,
true);
1578 if (current->alignTo == NULL) {
1596 x1 = refreshArea.x0 + refreshArea.width;
1597 y1 = refreshArea.y0 + refreshArea.height;
1600 if (area->x0 < refreshArea.x0) {
1602 refreshArea.x0 =
MAX(0, area->x0);
1605 if (((area->x0 + area->width) > x1) || (refreshArea.width == 0)) {
1607 x1 =
MIN(SCREEN_WIDTH, area->x0 + area->width);
1610 if (area->y0 < refreshArea.y0) {
1612 refreshArea.y0 =
MAX(0, area->y0) & ~(VERTICAL_ALIGNMENT - 1);
1615 if (((area->y0 + area->height) > y1) || (refreshArea.height == 0)) {
1617 y1 =
MIN(SCREEN_HEIGHT, area->y0 + area->height);
1619 y1 = (y1 + (VERTICAL_ALIGNMENT - 1)) & ~(VERTICAL_ALIGNMENT - 1);
1623 if (x1 > SCREEN_WIDTH) {
1625 "extendRefreshArea: Impossible area x0 = %d width %d\n",
1629 if (y1 > SCREEN_HEIGHT) {
1632 "extendRefreshArea: Impossible area y0 = %d height %d\n",
1634 refreshArea.height);
1640 refreshArea.width = x1 - refreshArea.x0;
1641 refreshArea.height = y1 - refreshArea.y0;
1644 if (area->bpp > refreshArea.bpp) {
1645 refreshArea.bpp = area->bpp;
1656 bool computePosition =
false;
1657 bool fromApp =
false;
1662 if (obj->type ==
SCREEN) {
1664 computePosition =
true;
1670 while (parent->parent != NULL) {
1671 parent = parent->parent;
1673 if (parent->type ==
SCREEN) {
1682 if ((os_sched_current_task() == TASK_BOLOS_UX) == fromApp) {
1686 if (objDrawingDisabled && fromApp) {
1689 draw_obj_and_chidren(obj, NULL, computePosition);
1709 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1715 "nbgl_refreshSpecial(), x0,y0 = [%d, %d], w,h = [%d, %d]\n",
1719 refreshArea.height);
1725 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1731 "nbgl_refreshSpecialNoPoff(), x0,y0 = [%d, %d], w,h = [%d, %d]\n",
1735 refreshArea.height);
1745 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1757#ifdef HAVE_SERIALIZED_NBGL
1760 refreshArea.x0 = SCREEN_WIDTH - 1;
1761 refreshArea.width = 0;
1762 refreshArea.y0 = SCREEN_HEIGHT - 1;
1763 refreshArea.height = 0;
1776 objDrawingDisabled =
false;
1789 objDrawingDisabled = !enable;
1811 while (parent->parent != NULL) {
1812 parent = parent->parent;
1814 if (parent->type ==
SCREEN) {
#define LOG_WARN(__logger,...)
#define LOG_DEBUG(__logger,...)
#define LOG_FATAL(__logger,...)
Middle Level API of the new BOLOS Graphical Library.
void nbgl_drawIcon(nbgl_area_t *area, nbgl_transformation_t transformation, nbgl_color_map_t color_map, const nbgl_icon_details_t *icon)
Helper function to render an icon directly from its nbgl_icon_details_t structure.
nbgl_font_id_e nbgl_drawText(const nbgl_area_t *area, const char *text, uint16_t textLen, nbgl_font_id_e fontId, color_t fontColor)
This function draws the given single-line text, with the given parameters.
void nbgl_drawRoundedBorderedRect(const nbgl_area_t *area, nbgl_radius_t radius, uint8_t stroke, color_t innerColor, color_t borderColor)
This functions draws a rounded corners rectangle with a border, with the given parameters.
void nbgl_drawQrCode(const nbgl_area_t *area, nbgl_qrcode_version_t version, const char *text, color_t backgroundColor)
Draws the given text into a V10 QR code (QR code version is fixed using qrcodegen_VERSION_MIN/qrcodeg...
void nbgl_drawRoundedRect(const nbgl_area_t *area, nbgl_radius_t radius, color_t innerColor)
This functions draws a rounded corners rectangle (without border), with the given parameters.
void nbgl_getTextMaxLenAndWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t *len, uint16_t *width, bool wrapping)
compute the max width of the first line of the given text fitting in maxWidth
uint16_t nbgl_getSingleLineTextWidth(nbgl_font_id_e fontId, const char *text)
return the max width in pixels of the given text until the first or \0 is encountered
@ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp
bool nbgl_getTextMaxLenAndWidthFromEnd(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t *len, uint16_t *width)
compute the len and width of the given text fitting in the maxWidth, starting from end of text
uint8_t nbgl_getFontHeight(nbgl_font_id_e fontId)
return the height in pixels of the font with the given font ID
uint16_t nbgl_getTextWidth(nbgl_font_id_e fontId, const char *text)
return the max width in pixels of the given text (can be multiline)
uint16_t nbgl_getTextLength(const char *text)
return the number of bytes of the given text, excluding final ' ' or '\0'
uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
compute the number of lines of the given text fitting in the given maxWidth
uint8_t nbgl_getFontLineHeight(nbgl_font_id_e fontId)
return the height in pixels of the line of font with the given font ID
uint16_t nbgl_getSingleLineTextWidthInLen(nbgl_font_id_e fontId, const char *text, uint16_t maxLen)
return the max width in pixels of the given text until the first or \0 is encountered,...
Font screen low-Level driver API, to draw elementary forms.
void nbgl_frontDrawLine(const nbgl_area_t *area, uint8_t dotStartIdx, color_t lineColor)
void nbgl_frontControlAreaMasking(uint8_t mask_index, nbgl_area_t *masked_area_or_null)
void nbgl_frontDrawImage(const nbgl_area_t *area, const uint8_t *buffer, nbgl_transformation_t transformation, nbgl_color_map_t colorMap)
void nbgl_frontDrawImageFile(const nbgl_area_t *area, const uint8_t *buffer, nbgl_color_map_t colorMap, const uint8_t *uzlib_chunk_buffer)
void nbgl_frontRefreshArea(const nbgl_area_t *area, nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
void nbgl_frontDrawRect(const nbgl_area_t *area)
void nbgl_objDraw(nbgl_obj_t *obj)
This function draws or redraws the given object and its children (recursive version)
void nbgl_refresh(void)
This functions refreshes the actual screen on display with what has changed since the last refresh.
void nbgl_refreshReset(void)
This functions resets all changes since the last refresh.
void nbgl_objAllowDrawing(bool enable)
This functions enables or disables drawing/refresh for all further calls.
void(* draw_function_t)(nbgl_obj_t *obj, nbgl_obj_t *prevObj, bool computePosition)
void nbgl_refreshSpecial(nbgl_refresh_mode_t mode)
This functions refreshes the actual screen on display with what has changed since the last refresh,...
bool nbgl_objIsUx(nbgl_obj_t *obj)
This function returns true if the object belongs to a UxScreen.
void nbgl_refreshSpecialWithPostRefresh(nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
uint8_t * nbgl_objGetRAMBuffer(void)
This function is used to get the all purpose RAM buffer.
uint8_t ramBuffer[GZLIB_UNCOMPRESSED_CHUNK]
bool nbgl_refreshIsNeeded(void)
This functions returns true if there is something to refresh.
void nbgl_objInit(void)
This functions inits all internal of nbgl objects layer.
API to draw all basic graphic objects.
struct PACKED__ nbgl_line_s nbgl_line_t
struct to represent a vertical or horizontal line
struct PACKED__ nbgl_navigation_bar_s nbgl_page_indicator_t
struct to represent a navigation bar (PAGE_INDICATOR type) There can be up to 5 page indicators,...
struct PACKED__ nbgl_radio_s nbgl_radio_t
struct to represent a radio button (RADIO_BUTTON type)
struct PACKED__ nbgl_text_area_s nbgl_text_area_t
struct to represent a text area (TEXT_AREA type)
struct PACKED__ nbgl_progress_bar_s nbgl_progress_bar_t
struct to represent a progress bar (PROGRESS_BAR type)
struct PACKED__ nbgl_keypad_s nbgl_keypad_t
struct to represent a keypad (KEYPAD type)
struct PACKED__ nbgl_mask_control_s nbgl_mask_control_t
struct PACKED__ nbgl_text_entry_s nbgl_text_entry_t
struct to represent a text entry area (TEXT_ENTRY type)
struct PACKED__ nbgl_keyboard_s nbgl_keyboard_t
struct to represent a keyboard (KEYBOARD type)
struct PACKED__ nbgl_image_s nbgl_image_t
struct to represent an image (IMAGE type)
struct PACKED__ nbgl_button_s nbgl_button_t
struct to represent a button (BUTTON type) that can contain a text and/or an icon
void nbgl_objDrawKeyboard(nbgl_keyboard_t *kbd)
This function draws a keyboard object.
#define NB_MAX_PAGES_WITH_DASHES
void nbgl_objDrawKeypad(nbgl_keypad_t *kbd)
This function draws a keypad object.
struct PACKED__ nbgl_container_s nbgl_container_t
struct to represent a container (CONTAINER type)
@ PROGRESSIVE_INDICATOR
all dashes before active page are black
struct PACKED__ nbgl_switch_s nbgl_switch_t
struct to represent a switch (size is fixed) (SWITCH type)
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
struct PACKED__ nbgl_spinner_s nbgl_spinner_t
struct to represent a "spinner", represented by the Ledger corners, in gray, with one of the corners ...
struct PACKED__ nbgl_image_file_s nbgl_image_file_t
struct to represent an image file object (IMAGE_FILE type) The source of the data is an image file wi...
struct PACKED__ nbgl_qrcode_s nbgl_qrcode_t
struct to represent a QR code (QR_CODE type), whose size is fixed
struct PACKED__ nbgl_screen_s nbgl_screen_t
struct to represent a screen (SCREEN type)
void nbgl_touchInit(bool fromUx)
Function to initialize the touch context.
nbgl_post_refresh_t
Post refresh modes.
@ POST_REFRESH_FORCE_POWER_OFF
Force screen power off after refresh.
uint8_t nbgl_color_map_t
Represents the color_map to be used for 2BPP image, or the foreground color for 1BPP image.
@ RADIUS_0_PIXELS
no radius (square angle)
@ VERTICAL
from top to bottom
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
#define GZLIB_UNCOMPRESSED_CHUNK
size of gzlib uncompression buffer in bytes
@ NO_ALIGNMENT
used when parent container layout is used
@ LEFT_TOP
on outside left
@ LEFT_BOTTOM
on outside left
@ RIGHT_TOP
on outside right
@ RIGHT_BOTTOM
on outside right
@ IMAGE
Bitmap (y and height must be multiple of 4 on Stax)
@ IMAGE_FILE
Image file (with Ledger compression)
@ TEXT_ENTRY
area for entered text, only for Nanos
@ SWITCH
Switch to turn on/off something.
@ RADIO_BUTTON
Indicator to inform whether something is on or off.
@ BUTTON
Rounded rectangle button with icon and/or text.
@ PROGRESS_BAR
horizontal bar to indicate progression of something (between 0% and 100%)
@ PAGE_INDICATOR
horizontal bar to indicate position within pages
@ LINE
Vertical or Horizontal line.
@ MASK_CONTROL
OS-specific object to enable/disable masked area.
@ CONTAINER
Empty container.
@ TEXT_AREA
Area to contain text line(s)
#define NO_TRANSFORMATION
@ NBGL_BPP_1
1 bit per pixel
@ NBGL_BPP_2
2 bits per pixel
struct PACKED__ nbgl_area_s nbgl_area_t
Represents a rectangle area of the screen.
nbgl_refresh_mode_t
different modes of refresh for nbgl_refreshSpecial()
@ FULL_COLOR_CLEAN_REFRESH
to be used for lock screen display (cleaner but longer refresh)