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",
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;
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;
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) {
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) {
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);
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);
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;
529 button->text = rowText;
531 button->obj.area.height = 14;
532 button->obj.alignment =
CENTER;
535 if (ellipsis && (rowText[consumed] !=
'\0') && (nbRows == (maxRows - 1))) {
547 memcpy(buttonTexts[nbRows], rowText, copyLen);
549 button->text = PIC(buttonTexts[nbRows]);
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];
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) {
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;
888 button->text = (
const char *) PIC(buttonInfo->
text);
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;
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) {
Random Number Generation.
nbgl_contentCenteredInfoStyle_t
possible styles for Centered Info Area
@ BOLD_TEXT1_INFO
bold is used for text1 (but '\b' can switch to regular)
@ BUTTON_INFO
bold is used for text1 and text2 as a white button
@ REGULAR_INFO
both texts regular (but '\b' can switch to bold)
#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.
@ HORIZONTAL_NAV
'<' and '>' are displayed, to navigate between pages and steps
@ LEFT_ARROW
left arrow is used
@ RIGHT_ARROW
right arrow is used
nbgl_contentSwitch_t nbgl_layoutSwitch_t
Deprecated, kept for retro compatibility.
void * nbgl_layout_t
type shared externally
struct nbgl_layoutDescription_s nbgl_layoutDescription_t
Structure containing all information when creating a layout. This structure must be passed as argumen...
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
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.
Internal functions/constants of NBGL layout layer.
#define NB_MAX_BUTTON_ROWS_PUBLIC
Maximum number of buttons used to display the sub text in BUTTON_INFO style with nbgl_layoutAddText()...
#define NB_MAX_CHAR_IN_BUTTON_ROW
Maximum number of bytes (including '\0') of the text of a button in BUTTON_INFO style....
#define NB_MAX_BUTTON_ROWS
Maximum number of buttons used to display the sub text in BUTTON_INFO style.
#define BUTTON_MARGIN_Y
Horizontal margin (sum of left and right) between the text of a button and its border.
int nbgl_layoutDraw(nbgl_layout_t *layoutParam)
Applies given layout. The screen will be redrawn.
int nbgl_layoutAddMenuList(nbgl_layout_t *layout, nbgl_layoutMenuList_t *list)
Creates a menu list (only for nanos) with the given parameters. The navigation (and selection) must b...
static void getButtonTextLen(const char *text, uint16_t maxWidth, uint16_t maxLen, uint16_t *len, uint16_t *width)
computes the part of the given text fitting in the given width and in the given number of bytes,...
int nbgl_layoutAddNavigation(nbgl_layout_t *layout, nbgl_layoutNavigation_t *info)
Creates navigation arrows on side(s) of the screen.
int layoutAddText(nbgl_layout_t *layout, const char *text, const char *subText, nbgl_contentCenteredInfoStyle_t style, uint8_t nbMaxLines, bool ellipsis)
Same as nbgl_layoutAddText(), with the choice of the max number of lines (or buttons in BUTTON_INFO s...
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...
int nbgl_layoutAddText(nbgl_layout_t *layout, const char *text, const char *subText, nbgl_contentCenteredInfoStyle_t style)
Creates an area with given text and sub text, using the given style.
static void addTextWithEllipsis(nbgl_layoutInternal_t *layoutInt, nbgl_container_t *container, nbgl_text_area_t *textArea, uint8_t nbLines, uint16_t areaHeight)
displays the given number of lines of the text of the given text area, the last line ending with an e...
static void buttonCallback(nbgl_screen_t *screen, nbgl_buttonEvent_t buttonEvent)
int nbgl_layoutAddProgressBar(nbgl_layout_t *layout, const nbgl_layoutProgressBar_t *barLayout)
Creates an area in main panel to display a progress bar, with a title text and a description under th...
#define NB_MAX_SCREEN_CHILDREN
int nbgl_layoutAddSwitch(nbgl_layout_t *layout, const nbgl_layoutSwitch_t *switchLayout)
Creates an area in main panel to display a switch.
int nbgl_layoutAddButton(nbgl_layout_t *layout, const nbgl_layoutButton_t *buttonInfo)
Creates an area in main panel to display a button, with the given style.
nbgl_layout_t * nbgl_layoutGet(const nbgl_layoutDescription_t *description)
returns a layout of the given type. The layout is reset
int nbgl_layoutRelease(nbgl_layout_t *layoutParam)
Release the layout obtained with nbgl_layoutGet().
void layoutAddObject(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj)
adds the given obj to the layout
static nbgl_layoutInternal_t gLayout[NB_MAX_LAYOUTS]
array of layouts, if used by modal
uint16_t layoutGetButtonRowLen(const char *text, uint16_t *len, uint16_t *width)
computes the part of the given text displayed in a single button in BUTTON_INFO style....
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)
void nbgl_keyboardCallback(nbgl_obj_t *obj, nbgl_buttonEvent_t buttonEvent)
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)
void nbgl_keypadCallback(nbgl_obj_t *obj, nbgl_buttonEvent_t buttonEvent)
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_screenPush(nbgl_obj_t ***elements, uint8_t nbElements, const nbgl_screenTickerConfiguration_t *ticker, nbgl_buttonCallback_t buttonCallback)
int nbgl_screenSet(nbgl_obj_t ***elements, uint8_t nbElements, const nbgl_screenTickerConfiguration_t *ticker, nbgl_buttonCallback_t buttonCallback)
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)
@ RADIUS_3_PIXELS
3 pixels
@ 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_layoutButtonCallback_t onActionCallback
the callback to be called on any action on the layout
uint8_t layer
layer in screen stack
nbgl_layoutTouchCallback_t callback
user callback for all controls
uint8_t nbChildren
number of children in above array
char buttonTexts[NB_MAX_BUTTON_ROWS][NB_MAX_CHAR_IN_BUTTON_ROW]
uint8_t modal
if true, means the screen is a modal
nbgl_obj_t ** children
children for main screen
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