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",
90 nbgl_keypadCallback(kpd, buttonEvent);
99 nbgl_keyboardCallback(kbd, buttonEvent);
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) {
278 if (style != BUTTON_INFO) {
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);
296 if (style == REGULAR_INFO) {
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;
318 button->radius = RADIUS_3_PIXELS;
319 button->text = (
const char *) PIC(subText);
321 button->obj.area.height = 14;
322 button->obj.alignment =
CENTER;
326 static char tmpString[NB_MAX_CHAR_IN_LINE];
333 button->obj.area.width = width + BUTTON_MARGIN_Y;
336 memcpy(tmpString, button->text,
MIN(len, (NB_MAX_CHAR_IN_LINE - 1)));
338 tmpString[
MIN(len, (NB_MAX_CHAR_IN_LINE - 1))] =
'\0';
339 button->text = PIC(tmpString);
340 button->obj.alignmentMarginY = 8 - 7;
343 button->obj.area.width = textWidth + BUTTON_MARGIN_Y;
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;
354 button->radius = RADIUS_3_PIXELS;
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;
362 static char tmpString2[NB_MAX_CHAR_IN_LINE];
370 button->obj.area.width = width + ellipsisWidth + BUTTON_MARGIN_Y;
372 uint16_t copyLen =
MIN(len, (NB_MAX_CHAR_IN_LINE - ELLIPSIS_SIZE));
373 memcpy(tmpString2, button->text, copyLen);
374 memcpy(tmpString2 + copyLen, ELLIPSIS, ELLIPSIS_SIZE);
375 button->text = PIC(tmpString2);
378 button->obj.area.width = textWidth + BUTTON_MARGIN_Y;
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) {
481 if ((info->
icon != NULL) && info->bottomIcon && (info->
text1 != NULL)) {
489 if ((style == REGULAR_INFO) && (info->
text2 == NULL)) {
490 style = BOLD_TEXT1_INFO;
494 image->foregroundColor =
WHITE;
495 image->buffer = PIC(info->
icon);
498 image->obj.alignTo = NULL;
507 container->nbChildren = 0;
508 if (info->
icon != NULL) {
510 image->foregroundColor =
WHITE;
511 image->buffer = PIC(info->
icon);
514 image->obj.alignTo = NULL;
516 fullHeight += image->buffer->height;
517 container->children[container->nbChildren] = (
nbgl_obj_t *) image;
518 container->nbChildren++;
520 if (info->
text1 != NULL) {
522 textArea->textColor =
WHITE;
523 textArea->text = PIC(info->
text1);
524 textArea->textAlignment =
CENTER;
528 textArea->wrapping =
true;
537 textArea->fontId, textArea->text,
AVAILABLE_WIDTH, nbLines, &len,
true);
541 textArea->obj.area.height = nbLines * font->
line_height;
543 if (info->
icon != NULL) {
545 textArea->obj.alignTo = (
nbgl_obj_t *) container->children[container->nbChildren - 1];
546 textArea->obj.alignmentMarginY = (nbLines < 3) ? 4 : 0;
548 else if (info->
text2 == NULL) {
549 textArea->obj.alignment =
CENTER;
550 textArea->obj.alignTo = NULL;
554 textArea->obj.alignTo = NULL;
557 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
559 container->children[container->nbChildren] = (
nbgl_obj_t *) textArea;
560 container->nbChildren++;
562 if (info->
text2 != NULL) {
564 textArea->textColor =
WHITE;
565 textArea->text = PIC(info->
text2);
566 textArea->textAlignment =
CENTER;
569 textArea->wrapping =
true;
576 textArea->nbMaxLines = nbLines;
578 textArea->fontId, textArea->text,
AVAILABLE_WIDTH, nbLines, &len,
true);
582 textArea->obj.area.height = nbLines * font->
line_height;
586 textArea->obj.alignTo = (
nbgl_obj_t *) container->children[container->nbChildren - 1];
587 textArea->obj.alignmentMarginY = 2;
589 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
591 container->children[container->nbChildren] = (
nbgl_obj_t *) textArea;
592 container->nbChildren++;
594 container->obj.area.height = fullHeight;
596 container->obj.alignmentMarginY = 0;
601 container->obj.alignment =
CENTER;
626 if (layout == NULL) {
629 if (barLayout->
text != NULL) {
634 textArea->textColor =
WHITE;
635 textArea->text = PIC(barLayout->
text);
636 textArea->textAlignment =
CENTER;
641 textArea->obj.alignmentMarginX = 0;
642 textArea->obj.alignmentMarginY = 16;
647 progress->foregroundColor =
WHITE;
648 progress->withBorder =
true;
650 progress->obj.area.width = 102;
651 progress->obj.area.height = 14;
653 progress->obj.alignmentMarginX = 0;
654 progress->obj.alignmentMarginY = 33;
657 if (barLayout->
subText != NULL) {
662 subTextArea->textColor =
WHITE;
663 subTextArea->text = PIC(barLayout->
subText);
664 subTextArea->textAlignment =
CENTER;
667 subTextArea->obj.area.height =
nbgl_getTextHeight(subTextArea->fontId, subTextArea->text);
669 subTextArea->obj.alignTo = (
nbgl_obj_t *) progress;
670 subTextArea->obj.alignmentMarginX = 0;
671 subTextArea->obj.alignmentMarginY = 4;
691 if (layout == NULL) {
695 button->foregroundColor =
BLACK;
696 button->innerColor =
WHITE;
697 button->borderColor =
WHITE;
698 button->radius = RADIUS_3_PIXELS;
699 button->text = (
const char *) PIC(buttonInfo->
text);
702 button->obj.area.width =
nbgl_getTextWidth(button->fontId, button->text) + BUTTON_MARGIN_Y;
703 button->obj.area.height = 14;
723 if (layout == NULL) {
728 textArea->textColor =
WHITE;
729 textArea->text = PIC(switchLayout->
text);
730 textArea->textAlignment =
CENTER;
733 textArea->wrapping =
true;
743 textArea->obj.alignmentMarginY = 3;
746 if (switchLayout->
subText != NULL) {
749 textArea->textColor =
WHITE;
750 textArea->text = PIC(switchLayout->
subText);
751 textArea->textAlignment =
CENTER;
755 textArea->wrapping =
true;
763 textArea->obj.alignment =
CENTER;
764 textArea->obj.alignmentMarginY = 1;
769 button->foregroundColor =
BLACK;
770 button->innerColor =
WHITE;
771 button->borderColor =
WHITE;
772 button->radius = RADIUS_3_PIXELS;
775 button->icon = (switchLayout->
initState ==
ON_STATE) ? &C_Switch_On_8px : &C_Switch_Off_8px;
777 button->obj.area.width
778 =
nbgl_getTextWidth(button->fontId, button->text) + 2 + C_Switch_Off_8px.width + 8;
779 button->obj.area.height = 12;
781 button->obj.alignmentMarginY = 3;
797 if (layout == NULL) {
816 if (layout == NULL) {
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)
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
@ 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...
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
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()
Internal functions/constants of NBGL layout layer.
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
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_layoutTouchCallback_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