21#include "os_helpers.h"
28#define NB_MAX_LAYOUTS 3
31#define NB_MAX_SCREEN_CHILDREN 7
33#define BUTTON_MARGIN_Y 12
36#define NB_MAX_CHAR_IN_LINE 20
39#define ELLIPSIS_SIZE sizeof(ELLIPSIS)
71 if ((screen->index == gLayout[i].layer) && (gLayout[i].nbChildren > 0)) {
80 "touchCallback(): screen->index = %d, buttonEvent = %d, no matching active layout\n",
139 if (description->
modal) {
140 if (gLayout[1].nbChildren == 0) {
141 layout = &gLayout[1];
143 else if (gLayout[2].nbChildren == 0) {
144 layout = &gLayout[2];
150 layout = &gLayout[0];
152 if (layout == NULL) {
162 if (description->
modal) {
191 if (layout == NULL) {
198 image->foregroundColor =
WHITE;
206 image->foregroundColor =
WHITE;
233 uint16_t fullHeight = 0;
236 if (layout == NULL) {
242 container->nbChildren = 1;
243 if (subText != NULL) {
244 container->nbChildren += 2;
251 textArea->textColor =
WHITE;
252 textArea->text = PIC(text);
253 textArea->textAlignment =
CENTER;
267 textArea->fontId, textArea->text,
AVAILABLE_WIDTH, nbLines, &len,
true);
271 textArea->obj.area.height = nbLines * font->
line_height;
272 textArea->wrapping =
true;
274 fullHeight += textArea->obj.area.height;
275 container->children[0] = (
nbgl_obj_t *) textArea;
277 if (subText != NULL) {
280 textArea->textColor =
WHITE;
281 textArea->text = PIC(subText);
282 textArea->wrapping =
true;
291 textArea->nbMaxLines = nbLines;
293 textArea->fontId, textArea->text,
AVAILABLE_WIDTH, nbLines, &len,
true);
297 textArea->obj.area.height = nbLines * font->
line_height;
303 textArea->textAlignment =
CENTER;
305 textArea->obj.alignmentMarginY = 2;
306 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
307 container->children[1] = (
nbgl_obj_t *) textArea;
315 button->foregroundColor =
BLACK;
316 button->innerColor =
WHITE;
317 button->borderColor =
WHITE;
319 button->text = (
const char *) PIC(subText);
321 button->obj.area.height = 14;
322 button->obj.alignment =
CENTER;
339 button->text = PIC(tmpString);
340 button->obj.alignmentMarginY = 8 - 7;
344 button->obj.alignmentMarginY = 8;
346 container->children[1] = (
nbgl_obj_t *) button;
351 button->foregroundColor =
BLACK;
352 button->innerColor =
WHITE;
353 button->borderColor =
WHITE;
355 button->text = (
const char *) PIC(subText) + len;
357 button->obj.area.height = 14;
358 button->obj.alignment =
CENTER;
359 button->obj.alignmentMarginY = 8 + 7;
373 memcpy(tmpString2, button->text, copyLen);
375 button->text = PIC(tmpString2);
380 container->children[2] = (
nbgl_obj_t *) button;
386 container->obj.area.height = fullHeight;
388 container->obj.alignment =
CENTER;
409 if (layout == NULL) {
426 textArea->textAlignment =
CENTER;
428 textArea->obj.area.height = 16;
430 textArea->obj.alignment =
CENTER;
431 textArea->obj.alignmentMarginY = ((i - list->
selectedChoice) * 16);
432 textArea->textColor =
WHITE;
463 uint16_t fullHeight = 0;
466 if (layout == NULL) {
474 container->nbChildren = 0;
475 if (info->
icon != NULL) {
477 image->foregroundColor =
WHITE;
478 image->buffer = PIC(info->
icon);
481 image->obj.alignTo = NULL;
483 fullHeight += image->buffer->height;
484 container->children[container->nbChildren] = (
nbgl_obj_t *) image;
485 container->nbChildren++;
487 if (info->
text1 != NULL) {
489 textArea->textColor =
WHITE;
490 textArea->text = PIC(info->
text1);
491 textArea->textAlignment =
CENTER;
495 textArea->wrapping =
true;
504 textArea->fontId, textArea->text,
AVAILABLE_WIDTH, nbLines, &len,
true);
508 textArea->obj.area.height = nbLines * font->
line_height;
510 if (info->
icon != NULL) {
512 textArea->obj.alignTo = (
nbgl_obj_t *) container->children[container->nbChildren - 1];
513 textArea->obj.alignmentMarginY = (nbLines < 3) ? 4 : 0;
515 else if (info->
text2 == NULL) {
516 textArea->obj.alignment =
CENTER;
517 textArea->obj.alignTo = NULL;
521 textArea->obj.alignTo = NULL;
524 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
526 container->children[container->nbChildren] = (
nbgl_obj_t *) textArea;
527 container->nbChildren++;
529 if (info->
text2 != NULL) {
531 textArea->textColor =
WHITE;
532 textArea->text = PIC(info->
text2);
533 textArea->textAlignment =
CENTER;
536 textArea->wrapping =
true;
543 textArea->nbMaxLines = nbLines;
545 textArea->fontId, textArea->text,
AVAILABLE_WIDTH, nbLines, &len,
true);
549 textArea->obj.area.height = nbLines * font->
line_height;
553 textArea->obj.alignTo = (
nbgl_obj_t *) container->children[container->nbChildren - 1];
554 textArea->obj.alignmentMarginY = 2;
556 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
558 container->children[container->nbChildren] = (
nbgl_obj_t *) textArea;
559 container->nbChildren++;
561 container->obj.area.height = fullHeight;
563 container->obj.alignmentMarginY = 0;
568 container->obj.alignment =
CENTER;
593 if (layout == NULL) {
596 if (barLayout->
text != NULL) {
601 textArea->textColor =
WHITE;
602 textArea->text = PIC(barLayout->
text);
603 textArea->textAlignment =
CENTER;
608 textArea->obj.alignmentMarginX = 0;
609 textArea->obj.alignmentMarginY = 16;
614 progress->foregroundColor =
WHITE;
615 progress->withBorder =
true;
617 progress->obj.area.width = 102;
618 progress->obj.area.height = 14;
620 progress->obj.alignmentMarginX = 0;
621 progress->obj.alignmentMarginY = 33;
624 if (barLayout->
subText != NULL) {
629 subTextArea->textColor =
WHITE;
630 subTextArea->text = PIC(barLayout->
subText);
631 subTextArea->textAlignment =
CENTER;
634 subTextArea->obj.area.height =
nbgl_getTextHeight(subTextArea->fontId, subTextArea->text);
636 subTextArea->obj.alignTo = (
nbgl_obj_t *) progress;
637 subTextArea->obj.alignmentMarginX = 0;
638 subTextArea->obj.alignmentMarginY = 4;
658 if (layout == NULL) {
662 button->foregroundColor =
BLACK;
663 button->innerColor =
WHITE;
664 button->borderColor =
WHITE;
666 button->text = (
const char *) PIC(buttonInfo->
text);
670 button->obj.area.height = 14;
690 if (layout == NULL) {
695 textArea->textColor =
WHITE;
696 textArea->text = PIC(switchLayout->
text);
697 textArea->textAlignment =
CENTER;
700 textArea->wrapping =
true;
710 textArea->obj.alignmentMarginY = 3;
713 if (switchLayout->
subText != NULL) {
716 textArea->textColor =
WHITE;
717 textArea->text = PIC(switchLayout->
subText);
718 textArea->textAlignment =
CENTER;
722 textArea->wrapping =
true;
730 textArea->obj.alignment =
CENTER;
731 textArea->obj.alignmentMarginY = 1;
736 button->foregroundColor =
BLACK;
737 button->innerColor =
WHITE;
738 button->borderColor =
WHITE;
742 button->icon = (switchLayout->
initState ==
ON_STATE) ? &C_Switch_On_8px : &C_Switch_Off_8px;
744 button->obj.area.width
745 =
nbgl_getTextWidth(button->fontId, button->text) + 2 + C_Switch_Off_8px.width + 8;
746 button->obj.area.height = 12;
748 button->obj.alignmentMarginY = 3;
764 if (layout == NULL) {
783 if (layout == NULL) {
Random Number Generation.
nbgl_contentCenteredInfoStyle_t
possible styles for Centered Info Area
@ 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)
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
void * nbgl_layout_t
type shared externally
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
Internal functions/constants of NBGL layout layer.
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...
#define NB_MAX_CHAR_IN_LINE
int nbgl_layoutAddNavigation(nbgl_layout_t *layout, nbgl_layoutNavigation_t *info)
Creates navigation arrows on side(s) of the screen.
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.
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
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
This structure contains info to build a centered (vertically and horizontally) area,...
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
This structure contains info to build a switch (on the right) with a description (on the left),...
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
Structure containing all information when creating a layout. This structure must be passed as argumen...
nbgl_screenTickerConfiguration_t ticker
nbgl_layoutButtonCallback_t onActionCallback
the callback to be called on any action on the layout
Structure containing all information about the current 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
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