Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
nbgl_layout.c
Go to the documentation of this file.
1
7#include "app_config.h"
8
9#ifdef HAVE_SE_TOUCH
10/*********************
11 * INCLUDES
12 *********************/
13#include <string.h>
14#include <stdlib.h>
15#include "nbgl_debug.h"
16#include "nbgl_front.h"
18#include "nbgl_obj.h"
19#include "nbgl_draw.h"
20#include "nbgl_screen.h"
21#include "nbgl_touch.h"
22#include "glyphs.h"
23#include "os_io_seph_ux.h"
24#include "os_pic.h"
25#include "os_helpers.h"
26#include "lcx_rng.h"
27
28/*********************
29 * DEFINES
30 *********************/
31// half internal margin, between items
32#define INTERNAL_SPACE 16
33// inner margin, between buttons
34#define INNER_MARGIN 12
35
36#define NB_MAX_LAYOUTS 3
37
38// used by container
39#define NB_MAX_CONTAINER_CHILDREN 20
40
41#define TAG_VALUE_ICON_WIDTH 32
42
43#if defined(TARGET_STAX)
44#define RADIO_CHOICE_HEIGHT 96
45#define BAR_INTERVALE 12
46#define FOOTER_BUTTON_HEIGHT 128
47#define FOOTER_IN_PAIR_HEIGHT 80
48#define ROUNDED_AND_FOOTER_FOOTER_HEIGHT 192
49#define FOOTER_TEXT_AND_NAV_WIDTH 160
50#define TAP_TO_CONTINUE_MARGIN 24
51#define SUB_HEADER_MARGIN 24
52#define PRE_FIRST_TEXT_MARGIN 24
53#define INTER_PARAGRAPHS_MARGIN 40
54#define PRE_TITLE_MARGIN 24
55#define PRE_DESCRIPTION_MARGIN 16
56#define PRE_FIRST_ROW_MARGIN 32
57#define INTER_ROWS_MARGIN 16
58#define QR_PRE_TEXT_MARGIN 24
59#define QR_INTER_TEXTS_MARGIN 40
60#define SPINNER_TEXT_MARGIN 20
61#define SPINNER_INTER_TEXTS_MARGIN 20
62#define BAR_TEXT_MARGIN 24
63#define BAR_INTER_TEXTS_MARGIN 16
64#define LEFT_CONTENT_TEXT_PADDING 0
65#define BUTTON_FROM_BOTTOM_MARGIN 4
66#define TOP_BUTTON_MARGIN VERTICAL_BORDER_MARGIN
67#define TOP_BUTTON_MARGIN_WITH_ACTION VERTICAL_BORDER_MARGIN
68#define SINGLE_BUTTON_MARGIN 24
69#define LONG_PRESS_PROGRESS_HEIGHT 8
70#define LONG_PRESS_PROGRESS_ALIGN 1
71#define LEFT_CONTENT_ICON_TEXT_X 16
72#define TIP_BOX_MARGIN_Y 24
73#define TIP_BOX_TEXT_ICON_MARGIN 24
74#elif defined(TARGET_FLEX)
75#define RADIO_CHOICE_HEIGHT 92
76#define BAR_INTERVALE 16
77#define FOOTER_BUTTON_HEIGHT 136
78#define FOOTER_IN_PAIR_HEIGHT 88
79#define ROUNDED_AND_FOOTER_FOOTER_HEIGHT 208
80#define FOOTER_TEXT_AND_NAV_WIDTH 192
81#define TAP_TO_CONTINUE_MARGIN 30
82#define SUB_HEADER_MARGIN 28
83#define PRE_FIRST_TEXT_MARGIN 0
84#define INTER_PARAGRAPHS_MARGIN 24
85#define PRE_TITLE_MARGIN 16
86#define PRE_DESCRIPTION_MARGIN 24
87#define PRE_FIRST_ROW_MARGIN 32
88#define INTER_ROWS_MARGIN 24
89#define QR_PRE_TEXT_MARGIN 24
90#define QR_INTER_TEXTS_MARGIN 28
91#define SPINNER_TEXT_MARGIN 24
92#define SPINNER_INTER_TEXTS_MARGIN 16
93#define BAR_TEXT_MARGIN 24
94#define BAR_INTER_TEXTS_MARGIN 16
95#define LEFT_CONTENT_TEXT_PADDING 4
96#define BUTTON_FROM_BOTTOM_MARGIN 4
97#define TOP_BUTTON_MARGIN VERTICAL_BORDER_MARGIN
98#define TOP_BUTTON_MARGIN_WITH_ACTION VERTICAL_BORDER_MARGIN
99#define SINGLE_BUTTON_MARGIN 24
100#define LONG_PRESS_PROGRESS_HEIGHT 8
101#define LONG_PRESS_PROGRESS_ALIGN 1
102#define LEFT_CONTENT_ICON_TEXT_X 16
103#define TIP_BOX_MARGIN_Y 24
104#define TIP_BOX_TEXT_ICON_MARGIN 32
105#elif defined(TARGET_APEX)
106#define RADIO_CHOICE_HEIGHT 68
107#define BAR_INTERVALE 8
108#define FOOTER_BUTTON_HEIGHT 88
109#define FOOTER_IN_PAIR_HEIGHT 60
110#define ROUNDED_AND_FOOTER_FOOTER_HEIGHT 128
111#define FOOTER_TEXT_AND_NAV_WIDTH 120
112#define TAP_TO_CONTINUE_MARGIN 30
113#define SUB_HEADER_MARGIN 16
114#define PRE_FIRST_TEXT_MARGIN 0
115#define INTER_PARAGRAPHS_MARGIN 16
116#define PRE_TITLE_MARGIN 16
117#define PRE_DESCRIPTION_MARGIN 12
118#define PRE_FIRST_ROW_MARGIN 24
119#define INTER_ROWS_MARGIN 12
120#define QR_PRE_TEXT_MARGIN 16
121#define QR_INTER_TEXTS_MARGIN 20
122#define SPINNER_TEXT_MARGIN 16
123#define SPINNER_INTER_TEXTS_MARGIN 16
124#define BAR_TEXT_MARGIN 16
125#define BAR_INTER_TEXTS_MARGIN 12
126#define LEFT_CONTENT_TEXT_PADDING 4
127#define BUTTON_FROM_BOTTOM_MARGIN 0
128#define TOP_BUTTON_MARGIN 12
129#define TOP_BUTTON_MARGIN_WITH_ACTION 0
130#define SINGLE_BUTTON_MARGIN 16
131#define LONG_PRESS_PROGRESS_HEIGHT 4
132#define LONG_PRESS_PROGRESS_ALIGN 0
133#define LEFT_CONTENT_ICON_TEXT_X 8
134#define TIP_BOX_MARGIN_Y 12
135#define TIP_BOX_TEXT_ICON_MARGIN 20
136#else // TARGETS
137#error Undefined target
138#endif // TARGETS
139
140// refresh period of the spinner, in ms
141#define SPINNER_REFRESH_PERIOD 400
142
143/**********************
144 * MACROS
145 **********************/
146
147/**********************
148 * TYPEDEFS
149 **********************/
150
157
158// used to build either a touchable bar or a switch
159typedef struct {
161 const nbgl_icon_details_t *iconLeft; // a buffer containing the 1BPP icon for icon on
162 // left (can be NULL)
163 const nbgl_icon_details_t *iconRight; // a buffer containing the 1BPP icon for icon 2 (can be
164 // NULL). Dimensions must be the same as iconLeft
165 const char *text; // text (can be NULL)
166 const char *subText; // sub text (can be NULL)
167 uint8_t token; // the token that will be used as argument of the callback
168 nbgl_state_t state; // state of the item
169 bool large; // set to true only for the main level of OS settings
170 uint8_t index; // index of obj (for callback)
171 tune_index_e tuneId; // if not @ref NBGL_NO_TUNE, a tune will be played
172} listItem_t;
173
174/**********************
175 * VARIABLES
176 **********************/
177
182static nbgl_layoutInternal_t gLayout[NB_MAX_LAYOUTS] = {0};
183
184// current top of stack
185static nbgl_layoutInternal_t *topLayout;
186
187// numbers of touchable controls for the whole page
188static uint8_t nbTouchableControls = 0;
189
190/**********************
191 * STATIC PROTOTYPES
192 **********************/
193// extern const char *get_ux_loc_string(UX_LOC_STRINGS_INDEX index);
194
195// Hold-to-approve parameters
196#if defined(TARGET_FLEX)
197// Percent of a single "hold-to-approve" bar
198#define HOLD_TO_APPROVE_STEP_PERCENT (7)
199// Duration between two bars
200#define HOLD_TO_APPROVE_STEP_DURATION_MS (100)
201// Number of bars displayed when the user start the "hold-to-approve" mechanism
202#define HOLD_TO_APPROVE_FIRST_STEP (0)
203#elif defined(TARGET_STAX)
204#define HOLD_TO_APPROVE_STEP_PERCENT (25)
205#define HOLD_TO_APPROVE_STEP_DURATION_MS (400)
206#define HOLD_TO_APPROVE_FIRST_STEP (1)
207#elif defined(TARGET_APEX)
208#define HOLD_TO_APPROVE_STEP_PERCENT (20)
209#define HOLD_TO_APPROVE_STEP_DURATION_MS (300)
210#define HOLD_TO_APPROVE_FIRST_STEP (1)
211#endif // TARGETS
212
213static inline uint8_t get_hold_to_approve_percent(uint32_t touch_duration)
214{
215 uint8_t current_step_nb
216 = (touch_duration / HOLD_TO_APPROVE_STEP_DURATION_MS) + HOLD_TO_APPROVE_FIRST_STEP;
217 return (current_step_nb * HOLD_TO_APPROVE_STEP_PERCENT);
218}
219
220// function used to retrieve the concerned layout and layout obj matching the given touched obj
221static bool getLayoutAndLayoutObj(nbgl_obj_t *obj,
222 nbgl_layoutInternal_t **layout,
223 layoutObj_t **layoutObj)
224{
225 // only try to find the object on top layout on the stack (the other cannot receive touch
226 // events)
227 *layout = NULL;
228 if ((topLayout) && (topLayout->isUsed)) {
229 uint8_t j;
230
231 // search index of obj in this layout
232 for (j = 0; j < topLayout->nbUsedCallbackObjs; j++) {
233 if (obj == topLayout->callbackObjPool[j].obj) {
235 "getLayoutAndLayoutObj(): obj found in layout %p "
236 "nbUsedCallbackObjs = %d\n",
237 topLayout,
238 topLayout->nbUsedCallbackObjs);
239 *layout = topLayout;
240 *layoutObj = &(topLayout->callbackObjPool[j]);
241 return true;
242 }
243 }
244 }
245 // not found
246 return false;
247}
248
249static void radioTouchCallback(nbgl_obj_t *obj,
250 nbgl_touchType_t eventType,
251 nbgl_layoutInternal_t *layout);
252static void longTouchCallback(nbgl_obj_t *obj,
253 nbgl_touchType_t eventType,
254 nbgl_layoutInternal_t *layout,
255 layoutObj_t *layoutObj);
256
257// callback for most touched object
258static void touchCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType)
259{
260 nbgl_layoutInternal_t *layout;
261 layoutObj_t *layoutObj;
262 bool needRefresh = false;
263
264 if (obj == NULL) {
265 return;
266 }
267 LOG_DEBUG(LAYOUT_LOGGER, "touchCallback(): eventType = %d, obj = %p\n", eventType, obj);
268 if (getLayoutAndLayoutObj(obj, &layout, &layoutObj) == false) {
269 // try with parent, if existing
270 if (getLayoutAndLayoutObj(obj->parent, &layout, &layoutObj) == false) {
271 LOG_WARN(
273 "touchCallback(): eventType = %d, obj = %p, no active layout or obj not found\n",
274 eventType,
275 obj);
276 return;
277 }
278 }
279
280 // case of swipe
281 if (((eventType == SWIPED_UP) || (eventType == SWIPED_DOWN) || (eventType == SWIPED_LEFT)
282 || (eventType == SWIPED_RIGHT))
283 && (obj->type == CONTAINER)) {
284#ifdef NBGL_KEYBOARD
285 if (layout->swipeUsage == SWIPE_USAGE_SUGGESTIONS) {
286 keyboardSwipeCallback(obj, eventType);
287 return;
288 }
289#endif // NBGL_KEYBOARD
290 if (layout->swipeUsage == SWIPE_USAGE_CUSTOM) {
291 layoutObj->index = eventType;
292 }
293 else if ((layout->swipeUsage == SWIPE_USAGE_NAVIGATION)
294 && ((nbgl_obj_t *) layout->container == obj)) {
295 nbgl_container_t *navContainer;
296 if (layout->footerType == FOOTER_NAV) {
297 navContainer = (nbgl_container_t *) layout->footerContainer;
298 }
299 else if (layout->footerType == FOOTER_TEXT_AND_NAV) {
300 navContainer = (nbgl_container_t *) layout->footerContainer->children[1];
301 }
302 else {
303 return;
304 }
305
307 (nbgl_obj_t *) navContainer, eventType, layout->nbPages, &layout->activePage)
308 == false) {
309 // navigation was impossible
310 return;
311 }
312 layoutObj->index = layout->activePage;
313 }
314 }
315
316 // case of navigation bar
317 if (((obj->parent == (nbgl_obj_t *) layout->footerContainer)
318 && (layout->footerType == FOOTER_NAV))
319 || ((obj->parent->type == CONTAINER)
320 && (obj->parent->parent == (nbgl_obj_t *) layout->footerContainer)
321 && (layout->footerType == FOOTER_TEXT_AND_NAV))) {
322 if (layoutNavigationCallback(obj, eventType, layout->nbPages, &layout->activePage)
323 == false) {
324 // navigation was impossible
325 return;
326 }
327 layoutObj->index = layout->activePage;
328 }
329
330 // case of switch
331 if ((obj->type == CONTAINER) && (((nbgl_container_t *) obj)->nbChildren >= 2)
332 && (((nbgl_container_t *) obj)->children[1] != NULL)
333 && (((nbgl_container_t *) obj)->children[1]->type == SWITCH)) {
334 nbgl_switch_t *lSwitch = (nbgl_switch_t *) ((nbgl_container_t *) obj)->children[1];
335 lSwitch->state = (lSwitch->state == ON_STATE) ? OFF_STATE : ON_STATE;
336 nbgl_objDraw((nbgl_obj_t *) lSwitch);
337 // refresh will be done after tune playback
338 needRefresh = true;
339 // index is used for state
340 layoutObj->index = lSwitch->state;
341 }
342 // case of radio
343 else if ((obj->type == CONTAINER) && (((nbgl_container_t *) obj)->nbChildren == 2)
344 && (((nbgl_container_t *) obj)->children[1] != NULL)
345 && (((nbgl_container_t *) obj)->children[1]->type == RADIO_BUTTON)) {
346 radioTouchCallback(obj, eventType, layout);
347 return;
348 }
349 // case of long press
350 else if ((obj->type == CONTAINER) && (((nbgl_container_t *) obj)->nbChildren == 4)
351 && (((nbgl_container_t *) obj)->children[3] != NULL)
352 && (((nbgl_container_t *) obj)->children[3]->type == PROGRESS_BAR)) {
353 longTouchCallback(obj, eventType, layout, layoutObj);
354 return;
355 }
356 LOG_DEBUG(LAYOUT_LOGGER, "touchCallback(): layout->callback = %p\n", layout->callback);
357 if ((layout->callback != NULL) && (layoutObj->token != NBGL_INVALID_TOKEN)) {
358#ifdef HAVE_PIEZO_SOUND
359 if (layoutObj->tuneId < NBGL_NO_TUNE) {
360 os_io_seph_cmd_piezo_play_tune(layoutObj->tuneId);
361 }
362#endif // HAVE_PIEZO_SOUND
363 if (needRefresh) {
365 }
366 layout->callback(layoutObj->token, layoutObj->index);
367 }
368}
369
370// callback for long press button
371static void longTouchCallback(nbgl_obj_t *obj,
372 nbgl_touchType_t eventType,
373 nbgl_layoutInternal_t *layout,
374 layoutObj_t *layoutObj)
375{
376 nbgl_container_t *container = (nbgl_container_t *) obj;
377 // 4th child of container is the progress bar
378 nbgl_progress_bar_t *progressBar = (nbgl_progress_bar_t *) container->children[3];
379
380 LOG_DEBUG(LAYOUT_LOGGER, "longTouchCallback(): eventType = %d, obj = %p\n", eventType, obj);
381
382 // case of pressing a long press button
383 if (eventType == TOUCHING) {
384 uint32_t touchDuration = nbgl_touchGetTouchDuration(obj);
385
386 // Compute the new progress bar state in %
387 uint8_t new_state = get_hold_to_approve_percent(touchDuration);
388
389 // Ensure the callback is triggered once,
390 // when the progress bar state reaches 100%
391 bool trigger_callback = (new_state >= 100) && (progressBar->state < 100);
392
393 // Cap progress bar state at 100%
394 if (new_state >= 100) {
395 new_state = 100;
396 }
397
398 // Update progress bar state
399 if (new_state != progressBar->state) {
400 progressBar->partialRedraw = true;
401 progressBar->state = new_state;
402
403 nbgl_objDraw((nbgl_obj_t *) progressBar);
404 // Ensure progress bar is fully drawn
405 // before calling the callback.
408 }
409
410 if (trigger_callback) {
411 // End of progress bar reached: trigger callback
412 if (layout->callback != NULL) {
413 layout->callback(layoutObj->token, layoutObj->index);
414 }
415 }
416 }
417 // case of releasing a long press button (or getting out of it)
418 else if ((eventType == TOUCH_RELEASED) || (eventType == OUT_OF_TOUCH)
419 || (eventType == SWIPED_LEFT) || (eventType == SWIPED_RIGHT)) {
421 progressBar->partialRedraw = true;
422 progressBar->state = 0;
423 nbgl_objDraw((nbgl_obj_t *) progressBar);
424 // It's necessary to redraw the grey/dotted line, that has been partially wiped
425 nbgl_line_t *line = (nbgl_line_t *) container->children[2];
426 nbgl_objDraw((nbgl_obj_t *) line);
428 }
429}
430
431// callback for radio button touch
432static void radioTouchCallback(nbgl_obj_t *obj,
433 nbgl_touchType_t eventType,
434 nbgl_layoutInternal_t *layout)
435{
436 uint8_t i = NB_MAX_LAYOUTS, radioIndex = 0, foundRadio = 0xFF, foundRadioIndex;
437
438 if (eventType != TOUCHED) {
439 return;
440 }
441
442 i = 0;
443 // parse all objs to find all containers of radio buttons
444 while (i < layout->nbUsedCallbackObjs) {
445 if ((obj == (nbgl_obj_t *) layout->callbackObjPool[i].obj)
446 && (layout->callbackObjPool[i].obj->type == CONTAINER)) {
447 nbgl_radio_t *radio
448 = (nbgl_radio_t *) ((nbgl_container_t *) layout->callbackObjPool[i].obj)
449 ->children[1];
450 nbgl_text_area_t *textArea
452 ->children[0];
453 foundRadio = i;
454 foundRadioIndex = radioIndex;
455 // set text as active (black and bold)
456 textArea->textColor = BLACK;
457 textArea->fontId = SMALL_BOLD_FONT;
458 // ensure that radio button is ON
459 radio->state = ON_STATE;
460 // redraw container
461 nbgl_objDraw((nbgl_obj_t *) obj);
462 }
463 else if ((layout->callbackObjPool[i].obj->type == CONTAINER)
464 && (((nbgl_container_t *) layout->callbackObjPool[i].obj)->nbChildren == 2)
465 && (((nbgl_container_t *) layout->callbackObjPool[i].obj)->children[1]->type
466 == RADIO_BUTTON)) {
467 nbgl_radio_t *radio
468 = (nbgl_radio_t *) ((nbgl_container_t *) layout->callbackObjPool[i].obj)
469 ->children[1];
470 nbgl_text_area_t *textArea
472 ->children[0];
473 radioIndex++;
474 // set to OFF the one that was in ON
475 if (radio->state == ON_STATE) {
476 radio->state = OFF_STATE;
477 // set text it as inactive (gray and normal)
478 textArea->textColor = LIGHT_TEXT_COLOR;
479 textArea->fontId = SMALL_REGULAR_FONT;
480 // redraw container
482 }
483 }
484 i++;
485 }
486 // call callback after redraw to avoid asynchronicity
487 if (foundRadio != 0xFF) {
488 if (layout->callback != NULL) {
489#ifdef HAVE_PIEZO_SOUND
490 if (layout->callbackObjPool[foundRadio].tuneId < NBGL_NO_TUNE) {
491 os_io_seph_cmd_piezo_play_tune(layout->callbackObjPool[foundRadio].tuneId);
492 }
493#endif // HAVE_PIEZO_SOUND
495 layout->callback(layout->callbackObjPool[foundRadio].token, foundRadioIndex);
496 }
497 }
498}
499
500// callback for spinner ticker
501static void spinnerTickerCallback(void)
502{
503 nbgl_spinner_t *spinner;
504 uint8_t i = 0;
505
506 if (!topLayout || !topLayout->isUsed) {
507 return;
508 }
509
510 // get index of obj
511 while (i < topLayout->container->nbChildren) {
512 if (topLayout->container->children[i]->type == CONTAINER) {
513 nbgl_container_t *container = (nbgl_container_t *) topLayout->container->children[i];
514 if (container->nbChildren && (container->children[0]->type == SPINNER)) {
515 spinner = (nbgl_spinner_t *) container->children[0];
516 spinner->position++;
517 // there are only NB_SPINNER_POSITIONS positions
518 if (spinner->position == NB_SPINNER_POSITIONS) {
519 spinner->position = 0;
520 }
521 nbgl_objDraw((nbgl_obj_t *) spinner);
523 return;
524 }
525 }
526 i++;
527 }
528}
529
530// callback for animation ticker
531static void animTickerCallback(void)
532{
533 nbgl_image_t *image;
534 uint8_t i = 0;
535 nbgl_layoutInternal_t *layout = topLayout;
536
537 if (!layout || !layout->isUsed || (layout->animation == NULL)) {
538 return;
539 }
540
541 // get index of image obj
542 while (i < layout->container->nbChildren) {
543 if (layout->container->children[i]->type == CONTAINER) {
544 nbgl_container_t *container = (nbgl_container_t *) layout->container->children[i];
545 if (container->children[1]->type == IMAGE) {
546 image = (nbgl_image_t *) container->children[1];
547 if (layout->animation->parsing == LOOP_PARSING) {
548 if (layout->iconIdxInAnim == (layout->animation->nbIcons - 1)) {
549 layout->iconIdxInAnim = 0;
550 }
551 else {
552 layout->iconIdxInAnim++;
553 }
554 }
555 else {
556 // Flip incrementAnim when reaching upper or lower limit
557 if ((layout->incrementAnim)
558 && (layout->iconIdxInAnim >= layout->animation->nbIcons - 1)) {
559 layout->incrementAnim = false;
560 }
561 else if (layout->iconIdxInAnim == 0) {
562 layout->incrementAnim = true;
563 }
564
565 // Increase / Decrease index according to incrementAnim
566 if (layout->incrementAnim) {
567 layout->iconIdxInAnim++;
568 }
569 else {
570 layout->iconIdxInAnim--;
571 }
572 }
573 image->buffer = layout->animation->icons[layout->iconIdxInAnim];
574 nbgl_objDraw((nbgl_obj_t *) image);
577 return;
578 }
579 }
580 i++;
581 }
582}
583
584static nbgl_line_t *createHorizontalLine(uint8_t layer)
585{
586 nbgl_line_t *line;
587
588 line = (nbgl_line_t *) nbgl_objPoolGet(LINE, layer);
589 line->lineColor = LIGHT_GRAY;
590 line->obj.area.width = SCREEN_WIDTH;
591 line->obj.area.height = 1;
592 line->direction = HORIZONTAL;
593 line->thickness = 1;
594 return line;
595}
596
597#ifdef TARGET_STAX
598static nbgl_line_t *createLeftVerticalLine(uint8_t layer)
599{
600 nbgl_line_t *line;
601
602 line = (nbgl_line_t *) nbgl_objPoolGet(LINE, layer);
603 line->lineColor = LIGHT_GRAY;
604 line->obj.area.width = 1;
605 line->obj.area.height = SCREEN_HEIGHT;
606 line->direction = VERTICAL;
607 line->thickness = 1;
608 line->obj.alignment = MID_LEFT;
609 return line;
610}
611#endif // TARGET_STAX
612
613// function adding a layout object in the callbackObjPool array for the given layout, and
614// configuring it
616 nbgl_obj_t *obj,
617 uint8_t token,
618 tune_index_e tuneId)
619{
620 layoutObj_t *layoutObj = NULL;
621
622 if (layout->nbUsedCallbackObjs < (LAYOUT_OBJ_POOL_LEN - 1)) {
623 layoutObj = &layout->callbackObjPool[layout->nbUsedCallbackObjs];
624 layout->nbUsedCallbackObjs++;
625 layoutObj->obj = obj;
626 layoutObj->token = token;
627 layoutObj->tuneId = tuneId;
628 }
629 else {
630 LOG_FATAL(LAYOUT_LOGGER, "layoutAddCallbackObj: no more callback obj\n");
631 }
632
633 return layoutObj;
634}
635
643{
644 if (layout->container->nbChildren == NB_MAX_CONTAINER_CHILDREN) {
645 LOG_FATAL(LAYOUT_LOGGER, "layoutAddObject(): No more object\n");
646 }
647 layout->container->children[layout->container->nbChildren] = obj;
648 layout->container->nbChildren++;
649}
650
660static int addSwipeInternal(nbgl_layoutInternal_t *layoutInt,
661 uint16_t swipesMask,
662 nbgl_swipe_usage_t usage,
663 uint8_t token,
664 tune_index_e tuneId)
665{
666 layoutObj_t *obj;
667
668 if ((swipesMask & SWIPE_MASK) == 0) {
669 return -1;
670 }
671
672 obj = layoutAddCallbackObj(layoutInt, (nbgl_obj_t *) layoutInt->container, token, tuneId);
673 if (obj == NULL) {
674 return -1;
675 }
676 layoutInt->container->obj.touchMask = swipesMask;
677 layoutInt->swipeUsage = usage;
678
679 return 0;
680}
681
689static nbgl_container_t *addListItem(nbgl_layoutInternal_t *layoutInt, const listItem_t *itemDesc)
690{
691 layoutObj_t *obj;
692 nbgl_text_area_t *textArea = NULL;
693 nbgl_container_t *container;
694 color_t color = ((itemDesc->type == TOUCHABLE_BAR_ITEM) && (itemDesc->state == OFF_STATE))
696 : BLACK;
697 nbgl_font_id_e fontId
698 = ((itemDesc->type == TOUCHABLE_BAR_ITEM) && (itemDesc->state == OFF_STATE))
700 : SMALL_BOLD_FONT;
701
702 LOG_DEBUG(LAYOUT_LOGGER, "addListItem():\n");
703
704 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
706 layoutInt, (nbgl_obj_t *) container, itemDesc->token, itemDesc->tuneId);
707 if (obj == NULL) {
708 return NULL;
709 }
710 obj->index = itemDesc->index;
711
712 // get container children (up to 4: text + left+right icons + sub text)
713 container->children = nbgl_containerPoolGet(4, layoutInt->layer);
714 container->nbChildren = 0;
715
716 container->obj.area.width = AVAILABLE_WIDTH;
717 container->obj.area.height
718 = LIST_ITEM_MIN_TEXT_HEIGHT
719 + 2 * (itemDesc->large ? LIST_ITEM_PRE_HEADING_LARGE : LIST_ITEM_PRE_HEADING);
720 container->layout = HORIZONTAL;
721 container->obj.alignmentMarginX = BORDER_MARGIN;
722 container->obj.alignment = NO_ALIGNMENT;
723 container->obj.alignTo = NULL;
724 // the bar can only be touched if not inactive AND if one of the icon is present
725 // otherwise it is seen as a title
726 if (((itemDesc->type == TOUCHABLE_BAR_ITEM) && (itemDesc->state == ON_STATE))
727 || (itemDesc->type == SWITCH_ITEM)) {
728 container->obj.touchMask = (1 << TOUCHED);
729 container->obj.touchId = CONTROLS_ID + nbTouchableControls;
730 nbTouchableControls++;
731 }
732
733 // allocate main text if not NULL
734 if (itemDesc->text != NULL) {
735 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
736 textArea->textColor = color;
737 textArea->text = PIC(itemDesc->text);
738 textArea->onDrawCallback = NULL;
739 textArea->fontId = fontId;
740 textArea->wrapping = true;
741 textArea->obj.area.width = container->obj.area.width;
742 if (itemDesc->iconLeft != NULL) {
743 // reduce text width accordingly
744 textArea->obj.area.width
745 -= ((nbgl_icon_details_t *) PIC(itemDesc->iconLeft))->width + BAR_INTERVALE;
746 }
747 if (itemDesc->iconRight != NULL) {
748 // reduce text width accordingly
749 textArea->obj.area.width
750 -= ((nbgl_icon_details_t *) PIC(itemDesc->iconRight))->width + BAR_INTERVALE;
751 }
752 else if (itemDesc->type == SWITCH_ITEM) {
753 textArea->obj.area.width -= SWITCH_ICON.width + BAR_INTERVALE;
754 }
755 textArea->obj.area.height = MAX(
756 LIST_ITEM_MIN_TEXT_HEIGHT,
758 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping));
759 textArea->style = NO_STYLE;
760 textArea->obj.alignment = TOP_LEFT;
761 textArea->obj.alignmentMarginY
762 = itemDesc->large ? LIST_ITEM_PRE_HEADING_LARGE : LIST_ITEM_PRE_HEADING;
763 if (textArea->obj.area.height > LIST_ITEM_MIN_TEXT_HEIGHT) {
764 textArea->obj.alignmentMarginY
765 -= (textArea->obj.area.height - LIST_ITEM_MIN_TEXT_HEIGHT) / 2;
766 }
767 textArea->textAlignment = MID_LEFT;
768 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
769 container->nbChildren++;
770 }
771
772 // allocate left icon if present
773 if (itemDesc->iconLeft != NULL) {
774 nbgl_image_t *imageLeft = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
775 imageLeft->foregroundColor = color;
776 imageLeft->buffer = PIC(itemDesc->iconLeft);
777 // align at the left of text
778 imageLeft->obj.alignment = MID_LEFT;
779 imageLeft->obj.alignTo = (nbgl_obj_t *) textArea;
780 imageLeft->obj.alignmentMarginX = BAR_INTERVALE;
781 container->children[container->nbChildren] = (nbgl_obj_t *) imageLeft;
782 container->nbChildren++;
783
784 if (textArea != NULL) {
785 textArea->obj.alignmentMarginX = imageLeft->buffer->width + BAR_INTERVALE;
786 }
787 }
788 // allocate right icon if present
789 if (itemDesc->iconRight != NULL) {
790 nbgl_image_t *imageRight = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
791 imageRight->foregroundColor = color;
792 imageRight->buffer = PIC(itemDesc->iconRight);
793 // align at the right of text
794 imageRight->obj.alignment = MID_RIGHT;
795 imageRight->obj.alignmentMarginX = BAR_INTERVALE;
796 imageRight->obj.alignTo = (nbgl_obj_t *) textArea;
797
798 container->children[container->nbChildren] = (nbgl_obj_t *) imageRight;
799 container->nbChildren++;
800 }
801 else if (itemDesc->type == SWITCH_ITEM) {
802 nbgl_switch_t *switchObj = (nbgl_switch_t *) nbgl_objPoolGet(SWITCH, layoutInt->layer);
803 switchObj->onColor = BLACK;
804 switchObj->offColor = LIGHT_GRAY;
805 switchObj->state = itemDesc->state;
806 switchObj->obj.alignment = MID_RIGHT;
807 switchObj->obj.alignmentMarginX = BAR_INTERVALE;
808 switchObj->obj.alignTo = (nbgl_obj_t *) textArea;
809
810 container->children[container->nbChildren] = (nbgl_obj_t *) switchObj;
811 container->nbChildren++;
812 }
813
814 if (itemDesc->subText != NULL) {
815 nbgl_text_area_t *subTextArea
817
818 subTextArea->textColor = color;
819 subTextArea->text = PIC(itemDesc->subText);
820 subTextArea->textAlignment = MID_LEFT;
821 subTextArea->fontId = SMALL_REGULAR_FONT;
822 subTextArea->style = NO_STYLE;
823 subTextArea->wrapping = true;
824 if (itemDesc->text != NULL) {
825 subTextArea->obj.alignment = BOTTOM_LEFT;
826 subTextArea->obj.alignTo = (nbgl_obj_t *) textArea;
827 subTextArea->obj.alignmentMarginY = LIST_ITEM_HEADING_SUB_TEXT;
828 }
829 else {
830 subTextArea->obj.alignment = TOP_LEFT;
831 subTextArea->obj.alignmentMarginY = SUB_HEADER_MARGIN;
832 container->obj.area.height = SUB_HEADER_MARGIN;
833 }
834 if (itemDesc->iconLeft != NULL) {
835 subTextArea->obj.alignmentMarginX
836 = -(((nbgl_icon_details_t *) PIC(itemDesc->iconLeft))->width + BAR_INTERVALE);
837 }
838 subTextArea->obj.area.width = container->obj.area.width;
839 subTextArea->obj.area.height = nbgl_getTextHeightInWidth(subTextArea->fontId,
840 subTextArea->text,
841 subTextArea->obj.area.width,
842 subTextArea->wrapping);
843 container->children[container->nbChildren] = (nbgl_obj_t *) subTextArea;
844 container->nbChildren++;
845 container->obj.area.height
846 += subTextArea->obj.area.height + subTextArea->obj.alignmentMarginY;
847 }
848 // set this new container as child of main container
849 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
850
851 return container;
852}
853
862static nbgl_container_t *addContentCenter(nbgl_layoutInternal_t *layoutInt,
863 const nbgl_contentCenter_t *info)
864{
865 nbgl_container_t *container;
866 nbgl_text_area_t *textArea = NULL;
867 nbgl_image_t *image = NULL;
868 uint16_t fullHeight = 0;
869
870 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
871
872 // get container children
873 container->nbChildren = 0;
874 // the max number is: icon + anim + title + small title + description + sub-text
875 container->children = nbgl_containerPoolGet(6, layoutInt->layer);
876
877 // add icon or animation if present
878 if (info->icon != NULL) {
879 image = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
880 image->foregroundColor = (layoutInt->invertedColors) ? WHITE : BLACK;
881 image->buffer = PIC(info->icon);
882 image->obj.alignment = TOP_MIDDLE;
883 image->obj.alignmentMarginY = info->iconHug;
884
885 fullHeight += image->buffer->height + info->iconHug;
886 container->children[container->nbChildren] = (nbgl_obj_t *) image;
887 container->nbChildren++;
888
889 if (info->illustrType == ANIM_ILLUSTRATION) {
890 nbgl_image_t *anim;
891 anim = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
892 anim->foregroundColor = (layoutInt->invertedColors) ? WHITE : BLACK;
893 anim->buffer = PIC(info->animation->icons[0]);
894 anim->obj.alignment = TOP_MIDDLE;
895 anim->obj.alignmentMarginY = info->iconHug + info->animOffsetY;
896 anim->obj.alignmentMarginX = info->animOffsetX;
897
898 container->children[container->nbChildren] = (nbgl_obj_t *) anim;
899 container->nbChildren++;
900
901 layoutInt->animation = info->animation;
902 layoutInt->incrementAnim = true;
903 layoutInt->iconIdxInAnim = 0;
904
905 // update ticker to update the animation periodically
907
908 tickerCfg.tickerIntervale = info->animation->delayMs; // ms
909 tickerCfg.tickerValue = info->animation->delayMs; // ms
910 tickerCfg.tickerCallback = &animTickerCallback;
911 nbgl_screenUpdateTicker(layoutInt->layer, &tickerCfg);
912 }
913 }
914 // add title if present
915 if (info->title != NULL) {
916 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
917 textArea->textColor = (layoutInt->invertedColors) ? WHITE : BLACK;
918 textArea->text = PIC(info->title);
919 textArea->textAlignment = CENTER;
920 textArea->fontId = LARGE_MEDIUM_FONT;
921 textArea->wrapping = true;
922 textArea->obj.area.width = AVAILABLE_WIDTH;
923 textArea->obj.area.height = nbgl_getTextHeightInWidth(
924 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
925
926 // if not the first child, put on bottom of the previous, with a margin
927 if (container->nbChildren > 0) {
928 textArea->obj.alignment = BOTTOM_MIDDLE;
929 textArea->obj.alignTo = (nbgl_obj_t *) image;
930 textArea->obj.alignmentMarginY = ICON_TITLE_MARGIN + info->iconHug;
931 }
932 else {
933 textArea->obj.alignment = TOP_MIDDLE;
934 }
935
936 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
937
938 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
939 container->nbChildren++;
940 }
941 // add small title if present
942 if (info->smallTitle != NULL) {
943 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
944 textArea->textColor = (layoutInt->invertedColors) ? WHITE : BLACK;
945 textArea->text = PIC(info->smallTitle);
946 textArea->textAlignment = CENTER;
947 textArea->fontId = SMALL_BOLD_FONT;
948 textArea->wrapping = true;
949 textArea->obj.area.width = AVAILABLE_WIDTH;
950 textArea->obj.area.height = nbgl_getTextHeightInWidth(
951 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
952
953 // if not the first child, put on bottom of the previous, with a margin
954 if (container->nbChildren > 0) {
955 textArea->obj.alignment = BOTTOM_MIDDLE;
956 textArea->obj.alignTo = (nbgl_obj_t *) container->children[container->nbChildren - 1];
957 textArea->obj.alignmentMarginY = VERTICAL_BORDER_MARGIN;
958 if (container->children[container->nbChildren - 1]->type == IMAGE) {
959 textArea->obj.alignmentMarginY = VERTICAL_BORDER_MARGIN + info->iconHug;
960 }
961 else {
962 textArea->obj.alignmentMarginY = TITLE_DESC_MARGIN;
963 }
964 }
965 else {
966 textArea->obj.alignment = TOP_MIDDLE;
967 }
968
969 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
970
971 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
972 container->nbChildren++;
973 }
974 // add description if present
975 if (info->description != NULL) {
976 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
977 textArea->textColor = (layoutInt->invertedColors) ? WHITE : BLACK;
978 textArea->text = PIC(info->description);
979 textArea->textAlignment = CENTER;
980 textArea->fontId = SMALL_REGULAR_FONT;
981 textArea->wrapping = true;
982 textArea->obj.area.width = AVAILABLE_WIDTH;
983 textArea->obj.area.height = nbgl_getTextHeightInWidth(
984 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
985
986 // if not the first child, put on bottom of the previous, with a margin
987 if (container->nbChildren > 0) {
988 textArea->obj.alignment = BOTTOM_MIDDLE;
989 textArea->obj.alignTo = (nbgl_obj_t *) container->children[container->nbChildren - 1];
990 if (container->children[container->nbChildren - 1]->type == TEXT_AREA) {
991 // if previous element is text, only space of 16 px
992 textArea->obj.alignmentMarginY = TITLE_DESC_MARGIN;
993 }
994 else {
995 textArea->obj.alignmentMarginY = ICON_TITLE_MARGIN + info->iconHug;
996 }
997 }
998 else {
999 textArea->obj.alignment = TOP_MIDDLE;
1000 }
1001
1002 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
1003
1004 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
1005 container->nbChildren++;
1006 }
1007 // add sub-text if present
1008 if (info->subText != NULL) {
1009 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1010 textArea->textColor = LIGHT_TEXT_COLOR;
1011 textArea->text = PIC(info->subText);
1012 textArea->textAlignment = CENTER;
1013 textArea->fontId = SMALL_REGULAR_FONT;
1014 textArea->wrapping = true;
1015 textArea->obj.area.width = AVAILABLE_WIDTH;
1016 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1017 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1018 // sub-text is included in a hug of 8px
1019 textArea->obj.area.height += 2 * 8;
1020 // if not the first child, put on bottom of the previous, with a margin
1021 if (container->nbChildren > 0) {
1022 textArea->obj.alignment = BOTTOM_MIDDLE;
1023 textArea->obj.alignTo = (nbgl_obj_t *) container->children[container->nbChildren - 1];
1024 textArea->obj.alignmentMarginY = 16;
1025 if (container->children[container->nbChildren - 1]->type == IMAGE) {
1026 textArea->obj.alignmentMarginY += info->iconHug;
1027 }
1028 }
1029 else {
1030 textArea->obj.alignment = TOP_MIDDLE;
1031 }
1032
1033 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
1034
1035 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
1036 container->nbChildren++;
1037 }
1038 container->layout = VERTICAL;
1039 container->obj.alignment = CENTER;
1040 container->obj.area.width = AVAILABLE_WIDTH;
1041 container->obj.area.height = fullHeight;
1042 if (info->padding) {
1043 container->obj.area.height += 40;
1044 }
1045
1046 // set this new container as child of main container
1047 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
1048
1049 return container;
1050}
1051
1052/**********************
1053 * GLOBAL FUNCTIONS
1054 **********************/
1055
1063{
1064 nbgl_layoutInternal_t *layout = NULL;
1065
1066 if (description->modal) {
1067 int i;
1068 // find an empty layout in the array of layouts (0 is reserved for background)
1069 for (i = 1; i < NB_MAX_LAYOUTS; i++) {
1070 if (!gLayout[i].isUsed) {
1071 layout = &gLayout[i];
1072 }
1073 }
1074 }
1075 else {
1076 // always use layout 0 for background
1077 layout = &gLayout[0];
1078 if (topLayout == NULL) {
1079 topLayout = layout;
1080 }
1081 }
1082 if (layout == NULL) {
1083 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutGet(): impossible to get a layout!\n");
1084 return NULL;
1085 }
1086
1087 // reset globals
1088 nbgl_layoutInternal_t *backgroundTop = gLayout[0].top;
1089 memset(layout, 0, sizeof(nbgl_layoutInternal_t));
1090 // link layout to other ones
1091 if (description->modal) {
1092 if (topLayout != NULL) {
1093 // if topLayout already existing, push this new one on top of it
1094 topLayout->top = layout;
1095 layout->bottom = topLayout;
1096 }
1097 else {
1098 // otherwise put it on top of background layout
1099 layout->bottom = &gLayout[0];
1100 gLayout[0].top = layout;
1101 }
1102 topLayout = layout;
1103 }
1104 else {
1105 // restore potentially valid background top layer
1106 gLayout[0].top = backgroundTop;
1107 }
1108
1109 nbTouchableControls = 0;
1110
1111 layout->callback = (nbgl_layoutTouchCallback_t) PIC(description->onActionCallback);
1112 layout->modal = description->modal;
1113 layout->withLeftBorder = description->withLeftBorder;
1114 if (description->modal) {
1115 layout->layer = nbgl_screenPush(&layout->children,
1117 &description->ticker,
1118 (nbgl_touchCallback_t) touchCallback);
1119 }
1120 else {
1121 nbgl_screenSet(&layout->children,
1123 &description->ticker,
1124 (nbgl_touchCallback_t) touchCallback);
1125 layout->layer = 0;
1126 }
1128 layout->container->obj.area.width = SCREEN_WIDTH;
1129 layout->container->obj.area.height = SCREEN_HEIGHT;
1130 layout->container->layout = VERTICAL;
1131 layout->container->children = nbgl_containerPoolGet(NB_MAX_CONTAINER_CHILDREN, layout->layer);
1132 // by default, if no header, main container is aligned on top-left
1133 layout->container->obj.alignment = TOP_LEFT;
1134 // main container is always the second object, leaving space for header
1135 layout->children[MAIN_CONTAINER_INDEX] = (nbgl_obj_t *) layout->container;
1136 layout->isUsed = true;
1137
1138 // if a tap text is defined, make the container tapable and display this text in gray
1139 if (description->tapActionText != NULL) {
1140 layoutObj_t *obj;
1141 const char *tapActionText = PIC(description->tapActionText);
1142
1143 obj = &layout->callbackObjPool[layout->nbUsedCallbackObjs];
1144 layout->nbUsedCallbackObjs++;
1145 obj->obj = (nbgl_obj_t *) layout->container;
1146 obj->token = description->tapActionToken;
1147 obj->tuneId = description->tapTuneId;
1148 layout->container->obj.touchMask = (1 << TOUCHED);
1149 layout->container->obj.touchId = WHOLE_SCREEN_ID;
1150
1151 if (strlen(tapActionText) > 0) {
1152 nbgl_layoutUpFooter_t footerDesc;
1153 footerDesc.type = UP_FOOTER_TEXT;
1154 footerDesc.text.text = tapActionText;
1155 footerDesc.text.token = description->tapActionToken;
1156 footerDesc.text.tuneId = description->tapTuneId;
1157 nbgl_layoutAddUpFooter((nbgl_layout_t *) layout, &footerDesc);
1158 }
1159 }
1160 return (nbgl_layout_t *) layout;
1161}
1162
1175 uint16_t swipesMask,
1176 const char *text,
1177 uint8_t token,
1178 tune_index_e tuneId)
1179{
1180 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1181
1182 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddSwipe():\n");
1183 if (layout == NULL) {
1184 return -1;
1185 }
1186
1187 if (text) {
1188 // create 'tap to continue' text area
1190 layoutInt->tapText->text = PIC(text);
1191 layoutInt->tapText->textColor = LIGHT_TEXT_COLOR;
1192 layoutInt->tapText->fontId = SMALL_REGULAR_FONT;
1193 layoutInt->tapText->obj.area.width = AVAILABLE_WIDTH;
1194 layoutInt->tapText->obj.area.height = nbgl_getFontLineHeight(layoutInt->tapText->fontId);
1195 layoutInt->tapText->textAlignment = CENTER;
1196 layoutInt->tapText->obj.alignmentMarginY = TAP_TO_CONTINUE_MARGIN;
1197 layoutInt->tapText->obj.alignment = BOTTOM_MIDDLE;
1198 }
1199 return addSwipeInternal(layoutInt, swipesMask, SWIPE_USAGE_CUSTOM, token, tuneId);
1200}
1201
1210{
1211 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1212
1213 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutInvertBackground():\n");
1214 if (layout == NULL) {
1215 return -1;
1216 }
1217 layoutInt->invertedColors = true;
1219
1220 // invert potential "Tap to continue"
1221 if ((layoutInt->upFooterContainer) && (layoutInt->upFooterContainer->nbChildren == 1)
1222 && (layoutInt->upFooterContainer->children[0]->type == TEXT_AREA)) {
1223 nbgl_text_area_t *textArea = (nbgl_text_area_t *) layoutInt->upFooterContainer->children[0];
1224 if (textArea->textColor == LIGHT_TEXT_COLOR) {
1225 textArea->textColor = INACTIVE_COLOR;
1226 }
1227 }
1228
1229 return 0;
1230}
1231
1242 const nbgl_icon_details_t *icon,
1243 uint8_t token,
1244 tune_index_e tuneId)
1245{
1246 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1247 layoutObj_t *obj;
1248 nbgl_button_t *button;
1249
1250 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddTopRightButton():\n");
1251 if (layout == NULL) {
1252 return -1;
1253 }
1254 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
1255 obj = layoutAddCallbackObj(layoutInt, (nbgl_obj_t *) button, token, tuneId);
1256 if (obj == NULL) {
1257 return -1;
1258 }
1259
1260 button->obj.area.width = BUTTON_WIDTH;
1261 button->obj.area.height = BUTTON_DIAMETER;
1262 button->radius = BUTTON_RADIUS;
1263 button->obj.alignmentMarginX = BORDER_MARGIN;
1264 button->obj.alignmentMarginY = BORDER_MARGIN;
1265 button->foregroundColor = BLACK;
1266 button->innerColor = WHITE;
1267 button->borderColor = LIGHT_GRAY;
1268 button->obj.touchMask = (1 << TOUCHED);
1269 button->obj.touchId = TOP_RIGHT_BUTTON_ID;
1270 button->icon = PIC(icon);
1271 button->obj.alignment = TOP_RIGHT;
1272
1273 // add to screen
1274 layoutInt->children[TOP_RIGHT_BUTTON_INDEX] = (nbgl_obj_t *) button;
1275
1276 return 0;
1277}
1278
1287{
1288 nbgl_layoutFooter_t footerDesc;
1289 footerDesc.type = FOOTER_NAV;
1290 footerDesc.separationLine = info->withSeparationLine;
1291 footerDesc.navigation.activePage = info->activePage;
1292 footerDesc.navigation.nbPages = info->nbPages;
1293 footerDesc.navigation.withExitKey = info->withExitKey;
1294 footerDesc.navigation.withBackKey = info->withBackKey;
1295 footerDesc.navigation.withPageIndicator = false;
1296 footerDesc.navigation.token = info->token;
1297 footerDesc.navigation.tuneId = info->tuneId;
1298 return nbgl_layoutAddExtendedFooter(layout, &footerDesc);
1299}
1300
1313 const nbgl_icon_details_t *icon,
1314 uint8_t token,
1315 bool separationLine,
1316 tune_index_e tuneId)
1317{
1318 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddBottomButton():\n");
1319 nbgl_layoutFooter_t footerDesc;
1320 footerDesc.type = FOOTER_SIMPLE_BUTTON;
1321 footerDesc.separationLine = separationLine;
1322 footerDesc.button.fittingContent = false;
1323 footerDesc.button.icon = PIC(icon);
1324 footerDesc.button.text = NULL;
1325 footerDesc.button.token = token;
1326 footerDesc.button.tuneId = tuneId;
1327 footerDesc.button.style = WHITE_BACKGROUND;
1328 return nbgl_layoutAddExtendedFooter(layout, &footerDesc);
1329}
1330
1339{
1340 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1341 nbgl_container_t *container;
1342 listItem_t itemDesc = {0};
1343
1344 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddTouchableBar():\n");
1345 if (layout == NULL) {
1346 return -1;
1347 }
1348 // main text is mandatory
1349 if (barLayout->text == NULL) {
1350 LOG_FATAL(LAYOUT_LOGGER, "nbgl_layoutAddTouchableBar(): main text is mandatory\n");
1351 }
1352
1353 itemDesc.iconLeft = barLayout->iconLeft;
1354 itemDesc.iconRight = barLayout->iconRight;
1355 itemDesc.text = barLayout->text;
1356 itemDesc.subText = barLayout->subText;
1357 itemDesc.token = barLayout->token;
1358 itemDesc.tuneId = barLayout->tuneId;
1359 itemDesc.state = (barLayout->inactive) ? OFF_STATE : ON_STATE;
1360 itemDesc.large = barLayout->large;
1361 itemDesc.type = TOUCHABLE_BAR_ITEM;
1362 container = addListItem(layoutInt, &itemDesc);
1363
1364 if (container == NULL) {
1365 return -1;
1366 }
1367 return container->obj.area.height;
1368}
1369
1378{
1379 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1380 nbgl_container_t *container;
1381 listItem_t itemDesc = {0};
1382
1383 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddSwitch():\n");
1384 if (layout == NULL) {
1385 return -1;
1386 }
1387 // main text is mandatory
1388 if (switchLayout->text == NULL) {
1389 LOG_FATAL(LAYOUT_LOGGER, "nbgl_layoutAddSwitch(): main text is mandatory\n");
1390 }
1391
1392 itemDesc.text = switchLayout->text;
1393 itemDesc.subText = switchLayout->subText;
1394 itemDesc.token = switchLayout->token;
1395 itemDesc.tuneId = switchLayout->tuneId;
1396 itemDesc.state = switchLayout->initState;
1397 itemDesc.large = false;
1398 itemDesc.type = SWITCH_ITEM;
1399 container = addListItem(layoutInt, &itemDesc);
1400
1401 if (container == NULL) {
1402 return -1;
1403 }
1404 return container->obj.area.height;
1405}
1406
1415int nbgl_layoutAddText(nbgl_layout_t *layout, const char *text, const char *subText)
1416{
1417 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1418 nbgl_container_t *container;
1419 listItem_t itemDesc = {0};
1420
1421 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddText():\n");
1422 if (layout == NULL) {
1423 return -1;
1424 }
1425
1426 itemDesc.text = text;
1427 itemDesc.subText = subText;
1428 itemDesc.token = NBGL_INVALID_TOKEN;
1429 itemDesc.tuneId = NBGL_NO_TUNE;
1430 itemDesc.type = TEXT_ITEM;
1431 container = addListItem(layoutInt, &itemDesc);
1432
1433 if (container == NULL) {
1434 return -1;
1435 }
1436 return container->obj.area.height;
1437}
1438
1451 const char *text,
1452 const char *subText,
1453 uint8_t token,
1454 uint8_t index)
1455{
1456 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1457 nbgl_container_t *container;
1458 listItem_t itemDesc = {0};
1459 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddTextWithAlias():\n");
1460 if (layout == NULL) {
1461 return -1;
1462 }
1463
1464 itemDesc.text = text;
1465 itemDesc.subText = subText;
1466 itemDesc.iconRight = &MINI_PUSH_ICON;
1467 itemDesc.token = token;
1468 itemDesc.tuneId = NBGL_NO_TUNE;
1469 itemDesc.type = TOUCHABLE_BAR_ITEM;
1470 itemDesc.index = index;
1471 itemDesc.state = ON_STATE;
1472 container = addListItem(layoutInt, &itemDesc);
1473
1474 if (container == NULL) {
1475 return -1;
1476 }
1477 return container->obj.area.height;
1478}
1479
1488int nbgl_layoutAddLargeCaseText(nbgl_layout_t *layout, const char *text, bool grayedOut)
1489{
1490 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1491 nbgl_text_area_t *textArea;
1492
1493 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddLargeCaseText():\n");
1494 if (layout == NULL) {
1495 return -1;
1496 }
1497 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1498
1499 textArea->textColor = grayedOut ? INACTIVE_TEXT_COLOR : BLACK;
1500 textArea->text = PIC(text);
1501 textArea->textAlignment = MID_LEFT;
1502 textArea->fontId = LARGE_MEDIUM_FONT;
1503 textArea->obj.area.width = AVAILABLE_WIDTH;
1504 textArea->wrapping = true;
1505 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1506 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1507 textArea->style = NO_STYLE;
1508 textArea->obj.alignment = NO_ALIGNMENT;
1509 textArea->obj.alignmentMarginX = BORDER_MARGIN;
1510 if (layoutInt->container->nbChildren == 0) {
1511 // if first object of container, increase the margin from top
1512 textArea->obj.alignmentMarginY += PRE_FIRST_TEXT_MARGIN;
1513 }
1514 else {
1515 textArea->obj.alignmentMarginY = INTER_PARAGRAPHS_MARGIN; // between paragraphs
1516 }
1517
1518 // set this new obj as child of main container
1519 layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
1520
1521 return 0;
1522}
1523
1537 const char *title,
1538 const char *description,
1539 const char *info)
1540{
1541 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1542 nbgl_text_area_t *textArea;
1543
1544 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddTextContent():\n");
1545 if (layout == NULL) {
1546 return -1;
1547 }
1548
1549 // create title
1550 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1551 textArea->textColor = BLACK;
1552 textArea->text = PIC(title);
1553 textArea->textAlignment = MID_LEFT;
1554 textArea->fontId = LARGE_MEDIUM_FONT;
1555 textArea->style = NO_STYLE;
1556 textArea->wrapping = true;
1557 textArea->obj.alignment = NO_ALIGNMENT;
1558 textArea->obj.alignmentMarginX = BORDER_MARGIN;
1559 textArea->obj.alignmentMarginY = PRE_TITLE_MARGIN;
1560 textArea->obj.area.width = AVAILABLE_WIDTH;
1561 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1562 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1563 // set this new obj as child of main container
1564 layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
1565
1566 // create description
1567 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1568 textArea->textColor = BLACK;
1569 textArea->text = PIC(description);
1570 textArea->fontId = SMALL_REGULAR_FONT;
1571 textArea->style = NO_STYLE;
1572 textArea->wrapping = true;
1573 textArea->obj.area.width = AVAILABLE_WIDTH;
1574 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1575 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1576 textArea->textAlignment = MID_LEFT;
1577 textArea->obj.alignment = NO_ALIGNMENT;
1578 textArea->obj.alignmentMarginX = BORDER_MARGIN;
1579 textArea->obj.alignmentMarginY = PRE_DESCRIPTION_MARGIN;
1580 // set this new obj as child of main container
1581 layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
1582
1583 // create info on the bottom
1584 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1585 textArea->textColor = LIGHT_TEXT_COLOR;
1586 textArea->text = PIC(info);
1587 textArea->fontId = SMALL_REGULAR_FONT;
1588 textArea->style = NO_STYLE;
1589 textArea->wrapping = true;
1590 textArea->obj.area.width = AVAILABLE_WIDTH;
1591 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1592 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1593 textArea->textAlignment = MID_LEFT;
1594 textArea->obj.alignment = BOTTOM_LEFT;
1595 textArea->obj.alignmentMarginX = BORDER_MARGIN;
1596 textArea->obj.alignmentMarginY = 40;
1597 // set this new obj as child of main container
1598 layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
1599
1600 return layoutInt->container->obj.area.height;
1601}
1602
1611{
1612 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1613 layoutObj_t *obj;
1614 uint8_t i;
1615
1616 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddRadioChoice():\n");
1617 if (layout == NULL) {
1618 return -1;
1619 }
1620 for (i = 0; i < choices->nbChoices; i++) {
1621 nbgl_container_t *container;
1622 nbgl_text_area_t *textArea;
1623 nbgl_radio_t *button;
1624 nbgl_line_t *line;
1625
1626 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
1627 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1628 button = (nbgl_radio_t *) nbgl_objPoolGet(RADIO_BUTTON, layoutInt->layer);
1629
1631 layoutInt, (nbgl_obj_t *) container, choices->token, choices->tuneId);
1632 if (obj == NULL) {
1633 return -1;
1634 }
1635
1636 // get container children (max 2)
1637 container->nbChildren = 2;
1638 container->children = nbgl_containerPoolGet(container->nbChildren, layoutInt->layer);
1639 container->obj.area.width = AVAILABLE_WIDTH;
1640 container->obj.area.height = RADIO_CHOICE_HEIGHT;
1641 container->obj.alignment = NO_ALIGNMENT;
1642 container->obj.alignmentMarginX = BORDER_MARGIN;
1643 container->obj.alignTo = (nbgl_obj_t *) NULL;
1644
1645 // init button for this choice
1646 button->activeColor = BLACK;
1647 button->borderColor = LIGHT_GRAY;
1648 button->obj.alignTo = (nbgl_obj_t *) container;
1649 button->obj.alignment = MID_RIGHT;
1650 button->state = OFF_STATE;
1651 container->children[1] = (nbgl_obj_t *) button;
1652
1653 // init text area for this choice
1654 if (choices->localized == true) {
1655#ifdef HAVE_LANGUAGE_PACK
1656 textArea->text = get_ux_loc_string(choices->nameIds[i]);
1657#endif // HAVE_LANGUAGE_PACK
1658 }
1659 else {
1660 textArea->text = PIC(choices->names[i]);
1661 }
1662 textArea->textAlignment = MID_LEFT;
1663 textArea->obj.area.width = container->obj.area.width - RADIO_WIDTH;
1664 textArea->style = NO_STYLE;
1665 textArea->obj.alignment = MID_LEFT;
1666 textArea->obj.alignTo = (nbgl_obj_t *) container;
1667 container->children[0] = (nbgl_obj_t *) textArea;
1668
1669 // whole container should be touchable
1670 container->obj.touchMask = (1 << TOUCHED);
1671 container->obj.touchId = CONTROLS_ID + nbTouchableControls;
1672 nbTouchableControls++;
1673
1674 // highlight init choice
1675 if (i == choices->initChoice) {
1676 button->state = ON_STATE;
1677 textArea->textColor = BLACK;
1678 textArea->fontId = SMALL_BOLD_FONT;
1679 }
1680 else {
1681 button->state = OFF_STATE;
1682 textArea->textColor = LIGHT_TEXT_COLOR;
1683 textArea->fontId = SMALL_REGULAR_FONT;
1684 }
1685 textArea->obj.area.height = nbgl_getFontHeight(textArea->fontId);
1686
1687 line = createHorizontalLine(layoutInt->layer);
1688 line->obj.alignmentMarginY = -1;
1689
1690 // set these new objs as child of main container
1691 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
1692 layoutAddObject(layoutInt, (nbgl_obj_t *) line);
1693 }
1694
1695 return 0;
1696}
1697
1707{
1708 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1709 nbgl_container_t *container;
1710 nbgl_contentCenter_t centeredInfo = {0};
1711
1712 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddCenteredInfo():\n");
1713 if (layout == NULL) {
1714 return -1;
1715 }
1716
1717 centeredInfo.icon = info->icon;
1718 centeredInfo.illustrType = ICON_ILLUSTRATION;
1719
1720 if (info->text1 != NULL) {
1721 if (info->style != NORMAL_INFO) {
1722 centeredInfo.title = info->text1;
1723 }
1724 else {
1725 centeredInfo.smallTitle = info->text1;
1726 }
1727 }
1728 if (info->text2 != NULL) {
1729 if (info->style != LARGE_CASE_BOLD_INFO) {
1730 centeredInfo.description = info->text2;
1731 }
1732 else {
1733 centeredInfo.smallTitle = info->text2;
1734 }
1735 }
1736 if (info->text3 != NULL) {
1737 if (info->style == LARGE_CASE_GRAY_INFO) {
1738 centeredInfo.subText = info->text3;
1739 }
1740 else {
1741 centeredInfo.description = info->text3;
1742 }
1743 }
1744 container = addContentCenter(layoutInt, &centeredInfo);
1745
1746 if (info->onTop) {
1747 container->obj.alignmentMarginX = BORDER_MARGIN;
1748 container->obj.alignmentMarginY = BORDER_MARGIN + info->offsetY;
1749 container->obj.alignment = NO_ALIGNMENT;
1750 }
1751 else {
1752 container->obj.alignmentMarginY = info->offsetY;
1753 }
1754
1755 return container->obj.area.height;
1756}
1757
1767{
1768 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1769 nbgl_container_t *container;
1770
1771 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddContentCenter():\n");
1772 if (layout == NULL) {
1773 return -1;
1774 }
1775
1776 container = addContentCenter(layoutInt, info);
1777
1778 return container->obj.area.height;
1779}
1780
1789{
1790 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1791 nbgl_container_t *container;
1792 nbgl_text_area_t *textArea;
1793 uint8_t row;
1794
1795 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddLeftContent():\n");
1796 if (layout == NULL) {
1797 return -1;
1798 }
1799 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
1800
1801 // get container children
1802 container->nbChildren = info->nbRows + 1;
1803 container->children = nbgl_containerPoolGet(container->nbChildren, layoutInt->layer);
1804 container->layout = VERTICAL;
1805 container->obj.area.width = AVAILABLE_WIDTH;
1806 container->obj.alignmentMarginX = BORDER_MARGIN;
1807
1808 // create title
1809 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1810 textArea->textColor = BLACK;
1811 textArea->text = PIC(info->title);
1812 textArea->textAlignment = MID_LEFT;
1813 textArea->fontId = LARGE_MEDIUM_FONT;
1814 textArea->wrapping = true;
1815#ifdef TARGET_STAX
1816 textArea->obj.alignmentMarginY = 24;
1817#endif
1818 textArea->obj.area.width = AVAILABLE_WIDTH;
1819 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1820 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1821
1822 container->obj.area.height += textArea->obj.area.height + textArea->obj.alignmentMarginY;
1823
1824 container->children[0] = (nbgl_obj_t *) textArea;
1825
1826 for (row = 0; row < info->nbRows; row++) {
1827 nbgl_container_t *rowContainer;
1828 nbgl_image_t *image;
1829
1830 // create a grid with 1 icon on the left column and 1 text on the right one
1831 rowContainer = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, 0);
1832 rowContainer->nbChildren = 2; // 1 icon + 1 text
1833 rowContainer->children = nbgl_containerPoolGet(rowContainer->nbChildren, 0);
1834 rowContainer->obj.area.width = AVAILABLE_WIDTH;
1835
1836 image = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, 0);
1837 image->foregroundColor = BLACK;
1838 image->buffer = PIC(info->rowIcons[row]);
1839 rowContainer->children[0] = (nbgl_obj_t *) image;
1840
1841 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, 0);
1842 textArea->textColor = BLACK;
1843 textArea->text = PIC(info->rowTexts[row]);
1844 textArea->textAlignment = MID_LEFT;
1845 textArea->fontId = SMALL_REGULAR_FONT;
1846 textArea->wrapping = true;
1847 textArea->obj.area.width
1848 = AVAILABLE_WIDTH - image->buffer->width - LEFT_CONTENT_ICON_TEXT_X;
1849 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1850 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1851 textArea->obj.alignment = MID_RIGHT;
1852 rowContainer->children[1] = (nbgl_obj_t *) textArea;
1853 rowContainer->obj.area.height
1854 = MAX(image->buffer->height, textArea->obj.area.height + LEFT_CONTENT_TEXT_PADDING);
1855
1856 if (row == 0) {
1857 rowContainer->obj.alignmentMarginY = PRE_FIRST_ROW_MARGIN;
1858 }
1859 else {
1860 rowContainer->obj.alignmentMarginY = INTER_ROWS_MARGIN;
1861 }
1862 container->children[1 + row] = (nbgl_obj_t *) rowContainer;
1863 container->obj.area.height
1864 += rowContainer->obj.area.height + rowContainer->obj.alignmentMarginY;
1865 }
1866 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
1867
1868 return container->obj.area.height;
1869}
1870
1871#ifdef NBGL_QRCODE
1881{
1882 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1883 nbgl_container_t *container;
1884 nbgl_text_area_t *textArea = NULL;
1886 uint16_t fullHeight = 0;
1887
1888 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddQRCode():\n");
1889 if (layout == NULL) {
1890 return -1;
1891 }
1892
1893 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
1894
1895 // get container children (max 2 (QRCode + text1 + text2))
1896 container->children = nbgl_containerPoolGet(3, layoutInt->layer);
1897 container->nbChildren = 0;
1898
1900 // version is forced to V10 if url is longer than 62 characters
1901 if (strlen(PIC(info->url)) > 62) {
1902 qrcode->version = QRCODE_V10;
1903 }
1904 else {
1905 qrcode->version = QRCODE_V4;
1906 }
1907 qrcode->foregroundColor = BLACK;
1908 // in QR V4, we use:
1909 // - 8*8 screen pixels for one QR pixel on Stax/Flex
1910 // - 5*5 screen pixels for one QR pixel on Apex
1911 // in QR V10, we use 4*4 screen pixels for one QR pixel
1912#ifndef TARGET_APEX
1913 qrcode->obj.area.width
1914 = (qrcode->version == QRCODE_V4) ? (QR_V4_NB_PIX_SIZE * 8) : (QR_V10_NB_PIX_SIZE * 4);
1915#else // TARGET_APEX
1916 qrcode->obj.area.width
1917 = (qrcode->version == QRCODE_V4) ? (QR_V4_NB_PIX_SIZE * 5) : (QR_V10_NB_PIX_SIZE * 4);
1918#endif // TARGET_APEX
1919 qrcode->obj.area.height = qrcode->obj.area.width;
1920 qrcode->text = PIC(info->url);
1921 qrcode->obj.area.bpp = NBGL_BPP_1;
1922 qrcode->obj.alignment = TOP_MIDDLE;
1923
1924 fullHeight += qrcode->obj.area.height;
1925 container->children[container->nbChildren] = (nbgl_obj_t *) qrcode;
1926 container->nbChildren++;
1927
1928 if (info->text1 != NULL) {
1929 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1930 textArea->textColor = BLACK;
1931 textArea->text = PIC(info->text1);
1932 textArea->textAlignment = CENTER;
1933 textArea->fontId = (info->largeText1 == true) ? LARGE_MEDIUM_FONT : SMALL_REGULAR_FONT;
1934 textArea->wrapping = true;
1935 textArea->obj.area.width = AVAILABLE_WIDTH;
1936 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1937 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1938 textArea->obj.alignment = BOTTOM_MIDDLE;
1939 textArea->obj.alignTo = (nbgl_obj_t *) container->children[container->nbChildren - 1];
1940 textArea->obj.alignmentMarginY = QR_PRE_TEXT_MARGIN;
1941
1942 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
1943
1944 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
1945 container->nbChildren++;
1946 }
1947 if (info->text2 != NULL) {
1948 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1949 textArea->textColor = LIGHT_TEXT_COLOR;
1950 textArea->text = PIC(info->text2);
1951 textArea->textAlignment = CENTER;
1952 textArea->fontId = SMALL_REGULAR_FONT;
1953 textArea->wrapping = true;
1954 textArea->obj.area.width = AVAILABLE_WIDTH;
1955 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1956 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1957 textArea->obj.alignment = BOTTOM_MIDDLE;
1958 textArea->obj.alignTo = (nbgl_obj_t *) container->children[container->nbChildren - 1];
1959 if (info->text1 != NULL) {
1960 textArea->obj.alignmentMarginY = QR_INTER_TEXTS_MARGIN;
1961 }
1962 else {
1963 textArea->obj.alignmentMarginY = QR_PRE_TEXT_MARGIN + 8;
1964 }
1965
1966 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY + 8;
1967
1968 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
1969 container->nbChildren++;
1970 }
1971 // ensure that fullHeight is fitting in main container height (with 16 px margin)
1972 if ((fullHeight >= (layoutInt->container->obj.area.height - 16))
1973 && (qrcode->version == QRCODE_V4)) {
1974 qrcode->version = QRCODE_V4_SMALL;
1975 // in QR V4 small, we use 4*4 screen pixels for one QR pixel
1976 qrcode->obj.area.width = QR_V4_NB_PIX_SIZE * 4;
1977 qrcode->obj.area.height = qrcode->obj.area.width;
1978 fullHeight -= QR_V4_NB_PIX_SIZE * 4;
1979 }
1980 container->obj.area.height = fullHeight;
1981 container->layout = VERTICAL;
1982 if (info->centered) {
1983 container->obj.alignment = CENTER;
1984 }
1985 else {
1986 container->obj.alignment = BOTTOM_MIDDLE;
1987 container->obj.alignTo
1988 = layoutInt->container->children[layoutInt->container->nbChildren - 1];
1989 }
1990 container->obj.alignmentMarginY = info->offsetY;
1991
1992 container->obj.area.width = AVAILABLE_WIDTH;
1993
1994 // set this new container as child of main container
1995 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
1996
1997 return fullHeight;
1998}
1999#endif // NBGL_QRCODE
2000
2010{
2011 nbgl_layoutFooter_t footerDesc;
2012 footerDesc.type = FOOTER_CHOICE_BUTTONS;
2013 footerDesc.separationLine = false;
2014 footerDesc.choiceButtons.bottomText = info->bottomText;
2015 footerDesc.choiceButtons.token = info->token;
2016 footerDesc.choiceButtons.topText = info->topText;
2017 footerDesc.choiceButtons.topIcon = info->topIcon;
2018 footerDesc.choiceButtons.style = info->style;
2019 footerDesc.choiceButtons.tuneId = info->tuneId;
2020 return nbgl_layoutAddExtendedFooter(layout, &footerDesc);
2021}
2022
2034{
2036 .horizontalButtons.leftIcon = info->leftIcon,
2037 .horizontalButtons.leftToken = info->leftToken,
2038 .horizontalButtons.rightText = info->rightText,
2039 .horizontalButtons.rightToken = info->rightToken,
2040 .horizontalButtons.tuneId = info->tuneId};
2041
2042 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddHorizontalButtons():\n");
2043 return nbgl_layoutAddUpFooter(layout, &upFooterDesc);
2044}
2045
2054{
2055 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
2056 nbgl_text_area_t *itemTextArea;
2057 nbgl_text_area_t *valueTextArea;
2058 nbgl_container_t *container;
2059 uint8_t i;
2060
2061 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddTagValueList():\n");
2062 if (layout == NULL) {
2063 return -1;
2064 }
2065
2066 for (i = 0; i < list->nbPairs; i++) {
2067 const nbgl_layoutTagValue_t *pair;
2068 uint16_t fullHeight = 0;
2069 const nbgl_icon_details_t *valueIcon = NULL;
2070
2071 if (list->pairs != NULL) {
2072 pair = &list->pairs[i];
2073 }
2074 else {
2075 pair = list->callback(list->startIndex + i);
2076 }
2077
2078 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
2079
2080 // get container children (max 3 if a valueIcon, otherwise 2)
2081 container->children
2082 = nbgl_containerPoolGet((pair->valueIcon != NULL) ? 3 : 2, layoutInt->layer);
2083
2084 itemTextArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2085 valueTextArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2086
2087 // init text area for this choice
2088 itemTextArea->textColor = LIGHT_TEXT_COLOR;
2089 itemTextArea->text = PIC(pair->item);
2090 itemTextArea->textAlignment = MID_LEFT;
2091 itemTextArea->fontId = SMALL_REGULAR_FONT;
2092 itemTextArea->wrapping = true;
2093 itemTextArea->obj.area.width = AVAILABLE_WIDTH;
2094 itemTextArea->obj.area.height = nbgl_getTextHeightInWidth(
2095 itemTextArea->fontId, itemTextArea->text, AVAILABLE_WIDTH, itemTextArea->wrapping);
2096 itemTextArea->style = NO_STYLE;
2097 itemTextArea->obj.alignment = NO_ALIGNMENT;
2098 itemTextArea->obj.alignmentMarginX = 0;
2099 itemTextArea->obj.alignmentMarginY = 0;
2100 itemTextArea->obj.alignTo = NULL;
2101 container->children[container->nbChildren] = (nbgl_obj_t *) itemTextArea;
2102 container->nbChildren++;
2103
2104 fullHeight += itemTextArea->obj.area.height;
2105
2106 // init button for this choice
2107 valueTextArea->textColor = BLACK;
2108 valueTextArea->text = PIC(pair->value);
2109 valueTextArea->textAlignment = MID_LEFT;
2110 if (list->smallCaseForValue) {
2111 valueTextArea->fontId = SMALL_BOLD_FONT;
2112 }
2113 else {
2114 valueTextArea->fontId = LARGE_MEDIUM_FONT;
2115 }
2116 if ((pair->aliasValue == 0) && (pair->valueIcon == NULL)) {
2117 valueTextArea->obj.area.width = AVAILABLE_WIDTH;
2118 }
2119 else {
2120 if (pair->aliasValue) {
2121 // if the value is an alias, we automatically display a (>) icon
2122 valueIcon = &MINI_PUSH_ICON;
2123 }
2124 else {
2125 // otherwise use the provided icon
2126 valueIcon = PIC(pair->valueIcon);
2127 }
2128 // decrease the available width for value text
2129 valueTextArea->obj.area.width = AVAILABLE_WIDTH - valueIcon->width - 12;
2130 }
2131
2132 // handle the nbMaxLinesForValue parameter, used to automatically keep only
2133 // nbMaxLinesForValue lines
2134 uint16_t nbLines = nbgl_getTextNbLinesInWidth(valueTextArea->fontId,
2135 valueTextArea->text,
2136 valueTextArea->obj.area.width,
2137 list->wrapping);
2138 // use this nbMaxLinesForValue parameter only if >0
2139 if ((list->nbMaxLinesForValue > 0) && (nbLines > list->nbMaxLinesForValue)) {
2140 nbLines = list->nbMaxLinesForValue;
2141 valueTextArea->nbMaxLines = list->nbMaxLinesForValue;
2142 }
2143 const nbgl_font_t *font = nbgl_getFont(valueTextArea->fontId);
2144 valueTextArea->obj.area.height = nbLines * font->line_height;
2145 valueTextArea->style = NO_STYLE;
2146 valueTextArea->obj.alignment = BOTTOM_LEFT;
2147 valueTextArea->obj.alignmentMarginY = 4;
2148 valueTextArea->obj.alignTo = (nbgl_obj_t *) itemTextArea;
2149 valueTextArea->wrapping = list->wrapping;
2150 container->children[container->nbChildren] = (nbgl_obj_t *) valueTextArea;
2151 container->nbChildren++;
2152
2153 fullHeight += valueTextArea->obj.area.height + valueTextArea->obj.alignmentMarginY;
2154 if (valueIcon != NULL) {
2155 nbgl_image_t *image = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
2156 // set the container as touchable, not only the image
2158 layoutInt, (nbgl_obj_t *) container, list->token, TUNE_TAP_CASUAL);
2159 obj->index = i;
2160 image->foregroundColor = BLACK;
2161 image->buffer = valueIcon;
2162 image->obj.alignment = RIGHT_TOP;
2163 image->obj.alignmentMarginX = 12;
2164 image->obj.alignTo = (nbgl_obj_t *) valueTextArea;
2165 // set the container as touchable, not only the image
2166 container->obj.touchMask = (1 << TOUCHED);
2167 container->obj.touchId = VALUE_BUTTON_1_ID + i;
2168
2169 container->children[container->nbChildren] = (nbgl_obj_t *) image;
2170 container->nbChildren++;
2171 }
2172
2173 container->obj.area.width = AVAILABLE_WIDTH;
2174 container->obj.area.height = fullHeight;
2175 container->layout = VERTICAL;
2176 container->obj.alignmentMarginX = BORDER_MARGIN;
2177 if (i > 0) {
2178 container->obj.alignmentMarginY = INTER_TAG_VALUE_MARGIN;
2179 }
2180 else {
2181 // if there is a header with a separation line, add a margin
2182 if (layoutInt->headerContainer && (layoutInt->headerContainer->nbChildren > 0)
2183 && (layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren - 1]
2184 ->type
2185 == LINE)) {
2186 container->obj.alignmentMarginY = INTER_TAG_VALUE_MARGIN;
2187 }
2188 else {
2189 container->obj.alignmentMarginY = PRE_TAG_VALUE_MARGIN;
2190 }
2191 }
2192 container->obj.alignment = NO_ALIGNMENT;
2193
2194 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
2195 }
2196
2197 return 0;
2198}
2199
2213 const char *text,
2214 const char *subText,
2215 uint8_t percentage)
2216{
2217 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
2218 nbgl_container_t *container;
2219 nbgl_text_area_t *textArea;
2220 nbgl_progress_bar_t *progress;
2221
2222 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddProgressBar():\n");
2223 if (layout == NULL) {
2224 return -1;
2225 }
2226
2227 // First Create Container :
2228 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
2229 // progressbar + text + subText
2230 container->nbChildren = (subText != NULL) ? 3 : 2;
2231 container->children = nbgl_containerPoolGet(container->nbChildren, layoutInt->layer);
2232
2233 container->obj.area.width = AVAILABLE_WIDTH;
2234 container->layout = VERTICAL;
2235 container->obj.alignment = CENTER;
2236
2237 // Create progressbar
2238 progress = (nbgl_progress_bar_t *) nbgl_objPoolGet(PROGRESS_BAR, layoutInt->layer);
2239 progress->foregroundColor = BLACK;
2240 progress->withBorder = true;
2241 progress->state = percentage;
2242 progress->obj.area.width = PROGRESSBAR_WIDTH;
2243 progress->obj.area.height = PROGRESSBAR_HEIGHT;
2244 progress->obj.alignment = TOP_MIDDLE;
2245
2246 // set this new progressbar as child of the container
2247 container->children[0] = (nbgl_obj_t *) progress;
2248
2249 // update container height
2250 container->obj.area.height = progress->obj.alignmentMarginY + progress->obj.area.height;
2251
2252 // create text area
2253 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2254 textArea->textColor = BLACK;
2255 textArea->text = PIC(text);
2256 textArea->textAlignment = CENTER;
2257 textArea->fontId = LARGE_MEDIUM_FONT;
2258 textArea->wrapping = true;
2259 textArea->obj.alignmentMarginY = BAR_TEXT_MARGIN;
2260 textArea->obj.alignTo = (nbgl_obj_t *) progress;
2261 textArea->obj.alignment = BOTTOM_MIDDLE;
2262 textArea->obj.area.width = AVAILABLE_WIDTH;
2263 textArea->obj.area.height = nbgl_getTextHeightInWidth(
2264 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
2265 textArea->style = NO_STYLE;
2266
2267 // update container height
2268 container->obj.area.height += textArea->obj.alignmentMarginY + textArea->obj.area.height;
2269
2270 // set this text as child of the container
2271 container->children[1] = (nbgl_obj_t *) textArea;
2272
2273 if (subText != NULL) {
2274 nbgl_text_area_t *subTextArea;
2275 // create sub-text area
2276 subTextArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2277 subTextArea->textColor = BLACK;
2278 subTextArea->text = PIC(subText);
2279 subTextArea->textAlignment = CENTER;
2280 subTextArea->fontId = SMALL_REGULAR_FONT;
2281 subTextArea->wrapping = true;
2282 subTextArea->obj.alignmentMarginY = BAR_INTER_TEXTS_MARGIN;
2283 subTextArea->obj.alignTo = (nbgl_obj_t *) textArea;
2284 subTextArea->obj.alignment = BOTTOM_MIDDLE;
2285 subTextArea->obj.area.width = AVAILABLE_WIDTH;
2286 subTextArea->obj.area.height = nbgl_getTextHeightInWidth(subTextArea->fontId,
2287 subTextArea->text,
2288 subTextArea->obj.area.width,
2289 subTextArea->wrapping);
2290 subTextArea->style = NO_STYLE;
2291
2292 // update container height
2293 container->obj.area.height
2294 += subTextArea->obj.alignmentMarginY + subTextArea->obj.area.height;
2295
2296 // set thissub-text as child of the container
2297 container->children[2] = (nbgl_obj_t *) subTextArea;
2298 }
2299 // The height of containers must be a multiple of eight
2300 container->obj.area.height = (container->obj.area.height + 7) & 0xFFF8;
2301
2302 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
2303
2304 return 2;
2305}
2306
2314{
2315 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
2316 nbgl_line_t *line;
2317
2318 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddSeparationLine():\n");
2319 line = createHorizontalLine(layoutInt->layer);
2320 line->obj.alignmentMarginY = -1;
2321 layoutAddObject(layoutInt, (nbgl_obj_t *) line);
2322 return 0;
2323}
2324
2333{
2334 layoutObj_t *obj;
2335 nbgl_button_t *button;
2336 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
2337
2338 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddButton():\n");
2339 if (layout == NULL) {
2340 return -1;
2341 }
2342
2343 // Add in footer if matching
2344 if ((buttonInfo->onBottom) && (!buttonInfo->fittingContent)) {
2345 if (layoutInt->footerContainer == NULL) {
2346 nbgl_layoutFooter_t footerDesc;
2347 footerDesc.type = FOOTER_SIMPLE_BUTTON;
2348 footerDesc.separationLine = false;
2349 footerDesc.button.text = buttonInfo->text;
2350 footerDesc.button.token = buttonInfo->token;
2351 footerDesc.button.tuneId = buttonInfo->tuneId;
2352 footerDesc.button.icon = buttonInfo->icon;
2353 footerDesc.button.style = buttonInfo->style;
2354 return nbgl_layoutAddExtendedFooter(layout, &footerDesc);
2355 }
2356 else {
2357 nbgl_layoutUpFooter_t upFooterDesc;
2358 upFooterDesc.type = UP_FOOTER_BUTTON;
2359 upFooterDesc.button.text = buttonInfo->text;
2360 upFooterDesc.button.token = buttonInfo->token;
2361 upFooterDesc.button.tuneId = buttonInfo->tuneId;
2362 upFooterDesc.button.icon = buttonInfo->icon;
2363 upFooterDesc.button.style = buttonInfo->style;
2364 return nbgl_layoutAddUpFooter(layout, &upFooterDesc);
2365 }
2366 }
2367
2368 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
2370 layoutInt, (nbgl_obj_t *) button, buttonInfo->token, buttonInfo->tuneId);
2371 if (obj == NULL) {
2372 return -1;
2373 }
2374
2375 button->obj.alignmentMarginX = BORDER_MARGIN;
2376 button->obj.alignmentMarginY = 12;
2377 button->obj.alignment = NO_ALIGNMENT;
2378 if (buttonInfo->style == BLACK_BACKGROUND) {
2379 button->innerColor = BLACK;
2380 button->foregroundColor = WHITE;
2381 }
2382 else {
2383 button->innerColor = WHITE;
2384 button->foregroundColor = BLACK;
2385 }
2386 if (buttonInfo->style == NO_BORDER) {
2387 button->borderColor = WHITE;
2388 }
2389 else {
2390 if (buttonInfo->style == BLACK_BACKGROUND) {
2391 button->borderColor = BLACK;
2392 }
2393 else {
2394 button->borderColor = LIGHT_GRAY;
2395 }
2396 }
2397 button->text = PIC(buttonInfo->text);
2398 button->fontId = SMALL_BOLD_FONT;
2399 button->icon = PIC(buttonInfo->icon);
2400 if (buttonInfo->fittingContent == true) {
2401 button->obj.area.width = nbgl_getTextWidth(button->fontId, button->text)
2402 + SMALL_BUTTON_HEIGHT
2403 + ((button->icon) ? (button->icon->width + 12) : 0);
2404 button->obj.area.height = SMALL_BUTTON_HEIGHT;
2405 button->radius = SMALL_BUTTON_RADIUS_INDEX;
2406 if (buttonInfo->onBottom != true) {
2407 button->obj.alignmentMarginX += (AVAILABLE_WIDTH - button->obj.area.width) / 2;
2408 }
2409 }
2410 else {
2411 button->obj.area.width = AVAILABLE_WIDTH;
2412 button->obj.area.height = BUTTON_DIAMETER;
2413 button->radius = BUTTON_RADIUS;
2414 }
2415 button->obj.alignTo = NULL;
2416 button->obj.touchMask = (1 << TOUCHED);
2417 button->obj.touchId = (buttonInfo->fittingContent) ? EXTRA_BUTTON_ID : SINGLE_BUTTON_ID;
2418 // set this new button as child of the container
2419 layoutAddObject(layoutInt, (nbgl_obj_t *) button);
2420
2421 return 0;
2422}
2423
2434 const char *text,
2435 uint8_t token,
2436 tune_index_e tuneId)
2437{
2439 .longPress.text = text,
2440 .longPress.token = token,
2441 .longPress.tuneId = tuneId};
2442
2443 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddLongPressButton():\n");
2444 if (layout == NULL) {
2445 return -1;
2446 }
2447
2448 return nbgl_layoutAddUpFooter(layout, &upFooterDesc);
2449}
2450
2462 const char *text,
2463 uint8_t token,
2464 tune_index_e tuneId)
2465{
2466 nbgl_layoutFooter_t footerDesc;
2467 footerDesc.type = FOOTER_SIMPLE_TEXT;
2468 footerDesc.separationLine = true;
2469 footerDesc.simpleText.text = text;
2470 footerDesc.simpleText.mutedOut = false;
2471 footerDesc.simpleText.token = token;
2472 footerDesc.simpleText.tuneId = tuneId;
2473 return nbgl_layoutAddExtendedFooter(layout, &footerDesc);
2474}
2475
2489 const char *leftText,
2490 uint8_t leftToken,
2491 const char *rightText,
2492 uint8_t rightToken,
2493 tune_index_e tuneId)
2494{
2495 nbgl_layoutFooter_t footerDesc;
2496 footerDesc.type = FOOTER_DOUBLE_TEXT;
2497 footerDesc.separationLine = true;
2498 footerDesc.doubleText.leftText = leftText;
2499 footerDesc.doubleText.leftToken = leftToken;
2500 footerDesc.doubleText.rightText = rightText;
2501 footerDesc.doubleText.rightToken = rightToken;
2502 footerDesc.doubleText.tuneId = tuneId;
2503 return nbgl_layoutAddExtendedFooter(layout, &footerDesc);
2504}
2505
2515{
2516 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
2517 layoutObj_t *obj;
2518 nbgl_text_area_t *textArea = NULL;
2519 nbgl_line_t *line = NULL;
2520 nbgl_image_t *image = NULL;
2521 nbgl_button_t *button = NULL;
2522
2523 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddHeader(): type = %d\n", headerDesc->type);
2524 if (layout == NULL) {
2525 return -1;
2526 }
2527 if ((headerDesc == NULL) || (headerDesc->type >= NB_HEADER_TYPES)) {
2528 return -2;
2529 }
2530
2531 layoutInt->headerContainer = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
2532 layoutInt->headerContainer->obj.area.width = SCREEN_WIDTH;
2533 layoutInt->headerContainer->layout = VERTICAL;
2534 layoutInt->headerContainer->children
2535 = (nbgl_obj_t **) nbgl_containerPoolGet(5, layoutInt->layer);
2536 layoutInt->headerContainer->obj.alignment = TOP_MIDDLE;
2537
2538 switch (headerDesc->type) {
2539 case HEADER_EMPTY: {
2540 layoutInt->headerContainer->obj.area.height = headerDesc->emptySpace.height;
2541 break;
2542 }
2545 case HEADER_EXTENDED_BACK: {
2546 const char *text = (headerDesc->type == HEADER_EXTENDED_BACK)
2547 ? PIC(headerDesc->extendedBack.text)
2548 : PIC(headerDesc->backAndText.text);
2549 uint8_t backToken = (headerDesc->type == HEADER_EXTENDED_BACK)
2550 ? headerDesc->extendedBack.backToken
2551 : headerDesc->backAndText.token;
2552 nbgl_button_t *actionButton = NULL;
2553 // add back button
2554 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
2555 // only make it active if valid token
2556 if (backToken != NBGL_INVALID_TOKEN) {
2557 obj = layoutAddCallbackObj(layoutInt,
2558 (nbgl_obj_t *) button,
2559 backToken,
2560 (headerDesc->type == HEADER_EXTENDED_BACK)
2561 ? headerDesc->extendedBack.tuneId
2562 : headerDesc->backAndText.tuneId);
2563 if (obj == NULL) {
2564 return -1;
2565 }
2566 }
2567
2568 button->obj.alignment = MID_LEFT;
2569 button->innerColor = WHITE;
2570 button->foregroundColor = (backToken != NBGL_INVALID_TOKEN) ? BLACK : WHITE;
2571 button->borderColor = WHITE;
2572 button->obj.area.width = BACK_KEY_WIDTH;
2573 button->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2574 button->text = NULL;
2575 button->icon = PIC(&LEFT_ARROW_ICON);
2576 button->obj.touchMask = (backToken != NBGL_INVALID_TOKEN) ? (1 << TOUCHED) : 0;
2577 button->obj.touchId = BACK_BUTTON_ID;
2578 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2579 = (nbgl_obj_t *) button;
2580 layoutInt->headerContainer->nbChildren++;
2581
2582 // add optional text if needed
2583 if (text != NULL) {
2584 // add optional icon if type is HEADER_BACK_ICON_AND_TEXT
2585 if (headerDesc->type == HEADER_BACK_ICON_AND_TEXT) {
2586 image = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
2587 image->buffer = PIC(headerDesc->backAndText.icon);
2588 image->foregroundColor = BLACK;
2589 image->obj.alignment = CENTER;
2590 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2591 = (nbgl_obj_t *) image;
2592 layoutInt->headerContainer->nbChildren++;
2593 }
2594 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2595 if ((headerDesc->type == HEADER_EXTENDED_BACK)
2596 && (headerDesc->extendedBack.textToken != NBGL_INVALID_TOKEN)) {
2597 obj = layoutAddCallbackObj(layoutInt,
2598 (nbgl_obj_t *) textArea,
2599 headerDesc->extendedBack.textToken,
2600 headerDesc->extendedBack.tuneId);
2601 if (obj == NULL) {
2602 return -1;
2603 }
2604 textArea->obj.touchMask = (1 << TOUCHED);
2605 }
2606 textArea->obj.alignment = CENTER;
2607 textArea->textColor = BLACK;
2608 textArea->obj.area.width
2609 = layoutInt->headerContainer->obj.area.width - 2 * BACK_KEY_WIDTH;
2610 // if icon, reduce to 1 line and fit text width
2611 if (headerDesc->type == HEADER_BACK_ICON_AND_TEXT) {
2612 textArea->obj.area.width -= 16 + image->buffer->width;
2613 }
2614 textArea->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2615 textArea->text = text;
2616 textArea->fontId = SMALL_BOLD_FONT;
2617 textArea->textAlignment = CENTER;
2618 textArea->wrapping = true;
2619 uint8_t nbMaxLines = (headerDesc->type == HEADER_BACK_ICON_AND_TEXT) ? 1 : 2;
2620 // ensure that text fits on 2 lines maximum
2621 if (nbgl_getTextNbLinesInWidth(textArea->fontId,
2622 textArea->text,
2623 textArea->obj.area.width,
2624 textArea->wrapping)
2625 > nbMaxLines) {
2626 textArea->obj.area.height
2627 = nbMaxLines * nbgl_getFontLineHeight(textArea->fontId);
2628#ifndef BUILD_SCREENSHOTS
2630 "nbgl_layoutAddHeader: text [%s] is too long for header\n",
2631 text);
2632#endif // BUILD_SCREENSHOTS
2633 }
2634 if (headerDesc->type == HEADER_BACK_ICON_AND_TEXT) {
2635 textArea->obj.area.width = nbgl_getTextWidth(textArea->fontId, textArea->text);
2636 }
2637 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2638 = (nbgl_obj_t *) textArea;
2639 layoutInt->headerContainer->nbChildren++;
2640 // if icon, realign icon & text
2641 if (headerDesc->type == HEADER_BACK_ICON_AND_TEXT) {
2642 textArea->obj.alignmentMarginX = 8 + image->buffer->width / 2;
2643 image->obj.alignmentMarginX = -8 - textArea->obj.area.width / 2;
2644 }
2645 }
2646 // add action key if the type is HEADER_EXTENDED_BACK
2647 if ((headerDesc->type == HEADER_EXTENDED_BACK)
2648 && (headerDesc->extendedBack.actionIcon)) {
2649 actionButton = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
2650 // if token is valid
2651 if (headerDesc->extendedBack.actionToken != NBGL_INVALID_TOKEN) {
2652 obj = layoutAddCallbackObj(layoutInt,
2653 (nbgl_obj_t *) actionButton,
2654 headerDesc->extendedBack.actionToken,
2655 headerDesc->extendedBack.tuneId);
2656 if (obj == NULL) {
2657 return -1;
2658 }
2659 actionButton->obj.touchMask = (1 << TOUCHED);
2660 }
2661
2662 actionButton->obj.alignment = MID_RIGHT;
2663 actionButton->innerColor = WHITE;
2664 button->foregroundColor
2666 : LIGHT_GRAY;
2667 actionButton->borderColor = WHITE;
2668 actionButton->obj.area.width = BACK_KEY_WIDTH;
2669 actionButton->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2670 actionButton->text = NULL;
2671 actionButton->icon = PIC(headerDesc->extendedBack.actionIcon);
2672 actionButton->obj.touchId = EXTRA_BUTTON_ID;
2673 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2674 = (nbgl_obj_t *) actionButton;
2675 layoutInt->headerContainer->nbChildren++;
2676 }
2677
2678 layoutInt->headerContainer->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2679 // add potential text under the line if the type is HEADER_EXTENDED_BACK
2680 if ((headerDesc->type == HEADER_EXTENDED_BACK)
2681 && (headerDesc->extendedBack.subText != NULL)) {
2682 nbgl_text_area_t *subTextArea;
2683
2684 line = createHorizontalLine(layoutInt->layer);
2685 line->obj.alignment = TOP_MIDDLE;
2686 line->obj.alignmentMarginY = TOUCHABLE_HEADER_BAR_HEIGHT;
2687 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2688 = (nbgl_obj_t *) line;
2689 layoutInt->headerContainer->nbChildren++;
2690
2691 subTextArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2692 subTextArea->textColor = BLACK;
2693 subTextArea->text = PIC(headerDesc->extendedBack.subText);
2694 subTextArea->textAlignment = MID_LEFT;
2695 subTextArea->fontId = SMALL_REGULAR_FONT;
2696 subTextArea->wrapping = true;
2697 subTextArea->obj.alignment = BOTTOM_MIDDLE;
2698 subTextArea->obj.alignmentMarginY = SUB_HEADER_MARGIN;
2699 subTextArea->obj.area.width = AVAILABLE_WIDTH;
2700 subTextArea->obj.area.height
2701 = nbgl_getTextHeightInWidth(subTextArea->fontId,
2702 subTextArea->text,
2703 subTextArea->obj.area.width,
2704 subTextArea->wrapping);
2705 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2706 = (nbgl_obj_t *) subTextArea;
2707 layoutInt->headerContainer->nbChildren++;
2708 layoutInt->headerContainer->obj.area.height
2709 += subTextArea->obj.area.height + 2 * SUB_HEADER_MARGIN;
2711 if (button != NULL) {
2712 button->obj.alignmentMarginY
2713 -= (subTextArea->obj.area.height + 2 * SUB_HEADER_MARGIN) / 2;
2714 }
2715 if (textArea != NULL) {
2716 textArea->obj.alignmentMarginY
2717 -= (subTextArea->obj.area.height + 2 * SUB_HEADER_MARGIN) / 2;
2718 }
2719 if (actionButton != NULL) {
2720 actionButton->obj.alignmentMarginY
2721 -= (subTextArea->obj.area.height + 2 * SUB_HEADER_MARGIN) / 2;
2722 }
2723 }
2724 break;
2725 }
2727#ifdef TARGET_STAX
2728 // add optional back button
2729 if (headerDesc->progressAndBack.withBack) {
2730 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
2731 obj = layoutAddCallbackObj(layoutInt,
2732 (nbgl_obj_t *) button,
2733 headerDesc->progressAndBack.token,
2734 headerDesc->progressAndBack.tuneId);
2735 if (obj == NULL) {
2736 return -1;
2737 }
2738
2739 button->obj.alignment = MID_LEFT;
2740 button->innerColor = WHITE;
2741 button->foregroundColor = BLACK;
2742 button->borderColor = WHITE;
2743 button->obj.area.width = BACK_KEY_WIDTH;
2744 button->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2745 button->text = NULL;
2746 button->icon = PIC(&LEFT_ARROW_ICON);
2747 button->obj.touchMask = (1 << TOUCHED);
2748 button->obj.touchId = BACK_BUTTON_ID;
2749 // add to container
2750 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2751 = (nbgl_obj_t *) button;
2752 layoutInt->headerContainer->nbChildren++;
2753 }
2754
2755 // add progress indicator
2756 if (headerDesc->progressAndBack.nbPages > 1
2758 nbgl_page_indicator_t *progress;
2759
2760 progress
2762 progress->activePage = headerDesc->progressAndBack.activePage;
2763 progress->nbPages = headerDesc->progressAndBack.nbPages;
2764 progress->obj.area.width = 224;
2765 progress->obj.alignment = CENTER;
2766 // add to container
2767 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2768 = (nbgl_obj_t *) progress;
2769 layoutInt->headerContainer->nbChildren++;
2770 }
2771 layoutInt->activePage = headerDesc->progressAndBack.activePage;
2772 layoutInt->nbPages = headerDesc->progressAndBack.nbPages;
2773 layoutInt->headerContainer->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2774#endif // TARGET_STAX
2775 break;
2776 }
2777 case HEADER_TITLE: {
2778 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2779 textArea->textColor = BLACK;
2780 textArea->obj.area.width = AVAILABLE_WIDTH;
2781 textArea->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2782 textArea->text = PIC(headerDesc->title.text);
2783 textArea->fontId = SMALL_BOLD_FONT;
2784 textArea->textAlignment = CENTER;
2785 textArea->wrapping = true;
2786 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2787 = (nbgl_obj_t *) textArea;
2788 layoutInt->headerContainer->nbChildren++;
2789 layoutInt->headerContainer->obj.area.height = textArea->obj.area.height;
2790 break;
2791 }
2792 case HEADER_RIGHT_TEXT: {
2793 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2794 obj = layoutAddCallbackObj(layoutInt,
2795 (nbgl_obj_t *) textArea,
2796 headerDesc->rightText.token,
2797 headerDesc->rightText.tuneId);
2798 if (obj == NULL) {
2799 return -1;
2800 }
2801 textArea->obj.alignment = MID_RIGHT;
2802 textArea->obj.alignmentMarginX = BORDER_MARGIN;
2803 textArea->textColor = BLACK;
2804 textArea->obj.area.width = AVAILABLE_WIDTH;
2805 textArea->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2806 textArea->text = PIC(headerDesc->rightText.text);
2807 textArea->fontId = SMALL_BOLD_FONT;
2808 textArea->textAlignment = MID_RIGHT;
2809 textArea->obj.touchMask = (1 << TOUCHED);
2810 textArea->obj.touchId = TOP_RIGHT_BUTTON_ID;
2811 // add to bottom container
2812 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2813 = (nbgl_obj_t *) textArea;
2814 layoutInt->headerContainer->nbChildren++;
2815 layoutInt->headerContainer->obj.area.height = textArea->obj.area.height;
2816 break;
2817 }
2818 default:
2819 return -2;
2820 }
2821 // draw separation line at bottom of container
2822 if (headerDesc->separationLine) {
2823 line = createHorizontalLine(layoutInt->layer);
2824 line->obj.alignment = BOTTOM_MIDDLE;
2825 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2826 = (nbgl_obj_t *) line;
2827 layoutInt->headerContainer->nbChildren++;
2828 }
2829 // header must be the first child
2830 layoutInt->children[HEADER_INDEX] = (nbgl_obj_t *) layoutInt->headerContainer;
2831
2832 // subtract header height from main container height
2833 layoutInt->container->obj.area.height -= layoutInt->headerContainer->obj.area.height;
2834 layoutInt->container->obj.alignTo = (nbgl_obj_t *) layoutInt->headerContainer;
2835 layoutInt->container->obj.alignment = BOTTOM_LEFT;
2836
2837 layoutInt->headerType = headerDesc->type;
2838
2839 return layoutInt->headerContainer->obj.area.height;
2840}
2841
2851{
2852 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
2853 layoutObj_t *obj;
2854 nbgl_text_area_t *textArea;
2855 nbgl_line_t *line, *separationLine = NULL;
2856 nbgl_button_t *button;
2857
2858 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddExtendedFooter():\n");
2859 if (layout == NULL) {
2860 return -1;
2861 }
2862 if ((footerDesc == NULL) || (footerDesc->type >= NB_FOOTER_TYPES)) {
2863 return -2;
2864 }
2865
2866 layoutInt->footerContainer = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
2867 layoutInt->footerContainer->obj.area.width = SCREEN_WIDTH;
2868 layoutInt->footerContainer->layout = VERTICAL;
2869 layoutInt->footerContainer->children
2870 = (nbgl_obj_t **) nbgl_containerPoolGet(5, layoutInt->layer);
2871 layoutInt->footerContainer->obj.alignment = BOTTOM_MIDDLE;
2872
2873 switch (footerDesc->type) {
2874 case FOOTER_EMPTY: {
2875 layoutInt->footerContainer->obj.area.height = footerDesc->emptySpace.height;
2876 break;
2877 }
2878 case FOOTER_SIMPLE_TEXT: {
2879 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2880 obj = layoutAddCallbackObj(layoutInt,
2881 (nbgl_obj_t *) textArea,
2882 footerDesc->simpleText.token,
2883 footerDesc->simpleText.tuneId);
2884 if (obj == NULL) {
2885 return -1;
2886 }
2887
2888 textArea->obj.alignment = BOTTOM_MIDDLE;
2889 textArea->textColor = (footerDesc->simpleText.mutedOut) ? LIGHT_TEXT_COLOR : BLACK;
2890 textArea->obj.area.width = AVAILABLE_WIDTH;
2891 textArea->obj.area.height
2892 = (footerDesc->simpleText.mutedOut) ? SMALL_FOOTER_HEIGHT : SIMPLE_FOOTER_HEIGHT;
2893 textArea->text = PIC(footerDesc->simpleText.text);
2894 textArea->fontId
2895 = (footerDesc->simpleText.mutedOut) ? SMALL_REGULAR_FONT : SMALL_BOLD_FONT;
2896 textArea->textAlignment = CENTER;
2897 textArea->obj.touchMask = (1 << TOUCHED);
2898 textArea->obj.touchId = BOTTOM_BUTTON_ID;
2899 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
2900 = (nbgl_obj_t *) textArea;
2901 layoutInt->footerContainer->nbChildren++;
2902 layoutInt->footerContainer->obj.area.height = textArea->obj.area.height;
2903 break;
2904 }
2905 case FOOTER_DOUBLE_TEXT: {
2906 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2907 obj = layoutAddCallbackObj(layoutInt,
2908 (nbgl_obj_t *) textArea,
2909 footerDesc->doubleText.leftToken,
2910 footerDesc->doubleText.tuneId);
2911 if (obj == NULL) {
2912 return -1;
2913 }
2914 textArea->obj.alignment = BOTTOM_LEFT;
2915 textArea->textColor = BLACK;
2916 textArea->obj.area.width = AVAILABLE_WIDTH / 2;
2917 textArea->obj.area.height = SIMPLE_FOOTER_HEIGHT;
2918 textArea->text = PIC(footerDesc->doubleText.leftText);
2919 textArea->fontId = SMALL_BOLD_FONT;
2920 textArea->textAlignment = CENTER;
2921 textArea->obj.touchMask = (1 << TOUCHED);
2922 textArea->obj.touchId = BOTTOM_BUTTON_ID;
2923 // add to bottom container
2924 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
2925 = (nbgl_obj_t *) textArea;
2926 layoutInt->footerContainer->nbChildren++;
2927
2928 // create right touchable text
2929 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2930 obj = layoutAddCallbackObj(layoutInt,
2931 (nbgl_obj_t *) textArea,
2932 footerDesc->doubleText.rightToken,
2933 footerDesc->doubleText.tuneId);
2934 if (obj == NULL) {
2935 return -1;
2936 }
2937
2938 textArea->obj.alignment = BOTTOM_RIGHT;
2939 textArea->textColor = BLACK;
2940 textArea->obj.area.width = AVAILABLE_WIDTH / 2;
2941 textArea->obj.area.height = SIMPLE_FOOTER_HEIGHT;
2942 textArea->text = PIC(footerDesc->doubleText.rightText);
2943 textArea->fontId = SMALL_BOLD_FONT;
2944 textArea->textAlignment = CENTER;
2945 textArea->obj.touchMask = (1 << TOUCHED);
2946 textArea->obj.touchId = RIGHT_BUTTON_ID;
2947 // add to bottom container
2948 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
2949 = (nbgl_obj_t *) textArea;
2950 layoutInt->footerContainer->nbChildren++;
2951 layoutInt->footerContainer->obj.area.height = textArea->obj.area.height;
2952
2953 // create vertical line separating texts
2954 separationLine = (nbgl_line_t *) nbgl_objPoolGet(LINE, layoutInt->layer);
2955 separationLine->lineColor = LIGHT_GRAY;
2956 separationLine->obj.area.width = 1;
2957 separationLine->obj.area.height = layoutInt->footerContainer->obj.area.height;
2958 separationLine->direction = VERTICAL;
2959 separationLine->thickness = 1;
2960 separationLine->obj.alignment = MID_LEFT;
2961 separationLine->obj.alignTo = (nbgl_obj_t *) textArea;
2962 separationLine->obj.alignmentMarginX = -1;
2963 break;
2964 }
2965 case FOOTER_TEXT_AND_NAV: {
2966 layoutInt->footerContainer->obj.area.height = SIMPLE_FOOTER_HEIGHT;
2967 // add touchable text on the left
2968 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2969 obj = layoutAddCallbackObj(layoutInt,
2970 (nbgl_obj_t *) textArea,
2971 footerDesc->textAndNav.token,
2972 footerDesc->textAndNav.tuneId);
2973 if (obj == NULL) {
2974 return -1;
2975 }
2976 textArea->obj.alignment = BOTTOM_LEFT;
2977 textArea->textColor = BLACK;
2978 textArea->obj.area.width = FOOTER_TEXT_AND_NAV_WIDTH;
2979 textArea->obj.area.height = SIMPLE_FOOTER_HEIGHT;
2980 textArea->text = PIC(footerDesc->textAndNav.text);
2981 textArea->fontId = SMALL_BOLD_FONT;
2982 textArea->textAlignment = CENTER;
2983 textArea->obj.touchMask = (1 << TOUCHED);
2984 textArea->obj.touchId = BOTTOM_BUTTON_ID;
2985 // add to bottom container
2986 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
2987 = (nbgl_obj_t *) textArea;
2988 layoutInt->footerContainer->nbChildren++;
2989
2990 // add navigation on the right
2991 nbgl_container_t *navContainer
2993 navContainer->obj.area.width = AVAILABLE_WIDTH;
2994 navContainer->layout = VERTICAL;
2995 navContainer->nbChildren = 4;
2996 navContainer->children
2997 = (nbgl_obj_t **) nbgl_containerPoolGet(navContainer->nbChildren, layoutInt->layer);
2998 navContainer->obj.alignment = BOTTOM_RIGHT;
2999 navContainer->obj.area.width = SCREEN_WIDTH - textArea->obj.area.width;
3000 navContainer->obj.area.height = SIMPLE_FOOTER_HEIGHT;
3001 layoutNavigationPopulate(navContainer, &footerDesc->navigation, layoutInt->layer);
3002 obj = layoutAddCallbackObj(layoutInt,
3003 (nbgl_obj_t *) navContainer,
3004 footerDesc->textAndNav.navigation.token,
3005 footerDesc->textAndNav.navigation.tuneId);
3006 if (obj == NULL) {
3007 return -1;
3008 }
3009
3010 // create vertical line separating text from nav
3011 separationLine = (nbgl_line_t *) nbgl_objPoolGet(LINE, layoutInt->layer);
3012 separationLine->lineColor = LIGHT_GRAY;
3013 separationLine->obj.area.width = 1;
3014 separationLine->obj.area.height = layoutInt->footerContainer->obj.area.height;
3015 separationLine->direction = VERTICAL;
3016 separationLine->thickness = 1;
3017 separationLine->obj.alignment = MID_LEFT;
3018 separationLine->obj.alignTo = (nbgl_obj_t *) navContainer;
3019 separationLine->obj.alignmentMarginX = -1;
3020
3021 layoutInt->activePage = footerDesc->textAndNav.navigation.activePage;
3022 layoutInt->nbPages = footerDesc->textAndNav.navigation.nbPages;
3023 // add to bottom container
3024 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3025 = (nbgl_obj_t *) navContainer;
3026 layoutInt->footerContainer->nbChildren++;
3027 break;
3028 }
3029 case FOOTER_NAV: {
3030 layoutInt->footerContainer->obj.area.height = SIMPLE_FOOTER_HEIGHT;
3032 layoutInt->footerContainer, &footerDesc->navigation, layoutInt->layer);
3033 layoutInt->footerContainer->nbChildren = 4;
3034 obj = layoutAddCallbackObj(layoutInt,
3035 (nbgl_obj_t *) layoutInt->footerContainer,
3036 footerDesc->navigation.token,
3037 footerDesc->navigation.tuneId);
3038 if (obj == NULL) {
3039 return -1;
3040 }
3041
3042 layoutInt->activePage = footerDesc->navigation.activePage;
3043 layoutInt->nbPages = footerDesc->navigation.nbPages;
3044 break;
3045 }
3046 case FOOTER_SIMPLE_BUTTON: {
3047 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
3048 obj = layoutAddCallbackObj(layoutInt,
3049 (nbgl_obj_t *) button,
3050 footerDesc->button.token,
3051 footerDesc->button.tuneId);
3052 if (obj == NULL) {
3053 return -1;
3054 }
3055
3056 button->obj.alignment = BOTTOM_MIDDLE;
3057 button->obj.alignmentMarginY = SINGLE_BUTTON_MARGIN;
3058 if (footerDesc->button.style == BLACK_BACKGROUND) {
3059 button->innerColor = BLACK;
3060 button->foregroundColor = WHITE;
3061 }
3062 else {
3063 button->innerColor = WHITE;
3064 button->foregroundColor = BLACK;
3065 }
3066
3067 if (footerDesc->button.style == NO_BORDER) {
3068 button->borderColor = WHITE;
3069 }
3070 else {
3071 if (footerDesc->button.style == BLACK_BACKGROUND) {
3072 button->borderColor = BLACK;
3073 }
3074 else {
3075 button->borderColor = LIGHT_GRAY;
3076 }
3077 }
3078 button->text = PIC(footerDesc->button.text);
3079 button->fontId = SMALL_BOLD_FONT;
3080 button->icon = PIC(footerDesc->button.icon);
3081 button->radius = BUTTON_RADIUS;
3082 button->obj.area.height = BUTTON_DIAMETER;
3083 layoutInt->footerContainer->obj.area.height = FOOTER_BUTTON_HEIGHT;
3084 if (footerDesc->button.text == NULL) {
3085 button->obj.area.width = BUTTON_DIAMETER;
3086 }
3087 else {
3088 button->obj.area.width = AVAILABLE_WIDTH;
3089 }
3090 button->obj.touchMask = (1 << TOUCHED);
3091 button->obj.touchId = button->text ? SINGLE_BUTTON_ID : BOTTOM_BUTTON_ID;
3092 // add to bottom container
3093 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3094 = (nbgl_obj_t *) button;
3095 layoutInt->footerContainer->nbChildren++;
3096 break;
3097 }
3098 case FOOTER_CHOICE_BUTTONS: {
3099 // texts cannot be NULL
3100 if ((footerDesc->choiceButtons.bottomText == NULL)
3101 || (footerDesc->choiceButtons.topText == NULL)) {
3102 return -1;
3103 }
3104
3105 // create bottom button (footer) at first
3106 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
3107 obj = layoutAddCallbackObj(layoutInt,
3108 (nbgl_obj_t *) button,
3109 footerDesc->choiceButtons.token,
3110 footerDesc->choiceButtons.tuneId);
3111 if (obj == NULL) {
3112 return -1;
3113 }
3114 // associate with with index 1
3115 obj->index = 1;
3116 // put at the bottom of the container
3117 button->obj.alignment = BOTTOM_MIDDLE;
3118 button->innerColor = WHITE;
3119 if (footerDesc->choiceButtons.style == BOTH_ROUNDED_STYLE) {
3120 button->obj.alignmentMarginY
3121 = SINGLE_BUTTON_MARGIN; // pixels from bottom of container
3122 button->borderColor = LIGHT_GRAY;
3123 button->obj.area.height = BUTTON_DIAMETER;
3124 }
3125 else {
3126 button->obj.alignmentMarginY
3127 = BUTTON_FROM_BOTTOM_MARGIN; // pixels from screen bottom
3128 button->borderColor = WHITE;
3129 button->obj.area.height = FOOTER_IN_PAIR_HEIGHT;
3130 }
3131 button->foregroundColor = BLACK;
3132 button->obj.area.width = AVAILABLE_WIDTH;
3133 button->radius = BUTTON_RADIUS;
3134 button->text = PIC(footerDesc->choiceButtons.bottomText);
3135 button->fontId = SMALL_BOLD_FONT;
3136 button->obj.touchMask = (1 << TOUCHED);
3137 button->obj.touchId = CHOICE_2_ID;
3138 // add to bottom container
3139 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3140 = (nbgl_obj_t *) button;
3141 layoutInt->footerContainer->nbChildren++;
3142
3143 // add line if needed
3144 if ((footerDesc->choiceButtons.style != ROUNDED_AND_FOOTER_STYLE)
3145 && (footerDesc->choiceButtons.style != BOTH_ROUNDED_STYLE)) {
3146 line = createHorizontalLine(layoutInt->layer);
3147 line->obj.alignment = TOP_MIDDLE;
3148 line->obj.alignTo = (nbgl_obj_t *) button;
3149 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3150 = (nbgl_obj_t *) line;
3151 layoutInt->footerContainer->nbChildren++;
3152 }
3153
3154 // then top button, on top of it
3155 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
3156 obj = layoutAddCallbackObj(layoutInt,
3157 (nbgl_obj_t *) button,
3158 footerDesc->choiceButtons.token,
3159 footerDesc->choiceButtons.tuneId);
3160 if (obj == NULL) {
3161 return -1;
3162 }
3163 // associate with with index 0
3164 obj->index = 0;
3165 button->obj.alignment = TOP_MIDDLE;
3166 if (footerDesc->choiceButtons.style == ROUNDED_AND_FOOTER_STYLE) {
3167 button->obj.alignmentMarginY = TOP_BUTTON_MARGIN; // pixels from top of container
3168 }
3169 else if (footerDesc->choiceButtons.style == BOTH_ROUNDED_STYLE) {
3170 button->obj.alignmentMarginY
3171 = SINGLE_BUTTON_MARGIN; // pixels from top of container
3172 }
3173 else {
3174 button->obj.alignmentMarginY
3175 = TOP_BUTTON_MARGIN_WITH_ACTION; // pixels from top of container
3176 }
3178 button->innerColor = WHITE;
3179 button->borderColor = LIGHT_GRAY;
3180 button->foregroundColor = BLACK;
3181 }
3182 else {
3183 button->innerColor = BLACK;
3184 button->borderColor = BLACK;
3185 button->foregroundColor = WHITE;
3186 }
3187 button->obj.area.width = AVAILABLE_WIDTH;
3188 button->obj.area.height = BUTTON_DIAMETER;
3189 button->radius = BUTTON_RADIUS;
3190 button->text = PIC(footerDesc->choiceButtons.topText);
3191 button->icon = (footerDesc->choiceButtons.style != ROUNDED_AND_FOOTER_STYLE)
3192 ? PIC(footerDesc->choiceButtons.topIcon)
3193 : NULL;
3194 button->fontId = SMALL_BOLD_FONT;
3195 button->obj.touchMask = (1 << TOUCHED);
3196 button->obj.touchId = CHOICE_1_ID;
3197 // add to bottom container
3198 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3199 = (nbgl_obj_t *) button;
3200 layoutInt->footerContainer->nbChildren++;
3201
3202 if (footerDesc->choiceButtons.style == ROUNDED_AND_FOOTER_STYLE) {
3203 layoutInt->footerContainer->obj.area.height = ROUNDED_AND_FOOTER_FOOTER_HEIGHT;
3204 }
3205 else if (footerDesc->choiceButtons.style == BOTH_ROUNDED_STYLE) {
3206 layoutInt->footerContainer->obj.area.height = BOTH_ROUNDED_FOOTER_HEIGHT;
3207 }
3208 else {
3209 layoutInt->footerContainer->obj.area.height = ACTION_AND_FOOTER_FOOTER_HEIGHT;
3210 }
3211
3212 break;
3213 }
3214 default:
3215 return -2;
3216 }
3217
3218 // add swipable feature for navigation
3219 if ((footerDesc->type == FOOTER_NAV) || (footerDesc->type == FOOTER_TEXT_AND_NAV)) {
3220 addSwipeInternal(layoutInt,
3221 ((1 << SWIPED_LEFT) | (1 << SWIPED_RIGHT)),
3223 (footerDesc->type == FOOTER_NAV) ? footerDesc->navigation.token
3224 : footerDesc->textAndNav.navigation.token,
3225 (footerDesc->type == FOOTER_NAV)
3226 ? footerDesc->navigation.tuneId
3227 : footerDesc->textAndNav.navigation.tuneId);
3228 }
3229
3230 if (footerDesc->separationLine) {
3231 line = createHorizontalLine(layoutInt->layer);
3232 line->obj.alignment = TOP_MIDDLE;
3233 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3234 = (nbgl_obj_t *) line;
3235 layoutInt->footerContainer->nbChildren++;
3236 }
3237 if (separationLine != NULL) {
3238 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3239 = (nbgl_obj_t *) separationLine;
3240 layoutInt->footerContainer->nbChildren++;
3241 }
3242
3243 layoutInt->children[FOOTER_INDEX] = (nbgl_obj_t *) layoutInt->footerContainer;
3244
3245 // subtract footer height from main container height
3246 layoutInt->container->obj.area.height -= layoutInt->footerContainer->obj.area.height;
3247
3248 layoutInt->footerType = footerDesc->type;
3249
3250 return layoutInt->footerContainer->obj.area.height;
3251}
3252
3262{
3263 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
3264 layoutObj_t *obj;
3265 nbgl_text_area_t *textArea;
3266 nbgl_line_t *line;
3267 nbgl_button_t *button;
3268
3269 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddUpFooter():\n");
3270 if (layout == NULL) {
3271 return -1;
3272 }
3273 if ((upFooterDesc == NULL) || (upFooterDesc->type >= NB_UP_FOOTER_TYPES)) {
3274 return -2;
3275 }
3276
3277 layoutInt->upFooterContainer
3279 layoutInt->upFooterContainer->obj.area.width = SCREEN_WIDTH;
3280 layoutInt->upFooterContainer->layout = VERTICAL;
3281 // maximum 4 children for long press button
3282 layoutInt->upFooterContainer->children
3283 = (nbgl_obj_t **) nbgl_containerPoolGet(4, layoutInt->layer);
3284 layoutInt->upFooterContainer->obj.alignTo = (nbgl_obj_t *) layoutInt->container;
3285 layoutInt->upFooterContainer->obj.alignment = BOTTOM_MIDDLE;
3286
3287 switch (upFooterDesc->type) {
3288 case UP_FOOTER_LONG_PRESS: {
3289 nbgl_progress_bar_t *progressBar;
3290
3291 obj = layoutAddCallbackObj(layoutInt,
3292 (nbgl_obj_t *) layoutInt->upFooterContainer,
3293 upFooterDesc->longPress.token,
3294 upFooterDesc->longPress.tuneId);
3295 if (obj == NULL) {
3296 return -1;
3297 }
3298 layoutInt->upFooterContainer->nbChildren = 4;
3299 layoutInt->upFooterContainer->obj.area.height = LONG_PRESS_BUTTON_HEIGHT;
3300 layoutInt->upFooterContainer->obj.touchId = LONG_PRESS_BUTTON_ID;
3301 layoutInt->upFooterContainer->obj.touchMask
3302 = ((1 << TOUCHING) | (1 << TOUCH_RELEASED) | (1 << OUT_OF_TOUCH)
3303 | (1 << SWIPED_LEFT) | (1 << SWIPED_RIGHT));
3304
3305 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
3306 button->obj.alignmentMarginX = BORDER_MARGIN;
3307 button->obj.alignment = MID_RIGHT;
3308 button->innerColor = BLACK;
3309 button->foregroundColor = WHITE;
3310 button->borderColor = BLACK;
3311 button->obj.area.width = BUTTON_DIAMETER;
3312 button->obj.area.height = BUTTON_DIAMETER;
3313 button->radius = BUTTON_RADIUS;
3314 button->icon = PIC(&VALIDATE_ICON);
3315 layoutInt->upFooterContainer->children[0] = (nbgl_obj_t *) button;
3316
3317 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
3318 textArea->textColor = BLACK;
3319 textArea->text = PIC(upFooterDesc->longPress.text);
3320 textArea->textAlignment = MID_LEFT;
3321 textArea->fontId = LARGE_MEDIUM_FONT;
3322 textArea->wrapping = true;
3323 textArea->obj.area.width = SCREEN_WIDTH - 3 * BORDER_MARGIN - button->obj.area.width;
3324 textArea->obj.area.height = nbgl_getTextHeightInWidth(
3325 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
3326 textArea->style = NO_STYLE;
3327 textArea->obj.alignment = MID_LEFT;
3328 textArea->obj.alignmentMarginX = BORDER_MARGIN;
3329 layoutInt->upFooterContainer->children[1] = (nbgl_obj_t *) textArea;
3330
3331 line = createHorizontalLine(layoutInt->layer);
3332 line->obj.alignment = TOP_MIDDLE;
3333 layoutInt->upFooterContainer->children[2] = (nbgl_obj_t *) line;
3334
3335 progressBar = (nbgl_progress_bar_t *) nbgl_objPoolGet(PROGRESS_BAR, layoutInt->layer);
3336 progressBar->obj.area.width = SCREEN_WIDTH;
3337 progressBar->obj.area.height = LONG_PRESS_PROGRESS_HEIGHT;
3338 progressBar->obj.alignment = TOP_MIDDLE;
3339 progressBar->obj.alignmentMarginY = LONG_PRESS_PROGRESS_ALIGN;
3340 progressBar->resetIfOverriden = true;
3341 progressBar->partialRedraw = true;
3342 layoutInt->upFooterContainer->children[3] = (nbgl_obj_t *) progressBar;
3343 break;
3344 }
3345 case UP_FOOTER_BUTTON: {
3346 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
3347 obj = layoutAddCallbackObj(layoutInt,
3348 (nbgl_obj_t *) button,
3349 upFooterDesc->button.token,
3350 upFooterDesc->button.tuneId);
3351 if (obj == NULL) {
3352 return -1;
3353 }
3354
3355 layoutInt->upFooterContainer->nbChildren = 1;
3356 layoutInt->upFooterContainer->obj.area.height = UP_FOOTER_BUTTON_HEIGHT;
3357 button->obj.alignment = CENTER;
3358
3359 if (upFooterDesc->button.style == BLACK_BACKGROUND) {
3360 button->innerColor = BLACK;
3361 button->foregroundColor = WHITE;
3362 }
3363 else {
3364 button->innerColor = WHITE;
3365 button->foregroundColor = BLACK;
3366 }
3367 if (upFooterDesc->button.style == NO_BORDER) {
3368 button->borderColor = WHITE;
3369 }
3370 else {
3371 if (upFooterDesc->button.style == BLACK_BACKGROUND) {
3372 button->borderColor = BLACK;
3373 }
3374 else {
3375 button->borderColor = LIGHT_GRAY;
3376 }
3377 }
3378 button->text = PIC(upFooterDesc->button.text);
3379 button->fontId = SMALL_BOLD_FONT;
3380 button->icon = PIC(upFooterDesc->button.icon);
3381 button->obj.area.width = AVAILABLE_WIDTH;
3382 button->obj.area.height = BUTTON_DIAMETER;
3383 button->radius = BUTTON_RADIUS;
3384
3385 button->obj.alignTo = NULL;
3386 button->obj.touchMask = (1 << TOUCHED);
3387 button->obj.touchId = SINGLE_BUTTON_ID;
3388 layoutInt->upFooterContainer->children[0] = (nbgl_obj_t *) button;
3389 break;
3390 }
3392 // icon & text cannot be NULL
3393 if ((upFooterDesc->horizontalButtons.leftIcon == NULL)
3394 || (upFooterDesc->horizontalButtons.rightText == NULL)) {
3395 return -1;
3396 }
3397
3398 layoutInt->upFooterContainer->nbChildren = 2;
3399 layoutInt->upFooterContainer->obj.area.height = UP_FOOTER_BUTTON_HEIGHT;
3400
3401 // create left button (in white) at first
3402 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
3403 obj = layoutAddCallbackObj(layoutInt,
3404 (nbgl_obj_t *) button,
3405 upFooterDesc->horizontalButtons.leftToken,
3406 upFooterDesc->horizontalButtons.tuneId);
3407 if (obj == NULL) {
3408 return -1;
3409 }
3410 // associate with with index 1
3411 obj->index = 1;
3412 button->obj.alignment = MID_LEFT;
3413 button->obj.alignmentMarginX = BORDER_MARGIN;
3414 button->borderColor = LIGHT_GRAY;
3415 button->innerColor = WHITE;
3416 button->foregroundColor = BLACK;
3417 button->obj.area.width = BUTTON_WIDTH;
3418 button->obj.area.height = BUTTON_DIAMETER;
3419 button->radius = BUTTON_RADIUS;
3420 button->icon = PIC(upFooterDesc->horizontalButtons.leftIcon);
3421 button->fontId = SMALL_BOLD_FONT;
3422 button->obj.touchMask = (1 << TOUCHED);
3423 button->obj.touchId = CHOICE_2_ID;
3424 layoutInt->upFooterContainer->children[0] = (nbgl_obj_t *) button;
3425
3426 // then black button, on right
3427 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
3428 obj = layoutAddCallbackObj(layoutInt,
3429 (nbgl_obj_t *) button,
3430 upFooterDesc->horizontalButtons.rightToken,
3431 upFooterDesc->horizontalButtons.tuneId);
3432 if (obj == NULL) {
3433 return -1;
3434 }
3435 // associate with with index 0
3436 obj->index = 0;
3437 button->obj.alignment = MID_RIGHT;
3438 button->obj.alignmentMarginX = BORDER_MARGIN;
3439 button->innerColor = BLACK;
3440 button->borderColor = BLACK;
3441 button->foregroundColor = WHITE;
3442 button->obj.area.width = AVAILABLE_WIDTH - BUTTON_WIDTH - LEFT_CONTENT_ICON_TEXT_X;
3443 button->obj.area.height = BUTTON_DIAMETER;
3444 button->radius = BUTTON_RADIUS;
3445 button->text = PIC(upFooterDesc->horizontalButtons.rightText);
3446 button->fontId = SMALL_BOLD_FONT;
3447 button->obj.touchMask = (1 << TOUCHED);
3448 button->obj.touchId = CHOICE_1_ID;
3449 layoutInt->upFooterContainer->children[1] = (nbgl_obj_t *) button;
3450 break;
3451 }
3452 case UP_FOOTER_TIP_BOX: {
3453 // text cannot be NULL
3454 if (upFooterDesc->tipBox.text == NULL) {
3455 return -1;
3456 }
3457 obj = layoutAddCallbackObj(layoutInt,
3458 (nbgl_obj_t *) layoutInt->upFooterContainer,
3459 upFooterDesc->tipBox.token,
3460 upFooterDesc->tipBox.tuneId);
3461 if (obj == NULL) {
3462 return -1;
3463 }
3464 layoutInt->upFooterContainer->nbChildren = 3;
3465 layoutInt->upFooterContainer->obj.touchId = TIP_BOX_ID;
3466 layoutInt->upFooterContainer->obj.touchMask = (1 << TOUCHED);
3467
3468 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
3469 textArea->textColor = BLACK;
3470 textArea->text = PIC(upFooterDesc->tipBox.text);
3471 textArea->textAlignment = MID_LEFT;
3472 textArea->fontId = SMALL_REGULAR_FONT;
3473 textArea->wrapping = true;
3474 textArea->obj.area.width = AVAILABLE_WIDTH;
3475 if (upFooterDesc->tipBox.icon != NULL) {
3476 textArea->obj.area.width
3477 -= ((nbgl_icon_details_t *) PIC(upFooterDesc->tipBox.icon))->width
3478 + TIP_BOX_TEXT_ICON_MARGIN;
3479 }
3480 textArea->obj.area.height = nbgl_getTextHeightInWidth(
3481 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
3482 textArea->obj.alignment = MID_LEFT;
3483 textArea->obj.alignmentMarginX = BORDER_MARGIN;
3484 layoutInt->upFooterContainer->children[0] = (nbgl_obj_t *) textArea;
3485 layoutInt->upFooterContainer->obj.area.height = textArea->obj.area.height;
3486
3487 line = createHorizontalLine(layoutInt->layer);
3488 line->obj.alignment = TOP_MIDDLE;
3489 layoutInt->upFooterContainer->children[1] = (nbgl_obj_t *) line;
3490
3491 if (upFooterDesc->tipBox.icon != NULL) {
3492 nbgl_image_t *image = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
3493 image->obj.alignmentMarginX = BORDER_MARGIN;
3494 image->obj.alignment = MID_RIGHT;
3495 image->foregroundColor = BLACK;
3496 image->buffer = PIC(upFooterDesc->tipBox.icon);
3497 layoutInt->upFooterContainer->children[2] = (nbgl_obj_t *) image;
3498 if (layoutInt->upFooterContainer->obj.area.height < image->buffer->height) {
3499 layoutInt->upFooterContainer->obj.area.height = image->buffer->height;
3500 }
3501 }
3502 layoutInt->upFooterContainer->obj.area.height += 2 * TIP_BOX_MARGIN_Y;
3503
3504 break;
3505 }
3506 case UP_FOOTER_TEXT: {
3507 obj = layoutAddCallbackObj(layoutInt,
3508 (nbgl_obj_t *) layoutInt->upFooterContainer,
3509 upFooterDesc->text.token,
3510 upFooterDesc->text.tuneId);
3511 if (obj == NULL) {
3512 return -1;
3513 }
3514 layoutInt->upFooterContainer->nbChildren = 1;
3515 layoutInt->upFooterContainer->obj.area.height = SMALL_FOOTER_HEIGHT;
3516 layoutInt->upFooterContainer->obj.touchId = WHOLE_SCREEN_ID;
3517 layoutInt->upFooterContainer->obj.touchMask = (1 << TOUCHED);
3518
3519 // only create text_area if text is not empty
3520 if (strlen(PIC(upFooterDesc->text.text))) {
3521 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
3522 textArea->textColor = LIGHT_TEXT_COLOR;
3523 textArea->text = PIC(upFooterDesc->text.text);
3524 textArea->textAlignment = CENTER;
3525 textArea->fontId = SMALL_REGULAR_FONT;
3526 textArea->wrapping = true;
3527 textArea->obj.area.width = AVAILABLE_WIDTH;
3528 textArea->obj.area.height = nbgl_getTextHeightInWidth(
3529 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
3530 textArea->obj.alignment = CENTER;
3531 layoutInt->upFooterContainer->children[0] = (nbgl_obj_t *) textArea;
3532 }
3533 break;
3534 }
3535 default:
3536 return -2;
3537 }
3538
3539 // subtract up footer height from main container height
3540 layoutInt->container->obj.area.height -= layoutInt->upFooterContainer->obj.area.height;
3541
3542 layoutInt->children[UP_FOOTER_INDEX] = (nbgl_obj_t *) layoutInt->upFooterContainer;
3543
3544 layoutInt->upFooterType = upFooterDesc->type;
3545
3546 return layoutInt->upFooterContainer->obj.area.height;
3547}
3548
3563 uint8_t activePage,
3564 uint8_t nbPages,
3565 bool withBack,
3566 uint8_t backToken,
3567 tune_index_e tuneId)
3568{
3570 .separationLine = false,
3571 .progressAndBack.activePage = activePage,
3572 .progressAndBack.nbPages = nbPages,
3573 .progressAndBack.token = backToken,
3574 .progressAndBack.tuneId = tuneId,
3575 .progressAndBack.withBack = withBack,
3576 .progressAndBack.actionIcon = NULL,
3577 .progressAndBack.actionToken = NBGL_INVALID_TOKEN};
3578 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddProgressIndicator():\n");
3579
3580 return nbgl_layoutAddHeader(layout, &headerDesc);
3581}
3582
3594 const char *text,
3595 const char *subText,
3596 uint8_t initPosition)
3597{
3598 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
3599 nbgl_container_t *container;
3600 nbgl_text_area_t *textArea;
3601 nbgl_spinner_t *spinner;
3602
3603 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddSpinner():\n");
3604 if (layout == NULL) {
3605 return -1;
3606 }
3607
3608 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
3609 // spinner + text + subText
3610 container->nbChildren = 3;
3611 container->children = nbgl_containerPoolGet(container->nbChildren, layoutInt->layer);
3612
3613 container->obj.area.width = AVAILABLE_WIDTH;
3614 container->layout = VERTICAL;
3615 container->obj.alignment = CENTER;
3616
3617 // create spinner
3618 spinner = (nbgl_spinner_t *) nbgl_objPoolGet(SPINNER, layoutInt->layer);
3619 spinner->position = initPosition;
3620 spinner->obj.alignment = TOP_MIDDLE;
3621 // set this new spinner as child of the container
3622 container->children[0] = (nbgl_obj_t *) spinner;
3623
3624 // update container height
3625 container->obj.area.height += SPINNER_HEIGHT;
3626
3627 // create text area
3628 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
3629 textArea->textColor = BLACK;
3630 textArea->text = PIC(text);
3631 textArea->textAlignment = CENTER;
3632 textArea->fontId = (subText != NULL) ? LARGE_MEDIUM_FONT : SMALL_REGULAR_FONT;
3633 textArea->wrapping = true;
3634 textArea->obj.alignmentMarginY = SPINNER_TEXT_MARGIN;
3635 textArea->obj.alignTo = (nbgl_obj_t *) spinner;
3636 textArea->obj.alignment = BOTTOM_MIDDLE;
3637 textArea->obj.area.width = AVAILABLE_WIDTH;
3638 textArea->obj.area.height = nbgl_getTextHeightInWidth(
3639 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
3640 textArea->style = NO_STYLE;
3641
3642 // update container height
3643 container->obj.area.height += textArea->obj.alignmentMarginY + textArea->obj.area.height;
3644
3645 // set this text as child of the container
3646 container->children[1] = (nbgl_obj_t *) textArea;
3647
3648 if (subText != NULL) {
3649 nbgl_text_area_t *subTextArea;
3650 // create sub-text area
3651 subTextArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
3652 subTextArea->textColor = BLACK;
3653 subTextArea->text = PIC(subText);
3654 subTextArea->textAlignment = CENTER;
3655 subTextArea->fontId = SMALL_REGULAR_FONT;
3656 subTextArea->wrapping = true;
3657 subTextArea->obj.alignmentMarginY = SPINNER_INTER_TEXTS_MARGIN;
3658 subTextArea->obj.alignTo = (nbgl_obj_t *) textArea;
3659 subTextArea->obj.alignment = BOTTOM_MIDDLE;
3660 subTextArea->obj.area.width = AVAILABLE_WIDTH;
3661 subTextArea->obj.area.height = nbgl_getTextHeightInWidth(subTextArea->fontId,
3662 subTextArea->text,
3663 subTextArea->obj.area.width,
3664 subTextArea->wrapping);
3665 subTextArea->style = NO_STYLE;
3666
3667 // update container height
3668 container->obj.area.height
3669 += subTextArea->obj.alignmentMarginY + subTextArea->obj.area.height;
3670
3671 // set thissub-text as child of the container
3672 container->children[2] = (nbgl_obj_t *) subTextArea;
3673 }
3674 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
3675
3676 if (initPosition != SPINNER_FIXED) {
3677 // update ticker to update the spinner periodically
3679
3680 tickerCfg.tickerIntervale = SPINNER_REFRESH_PERIOD; // ms
3681 tickerCfg.tickerValue = SPINNER_REFRESH_PERIOD; // ms
3682 tickerCfg.tickerCallback = &spinnerTickerCallback;
3683 nbgl_screenUpdateTicker(layoutInt->layer, &tickerCfg);
3684 }
3685
3686 return 0;
3687}
3688
3701 const char *text,
3702 const char *subText,
3703 uint8_t position)
3704{
3705 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
3706 nbgl_container_t *container;
3707 nbgl_text_area_t *textArea;
3708 nbgl_spinner_t *spinner;
3709 int ret = 0;
3710
3711 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutUpdateSpinner():\n");
3712 if ((layout == NULL) || (layoutInt->container->nbChildren == 0)) {
3713 return -1;
3714 }
3715
3716 container = (nbgl_container_t *) layoutInt->container->children[0];
3717 if ((container->obj.type != CONTAINER) || (container->nbChildren < 2)) {
3718 return -1;
3719 }
3720
3721 spinner = (nbgl_spinner_t *) container->children[0];
3722 if (spinner->obj.type != SPINNER) {
3723 return -1;
3724 }
3725 // if position is different, redraw
3726 if (spinner->position != position) {
3727 spinner->position = position;
3728 nbgl_objDraw((nbgl_obj_t *) spinner);
3729 ret = 1;
3730 }
3731
3732 // update text area if necessary
3733 textArea = (nbgl_text_area_t *) container->children[1];
3734 if (textArea->obj.type != TEXT_AREA) {
3735 return -1;
3736 }
3737 const char *newText = PIC(text);
3738 size_t newTextLen = strlen(newText);
3739 // if text is different, redraw (don't use strcmp because it crashes with Rust SDK)
3740 if ((newTextLen != strlen(textArea->text)) || memcmp(textArea->text, newText, newTextLen)) {
3741 textArea->text = newText;
3742 nbgl_objDraw((nbgl_obj_t *) textArea);
3743 ret = 2;
3744 }
3745
3746 if (subText != NULL) {
3747 nbgl_text_area_t *subTextArea;
3748
3749 if (container->nbChildren != 3) {
3750 return -1;
3751 }
3752 subTextArea = (nbgl_text_area_t *) container->children[2];
3753 if (subTextArea->obj.type != TEXT_AREA) {
3754 return -1;
3755 }
3756 const char *newSubText = PIC(subText);
3757 size_t newSubTextLen = strlen(newSubText);
3758 // if text is different, redraw
3759 if ((newSubTextLen != strlen(subTextArea->text))
3760 || memcmp(subTextArea->text, newSubText, newSubTextLen)) {
3761 subTextArea->text = newSubText;
3762 nbgl_objDraw((nbgl_obj_t *) subTextArea);
3763 ret = 2;
3764 }
3765 }
3766
3767 return ret;
3768}
3769
3777{
3778 nbgl_layoutInternal_t *layout = (nbgl_layoutInternal_t *) layoutParam;
3779
3780 if (layout == NULL) {
3781 return -1;
3782 }
3783 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutDraw(): layout->isUsed = %d\n", layout->isUsed);
3784 if (layout->tapText) {
3785 // set this new container as child of main container
3786 layoutAddObject(layout, (nbgl_obj_t *) layout->tapText);
3787 }
3788#ifdef TARGET_STAX
3789 if (layout->withLeftBorder == true) {
3790 // draw now the line
3791 nbgl_line_t *line = createLeftVerticalLine(layout->layer);
3792 layout->children[LEFT_BORDER_INDEX] = (nbgl_obj_t *) line;
3793 }
3794#endif // TARGET_STAX
3796
3797 return 0;
3798}
3799
3807{
3808 nbgl_layoutInternal_t *layout = (nbgl_layoutInternal_t *) layoutParam;
3809 LOG_DEBUG(PAGE_LOGGER, "nbgl_layoutRelease(): \n");
3810 if ((layout == NULL) || (!layout->isUsed)) {
3811 return -1;
3812 }
3813 // if modal
3814 if (layout->modal) {
3815 nbgl_screenPop(layout->layer);
3816 // if this layout was on top, use its bottom layout as top
3817 if (layout == topLayout) {
3818 topLayout = layout->bottom;
3819 topLayout->top = NULL;
3820 }
3821 else {
3822 // otherwise connect top to bottom
3823 layout->bottom->top = layout->top;
3824 layout->top->bottom = layout->bottom;
3825 }
3826 }
3827 layout->isUsed = false;
3828 return 0;
3829}
3830
3831#endif // HAVE_SE_TOUCH
Random Number Generation.
@ ANIM_ILLUSTRATION
animation
@ ICON_ILLUSTRATION
simple icon
@ LARGE_CASE_BOLD_INFO
@ NORMAL_INFO
@ LARGE_CASE_GRAY_INFO
debug traces management
#define LOG_WARN(__logger,...)
Definition nbgl_debug.h:87
#define LOG_DEBUG(__logger,...)
Definition nbgl_debug.h:86
#define LOG_FATAL(__logger,...)
Definition nbgl_debug.h:88
@ LAYOUT_LOGGER
Definition nbgl_debug.h:33
@ PAGE_LOGGER
Definition nbgl_debug.h:34
#define qrcode
Definition nbgl_draw.c:54
Middle Level API of the new BOLOS Graphical Library.
#define QR_V10_NB_PIX_SIZE
Definition nbgl_draw.h:24
#define QR_V4_NB_PIX_SIZE
Definition nbgl_draw.h:23
nbgl_font_id_e
Definition nbgl_fonts.h:143
uint8_t nbgl_getFontHeight(nbgl_font_id_e fontId)
return the height in pixels of the font with the given font ID
Definition nbgl_fonts.c:393
uint16_t nbgl_getTextWidth(nbgl_font_id_e fontId, const char *text)
return the max width in pixels of the given text (can be multiline)
Definition nbgl_fonts.c:355
uint16_t nbgl_getTextHeightInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
return the height of the given multiline text, with the given font.
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
Definition nbgl_fonts.c:727
const nbgl_font_t * nbgl_getFont(nbgl_font_id_e fontId)
uint8_t nbgl_getFontLineHeight(nbgl_font_id_e fontId)
return the height in pixels of the line of font with the given font ID
Definition nbgl_fonts.c:405
Font screen low-Level driver API, to draw elementary forms.
int nbgl_layoutAddTagValueList(nbgl_layout_t *layout, const nbgl_layoutTagValueList_t *list)
Creates a list of [tag,value] pairs.
int nbgl_layoutAddContentCenter(nbgl_layout_t *layout, const nbgl_contentCenter_t *info)
Creates an area on the center of the main panel, with a possible icon, and possible texts under it.
int nbgl_layoutAddUpFooter(nbgl_layout_t *layout, const nbgl_layoutUpFooter_t *upFooterDesc)
Creates a touchable area on top of the footer of the screen, containing various controls,...
int nbgl_layoutDraw(nbgl_layout_t *layoutParam)
Applies given layout. The screen will be redrawn.
#define NB_MAX_CONTAINER_CHILDREN
Definition nbgl_layout.c:39
int nbgl_layoutAddTextContent(nbgl_layout_t *layout, const char *title, const char *description, const char *info)
Creates in the main container three text areas:
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)
int nbgl_layoutAddProgressIndicator(nbgl_layout_t *layout, uint8_t activePage, uint8_t nbPages, bool withBack, uint8_t backToken, tune_index_e tuneId)
Creates a kind of navigation bar with an optional <- arrow on the left. This widget is placed on top ...
int nbgl_layoutAddNavigationBar(nbgl_layout_t *layout, const nbgl_layoutNavigationBar_t *info)
Creates a navigation bar on bottom of main container.
int nbgl_layoutAddSeparationLine(nbgl_layout_t *layout)
adds a separation line on bottom of the last added item
int nbgl_layoutAddQRCode(nbgl_layout_t *layout, const nbgl_layoutQRCode_t *info)
Creates an area on the center of the main panel, with a QRCode, a possible text in black (bold) under...
int nbgl_layoutAddRadioChoice(nbgl_layout_t *layout, const nbgl_layoutRadioChoice_t *choices)
Creates a list of radio buttons (on the right)
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_layoutAddSplitFooter(nbgl_layout_t *layout, const char *leftText, uint8_t leftToken, const char *rightText, uint8_t rightToken, tune_index_e tuneId)
Creates 2 touchable texts at the footer of the screen, separated with a thin line from the rest of th...
int nbgl_layoutAddTextWithAlias(nbgl_layout_t *layout, const char *text, const char *subText, uint8_t token, uint8_t index)
Creates an area with given text (in bold) and sub text (in regular), with a ‍icon on right of text to...
int nbgl_layoutAddTouchableBar(nbgl_layout_t *layout, const nbgl_layoutBar_t *barLayout)
Creates a touchable bar in main panel.
#define SPINNER_REFRESH_PERIOD
int nbgl_layoutAddTopRightButton(nbgl_layout_t *layout, const nbgl_icon_details_t *icon, uint8_t token, tune_index_e tuneId)
Creates a Top-right button in the top right corner of the top panel.
int nbgl_layoutInvertBackground(nbgl_layout_t *layout)
Inverts the background color (black instead of white)
int nbgl_layoutAddSwipe(nbgl_layout_t *layout, uint16_t swipesMask, const char *text, uint8_t token, tune_index_e tuneId)
Creates a swipe interaction on the main container.
int nbgl_layoutAddSwitch(nbgl_layout_t *layout, const nbgl_layoutSwitch_t *switchLayout)
Creates a switch with the given text and its state.
int nbgl_layoutAddHorizontalButtons(nbgl_layout_t *layout, const nbgl_layoutHorizontalButtons_t *info)
Creates two buttons to make a choice. Both buttons are mandatory The left one contains only an icon a...
listItemType_t
@ NB_ITEM_TYPES
@ TOUCHABLE_BAR_ITEM
@ TEXT_ITEM
@ SWITCH_ITEM
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_layoutAddExtendedFooter(nbgl_layout_t *layout, const nbgl_layoutFooter_t *footerDesc)
Creates a touchable area at the footer of the screen, containing various controls,...
int nbgl_layoutAddLeftContent(nbgl_layout_t *layout, const nbgl_layoutLeftContent_t *info)
Creates an area with a title, and rows of icon + text, left aligned.
#define NB_MAX_LAYOUTS
Definition nbgl_layout.c:36
int nbgl_layoutAddChoiceButtons(nbgl_layout_t *layout, const nbgl_layoutChoiceButtons_t *info)
Creates two buttons to make a choice. Both buttons are mandatory. Both buttons are full width,...
int nbgl_layoutRelease(nbgl_layout_t *layoutParam)
Release the layout obtained with nbgl_layoutGet()
int nbgl_layoutAddSpinner(nbgl_layout_t *layout, const char *text, const char *subText, uint8_t initPosition)
Creates a centered (vertically & horizontally) spinner with a text under it.
int nbgl_layoutUpdateSpinner(nbgl_layout_t *layout, const char *text, const char *subText, uint8_t position)
Update an existing spinner (must be the only object of the layout)
int nbgl_layoutAddLongPressButton(nbgl_layout_t *layout, const char *text, uint8_t token, tune_index_e tuneId)
Creates a long press button in the main container.
void layoutAddObject(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj)
adds the given obj to the main container
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.
int nbgl_layoutAddHeader(nbgl_layout_t *layout, const nbgl_layoutHeader_t *headerDesc)
Creates a touchable (or not) area at the header of the screen, containing various controls,...
int nbgl_layoutAddBottomButton(nbgl_layout_t *layout, const nbgl_icon_details_t *icon, uint8_t token, bool separationLine, tune_index_e tuneId)
Creates a centered button at bottom of main container.
int nbgl_layoutAddFooter(nbgl_layout_t *layout, const char *text, uint8_t token, tune_index_e tuneId)
Creates a touchable text at the footer of the screen, separated with a thin line from the rest of the...
int nbgl_layoutAddLargeCaseText(nbgl_layout_t *layout, const char *text, bool grayedOut)
Creates an area with given text in 32px font (in Black or Light Gray)
layoutObj_t * layoutAddCallbackObj(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj, uint8_t token, tune_index_e tuneId)
void(* nbgl_layoutTouchCallback_t)(int token, uint8_t index)
prototype of function to be called when an object is touched
@ WHITE_BACKGROUND
rounded bordered button, with text/icon in black, on white background
@ NO_BORDER
simple clickable text, in black
@ BLACK_BACKGROUND
rounded bordered button, with text/icon in white, on black background
#define AVAILABLE_WIDTH
@ UP_FOOTER_TEXT
grayed-out text, for example "Tap to continue"
@ NB_UP_FOOTER_TYPES
@ UP_FOOTER_BUTTON
simple button
@ UP_FOOTER_LONG_PRESS
long-press button
@ UP_FOOTER_TIP_BOX
Tip-box.
@ UP_FOOTER_HORIZONTAL_BUTTONS
2 buttons, on the same line
void * nbgl_layout_t
type shared externally
@ HEADER_TITLE
simple centered text
@ HEADER_BACK_AND_PROGRESS
optional back key and progress indicator (only on Stax)
@ HEADER_EMPTY
empty space, to have a better vertical centering of centered info
@ NB_HEADER_TYPES
@ HEADER_EXTENDED_BACK
back key, centered text and touchable key on the right
@ HEADER_BACK_AND_TEXT
back key and optional text
@ HEADER_RIGHT_TEXT
touchable text on the right, with a vertical separation line
@ HEADER_BACK_ICON_AND_TEXT
back key and optional icon and text
#define NBGL_INVALID_TOKEN
Definition nbgl_layout.h:30
#define SPINNER_FIXED
position to use for a "fixed" spinner
@ SOFT_ACTION_AND_FOOTER_STYLE
A white button on top of a footer, with a separation line.
@ BOTH_ROUNDED_STYLE
A black button on top of a white button.
@ ROUNDED_AND_FOOTER_STYLE
A black background button on top of a footer.
#define NBGL_NO_PROGRESS_INDICATOR
To be used when a control token shall not be used.
Definition nbgl_layout.h:27
#define NBGL_NO_TUNE
Definition nbgl_layout.h:26
@ FOOTER_SIMPLE_TEXT
simple touchable text in bold
@ FOOTER_NAV
navigation bar
@ FOOTER_SIMPLE_BUTTON
simple black or white button (see nbgl_layoutButtonStyle_t)
@ FOOTER_TEXT_AND_NAV
@ FOOTER_DOUBLE_TEXT
2 touchable texts in bold, separated by a vertical line (only on Stax)
@ NB_FOOTER_TYPES
@ FOOTER_EMPTY
empty space, to have a better vertical centering of centered info
@ FOOTER_CHOICE_BUTTONS
double buttons (see nbgl_layoutChoiceButtonsStyle_t)
Internal functions/constants of NBGL layout layer.
nbgl_swipe_usage_t
@ SWIPE_USAGE_CUSTOM
@ SWIPE_USAGE_SUGGESTIONS
@ SWIPE_USAGE_NAVIGATION
bool keyboardSwipeCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType)
void layoutNavigationPopulate(nbgl_container_t *navContainer, const nbgl_layoutNavigationBar_t *navConfig, uint8_t layer)
This function creates a full navigation bar "object", with buttons and returns it as a container.
#define LAYOUT_OBJ_POOL_LEN
Max number of complex objects with callback retrievable from pool.
bool layoutNavigationCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType, uint8_t nbPages, uint8_t *activePage)
function to be called when any of the controls in navigation bar is touched
@ UP_FOOTER_INDEX
@ FOOTER_INDEX
@ HEADER_INDEX
@ TOP_RIGHT_BUTTON_INDEX
@ MAIN_CONTAINER_INDEX
@ LEFT_BORDER_INDEX
@ NB_MAX_SCREEN_CHILDREN
API to draw all basic graphic objects.
struct PACKED__ nbgl_line_s nbgl_line_t
struct to represent a vertical or horizontal line
struct PACKED__ nbgl_navigation_bar_s nbgl_page_indicator_t
struct to represent a navigation bar (PAGE_INDICATOR type) There can be up to 5 page indicators,...
struct PACKED__ nbgl_radio_s nbgl_radio_t
struct to represent a radio button (RADIO_BUTTON type)
#define NB_SPINNER_POSITIONS
Definition nbgl_obj.h:264
#define LIGHT_TEXT_COLOR
Definition nbgl_obj.h:282
void(* nbgl_touchCallback_t)(void *obj, nbgl_touchType_t eventType)
prototype of function to be called when a touch event is received by an object
Definition nbgl_obj.h:346
struct PACKED__ nbgl_text_area_s nbgl_text_area_t
struct to represent a text area (TEXT_AREA type)
void nbgl_objDraw(nbgl_obj_t *obj)
This function draws or redraws the given object and its children (recursive version)
Definition nbgl_obj.c:1677
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.
#define SWIPE_MASK
Definition nbgl_obj.h:292
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.
void nbgl_refreshSpecial(nbgl_refresh_mode_t mode)
This functions refreshes the actual screen on display with what has changed since the last refresh,...
Definition nbgl_obj.c:1730
struct PACKED__ nbgl_image_s nbgl_image_t
struct to represent an image (IMAGE type)
#define INACTIVE_SMALL_FONT
Definition nbgl_obj.h:281
struct PACKED__ nbgl_button_s nbgl_button_t
struct to represent a button (BUTTON type) that can contain a text and/or an icon
#define INACTIVE_COLOR
Definition nbgl_obj.h:279
#define INACTIVE_TEXT_COLOR
Definition nbgl_obj.h:280
void nbgl_refreshSpecialWithPostRefresh(nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
Definition nbgl_obj.c:1746
@ CHOICE_1_ID
Definition nbgl_obj.h:683
@ TOP_RIGHT_BUTTON_ID
Definition nbgl_obj.h:679
@ LONG_PRESS_BUTTON_ID
Definition nbgl_obj.h:692
@ CONTROLS_ID
Definition nbgl_obj.h:694
@ RIGHT_BUTTON_ID
Definition nbgl_obj.h:677
@ WHOLE_SCREEN_ID
Definition nbgl_obj.h:678
@ BOTTOM_BUTTON_ID
Definition nbgl_obj.h:675
@ SINGLE_BUTTON_ID
Definition nbgl_obj.h:681
@ BACK_BUTTON_ID
Definition nbgl_obj.h:680
@ VALUE_BUTTON_1_ID
Definition nbgl_obj.h:689
@ TIP_BOX_ID
Definition nbgl_obj.h:693
@ EXTRA_BUTTON_ID
Definition nbgl_obj.h:682
@ CHOICE_2_ID
Definition nbgl_obj.h:684
#define BUTTON_DIAMETER
Definition nbgl_obj.h:99
struct PACKED__ nbgl_container_s nbgl_container_t
struct to represent a container (CONTAINER type)
#define BUTTON_WIDTH
Definition nbgl_obj.h:104
struct PACKED__ nbgl_switch_s nbgl_switch_t
struct to represent a switch (size is fixed) (SWITCH type)
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
struct PACKED__ nbgl_spinner_s nbgl_spinner_t
struct to represent a "spinner", represented by the Ledger corners, in gray, with one of the corners ...
struct PACKED__ nbgl_qrcode_s nbgl_qrcode_t
struct to represent a QR code (QR_CODE type), whose size is fixed
API to manage screens.
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....
void nbgl_wait_pipeline(void)
int nbgl_screenUpdateTicker(uint8_t screenIndex, const nbgl_screenTickerConfiguration_t *ticker)
Updates the ticker configuration of the screen at the given screenIndex, always set at WHITE in.
int nbgl_screenPop(uint8_t screenIndex)
Release the screen at the given index in screen array (index returned by nbgl_screenPush())....
struct PACKED__ nbgl_screenTickerConfiguration_s nbgl_screenTickerConfiguration_t
struct to configure a screen layer
int nbgl_screenUpdateBackgroundColor(uint8_t screenIndex, color_t color)
Updates the background color of the screen at the given screenIndex, always set at WHITE in.
void nbgl_screenRedraw(void)
This function redraws the whole screen on top of stack and its children.
Definition nbgl_screen.c:66
uint32_t nbgl_touchGetTouchDuration(nbgl_obj_t *obj)
Definition nbgl_touch.c:407
color_t
Definition nbgl_types.h:140
@ WHITE
Definition nbgl_types.h:144
@ LIGHT_GRAY
Definition nbgl_types.h:143
@ BLACK
Definition nbgl_types.h:141
nbgl_state_t
to represent a boolean state.
Definition nbgl_types.h:199
@ ON_STATE
Definition nbgl_types.h:201
@ OFF_STATE
Definition nbgl_types.h:200
@ POST_REFRESH_FORCE_POWER_OFF
Force screen power off after refresh.
Definition nbgl_types.h:353
@ POST_REFRESH_FORCE_POWER_ON
Force screen power on after refresh.
Definition nbgl_types.h:354
@ POST_REFRESH_FORCE_POWER_ON_WITH_PIPELINE
Force screen power on and enable pipeline.
Definition nbgl_types.h:355
nbgl_touchType_t
The different types of Touchscreen events.
Definition nbgl_types.h:259
@ SWIPED_LEFT
Definition nbgl_types.h:275
@ SWIPED_UP
Definition nbgl_types.h:272
@ SWIPED_DOWN
Definition nbgl_types.h:273
@ SWIPED_RIGHT
Definition nbgl_types.h:274
@ TOUCH_RELEASED
Definition nbgl_types.h:269
@ TOUCHED
Definition nbgl_types.h:260
@ TOUCHING
corresponding to an object that is currently touched
Definition nbgl_types.h:264
@ OUT_OF_TOUCH
Definition nbgl_types.h:265
@ QRCODE_V10
QRCode V10, can encode text len up to 1500 chars, display size = 228*228.
Definition nbgl_types.h:231
@ QRCODE_V4_SMALL
QRCode V4, can encode text len up to 1500 chars, display size = 132*132.
Definition nbgl_types.h:232
@ QRCODE_V4
QRCode V4, can encode text len up to 62 chars, display size = 264*264.
Definition nbgl_types.h:230
@ VERTICAL
from top to bottom
Definition nbgl_types.h:209
@ HORIZONTAL
from left to right
Definition nbgl_types.h:210
@ LOOP_PARSING
0, 1, 2, 0, 1, 2, ...
Definition nbgl_types.h:409
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
@ TOP_MIDDLE
Definition nbgl_types.h:182
@ CENTER
Definition nbgl_types.h:185
@ BOTTOM_RIGHT
Definition nbgl_types.h:189
@ TOP_LEFT
Definition nbgl_types.h:181
@ NO_ALIGNMENT
used when parent container layout is used
Definition nbgl_types.h:180
@ BOTTOM_LEFT
Definition nbgl_types.h:187
@ MID_RIGHT
Definition nbgl_types.h:186
@ RIGHT_TOP
on outside right
Definition nbgl_types.h:192
@ TOP_RIGHT
Definition nbgl_types.h:183
@ MID_LEFT
Definition nbgl_types.h:184
@ BOTTOM_MIDDLE
Definition nbgl_types.h:188
@ IMAGE
Bitmap (y and height must be multiple of 4 on Stax)
Definition nbgl_types.h:157
@ SWITCH
Switch to turn on/off something.
Definition nbgl_types.h:161
@ RADIO_BUTTON
Indicator to inform whether something is on or off.
Definition nbgl_types.h:164
@ SPINNER
Spinner.
Definition nbgl_types.h:168
@ BUTTON
Rounded rectangle button with icon and/or text.
Definition nbgl_types.h:160
@ PROGRESS_BAR
horizontal bar to indicate progression of something (between 0% and 100%)
Definition nbgl_types.h:163
@ QR_CODE
QR Code.
Definition nbgl_types.h:165
@ PAGE_INDICATOR
horizontal bar to indicate position within pages
Definition nbgl_types.h:162
@ LINE
Vertical or Horizontal line.
Definition nbgl_types.h:158
@ CONTAINER
Empty container.
Definition nbgl_types.h:156
@ TEXT_AREA
Area to contain text line(s)
Definition nbgl_types.h:159
#define MAX(x, y)
Definition nbgl_types.h:121
@ NBGL_BPP_1
1 bit per pixel
Definition nbgl_types.h:284
@ NO_STYLE
no border
Definition nbgl_types.h:218
@ BLACK_AND_WHITE_REFRESH
to be used for pure B&W area, when contrast is important
Definition nbgl_types.h:330
@ BLACK_AND_WHITE_FAST_REFRESH
to be used for pure B&W area, when contrast is not priority
Definition nbgl_types.h:331
@ FULL_COLOR_PARTIAL_REFRESH
to be used for small partial refresh (radio buttons, switches)
Definition nbgl_types.h:328
tune_index_e tuneId
uint8_t index
nbgl_state_t state
const char * text
const nbgl_icon_details_t * iconRight
tune_index_e tuneId
const char * subText
listItemType_t type
uint8_t token
const nbgl_icon_details_t * iconLeft
uint16_t delayMs
delay between 2 drawings
Definition nbgl_types.h:421
uint8_t nbIcons
number of icons in icons array
Definition nbgl_types.h:419
const nbgl_icon_details_t ** icons
array of nbIcons pointers on icons
Definition nbgl_types.h:418
nbgl_parsingType_t parsing
Definition nbgl_types.h:420
This structure contains info to build a centered (vertically and horizontally) area,...
uint16_t iconHug
vertical margin to apply on top and bottom of the icon
const nbgl_icon_details_t * icon
the icon (can be null)
const char * title
title in black large (can be null)
const char * description
description in black small regular case (can be null)
const char * subText
sub-text in dark gray regular small case
uint16_t animOffsetY
vertical offset of animation in icon if integrated (but usually 0)
bool padding
if true, apply a padding of 40px at the bottom
const nbgl_animation_t * animation
the animation (can be null), used if illustrType is ANIM_ILLUSTRATION
const char * smallTitle
sub-title in black small bold case (can be null)
uint16_t animOffsetX
horizontal offset of animation in icon if integrated (but usually 0)
nbgl_contentIllustrationType_t illustrType
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
int16_t offsetY
vertical shift to apply to this info (if >0, shift to bottom)
const char * text3
third text (can be null)
const nbgl_icon_details_t * icon
a buffer containing the 1BPP icon
This structure contains a list of names to build a list of radio buttons (on the right part of screen...
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when selecting a radio button)
uint8_t token
the token that will be used as argument of the callback
bool localized
if set to true, use nameIds and not names
uint8_t initChoice
index of the current choice
const char *const * names
array of strings giving the choices (nbChoices)
uint8_t nbChoices
number of choices
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
uint8_t token
the token that will be used as argument of the callback (unused on Nano)
nbgl_state_t initState
initial state of the switch
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played
const char * subText
description under main text (NULL terminated, single line, may be null)
This structure contains a list of [tag,value] pairs.
const nbgl_contentTagValue_t * pairs
array of [tag,value] pairs (nbPairs items). If NULL, callback is used instead
nbgl_contentTagValueCallback_t callback
function to call to retrieve a given pair
bool wrapping
if set to true, value text will be wrapped on ' ' to avoid cutting words
uint8_t startIndex
index of the first pair to get with callback
This structure contains a [tag,value] pair and possible extensions.
const nbgl_icon_details_t * valueIcon
const char * value
string giving the value name
const char * item
string giving the tag name
const char * text
text of the tip-box
const nbgl_icon_details_t * icon
icon of the tip-box
uint8_t token
token used when tip-box is tapped
tune_index_e tuneId
tune played when tip-box is tapped
structure defining an ASCII font
Definition nbgl_fonts.h:83
uint8_t line_height
height of a line for all characters in pixels
Definition nbgl_fonts.h:88
This structure contains info to build a clickable "bar" with a text and an icon.
bool inactive
if set to true, the bar is grayed-out and cannot be touched
const char * text
text (can be NULL)
uint8_t token
the token that will be used as argument of the callback
bool large
set to true only for the main level of OS settings
const char * subText
sub text (can be NULL)
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played
const nbgl_icon_details_t * iconLeft
a buffer containing the 1BPP icon for icon on left (can be NULL)
const nbgl_icon_details_t * iconRight
This structure contains info to build a single button.
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played
const char * text
button text
uint8_t token
the token that will be used as argument of the callback
const nbgl_icon_details_t * icon
a buffer containing the 1BPP icon for button
nbgl_layoutButtonStyle_t style
bool fittingContent
if set to true, fit the width of button to text, otherwise full width
This structure contains info to build a pair of buttons, one on top of the other.
nbgl_layoutChoiceButtonsStyle_t style
the style of the pair
const nbgl_icon_details_t * topIcon
icon of top button
uint8_t token
the token that will be used as argument of the callback
const char * topText
up-button text (index 0)
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played
const char * bottomText
bottom-button text (index 1)
Structure containing all information when creating a layout. This structure must be passed as argumen...
nbgl_screenTickerConfiguration_t ticker
const char * tapActionText
Light gray text used when main container is "tapable".
nbgl_layoutTouchCallback_t onActionCallback
the callback to be called on any action on the layout
This structure contains info to build an extended footer.
nbgl_layoutChoiceButtons_t choiceButtons
if type is FOOTER_CHOICE_BUTTONS
struct nbgl_layoutFooter_t::@19::@24 textAndNav
if type is FOOTER_TEXT_AND_NAV
bool separationLine
if true, a separation line is added at the top of this control
const char * leftText
struct nbgl_layoutFooter_t::@19::@22 simpleText
if type is FOOTER_SIMPLE_TEXT
nbgl_layoutButton_t button
if type is FOOTER_SIMPLE_BUTTON
struct nbgl_layoutFooter_t::@19::@23 doubleText
if type is FOOTER_DOUBLE_TEXT
bool mutedOut
if true, text is displayed in gray
struct nbgl_layoutFooter_t::@19::@21 emptySpace
if type is FOOTER_EMPTY
nbgl_layoutFooterType_t type
type of footer
nbgl_layoutNavigationBar_t navigation
if type is FOOTER_NAV
const char * rightText
const char * text
tune_index_e tuneId
This structure contains info to build a header.
nbgl_layoutHeaderType_t type
type of header
const nbgl_icon_details_t * icon
icon on left of text (only if HEADER_BACK_ICON_AND_TEXT)
uint8_t backToken
when back key is pressed
struct nbgl_layoutHeader_t::@11::@16 title
if type is HEADER_TITLE
struct nbgl_layoutHeader_t::@11::@18 rightText
if type is HEADER_RIGHT_TEXT
const char * subText
text under the line (can be NULL)
const nbgl_icon_details_t * actionIcon
right button icon
uint8_t actionToken
when optional right button is pressed
bool separationLine
if true, a separation line is added at the bottom of this control
tune_index_e tuneId
when back key is pressed
const char * text
can be NULL if no text
struct nbgl_layoutHeader_t::@11::@13 emptySpace
if type is HEADER_EMPTY
struct nbgl_layoutHeader_t::@11::@17 extendedBack
if type is HEADER_EXTENDED_BACK
uint8_t textToken
when text is touched
struct nbgl_layoutHeader_t::@11::@14 backAndText
if type is HEADER_BACK_ICON_AND_TEXT or HEADER_BACK_AND_TEXT
uint8_t token
when back key is pressed
struct nbgl_layoutHeader_t::@11::@15 progressAndBack
if type is HEADER_BACK_AND_PROGRESS
This structure contains info to build a pair of buttons, the small one, with icon,...
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played
const nbgl_icon_details_t * leftIcon
a buffer containing the 1BPP icon for left button
uint8_t leftToken
the token used when left button is pressed
uint8_t rightToken
the token used when right button is pressed
const char * rightText
right-button text
Structure containing all information about the current layout.
nbgl_container_t * footerContainer
container used to store footer (buttons, nav....)
uint8_t activePage
index of active page for navigation bar
uint8_t layer
layer in screen stack
struct nbgl_layoutInternal_s * top
layout above this one, in stack
nbgl_swipe_usage_t swipeUsage
nbgl_layoutTouchCallback_t callback
user callback for all controls
struct nbgl_layoutInternal_s * bottom
layout under this one, in stack
uint8_t invertedColors
if true, means that background is black
nbgl_container_t * container
uint8_t iconIdxInAnim
current icon index in animation
nbgl_container_t * headerContainer
container used to store header (progress, back, empty space...)
uint8_t isUsed
if true, means this layout is in use
nbgl_layoutFooterType_t footerType
type of footer
nbgl_layoutHeaderType_t headerType
type of header
nbgl_container_t * upFooterContainer
uint8_t incrementAnim
if true, means that animation index is currently incrementing
uint8_t nbPages
number of pages for navigation bar
nbgl_layoutUpFooterType_t upFooterType
type of up-footer
uint8_t modal
if true, means the screen is a modal
layoutObj_t callbackObjPool[LAYOUT_OBJ_POOL_LEN]
nbgl_text_area_t * tapText
nbgl_obj_t ** children
children for main screen
const nbgl_animation_t * animation
current animation (if not NULL)
This structure contains info to build a left content area.
uint8_t nbRows
number of rows in the area
const char * title
title of area in bold
const nbgl_icon_details_t ** rowIcons
array of nbRows icon
const char ** rowTexts
array of nbRows texts (displayed in regular)
This structure contains info to build a navigation bar at the bottom of the screen.
uint8_t activePage
index of active page (from 0 to nbPages-1).
tune_index_e tuneId
if not NBGL_NO_TUNE, a tune will be played when pressing keys)
bool withBackKey
if set to true, the "back" key is drawn
bool withExitKey
if set to true, an exit button is drawn (X on the left)
uint8_t token
the token that will be used as argument of the callback
uint8_t nbPages
number of pages. (if 0, no navigation)
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)
const char * url
URL for QR code.
bool largeText1
if set to true, use 32px font for text1
int16_t offsetY
vertical shift to apply to this info (if > 0, shift to bottom)
bool centered
if set to true, center vertically
This structure contains info to build an up-footer (area on top of footer).
nbgl_layoutButton_t button
if type is UP_FOOTER_BUTTON
tune_index_e tuneId
tune played when button is long-pressed
nbgl_contentTipBox_t tipBox
if type is UP_FOOTER_TIP_BOX
const char * text
text in the long-press button
nbgl_layoutUpFooterType_t type
type of up-footer
struct nbgl_layoutUpFooter_t::@25::@27 longPress
if type is UP_FOOTER_LONG_PRESS
uint8_t token
token used when button is long-pressed
nbgl_layoutHorizontalButtons_t horizontalButtons
if type is UP_FOOTER_HORIZONTAL_BUTTONS