21 #include "os_helpers.h"
28 #define NB_MAX_LAYOUTS 3
31 #define NB_MAX_SCREEN_CHILDREN 7
63 if ((screen->index == gLayout[i].layer) && (gLayout[i].nbChildren > 0)) {
72 "touchCallback(): screen->index = %d, buttonEvent = %d, no matching active layout\n",
82 nbgl_keypadCallback(kpd, buttonEvent);
91 nbgl_keyboardCallback(kbd, buttonEvent);
131 if (description->
modal) {
132 if (gLayout[1].nbChildren == 0) {
133 layout = &gLayout[1];
135 else if (gLayout[2].nbChildren == 0) {
136 layout = &gLayout[2];
142 layout = &gLayout[0];
144 if (layout == NULL) {
154 if (description->
modal) {
183 if (layout == NULL) {
190 image->foregroundColor =
WHITE;
198 image->foregroundColor =
WHITE;
227 if (layout == NULL) {
233 container->nbChildren = 1;
234 if (subText != NULL) {
235 container->nbChildren++;
242 textArea->textColor =
WHITE;
243 textArea->text = PIC(text);
244 textArea->textAlignment =
CENTER;
258 textArea->fontId, textArea->text,
AVAILABLE_WIDTH, nbLines, &len,
true);
262 textArea->obj.area.height = nbLines * font->
line_height;
263 textArea->wrapping =
true;
265 fullHeight += textArea->obj.area.height;
266 container->children[0] = (
nbgl_obj_t *) textArea;
268 if (subText != NULL) {
270 textArea->textColor =
WHITE;
271 textArea->text = PIC(subText);
272 textArea->wrapping =
true;
281 textArea->nbMaxLines = nbLines;
283 textArea->fontId, textArea->text,
AVAILABLE_WIDTH, nbLines, &len,
true);
286 textArea->obj.area.height = nbLines * font->
line_height;
287 textArea->textAlignment =
CENTER;
289 textArea->obj.alignmentMarginY = 2;
290 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
291 container->children[1] = (
nbgl_obj_t *) textArea;
293 container->obj.area.height = fullHeight;
295 container->obj.alignment =
CENTER;
316 if (layout == NULL) {
333 textArea->textAlignment =
CENTER;
335 textArea->obj.area.height = 12;
337 textArea->obj.alignment =
CENTER;
338 textArea->obj.alignmentMarginY = ((i - list->
selectedChoice) * 16);
339 textArea->textColor =
WHITE;
373 if (layout == NULL) {
381 container->nbChildren = 0;
382 if (info->
icon != NULL) {
384 image->foregroundColor =
WHITE;
385 image->buffer = PIC(info->
icon);
388 image->obj.alignTo = NULL;
390 fullHeight += image->buffer->height;
391 container->children[container->nbChildren] = (
nbgl_obj_t *) image;
392 container->nbChildren++;
394 if (info->
text1 != NULL) {
396 textArea->textColor =
WHITE;
397 textArea->text = PIC(info->
text1);
398 textArea->textAlignment =
CENTER;
402 textArea->wrapping =
true;
411 textArea->fontId, textArea->text,
AVAILABLE_WIDTH, nbLines, &len,
true);
415 textArea->obj.area.height = nbLines * font->
line_height;
417 if (info->
icon != NULL) {
419 textArea->obj.alignTo = (
nbgl_obj_t *) container->children[container->nbChildren - 1];
420 textArea->obj.alignmentMarginY = (nbLines < 3) ? 4 : 0;
422 else if (info->
text2 == NULL) {
423 textArea->obj.alignment =
CENTER;
424 textArea->obj.alignTo = NULL;
428 textArea->obj.alignTo = NULL;
431 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
433 container->children[container->nbChildren] = (
nbgl_obj_t *) textArea;
434 container->nbChildren++;
436 if (info->
text2 != NULL) {
438 textArea->textColor =
WHITE;
439 textArea->text = PIC(info->
text2);
440 textArea->textAlignment =
CENTER;
449 textArea->nbMaxLines = nbLines;
451 textArea->fontId, textArea->text,
AVAILABLE_WIDTH, nbLines, &len,
true);
455 textArea->obj.area.height = nbLines * font->
line_height;
459 textArea->obj.alignTo = (
nbgl_obj_t *) container->children[container->nbChildren - 1];
460 textArea->obj.alignmentMarginY = 2;
462 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
464 container->children[container->nbChildren] = (
nbgl_obj_t *) textArea;
465 container->nbChildren++;
467 container->obj.area.height = fullHeight;
469 container->obj.alignmentMarginY = 0;
474 container->obj.alignment =
CENTER;
499 if (layout == NULL) {
502 if (barLayout->
text != NULL) {
507 textArea->textColor =
WHITE;
508 textArea->text = PIC(barLayout->
text);
509 textArea->textAlignment =
CENTER;
514 textArea->obj.alignmentMarginX = 0;
515 textArea->obj.alignmentMarginY = 16;
520 progress->foregroundColor =
WHITE;
521 progress->withBorder =
true;
523 progress->obj.area.width = 102;
524 progress->obj.area.height = 14;
526 progress->obj.alignmentMarginX = 0;
527 progress->obj.alignmentMarginY = 33;
530 if (barLayout->
subText != NULL) {
535 subTextArea->textColor =
WHITE;
536 subTextArea->text = PIC(barLayout->
subText);
537 subTextArea->textAlignment =
CENTER;
540 subTextArea->obj.area.height =
nbgl_getTextHeight(subTextArea->fontId, subTextArea->text);
542 subTextArea->obj.alignTo = (
nbgl_obj_t *) progress;
543 subTextArea->obj.alignmentMarginX = 0;
544 subTextArea->obj.alignmentMarginY = 4;
561 if (layout == NULL) {
580 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.
bool nbgl_getTextMaxLenInNbLines(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t maxNbLines, uint16_t *len, bool wrapping)
compute the len of the given text (in bytes) fitting in the given maximum nb lines,...
@ BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp
@ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp
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
uint16_t nbgl_getTextHeight(nbgl_font_id_e fontId, const char *text)
return the height of the given multiline text, with the given font.
const nbgl_font_t * nbgl_getFont(nbgl_font_id_e fontId)
return the non-unicode font corresponding to the given font ID
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_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...
int nbgl_layoutDraw(nbgl_layout_t *layout)
Applies given layout. The screen will be redrawn.
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
int nbgl_layoutRelease(nbgl_layout_t *layout)
Release the layout obtained with nbgl_layoutGet()
nbgl_layout_t * nbgl_layoutGet(const nbgl_layoutDescription_t *description)
returns a layout of the given type. The layout is reset
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)
Gets a new container from the pool, with the given number of obj pointers.
struct PACKED__ nbgl_image_s nbgl_image_t
struct to represent an image (IMAGE type)
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...
nbgl_obj_t * nbgl_objPoolGet(nbgl_obj_type_t type, uint8_t layer)
Gets a new graphic object from the pool, with the given type. The type field of the object is set.
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)
Configures the lowest layer screen. To be used by applications A nbgl_screenRedraw() can be called af...
int nbgl_screenPush(nbgl_obj_t ***elements, uint8_t nbElements, const nbgl_screenTickerConfiguration_t *ticker, nbgl_touchCallback_t touchCallback)
Pushes a screen on top of the stack, with the given number of elements, if possible....
struct PACKED__ nbgl_screen_s nbgl_screen_t
struct to represent a screen (SCREEN type)
int nbgl_screenPop(uint8_t screenIndex)
Release the screen at the given index in screen array (index returned by nbgl_screenPush())....
nbgl_obj_t * nbgl_screenContainsObjType(nbgl_screen_t *screen, nbgl_obj_type_t type)
return an object of the given type in the given screen
void nbgl_screenRedraw(void)
This function redraws the whole screen on top of stack and its children.
@ VERTICAL
from top to bottom
@ NO_ALIGNMENT
used when parent container layout is used
@ IMAGE
Bitmap (y and height must be multiple of 4 on Stax)
@ 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
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.
nbgl_layoutTouchCallback_t callback
bool modal
if true, means the screen is a modal
uint8_t nbChildren
number of children in above array
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