14#include "nbgl_layout_internal_nanos.h"
21#include "os_helpers.h"
28#define NB_MAX_LAYOUTS 3
31#define NB_MAX_SCREEN_CHILDREN 7
34#define ELLIPSIS_SIZE sizeof(ELLIPSIS)
66 if ((screen->index ==
gLayout[i].layer) && (
gLayout[i].nbChildren > 0)) {
75 "touchCallback(): screen->index = %d, buttonEvent = %d, no matching active layout\n",
85 nbgl_keypadCallback(kpd, buttonEvent);
94 nbgl_keyboardCallback(kbd, buttonEvent);
121 layout->
children[layout->nbChildren] = obj;
122 layout->nbChildren++;
135static void getButtonTextLen(
const char *text,
147 while ((*len > 0) && ((text[*len] & 0xC0) == 0x80)) {
172 const char *text = textArea->text;
177 uint16_t firstLinesLen = 0;
178 uint16_t lastLineStart = 0;
179 uint16_t lastLineLen = 0;
180 uint16_t lastLineWidth = 0;
186 textArea->fontId, text,
AVAILABLE_WIDTH, nbLines - 1, &firstLinesLen,
true);
188 lastLineStart = (text[firstLinesLen] ==
'\n') ? (firstLinesLen + 1) : firstLinesLen;
191 if (firstLinesLen == 0) {
192 textArea->text = NULL;
194 textArea->len = firstLinesLen;
195 textArea->nbMaxLines = nbLines - 1;
196 textArea->obj.area.height = (nbLines - 1) * lineHeight;
197 textArea->obj.alignmentMarginY += (areaHeight - nbLines * lineHeight) / 2;
201 lastLineArea->textColor =
WHITE;
202 lastLineArea->fontId = textArea->fontId;
203 lastLineArea->obj.alignTo = (
nbgl_obj_t *) textArea;
204 container->children[2] = (
nbgl_obj_t *) lastLineArea;
207 &text[lastLineStart],
213 lastLineArea->text = (lastLineLen > 0) ? &text[lastLineStart] : NULL;
214 lastLineArea->len = lastLineLen;
215 lastLineArea->nbMaxLines = 1;
216 lastLineArea->wrapping =
false;
217 lastLineArea->textAlignment =
CENTER;
218 lastLineArea->obj.area.width = lastLineWidth;
219 lastLineArea->obj.area.height = lineHeight;
222 lastLineArea->obj.alignmentMarginX = -(ellipsisWidth / 2);
226 ellipsisArea->textColor =
WHITE;
227 ellipsisArea->text = (
const char *) PIC(ELLIPSIS);
228 ellipsisArea->fontId = textArea->fontId;
229 ellipsisArea->textAlignment =
CENTER;
230 ellipsisArea->obj.area.width = ellipsisWidth;
231 ellipsisArea->obj.area.height = lineHeight;
233 ellipsisArea->obj.alignTo = (
nbgl_obj_t *) lastLineArea;
234 container->children[3] = (
nbgl_obj_t *) ellipsisArea;
246uint16_t layoutGetButtonRowLen(
const char *text, uint16_t *len, uint16_t *width)
252 text,
AVAILABLE_WIDTH - BUTTON_MARGIN_Y, NB_MAX_CHAR_IN_BUTTON_ROW - 1, len, width);
255 if (text[consumed] ==
'\n') {
259 if ((consumed == 0) && (text[0] !=
'\0')) {
276 if (description->
modal) {
277 if (
gLayout[1].nbChildren == 0) {
280 else if (
gLayout[2].nbChildren == 0) {
289 if (layout == NULL) {
299 if (description->
modal) {
328 if (layout == NULL) {
335 image->foregroundColor =
WHITE;
343 image->foregroundColor =
WHITE;
370 if (style == BUTTON_INFO) {
371 return layoutAddText(layout, text, subText, style, NB_MAX_BUTTON_ROWS_PUBLIC,
true);
373 return layoutAddText(layout, text, subText, style, 0,
false);
402 uint16_t fullHeight = 0;
404 uint8_t subTextMaxLines = 0;
405 uint16_t subTextNbLines = 0;
408 if (layout == NULL) {
414 container->nbChildren = 1;
415 if (subText != NULL) {
416 if (style == BUTTON_INFO) {
417 subTextMaxLines = ((nbMaxLines > 0) && (nbMaxLines < NB_MAX_BUTTON_ROWS))
419 : NB_MAX_BUTTON_ROWS;
421 container->nbChildren += subTextMaxLines;
425 subTextMaxLines = ((nbMaxLines > 0) && (nbMaxLines < (
NB_MAX_LINES - 1)))
432 container->nbChildren += ((subTextNbLines > subTextMaxLines) && ellipsis) ? 3 : 1;
440 textArea->textColor =
WHITE;
441 textArea->text = PIC(text);
442 textArea->textAlignment =
CENTER;
456 textArea->fontId, textArea->text,
AVAILABLE_WIDTH, nbLines, &len,
true);
460 textArea->obj.area.height = nbLines * font->
line_height;
461 textArea->wrapping =
true;
463 fullHeight += textArea->obj.area.height;
464 container->children[0] = (
nbgl_obj_t *) textArea;
466 if (subText != NULL) {
467 if (style != BUTTON_INFO) {
469 textArea->textColor =
WHITE;
470 textArea->text = PIC(subText);
471 textArea->wrapping =
true;
474 nbLines = subTextNbLines;
476 bool truncated = (nbLines > subTextMaxLines);
479 nbLines = subTextMaxLines;
480 textArea->nbMaxLines = nbLines;
482 textArea->fontId, textArea->text,
AVAILABLE_WIDTH, nbLines, &len,
true);
485 if (style == REGULAR_INFO) {
486 textArea->obj.area.height = nbLines * font->
line_height;
492 textArea->textAlignment =
CENTER;
494 textArea->obj.alignmentMarginY = 2;
495 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
496 container->children[1] = (
nbgl_obj_t *) textArea;
497 if (truncated && ellipsis) {
500 layoutInt, container, textArea, nbLines, textArea->obj.area.height);
505 static const int16_t marginsY[NB_MAX_BUTTON_ROWS][NB_MAX_BUTTON_ROWS] = {
512 char(*buttonTexts)[NB_MAX_CHAR_IN_BUTTON_ROW] = layoutInt->buttonTexts;
514 const char *rowText = (
const char *) PIC(subText);
516 uint8_t maxRows = subTextMaxLines;
519 while ((rowText != NULL) && (nbRows < maxRows)) {
525 button->foregroundColor =
BLACK;
526 button->innerColor =
WHITE;
527 button->borderColor =
WHITE;
528 button->radius = RADIUS_3_PIXELS;
529 button->text = rowText;
531 button->obj.area.height = 14;
532 button->obj.alignment =
CENTER;
534 consumed = layoutGetButtonRowLen(rowText, &len, &width);
535 if (ellipsis && (rowText[consumed] !=
'\0') && (nbRows == (maxRows - 1))) {
538 getButtonTextLen(rowText,
540 NB_MAX_CHAR_IN_BUTTON_ROW - ELLIPSIS_SIZE,
543 button->obj.area.width = width + ellipsisWidth + BUTTON_MARGIN_Y;
546 uint16_t copyLen =
MIN(len, (NB_MAX_CHAR_IN_BUTTON_ROW - ELLIPSIS_SIZE));
547 memcpy(buttonTexts[nbRows], rowText, copyLen);
548 memcpy(buttonTexts[nbRows] + copyLen, ELLIPSIS, ELLIPSIS_SIZE);
549 button->text = PIC(buttonTexts[nbRows]);
553 button->obj.area.width = width + BUTTON_MARGIN_Y;
556 uint16_t copyLen =
MIN(len, (NB_MAX_CHAR_IN_BUTTON_ROW - 1));
557 memcpy(buttonTexts[nbRows], rowText, copyLen);
559 buttonTexts[nbRows][copyLen] =
'\0';
560 button->text = PIC(buttonTexts[nbRows]);
562 rowText = (rowText[consumed] !=
'\0') ? (rowText + consumed) : NULL;
564 buttons[nbRows] = button;
565 container->children[1 + nbRows] = (
nbgl_obj_t *) button;
568 for (uint8_t i = 0; i < nbRows; i++) {
569 buttons[i]->obj.alignmentMarginY = marginsY[nbRows - 1][i];
572 fullHeight += (nbRows == NB_MAX_BUTTON_ROWS) ? 48 : 44;
575 container->obj.area.height = fullHeight;
577 container->obj.alignment =
CENTER;
598 if (layout == NULL) {
615 textArea->textAlignment =
CENTER;
617 textArea->obj.area.height = 16;
619 textArea->obj.alignment =
CENTER;
620 textArea->obj.alignmentMarginY = ((i - list->
selectedChoice) * 16);
621 textArea->textColor =
WHITE;
652 uint16_t fullHeight = 0;
655 if (layout == NULL) {
670 if ((info->
icon != NULL) && info->bottomIcon && (info->
text1 != NULL)) {
678 if ((style == REGULAR_INFO) && (info->
text2 == NULL)) {
679 style = BOLD_TEXT1_INFO;
683 image->foregroundColor =
WHITE;
684 image->buffer = PIC(info->
icon);
687 image->obj.alignTo = NULL;
696 container->nbChildren = 0;
697 if (info->
icon != NULL) {
699 image->foregroundColor =
WHITE;
700 image->buffer = PIC(info->
icon);
703 image->obj.alignTo = NULL;
705 fullHeight += image->buffer->height;
706 container->children[container->nbChildren] = (
nbgl_obj_t *) image;
707 container->nbChildren++;
709 if (info->
text1 != NULL) {
711 textArea->textColor =
WHITE;
712 textArea->text = PIC(info->
text1);
713 textArea->textAlignment =
CENTER;
717 textArea->wrapping =
true;
726 textArea->fontId, textArea->text,
AVAILABLE_WIDTH, nbLines, &len,
true);
730 textArea->obj.area.height = nbLines * font->
line_height;
732 if (info->
icon != NULL) {
734 textArea->obj.alignTo = (
nbgl_obj_t *) container->children[container->nbChildren - 1];
735 textArea->obj.alignmentMarginY = (nbLines < 3) ? 4 : 0;
737 else if (info->
text2 == NULL) {
738 textArea->obj.alignment =
CENTER;
739 textArea->obj.alignTo = NULL;
743 textArea->obj.alignTo = NULL;
746 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
748 container->children[container->nbChildren] = (
nbgl_obj_t *) textArea;
749 container->nbChildren++;
751 if (info->
text2 != NULL) {
753 textArea->textColor =
WHITE;
754 textArea->text = PIC(info->
text2);
755 textArea->textAlignment =
CENTER;
758 textArea->wrapping =
true;
765 textArea->nbMaxLines = nbLines;
767 textArea->fontId, textArea->text,
AVAILABLE_WIDTH, nbLines, &len,
true);
771 textArea->obj.area.height = nbLines * font->
line_height;
775 textArea->obj.alignTo = (
nbgl_obj_t *) container->children[container->nbChildren - 1];
776 textArea->obj.alignmentMarginY = 2;
778 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
780 container->children[container->nbChildren] = (
nbgl_obj_t *) textArea;
781 container->nbChildren++;
783 container->obj.area.height = fullHeight;
785 container->obj.alignmentMarginY = 0;
790 container->obj.alignment =
CENTER;
815 if (layout == NULL) {
818 if (barLayout->
text != NULL) {
823 textArea->textColor =
WHITE;
824 textArea->text = PIC(barLayout->
text);
825 textArea->textAlignment =
CENTER;
830 textArea->obj.alignmentMarginX = 0;
831 textArea->obj.alignmentMarginY = 16;
836 progress->foregroundColor =
WHITE;
837 progress->withBorder =
true;
839 progress->obj.area.width = 102;
840 progress->obj.area.height = 14;
842 progress->obj.alignmentMarginX = 0;
843 progress->obj.alignmentMarginY = 33;
846 if (barLayout->
subText != NULL) {
851 subTextArea->textColor =
WHITE;
852 subTextArea->text = PIC(barLayout->
subText);
853 subTextArea->textAlignment =
CENTER;
856 subTextArea->obj.area.height =
nbgl_getTextHeight(subTextArea->fontId, subTextArea->text);
858 subTextArea->obj.alignTo = (
nbgl_obj_t *) progress;
859 subTextArea->obj.alignmentMarginX = 0;
860 subTextArea->obj.alignmentMarginY = 4;
880 if (layout == NULL) {
884 button->foregroundColor =
BLACK;
885 button->innerColor =
WHITE;
886 button->borderColor =
WHITE;
887 button->radius = RADIUS_3_PIXELS;
888 button->text = (
const char *) PIC(buttonInfo->
text);
891 button->obj.area.width =
nbgl_getTextWidth(button->fontId, button->text) + BUTTON_MARGIN_Y;
892 button->obj.area.height = 14;
912 if (layout == NULL) {
917 textArea->textColor =
WHITE;
918 textArea->text = PIC(switchLayout->
text);
919 textArea->textAlignment =
CENTER;
922 textArea->wrapping =
true;
928 LAYOUT_LOGGER,
"nbgl_layoutAddSwitch(): item text too long (%d lines > 1)\n", nbLines);
933 textArea->obj.alignmentMarginY = 3;
936 if (switchLayout->
subText != NULL) {
939 textArea->textColor =
WHITE;
940 textArea->text = PIC(switchLayout->
subText);
941 textArea->textAlignment =
CENTER;
945 textArea->wrapping =
true;
951 "nbgl_layoutAddSwitch(): sub text too long (%d lines > 2)\n",
955 textArea->obj.alignment =
CENTER;
956 textArea->obj.alignmentMarginY = 1;
961 button->foregroundColor =
BLACK;
962 button->innerColor =
WHITE;
963 button->borderColor =
WHITE;
964 button->radius = RADIUS_3_PIXELS;
967 button->icon = (switchLayout->
initState ==
ON_STATE) ? &C_Switch_On_8px : &C_Switch_Off_8px;
969 button->obj.area.width
970 =
nbgl_getTextWidth(button->fontId, button->text) + 2 + C_Switch_Off_8px.width + 8;
971 button->obj.area.height = 12;
973 button->obj.alignmentMarginY = 3;
989 if (layout == NULL) {
1009 if (layout == NULL) {
1013 if (layout->
modal) {
1016 layout->nbChildren = 0;
Random Number Generation.
nbgl_contentCenteredInfoStyle_t
possible styles for Centered Info Area
#define LOG_WARN(__logger,...)
#define LOG_DEBUG(__logger,...)
#define LOG_FATAL(__logger,...)
Middle Level API of the new BOLOS Graphical Library.
void nbgl_getTextMaxLenAndWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t *len, uint16_t *width, bool wrapping)
bool nbgl_getTextMaxLenInNbLines(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t maxNbLines, uint16_t *len, bool wrapping)
@ BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp
@ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp
uint16_t nbgl_getTextWidth(nbgl_font_id_e fontId, const char *text)
uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
const nbgl_font_t * nbgl_getFont(nbgl_font_id_e fontId)
uint16_t nbgl_getTextHeight(nbgl_font_id_e fontId, const char *text)
uint8_t nbgl_getFontLineHeight(nbgl_font_id_e fontId)
uint16_t nbgl_getSingleLineTextWidthInLen(nbgl_font_id_e fontId, const char *text, uint16_t maxLen)
Font screen low-Level driver API, to draw elementary forms.
void layoutAddObject(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj)
adds the given obj to the main container
static nbgl_layoutInternal_t gLayout[NB_MAX_LAYOUTS]
array of layouts, if used by modal
@ HORIZONTAL_NAV
'<' and '>' are displayed, to navigate between pages and steps
int nbgl_layoutAddText(nbgl_layout_t *layout, const char *text, const char *subText)
Creates an area with given text (in bold) and sub text (in regular).
@ LEFT_ARROW
left arrow is used
@ RIGHT_ARROW
right arrow is used
int nbgl_layoutAddCenteredInfo(nbgl_layout_t *layout, const nbgl_layoutCenteredInfo_t *info)
Creates an area on the center of the main panel, with a possible icon/image, a possible text in black...
nbgl_contentSwitch_t nbgl_layoutSwitch_t
Deprecated, kept for retro compatibility.
int nbgl_layoutDraw(nbgl_layout_t *layout)
Applies given layout. The screen will be redrawn.
void * nbgl_layout_t
type shared externally
int nbgl_layoutAddSwitch(nbgl_layout_t *layout, const nbgl_layoutSwitch_t *switchLayout)
Creates a switch with the given text and its state.
int nbgl_layoutAddButton(nbgl_layout_t *layout, const nbgl_layoutButton_t *buttonInfo)
Creates a rounded button in the main container.
nbgl_layout_t * nbgl_layoutGet(const nbgl_layoutDescription_t *description)
returns a layout of the given type. The layout is reset
struct nbgl_layoutDescription_s nbgl_layoutDescription_t
Structure containing all information when creating a layout. This structure must be passed as argumen...
int nbgl_layoutAddProgressBar(nbgl_layout_t *layout, const char *text, const char *subText, uint8_t percentage)
Creates an area in main panel to display a progress bar, with a title text and a subtext if needed.
void(* nbgl_layoutButtonCallback_t)(nbgl_layout_t *layout, nbgl_buttonEvent_t event)
prototype of function to be called when buttons are touched on a screen
int nbgl_layoutRelease(nbgl_layout_t *layout)
Release the layout obtained with nbgl_layoutGet().
nbgl_contentCenteredInfo_t nbgl_layoutCenteredInfo_t
Deprecated, kept for retro compatibility.
struct nbgl_layoutInternal_s nbgl_layoutInternal_t
Structure containing all information about the current layout.
API to draw all basic graphic objects.
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)
nbgl_obj_t ** nbgl_containerPoolGet(uint8_t nbObjs, uint8_t layer)
nbgl_obj_t * nbgl_objPoolGet(nbgl_obj_type_t type, uint8_t layer)
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_buttonCallback_t)(void *obj, nbgl_buttonEvent_t buttonEvent)
prototype of function to be called when a button event is received by an object (TODO: change to scre...
struct PACKED__ nbgl_container_s nbgl_container_t
struct to represent a container (CONTAINER type)
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
int nbgl_screenSet(nbgl_obj_t ***elements, uint8_t nbElements, const nbgl_screenTickerConfiguration_t *ticker, nbgl_touchCallback_t touchCallback)
int nbgl_screenPush(nbgl_obj_t ***elements, uint8_t nbElements, const nbgl_screenTickerConfiguration_t *ticker, nbgl_touchCallback_t touchCallback)
struct PACKED__ nbgl_screen_s nbgl_screen_t
struct to represent a screen (SCREEN type)
int nbgl_screenPop(uint8_t screenIndex)
nbgl_obj_t * nbgl_screenContainsObjType(nbgl_screen_t *screen, nbgl_obj_type_t type)
void nbgl_screenRedraw(void)
@ VERTICAL
from top to bottom
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
@ NO_ALIGNMENT
used when parent container layout is used
@ IMAGE
Bitmap (y and height must be multiple of 4 on Stax).
@ BUTTON
Rounded rectangle button with icon and/or text.
@ PROGRESS_BAR
horizontal bar to indicate progression of something (between 0% and 100%)
@ CONTAINER
Empty container.
@ TEXT_AREA
Area to contain text line(s).
@ NBGL_BPP_1
1 bit per pixel
const char * text2
second text (can be null)
const char * text1
first text (can be null)
bool onTop
if set to true, align only horizontally
nbgl_contentCenteredInfoStyle_t style
style to apply to this info
const nbgl_icon_details_t * icon
a buffer containing the 1BPP icon
const char * text
main text for the switch
nbgl_state_t initState
initial state of the switch
const char * subText
description under main text (NULL terminated, single line, may be null)
structure defining an ASCII font
uint8_t line_height
height of a line for all characters in pixels
nbgl_screenTickerConfiguration_t ticker
nbgl_layoutTouchCallback_t onActionCallback
the callback to be called on any action on the layout
uint8_t layer
layer in screen stack
nbgl_obj_t ** children
children for main screen
nbgl_layoutTouchCallback_t callback
user callback for all controls
uint8_t modal
if true, means the screen is a modal
This structure contains info to build a navigation bar at the bottom of the screen.
nbgl_layoutNavDirection_t direction
vertical or horizontal navigation
nbgl_layoutNavIndication_t indication
specifies which arrows to use (left or right)
This structure contains info to build a progress bar with info. The progress bar itself is 120px widt...
uint8_t percentage
percentage of completion, from 0 to 100.
const char * text
text in black, on top of progress bar
const char * subText
text in gray, under progress bar