Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
nbgl_layout.c
Go to the documentation of this file.
1
6
7#include "app_config.h"
8#include "nbgl_types.h"
9
10#ifdef HAVE_SE_TOUCH
11/*********************
12 * INCLUDES
13 *********************/
14#include <string.h>
15#include <stdlib.h>
16
17#ifdef HAVE_BOLOS
18#include "localization.h"
19#endif
20#include "nbgl_debug.h"
21#include "nbgl_front.h"
23#include "nbgl_obj.h"
24#include "nbgl_draw.h"
25#include "nbgl_screen.h"
26#include "nbgl_touch.h"
27#include "glyphs.h"
28#include "os_io_seph_ux.h"
29#include "os_pic.h"
30#include "os_helpers.h"
31#include "lcx_rng.h"
32
33/*********************
34 * DEFINES
35 *********************/
36// half internal margin, between items
37#define INTERNAL_SPACE 16
38// inner margin, between buttons
39#define INNER_MARGIN 12
40
41#define NB_MAX_LAYOUTS 3
42
43// used by container
44#define NB_MAX_CONTAINER_CHILDREN 20
45
46#define TAG_VALUE_ICON_WIDTH 32
47
48#if defined(TARGET_STAX)
49#define RADIO_CHOICE_HEIGHT 96
50#define BAR_INTERVALE 12
51#define FOOTER_BUTTON_HEIGHT 128
52#define FOOTER_IN_PAIR_HEIGHT 80
53#define ROUNDED_AND_FOOTER_FOOTER_HEIGHT 192
54#define FOOTER_TEXT_AND_NAV_WIDTH 160
55#define TAP_TO_CONTINUE_MARGIN 24
56#define SUB_HEADER_MARGIN 24
57#define PRE_FIRST_TEXT_MARGIN 24
58#define INTER_PARAGRAPHS_MARGIN 40
59#define PRE_TITLE_MARGIN 24
60#define PRE_DESCRIPTION_MARGIN 16
61#define INTER_DESCRIPTIONS_MARGIN 16
62#define PRE_FIRST_ROW_MARGIN 32
63#define INTER_ROWS_MARGIN 16
64#define QR_PRE_TEXT_MARGIN 24
65#define QR_INTER_TEXTS_MARGIN 40
66#define SPINNER_TEXT_MARGIN 20
67#define SPINNER_INTER_TEXTS_MARGIN 20
68#define BAR_TEXT_MARGIN 24
69#define BAR_INTER_TEXTS_MARGIN 16
70#define LEFT_CONTENT_TEXT_PADDING 0
71#define BUTTON_FROM_BOTTOM_MARGIN 4
72#define TOP_BUTTON_MARGIN VERTICAL_BORDER_MARGIN
73#define TOP_BUTTON_MARGIN_WITH_ACTION VERTICAL_BORDER_MARGIN
74#define SINGLE_BUTTON_MARGIN 24
75#define LONG_PRESS_PROGRESS_HEIGHT 8
76#define LONG_PRESS_PROGRESS_ALIGN 1
77#define LEFT_CONTENT_ICON_TEXT_X 16
78#define TIP_BOX_MARGIN_Y 24
79#define TIP_BOX_TEXT_ICON_MARGIN 24
80#elif defined(TARGET_FLEX) || defined(TARGET_APOLLO)
81#define RADIO_CHOICE_HEIGHT 92
82#define BAR_INTERVALE 16
83#define FOOTER_BUTTON_HEIGHT 136
84#define FOOTER_IN_PAIR_HEIGHT 88
85#define ROUNDED_AND_FOOTER_FOOTER_HEIGHT 208
86#define FOOTER_TEXT_AND_NAV_WIDTH 192
87#define TAP_TO_CONTINUE_MARGIN 30
88#define SUB_HEADER_MARGIN 28
89#define PRE_FIRST_TEXT_MARGIN 0
90#define INTER_PARAGRAPHS_MARGIN 24
91#define PRE_TITLE_MARGIN 16
92#define PRE_DESCRIPTION_MARGIN 24
93#define INTER_DESCRIPTIONS_MARGIN 24
94#define PRE_FIRST_ROW_MARGIN 32
95#define INTER_ROWS_MARGIN 24
96#define QR_PRE_TEXT_MARGIN 24
97#define QR_INTER_TEXTS_MARGIN 28
98#define SPINNER_TEXT_MARGIN 24
99#define SPINNER_INTER_TEXTS_MARGIN 16
100#define BAR_TEXT_MARGIN 24
101#define BAR_INTER_TEXTS_MARGIN 16
102#define LEFT_CONTENT_TEXT_PADDING 4
103#define BUTTON_FROM_BOTTOM_MARGIN 4
104#define TOP_BUTTON_MARGIN VERTICAL_BORDER_MARGIN
105#define TOP_BUTTON_MARGIN_WITH_ACTION VERTICAL_BORDER_MARGIN
106#define SINGLE_BUTTON_MARGIN 24
107#define LONG_PRESS_PROGRESS_HEIGHT 8
108#define LONG_PRESS_PROGRESS_ALIGN 1
109#define LEFT_CONTENT_ICON_TEXT_X 16
110#define TIP_BOX_MARGIN_Y 24
111#define TIP_BOX_TEXT_ICON_MARGIN 32
112#elif defined(TARGET_APEX)
113#define RADIO_CHOICE_HEIGHT 68
114#define BAR_INTERVALE 8
115#define FOOTER_BUTTON_HEIGHT 88
116#define FOOTER_IN_PAIR_HEIGHT 60
117#define ROUNDED_AND_FOOTER_FOOTER_HEIGHT 128
118#define FOOTER_TEXT_AND_NAV_WIDTH 120
119#define TAP_TO_CONTINUE_MARGIN 30
120#define SUB_HEADER_MARGIN 16
121#define PRE_FIRST_TEXT_MARGIN 0
122#define INTER_PARAGRAPHS_MARGIN 16
123#define PRE_TITLE_MARGIN 16
124#define PRE_DESCRIPTION_MARGIN 12
125#define INTER_DESCRIPTIONS_MARGIN 12
126#define PRE_FIRST_ROW_MARGIN 24
127#define INTER_ROWS_MARGIN 12
128#define QR_PRE_TEXT_MARGIN 16
129#define QR_INTER_TEXTS_MARGIN 20
130#define SPINNER_TEXT_MARGIN 16
131#define SPINNER_INTER_TEXTS_MARGIN 16
132#define BAR_TEXT_MARGIN 16
133#define BAR_INTER_TEXTS_MARGIN 12
134#define LEFT_CONTENT_TEXT_PADDING 4
135#define BUTTON_FROM_BOTTOM_MARGIN 0
136#define TOP_BUTTON_MARGIN 12
137#define TOP_BUTTON_MARGIN_WITH_ACTION 0
138#define SINGLE_BUTTON_MARGIN 16
139#define LONG_PRESS_PROGRESS_HEIGHT 4
140#define LONG_PRESS_PROGRESS_ALIGN 0
141#define LEFT_CONTENT_ICON_TEXT_X 8
142#define TIP_BOX_MARGIN_Y 12
143#define TIP_BOX_TEXT_ICON_MARGIN 20
144#else // TARGETS
145#error Undefined target
146#endif // TARGETS
147
148// refresh period of the spinner, in ms
149#define SPINNER_REFRESH_PERIOD 400
150
151/**********************
152 * MACROS
153 **********************/
154
155/**********************
156 * TYPEDEFS
157 **********************/
158
159typedef enum {
160 TOUCHABLE_BAR_ITEM,
161 SWITCH_ITEM,
162 TEXT_ITEM,
163 NB_ITEM_TYPES
164} listItemType_t;
165
166// used to build either a touchable bar or a switch
167typedef struct {
168 listItemType_t type;
169 const nbgl_icon_details_t *iconLeft; // a buffer containing the 1BPP icon for icon on
170 // left (can be NULL)
171 const nbgl_icon_details_t *iconRight; // a buffer containing the 1BPP icon for icon 2 (can be
172 // NULL). Dimensions must be the same as iconLeft
173 const char *text; // text (can be NULL)
174 const char *subText; // sub text (can be NULL)
175 uint8_t token; // the token that will be used as argument of the callback
176 nbgl_state_t state; // state of the item
177 bool large; // set to true only for the main level of OS settings
178 uint8_t index; // index of obj (for callback)
179 tune_index_e tuneId; // if not @ref NBGL_NO_TUNE, a tune will be played
180} listItem_t;
181
182/**********************
183 * VARIABLES
184 **********************/
185
191
192// current top of stack
193static nbgl_layoutInternal_t *topLayout;
194
195// numbers of touchable controls for the whole page
196static uint8_t nbTouchableControls = 0;
197
198/**********************
199 * STATIC PROTOTYPES
200 **********************/
201// extern const char *get_ux_loc_string(UX_LOC_STRINGS_INDEX index);
202
203// Hold-to-approve parameters
204#if defined(TARGET_FLEX) || defined(TARGET_APOLLO)
205// Percent of a single "hold-to-approve" bar
206#define HOLD_TO_APPROVE_STEP_PERCENT (7)
207// Duration between two bars
208#define HOLD_TO_APPROVE_STEP_DURATION_MS (100)
209// Number of bars displayed when the user start the "hold-to-approve" mechanism
210#define HOLD_TO_APPROVE_FIRST_STEP (0)
211#elif defined(TARGET_STAX)
212#define HOLD_TO_APPROVE_STEP_PERCENT (25)
213#define HOLD_TO_APPROVE_STEP_DURATION_MS (400)
214#define HOLD_TO_APPROVE_FIRST_STEP (1)
215#elif defined(TARGET_APEX)
216#define HOLD_TO_APPROVE_STEP_PERCENT (20)
217#define HOLD_TO_APPROVE_STEP_DURATION_MS (300)
218#define HOLD_TO_APPROVE_FIRST_STEP (1)
219#endif // TARGETS
220
221static inline uint8_t get_hold_to_approve_percent(uint32_t touch_duration)
222{
223 uint8_t current_step_nb
224 = (touch_duration / HOLD_TO_APPROVE_STEP_DURATION_MS) + HOLD_TO_APPROVE_FIRST_STEP;
225 return (current_step_nb * HOLD_TO_APPROVE_STEP_PERCENT);
226}
227
228// function used to retrieve the concerned layout and layout obj matching the given touched obj
229static bool getLayoutAndLayoutObj(nbgl_obj_t *obj,
230 nbgl_layoutInternal_t **layout,
231 layoutObj_t **layoutObj)
232{
233 // only try to find the object on top layout on the stack (the other cannot receive touch
234 // events)
235 *layout = NULL;
236 if ((topLayout) && (topLayout->isUsed)) {
237 uint8_t j;
238
239 // search index of obj in this layout
240 for (j = 0; j < topLayout->nbUsedCallbackObjs; j++) {
241 if (obj == topLayout->callbackObjPool[j].obj) {
243 "getLayoutAndLayoutObj(): obj found in layout %p "
244 "nbUsedCallbackObjs = %d\n",
245 topLayout,
246 topLayout->nbUsedCallbackObjs);
247 *layout = topLayout;
248 *layoutObj = &(topLayout->callbackObjPool[j]);
249 return true;
250 }
251 }
252 }
253 // not found
254 return false;
255}
256
257static void radioTouchCallback(nbgl_obj_t *obj,
258 nbgl_touchType_t eventType,
259 nbgl_layoutInternal_t *layout);
260static void longTouchCallback(nbgl_obj_t *obj,
261 nbgl_touchType_t eventType,
262 nbgl_layoutInternal_t *layout,
263 layoutObj_t *layoutObj);
264
265// callback for most touched object
266static void touchCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType)
267{
268 nbgl_layoutInternal_t *layout;
269 layoutObj_t *layoutObj;
270 bool needRefresh = false;
271
272 if (obj == NULL) {
273 LOG_WARN(LAYOUT_LOGGER, "touchCallback(): obj not found\n");
274 return;
275 }
276 LOG_DEBUG(LAYOUT_LOGGER, "touchCallback(): eventType = %d, obj = %p\n", eventType, obj);
277 if (getLayoutAndLayoutObj(obj, &layout, &layoutObj) == false) {
278 // try with parent, if existing
279 if (getLayoutAndLayoutObj(obj->parent, &layout, &layoutObj) == false) {
280 LOG_WARN(
282 "touchCallback(): eventType = %d, obj = %p, no active layout or obj not found\n",
283 eventType,
284 obj);
285 return;
286 }
287 }
288
289 // case of swipe
290 if (((eventType == SWIPED_UP) || (eventType == SWIPED_DOWN) || (eventType == SWIPED_LEFT)
291 || (eventType == SWIPED_RIGHT))
292 && (obj->type == CONTAINER)) {
293#ifdef NBGL_KEYBOARD
294 if (layout->swipeUsage == SWIPE_USAGE_SUGGESTIONS) {
295 keyboardSwipeCallback(layout, obj, eventType);
296 return;
297 }
298#endif // NBGL_KEYBOARD
299 if (layout->swipeUsage == SWIPE_USAGE_CUSTOM) {
300 layoutObj->index = eventType;
301 }
302 else if ((layout->swipeUsage == SWIPE_USAGE_NAVIGATION)
303 && ((nbgl_obj_t *) layout->container == obj)) {
304 nbgl_container_t *navContainer;
305 if (layout->footerType == FOOTER_NAV) {
306 navContainer = (nbgl_container_t *) layout->footerContainer;
307 }
308 else if (layout->footerType == FOOTER_TEXT_AND_NAV) {
309 navContainer = (nbgl_container_t *) layout->footerContainer->children[1];
310 }
311 else {
312 return;
313 }
314
316 (nbgl_obj_t *) navContainer, eventType, layout->nbPages, &layout->activePage)
317 == false) {
318 // navigation was impossible
319 return;
320 }
321 layoutObj->index = layout->activePage;
322 }
323 }
324
325 // case of navigation bar
326 if (((obj->parent == (nbgl_obj_t *) layout->footerContainer)
327 && (layout->footerType == FOOTER_NAV))
328 || ((obj->parent->type == CONTAINER)
329 && (obj->parent->parent == (nbgl_obj_t *) layout->footerContainer)
330 && (layout->footerType == FOOTER_TEXT_AND_NAV))) {
331 if (layoutNavigationCallback(obj, eventType, layout->nbPages, &layout->activePage)
332 == false) {
333 // navigation was impossible
334 return;
335 }
336 layoutObj->index = layout->activePage;
337 }
338
339 // case of switch
340 if ((obj->type == CONTAINER) && (((nbgl_container_t *) obj)->nbChildren >= 2)
341 && (((nbgl_container_t *) obj)->children[1] != NULL)
342 && (((nbgl_container_t *) obj)->children[1]->type == SWITCH)) {
343 nbgl_switch_t *lSwitch = (nbgl_switch_t *) ((nbgl_container_t *) obj)->children[1];
344 lSwitch->state = (lSwitch->state == ON_STATE) ? OFF_STATE : ON_STATE;
345 nbgl_objDraw((nbgl_obj_t *) lSwitch);
346 // refresh will be done after tune playback
347 needRefresh = true;
348 // index is used for state
349 layoutObj->index = lSwitch->state;
350 }
351 // case of radio
352 else if ((obj->type == CONTAINER) && (((nbgl_container_t *) obj)->nbChildren == 2)
353 && (((nbgl_container_t *) obj)->children[1] != NULL)
354 && (((nbgl_container_t *) obj)->children[1]->type == RADIO_BUTTON)) {
355 radioTouchCallback(obj, eventType, layout);
356 return;
357 }
358 // case of long press
359 else if ((obj->type == CONTAINER) && (((nbgl_container_t *) obj)->nbChildren == 4)
360 && (((nbgl_container_t *) obj)->children[3] != NULL)
361 && (((nbgl_container_t *) obj)->children[3]->type == PROGRESS_BAR)) {
362 longTouchCallback(obj, eventType, layout, layoutObj);
363 return;
364 }
365 LOG_DEBUG(LAYOUT_LOGGER, "touchCallback(): layout->callback = %p\n", layout->callback);
366 if ((layout->callback != NULL) && (layoutObj->token != NBGL_INVALID_TOKEN)) {
367#ifdef HAVE_PIEZO_SOUND
368 if (layoutObj->tuneId < NBGL_NO_TUNE) {
369 os_io_seph_cmd_piezo_play_tune(layoutObj->tuneId);
370 }
371#endif // HAVE_PIEZO_SOUND
372 if (needRefresh) {
374 }
375 layout->callback(layoutObj->token, layoutObj->index);
376 }
377}
378
379// callback for long press button
380static void longTouchCallback(nbgl_obj_t *obj,
381 nbgl_touchType_t eventType,
382 nbgl_layoutInternal_t *layout,
383 layoutObj_t *layoutObj)
384{
385 nbgl_container_t *container = (nbgl_container_t *) obj;
386 // 4th child of container is the progress bar
387 nbgl_progress_bar_t *progressBar = (nbgl_progress_bar_t *) container->children[3];
388
389 LOG_DEBUG(LAYOUT_LOGGER, "longTouchCallback(): eventType = %d, obj = %p\n", eventType, obj);
390
391 // case of pressing a long press button
392 if (eventType == TOUCHING) {
393 uint32_t touchDuration = nbgl_touchGetTouchDuration(obj);
394
395 // Compute the new progress bar state in %
396 uint8_t new_state = get_hold_to_approve_percent(touchDuration);
397
398 // Ensure the callback is triggered once,
399 // when the progress bar state reaches 100%
400 bool trigger_callback = (new_state >= 100) && (progressBar->state < 100);
401
402 // Cap progress bar state at 100%
403 if (new_state >= 100) {
404 new_state = 100;
405 }
406
407 // Update progress bar state
408 if (new_state != progressBar->state) {
409 progressBar->partialRedraw = true;
410 progressBar->state = new_state;
411
412 nbgl_objDraw((nbgl_obj_t *) progressBar);
413 // Ensure progress bar is fully drawn
414 // before calling the callback.
417 }
418
419 if (trigger_callback) {
420 // End of progress bar reached: trigger callback
421 if (layout->callback != NULL) {
422 layout->callback(layoutObj->token, layoutObj->index);
423 }
424 }
425 }
426 // case of releasing a long press button (or getting out of it)
427 else if ((eventType == TOUCH_RELEASED) || (eventType == OUT_OF_TOUCH)
428 || (eventType == SWIPED_LEFT) || (eventType == SWIPED_RIGHT)) {
429#ifdef HAVE_SE_EINK_DISPLAY
431#endif // HAVE_SE_EINK_DISPLAY
432 progressBar->partialRedraw = true;
433 progressBar->state = 0;
434 nbgl_objDraw((nbgl_obj_t *) progressBar);
435 // It's necessary to redraw the grey/dotted line, that has been partially wiped
436 nbgl_line_t *line = (nbgl_line_t *) container->children[2];
437 nbgl_objDraw((nbgl_obj_t *) line);
439 }
440}
441
442// callback for radio button touch
443static void radioTouchCallback(nbgl_obj_t *obj,
444 nbgl_touchType_t eventType,
445 nbgl_layoutInternal_t *layout)
446{
447 uint8_t i = NB_MAX_LAYOUTS, radioIndex = 0, foundRadio = 0xFF, foundRadioIndex;
448
449 if (eventType != TOUCHED) {
450 return;
451 }
452
453 i = 0;
454 // parse all objs to find all containers of radio buttons
455 while (i < layout->nbUsedCallbackObjs) {
456 if ((obj == (nbgl_obj_t *) layout->callbackObjPool[i].obj)
457 && (layout->callbackObjPool[i].obj->type == CONTAINER)) {
458 nbgl_radio_t *radio
459 = (nbgl_radio_t *) ((nbgl_container_t *) layout->callbackObjPool[i].obj)
460 ->children[1];
461 nbgl_text_area_t *textArea
463 ->children[0];
464 foundRadio = i;
465 foundRadioIndex = radioIndex;
466 // set text as active (black and bold)
467 textArea->textColor = BLACK;
468 textArea->fontId = SMALL_BOLD_FONT;
469 // ensure that radio button is ON
470 radio->state = ON_STATE;
471 // redraw container
472 nbgl_objDraw((nbgl_obj_t *) obj);
473 }
474 else if ((layout->callbackObjPool[i].obj->type == CONTAINER)
475 && (((nbgl_container_t *) layout->callbackObjPool[i].obj)->nbChildren == 2)
476 && (((nbgl_container_t *) layout->callbackObjPool[i].obj)->children[1]->type
477 == RADIO_BUTTON)) {
478 nbgl_radio_t *radio
479 = (nbgl_radio_t *) ((nbgl_container_t *) layout->callbackObjPool[i].obj)
480 ->children[1];
481 nbgl_text_area_t *textArea
483 ->children[0];
484 radioIndex++;
485 // set to OFF the one that was in ON
486 if (radio->state == ON_STATE) {
487 radio->state = OFF_STATE;
488 // set text it as inactive (gray and normal)
489 textArea->textColor = LIGHT_TEXT_COLOR;
490 textArea->fontId = SMALL_REGULAR_FONT;
491 // redraw container
493 }
494 }
495 i++;
496 }
497 // call callback after redraw to avoid asynchronicity
498 if (foundRadio != 0xFF) {
499 if (layout->callback != NULL) {
500#ifdef HAVE_PIEZO_SOUND
501 if (layout->callbackObjPool[foundRadio].tuneId < NBGL_NO_TUNE) {
502 os_io_seph_cmd_piezo_play_tune(layout->callbackObjPool[foundRadio].tuneId);
503 }
504#endif // HAVE_PIEZO_SOUND
506 layout->callback(layout->callbackObjPool[foundRadio].token, foundRadioIndex);
507 }
508 }
509}
510
511// callback for spinner ticker
512static void spinnerTickerCallback(void)
513{
514 nbgl_spinner_t *spinner;
515 uint8_t i = 0;
516
517 if (!topLayout || !topLayout->isUsed) {
518 return;
519 }
520
521 // get index of obj
522 while (i < topLayout->container->nbChildren) {
523 if (topLayout->container->children[i]->type == CONTAINER) {
524 nbgl_container_t *container = (nbgl_container_t *) topLayout->container->children[i];
525 if (container->nbChildren && (container->children[0]->type == SPINNER)) {
526 spinner = (nbgl_spinner_t *) container->children[0];
527 spinner->position++;
528 // there are only NB_SPINNER_POSITIONS positions
529 if (spinner->position == NB_SPINNER_POSITIONS) {
530 spinner->position = 0;
531 }
532 nbgl_objDraw((nbgl_obj_t *) spinner);
534 return;
535 }
536 }
537 i++;
538 }
539}
540
541// callback for animation ticker
542static void animTickerCallback(void)
543{
544 nbgl_image_t *image;
545 uint8_t i = 0;
546 nbgl_layoutInternal_t *layout = topLayout;
547
548 if (!layout || !layout->isUsed || (layout->animation == NULL)) {
549 return;
550 }
551
552 // get index of image obj
553 while (i < layout->container->nbChildren) {
554 if (layout->container->children[i]->type == CONTAINER) {
555 nbgl_container_t *container = (nbgl_container_t *) layout->container->children[i];
556 if (container->children[1]->type == IMAGE) {
557 image = (nbgl_image_t *) container->children[1];
558 if (layout->animation->parsing == LOOP_PARSING) {
559 if (layout->iconIdxInAnim == (layout->animation->nbIcons - 1)) {
560 layout->iconIdxInAnim = 0;
561 }
562 else {
563 layout->iconIdxInAnim++;
564 }
565 }
566 else {
567 // Flip incrementAnim when reaching upper or lower limit
568 if ((layout->incrementAnim)
569 && (layout->iconIdxInAnim >= layout->animation->nbIcons - 1)) {
570 layout->incrementAnim = false;
571 }
572 else if (layout->iconIdxInAnim == 0) {
573 layout->incrementAnim = true;
574 }
575
576 // Increase / Decrease index according to incrementAnim
577 if (layout->incrementAnim) {
578 layout->iconIdxInAnim++;
579 }
580 else {
581 layout->iconIdxInAnim--;
582 }
583 }
584 image->buffer = layout->animation->icons[layout->iconIdxInAnim];
585 nbgl_objDraw((nbgl_obj_t *) image);
588 return;
589 }
590 }
591 i++;
592 }
593}
594
595static nbgl_line_t *createHorizontalLine(uint8_t layer)
596{
597 nbgl_line_t *line;
598
599 line = (nbgl_line_t *) nbgl_objPoolGet(LINE, layer);
600 line->lineColor = LIGHT_GRAY;
601 line->obj.area.width = SCREEN_WIDTH;
602 line->obj.area.height = 1;
603 line->direction = HORIZONTAL;
604 line->thickness = 1;
605 return line;
606}
607
608#ifdef TARGET_STAX
609static nbgl_line_t *createLeftVerticalLine(uint8_t layer)
610{
611 nbgl_line_t *line;
612
613 line = (nbgl_line_t *) nbgl_objPoolGet(LINE, layer);
614 line->lineColor = LIGHT_GRAY;
615 line->obj.area.width = 1;
616 line->obj.area.height = SCREEN_HEIGHT;
617 line->direction = VERTICAL;
618 line->thickness = 1;
619 line->obj.alignment = MID_LEFT;
620 return line;
621}
622#endif // TARGET_STAX
623
624// function adding a layout object in the callbackObjPool array for the given layout, and
625// configuring it
627 nbgl_obj_t *obj,
628 uint8_t token,
629 tune_index_e tuneId)
630{
631 layoutObj_t *layoutObj = NULL;
632
633 if (layout->nbUsedCallbackObjs < (LAYOUT_OBJ_POOL_LEN - 1)) {
634 layoutObj = &layout->callbackObjPool[layout->nbUsedCallbackObjs];
635 layout->nbUsedCallbackObjs++;
636 layoutObj->obj = obj;
637 layoutObj->token = token;
638 layoutObj->tuneId = tuneId;
639 }
640 else {
641 LOG_FATAL(LAYOUT_LOGGER, "layoutAddCallbackObj: no more callback obj\n");
642 }
643
644 return layoutObj;
645}
646
655void layoutUpdateCallbackObjToken(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj, uint8_t token)
656{
657 if (layout == NULL) {
658 LOG_WARN(LAYOUT_LOGGER, "layoutUpdateCallbackObjToken(): layout is NULL\n");
659 return;
660 }
661
662 if (obj == NULL) {
663 LOG_WARN(LAYOUT_LOGGER, "layoutUpdateCallbackObjToken(): obj is NULL\n");
664 return;
665 }
666
667 layoutObj_t *layoutObj = NULL;
668 for (size_t i = 0; i < layout->nbUsedCallbackObjs; i++) {
669 layoutObj = &layout->callbackObjPool[i];
670 if (layoutObj->obj == obj) {
671 layoutObj->token = token;
672 return;
673 }
674 }
675}
676
684{
685 if (layout->container->nbChildren >= NB_MAX_CONTAINER_CHILDREN) {
686 LOG_FATAL(LAYOUT_LOGGER, "layoutAddObject(): No more object\n");
687 // LOG_FATAL is a no-op in release builds: never write past the array
688 return;
689 }
690 layout->container->children[layout->container->nbChildren] = obj;
691 layout->container->nbChildren++;
692}
693
704static int addSwipeInternal(nbgl_layoutInternal_t *layoutInt,
705 uint16_t swipesMask,
706 nbgl_swipe_usage_t usage,
707 uint8_t token,
708 tune_index_e tuneId)
709{
710 layoutObj_t *obj;
711
712 if ((swipesMask & SWIPE_MASK) == 0) {
713 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddSwipe(): invalid swipesMask 0x%x\n", swipesMask);
714 return -1;
715 }
716
717 obj = layoutAddCallbackObj(layoutInt, (nbgl_obj_t *) layoutInt->container, token, tuneId);
718 if (obj == NULL) {
719 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddSwipe(): no more callback obj\n");
720 return -1;
721 }
722 layoutInt->container->obj.touchMask = swipesMask;
723 layoutInt->swipeUsage = usage;
724
725 return 0;
726}
727
735static nbgl_container_t *addListItem(nbgl_layoutInternal_t *layoutInt, const listItem_t *itemDesc)
736{
737 layoutObj_t *obj;
738 nbgl_text_area_t *textArea = NULL;
739 nbgl_container_t *container;
740
741 color_t common_color = WHITE; // Color of all elements, except the right icon
742 color_t right_icon_color = WHITE; // Color of right icon, only
743 if ((itemDesc->type == TOUCHABLE_BAR_ITEM) && (itemDesc->state == OFF_STATE)) {
744 common_color = INACTIVE_TEXT_COLOR;
745 right_icon_color = INACTIVE_ARROW_COLOR;
746 }
747 else {
748 common_color = BLACK;
749 right_icon_color = BLACK;
750 }
751
752 nbgl_font_id_e fontId
753 = ((itemDesc->type == TOUCHABLE_BAR_ITEM) && (itemDesc->state == OFF_STATE))
755 : SMALL_BOLD_FONT;
756
757 LOG_DEBUG(LAYOUT_LOGGER, "addListItem():\n");
758
759 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
761 layoutInt, (nbgl_obj_t *) container, itemDesc->token, itemDesc->tuneId);
762 if (obj == NULL) {
763 LOG_WARN(LAYOUT_LOGGER, "addListItem(): no more callback obj\n");
764 return NULL;
765 }
766 obj->index = itemDesc->index;
767
768 // get container children (up to 4: text + left+right icons + sub text)
769 container->children = nbgl_containerPoolGet(4, layoutInt->layer);
770 container->nbChildren = 0;
771
772 container->obj.area.width = AVAILABLE_WIDTH;
773 container->obj.area.height
774 = LIST_ITEM_MIN_TEXT_HEIGHT
775 + 2 * (itemDesc->large ? LIST_ITEM_PRE_HEADING_LARGE : LIST_ITEM_PRE_HEADING);
776 container->layout = HORIZONTAL;
777 container->obj.alignmentMarginX = BORDER_MARGIN;
778 container->obj.alignment = NO_ALIGNMENT;
779 container->obj.alignTo = NULL;
780 // the bar can only be touched if not inactive AND if one of the icon is present
781 // otherwise it is seen as a title
782 if (((itemDesc->type == TOUCHABLE_BAR_ITEM) && (itemDesc->state == ON_STATE))
783 || (itemDesc->type == SWITCH_ITEM)) {
784 container->obj.touchMask = (1 << TOUCHED);
785 container->obj.touchId = CONTROLS_ID + nbTouchableControls;
786 nbTouchableControls++;
787 }
788
789 // allocate main text if not NULL
790 if (itemDesc->text != NULL) {
791 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
792 textArea->textColor = common_color;
793 textArea->text = PIC(itemDesc->text);
794 textArea->onDrawCallback = NULL;
795 textArea->fontId = fontId;
796 textArea->wrapping = true;
797 textArea->obj.area.width = container->obj.area.width;
798 if (itemDesc->iconLeft != NULL) {
799 // reduce text width accordingly
800 textArea->obj.area.width
801 -= ((nbgl_icon_details_t *) PIC(itemDesc->iconLeft))->width + BAR_INTERVALE;
802 }
803 if (itemDesc->iconRight != NULL) {
804 // reduce text width accordingly
805 textArea->obj.area.width
806 -= ((nbgl_icon_details_t *) PIC(itemDesc->iconRight))->width + BAR_INTERVALE;
807 }
808 else if (itemDesc->type == SWITCH_ITEM) {
809 textArea->obj.area.width -= SWITCH_ICON.width + BAR_INTERVALE;
810 }
811 textArea->obj.area.height = MAX(
812 LIST_ITEM_MIN_TEXT_HEIGHT,
814 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping));
815 textArea->style = NO_STYLE;
816 textArea->obj.alignment = TOP_LEFT;
817 textArea->obj.alignmentMarginY
818 = itemDesc->large ? LIST_ITEM_PRE_HEADING_LARGE : LIST_ITEM_PRE_HEADING;
819 if (textArea->obj.area.height > LIST_ITEM_MIN_TEXT_HEIGHT) {
820 textArea->obj.alignmentMarginY
821 -= (textArea->obj.area.height - LIST_ITEM_MIN_TEXT_HEIGHT) / 2;
822 }
823 textArea->textAlignment = MID_LEFT;
824 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
825 container->nbChildren++;
826 }
827
828 // allocate left icon if present
829 if (itemDesc->iconLeft != NULL) {
830 nbgl_image_t *imageLeft = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
831 imageLeft->foregroundColor = common_color;
832 imageLeft->buffer = PIC(itemDesc->iconLeft);
833 // align at the left of text
834 imageLeft->obj.alignment = MID_LEFT;
835 imageLeft->obj.alignTo = (nbgl_obj_t *) textArea;
836 imageLeft->obj.alignmentMarginX = BAR_INTERVALE;
837 container->children[container->nbChildren] = (nbgl_obj_t *) imageLeft;
838 container->nbChildren++;
839
840 if (textArea != NULL) {
841 textArea->obj.alignmentMarginX = imageLeft->buffer->width + BAR_INTERVALE;
842 }
843 }
844 // allocate right icon if present
845 if (itemDesc->iconRight != NULL) {
846 nbgl_image_t *imageRight = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
847 imageRight->foregroundColor = right_icon_color;
848 imageRight->buffer = PIC(itemDesc->iconRight);
849 // align at the right of text
850 imageRight->obj.alignment = MID_RIGHT;
851 imageRight->obj.alignmentMarginX = BAR_INTERVALE;
852 imageRight->obj.alignTo = (nbgl_obj_t *) textArea;
853
854 container->children[container->nbChildren] = (nbgl_obj_t *) imageRight;
855 container->nbChildren++;
856 }
857 else if (itemDesc->type == SWITCH_ITEM) {
858 nbgl_switch_t *switchObj = (nbgl_switch_t *) nbgl_objPoolGet(SWITCH, layoutInt->layer);
859 switchObj->onColor = BLACK;
860 switchObj->offColor = LIGHT_GRAY;
861 switchObj->state = itemDesc->state;
862 switchObj->obj.alignment = MID_RIGHT;
863 switchObj->obj.alignmentMarginX = BAR_INTERVALE;
864 switchObj->obj.alignTo = (nbgl_obj_t *) textArea;
865
866 container->children[container->nbChildren] = (nbgl_obj_t *) switchObj;
867 container->nbChildren++;
868 }
869
870 if (itemDesc->subText != NULL) {
871 nbgl_text_area_t *subTextArea
873
874 subTextArea->textColor = common_color;
875 subTextArea->text = PIC(itemDesc->subText);
876 subTextArea->textAlignment = MID_LEFT;
877 subTextArea->fontId = SMALL_REGULAR_FONT;
878 subTextArea->style = NO_STYLE;
879 subTextArea->wrapping = true;
880 if (itemDesc->text != NULL) {
881 subTextArea->obj.alignment = BOTTOM_LEFT;
882 subTextArea->obj.alignTo = (nbgl_obj_t *) textArea;
883 subTextArea->obj.alignmentMarginY = LIST_ITEM_HEADING_SUB_TEXT;
884 }
885 else {
886 subTextArea->obj.alignment = TOP_LEFT;
887 subTextArea->obj.alignmentMarginY = SUB_HEADER_MARGIN;
888 container->obj.area.height = SUB_HEADER_MARGIN;
889 }
890 if (itemDesc->iconLeft != NULL) {
891 subTextArea->obj.alignmentMarginX
892 = -(((nbgl_icon_details_t *) PIC(itemDesc->iconLeft))->width + BAR_INTERVALE);
893 }
894 subTextArea->obj.area.width = container->obj.area.width;
895 subTextArea->obj.area.height = nbgl_getTextHeightInWidth(subTextArea->fontId,
896 subTextArea->text,
897 subTextArea->obj.area.width,
898 subTextArea->wrapping);
899 container->children[container->nbChildren] = (nbgl_obj_t *) subTextArea;
900 container->nbChildren++;
901 container->obj.area.height
902 += subTextArea->obj.area.height + subTextArea->obj.alignmentMarginY;
903 }
904 // set this new container as child of main container
905 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
906
907 return container;
908}
909
918static nbgl_container_t *addContentCenter(nbgl_layoutInternal_t *layoutInt,
919 const nbgl_contentCenter_t *info)
920{
921 nbgl_container_t *container;
922 nbgl_text_area_t *textArea = NULL;
923 nbgl_image_t *image = NULL;
924 uint16_t fullHeight = 0;
925
926 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
927
928 // get container children
929 container->nbChildren = 0;
930 // the max number is: icon + anim + title + small title + description + sub-text
931 container->children = nbgl_containerPoolGet(6, layoutInt->layer);
932
933 // add icon or animation if present
934 if (info->icon != NULL) {
935 image = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
936 image->foregroundColor = (layoutInt->invertedColors) ? WHITE : BLACK;
937 image->buffer = PIC(info->icon);
938 image->obj.alignment = TOP_MIDDLE;
939 image->obj.alignmentMarginY = info->iconHug;
940
941 fullHeight += image->buffer->height + info->iconHug;
942 container->children[container->nbChildren] = (nbgl_obj_t *) image;
943 container->nbChildren++;
944
945 if (info->illustrType == ANIM_ILLUSTRATION) {
946 nbgl_image_t *anim;
947 anim = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
948 anim->foregroundColor = (layoutInt->invertedColors) ? WHITE : BLACK;
949 anim->buffer = PIC(info->animation->icons[0]);
950 anim->obj.alignment = TOP_MIDDLE;
951 anim->obj.alignmentMarginY = info->iconHug + info->animOffsetY;
952 anim->obj.alignmentMarginX = info->animOffsetX;
953
954 container->children[container->nbChildren] = (nbgl_obj_t *) anim;
955 container->nbChildren++;
956
957 layoutInt->animation = info->animation;
958 layoutInt->incrementAnim = true;
959 layoutInt->iconIdxInAnim = 0;
960
961 // update ticker to update the animation periodically
962 nbgl_screenTickerConfiguration_t tickerCfg = {0};
963
964 tickerCfg.tickerIntervale = info->animation->delayMs; // ms
965 tickerCfg.tickerValue = info->animation->delayMs; // ms
966 tickerCfg.tickerCallback = &animTickerCallback;
967 nbgl_screenUpdateTicker(layoutInt->layer, &tickerCfg);
968 }
969 }
970 // add title if present
971 if (info->title != NULL) {
972 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
973 textArea->textColor = (layoutInt->invertedColors) ? WHITE : BLACK;
974 textArea->text = PIC(info->title);
975 textArea->textAlignment = CENTER;
976 textArea->fontId = LARGE_MEDIUM_FONT;
977 textArea->wrapping = true;
978 textArea->obj.area.width = AVAILABLE_WIDTH;
979 textArea->obj.area.height = nbgl_getTextHeightInWidth(
980 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
981
982 // if not the first child, put on bottom of the previous, with a margin
983 if (container->nbChildren > 0) {
984 textArea->obj.alignment = BOTTOM_MIDDLE;
985 textArea->obj.alignTo = (nbgl_obj_t *) image;
986 textArea->obj.alignmentMarginY = ICON_TITLE_MARGIN + info->iconHug;
987 }
988 else {
989 textArea->obj.alignment = TOP_MIDDLE;
990 }
991
992 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
993
994 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
995 container->nbChildren++;
996 }
997 // add small title if present
998 if (info->smallTitle != NULL) {
999 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1000 textArea->textColor = (layoutInt->invertedColors) ? WHITE : BLACK;
1001 textArea->text = PIC(info->smallTitle);
1002 textArea->textAlignment = CENTER;
1003 textArea->fontId = SMALL_BOLD_FONT;
1004 textArea->wrapping = true;
1005 textArea->obj.area.width = AVAILABLE_WIDTH;
1006 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1007 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1008
1009 // if not the first child, put on bottom of the previous, with a margin
1010 if (container->nbChildren > 0) {
1011 textArea->obj.alignment = BOTTOM_MIDDLE;
1012 textArea->obj.alignTo = (nbgl_obj_t *) container->children[container->nbChildren - 1];
1013 textArea->obj.alignmentMarginY = VERTICAL_BORDER_MARGIN;
1014 if (container->children[container->nbChildren - 1]->type == IMAGE) {
1015 textArea->obj.alignmentMarginY = VERTICAL_BORDER_MARGIN + info->iconHug;
1016 }
1017 else {
1018 textArea->obj.alignmentMarginY = TITLE_DESC_MARGIN;
1019 }
1020 }
1021 else {
1022 textArea->obj.alignment = TOP_MIDDLE;
1023 }
1024
1025 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
1026
1027 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
1028 container->nbChildren++;
1029 }
1030 // add description if present
1031 if (info->description != NULL) {
1032 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1033 textArea->textColor = (layoutInt->invertedColors) ? WHITE : BLACK;
1034 textArea->text = PIC(info->description);
1035 textArea->textAlignment = CENTER;
1036 textArea->fontId = SMALL_REGULAR_FONT;
1037 textArea->wrapping = true;
1038 textArea->obj.area.width = AVAILABLE_WIDTH;
1039 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1040 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1041
1042 // if not the first child, put on bottom of the previous, with a margin
1043 if (container->nbChildren > 0) {
1044 textArea->obj.alignment = BOTTOM_MIDDLE;
1045 textArea->obj.alignTo = (nbgl_obj_t *) container->children[container->nbChildren - 1];
1046 if (container->children[container->nbChildren - 1]->type == TEXT_AREA) {
1047 // if previous element is text, only space of 16 px
1048 textArea->obj.alignmentMarginY = TITLE_DESC_MARGIN;
1049 }
1050 else {
1051 textArea->obj.alignmentMarginY = ICON_TITLE_MARGIN + info->iconHug;
1052 }
1053 }
1054 else {
1055 textArea->obj.alignment = TOP_MIDDLE;
1056 }
1057
1058 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
1059
1060 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
1061 container->nbChildren++;
1062 }
1063 // add sub-text if present
1064 if (info->subText != NULL) {
1065 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1066 textArea->textColor = LIGHT_TEXT_COLOR;
1067 textArea->text = PIC(info->subText);
1068 textArea->textAlignment = CENTER;
1069 textArea->fontId = SMALL_REGULAR_FONT;
1070 textArea->wrapping = true;
1071 textArea->obj.area.width = AVAILABLE_WIDTH;
1072 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1073 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1074 // sub-text is included in a hug of 8px
1075 textArea->obj.area.height += 2 * 8;
1076 // if not the first child, put on bottom of the previous, with a margin
1077 if (container->nbChildren > 0) {
1078 textArea->obj.alignment = BOTTOM_MIDDLE;
1079 textArea->obj.alignTo = (nbgl_obj_t *) container->children[container->nbChildren - 1];
1080 textArea->obj.alignmentMarginY = 16;
1081 if (container->children[container->nbChildren - 1]->type == IMAGE) {
1082 textArea->obj.alignmentMarginY += info->iconHug;
1083 }
1084 }
1085 else {
1086 textArea->obj.alignment = TOP_MIDDLE;
1087 }
1088
1089 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
1090
1091 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
1092 container->nbChildren++;
1093 }
1094 container->layout = VERTICAL;
1095 container->obj.alignment = CENTER;
1096 container->obj.area.width = AVAILABLE_WIDTH;
1097 container->obj.area.height = fullHeight;
1098 if (info->padding) {
1099 container->obj.area.height += 40;
1100 }
1101
1102 // set this new container as child of main container
1103 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
1104
1105 return container;
1106}
1107
1108/**********************
1109 * GLOBAL FUNCTIONS
1110 **********************/
1111
1119{
1120 nbgl_layoutInternal_t *layout = NULL;
1121
1122 if (description->modal) {
1123 int i;
1124 // find an empty layout in the array of layouts (0 is reserved for background)
1125 for (i = 1; i < NB_MAX_LAYOUTS; i++) {
1126 if (!gLayout[i].isUsed) {
1127 layout = &gLayout[i];
1128 }
1129 }
1130 }
1131 else {
1132 // always use layout 0 for background
1133 layout = &gLayout[0];
1134 if (topLayout == NULL) {
1135 topLayout = layout;
1136 }
1137 }
1138 if (layout == NULL) {
1139 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutGet(): impossible to get a layout!\n");
1140 return NULL;
1141 }
1142
1143 // reset globals
1144 nbgl_layoutInternal_t *backgroundTop = gLayout[0].top;
1145 memset(layout, 0, sizeof(nbgl_layoutInternal_t));
1146 // link layout to other ones
1147 if (description->modal) {
1148 if (topLayout != NULL) {
1149 // if topLayout already existing, push this new one on top of it
1150 topLayout->top = layout;
1151 layout->bottom = topLayout;
1152 }
1153 else {
1154 // otherwise put it on top of background layout
1155 layout->bottom = &gLayout[0];
1156 gLayout[0].top = layout;
1157 }
1158 topLayout = layout;
1159 }
1160 else {
1161 // restore potentially valid background top layer
1162 gLayout[0].top = backgroundTop;
1163 }
1164
1165 nbTouchableControls = 0;
1166
1167 layout->callback = (nbgl_layoutTouchCallback_t) PIC(description->onActionCallback);
1168 layout->modal = description->modal;
1169 layout->withLeftBorder = description->withLeftBorder;
1170 if (description->modal) {
1171 layout->layer = nbgl_screenPush(&layout->children,
1173 &description->ticker,
1174 (nbgl_touchCallback_t) touchCallback);
1175 }
1176 else {
1177 nbgl_screenSet(&layout->children,
1179 &description->ticker,
1180 (nbgl_touchCallback_t) touchCallback);
1181 layout->layer = 0;
1182 }
1184 layout->container->obj.area.width = SCREEN_WIDTH;
1185 layout->container->obj.area.height = SCREEN_HEIGHT;
1186 layout->container->layout = VERTICAL;
1187 layout->container->children = nbgl_containerPoolGet(NB_MAX_CONTAINER_CHILDREN, layout->layer);
1188 // by default, if no header, main container is aligned on top-left
1189 layout->container->obj.alignment = TOP_LEFT;
1190 // main container is always the second object, leaving space for header
1191 layout->children[MAIN_CONTAINER_INDEX] = (nbgl_obj_t *) layout->container;
1192 layout->isUsed = true;
1193
1194 // if a tap text is defined, make the container tapable and display this text in gray
1195 if (description->tapActionText != NULL) {
1196 layoutObj_t *obj;
1197 const char *tapActionText = PIC(description->tapActionText);
1198
1199 obj = &layout->callbackObjPool[layout->nbUsedCallbackObjs];
1200 layout->nbUsedCallbackObjs++;
1201 obj->obj = (nbgl_obj_t *) layout->container;
1202 obj->token = description->tapActionToken;
1203 obj->tuneId = description->tapTuneId;
1204 layout->container->obj.touchMask = (1 << TOUCHED);
1205 layout->container->obj.touchId = WHOLE_SCREEN_ID;
1206
1207 if (strlen(tapActionText) > 0) {
1208 nbgl_layoutUpFooter_t footerDesc = {0};
1209 footerDesc.type = UP_FOOTER_TEXT;
1210 footerDesc.text.text = tapActionText;
1211 footerDesc.text.token = description->tapActionToken;
1212 footerDesc.text.tuneId = description->tapTuneId;
1213 nbgl_layoutAddUpFooter((nbgl_layout_t *) layout, &footerDesc);
1214 }
1215 }
1216 return (nbgl_layout_t *) layout;
1217}
1218
1229
1230int nbgl_layoutAddSwipe(nbgl_layout_t *layout,
1231 uint16_t swipesMask,
1232 const char *text,
1233 uint8_t token,
1234 tune_index_e tuneId)
1235{
1236 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1237
1238 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddSwipe():\n");
1239 if (layout == NULL) {
1240 return -1;
1241 }
1242
1243 if (text) {
1244 // create 'tap to continue' text area
1246 layoutInt->tapText->text = PIC(text);
1247 layoutInt->tapText->textColor = LIGHT_TEXT_COLOR;
1248 layoutInt->tapText->fontId = SMALL_REGULAR_FONT;
1249 layoutInt->tapText->obj.area.width = AVAILABLE_WIDTH;
1250 layoutInt->tapText->obj.area.height = nbgl_getFontLineHeight(layoutInt->tapText->fontId);
1251 layoutInt->tapText->textAlignment = CENTER;
1252 layoutInt->tapText->obj.alignmentMarginY = TAP_TO_CONTINUE_MARGIN;
1253 layoutInt->tapText->obj.alignment = BOTTOM_MIDDLE;
1254 }
1255 return addSwipeInternal(layoutInt, swipesMask, SWIPE_USAGE_CUSTOM, token, tuneId);
1256}
1257
1264
1265int nbgl_layoutInvertBackground(nbgl_layout_t *layout)
1266{
1267 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1268
1269 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutInvertBackground():\n");
1270 if (layout == NULL) {
1271 return -1;
1272 }
1273 layoutInt->invertedColors = true;
1275
1276 // invert potential "Tap to continue"
1277 if ((layoutInt->upFooterContainer) && (layoutInt->upFooterContainer->nbChildren == 1)
1278 && (layoutInt->upFooterContainer->children[0]->type == TEXT_AREA)) {
1279 nbgl_text_area_t *textArea = (nbgl_text_area_t *) layoutInt->upFooterContainer->children[0];
1280 if (textArea->textColor == LIGHT_TEXT_COLOR) {
1281 textArea->textColor = INACTIVE_COLOR;
1282 }
1283 }
1284
1285 return 0;
1286}
1287
1297int nbgl_layoutAddTopRightButton(nbgl_layout_t *layout,
1298 const nbgl_icon_details_t *icon,
1299 uint8_t token,
1300 tune_index_e tuneId)
1301{
1302 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1303 layoutObj_t *obj;
1304 nbgl_button_t *button;
1305
1306 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddTopRightButton():\n");
1307 if (layout == NULL) {
1308 return -1;
1309 }
1310 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
1311 obj = layoutAddCallbackObj(layoutInt, (nbgl_obj_t *) button, token, tuneId);
1312 if (obj == NULL) {
1313 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddTopRightButton(): no more callback obj\n");
1314 return -1;
1315 }
1316
1317 button->obj.area.width = BUTTON_WIDTH;
1318 button->obj.area.height = BUTTON_DIAMETER;
1319 button->radius = BUTTON_RADIUS;
1320 button->obj.alignmentMarginX = BORDER_MARGIN;
1321 button->obj.alignmentMarginY = BORDER_MARGIN;
1322 button->foregroundColor = BLACK;
1323 button->innerColor = WHITE;
1324 button->borderColor = LIGHT_GRAY;
1325 button->obj.touchMask = (1 << TOUCHED);
1326 button->obj.touchId = TOP_RIGHT_BUTTON_ID;
1327 button->icon = PIC(icon);
1328 button->obj.alignment = TOP_RIGHT;
1329
1330 // add to screen
1331 layoutInt->children[TOP_RIGHT_BUTTON_INDEX] = (nbgl_obj_t *) button;
1332
1333 return 0;
1334}
1335
1343int nbgl_layoutAddNavigationBar(nbgl_layout_t *layout, const nbgl_layoutNavigationBar_t *info)
1344{
1345 nbgl_layoutFooter_t footerDesc = {0};
1346 footerDesc.type = FOOTER_NAV;
1347 footerDesc.separationLine = info->withSeparationLine;
1348 footerDesc.navigation.activePage = info->activePage;
1349 footerDesc.navigation.nbPages = info->nbPages;
1350 footerDesc.navigation.withExitKey = info->withExitKey;
1351 footerDesc.navigation.withBackKey = info->withBackKey;
1352 footerDesc.navigation.token = info->token;
1353 footerDesc.navigation.tuneId = info->tuneId;
1354 return nbgl_layoutAddExtendedFooter(layout, &footerDesc);
1355}
1356
1368int nbgl_layoutAddBottomButton(nbgl_layout_t *layout,
1369 const nbgl_icon_details_t *icon,
1370 uint8_t token,
1371 bool separationLine,
1372 tune_index_e tuneId)
1373{
1374 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddBottomButton():\n");
1375 nbgl_layoutFooter_t footerDesc = {0};
1376 footerDesc.type = FOOTER_SIMPLE_BUTTON;
1377 footerDesc.separationLine = separationLine;
1378 footerDesc.button.icon = PIC(icon);
1379 footerDesc.button.token = token;
1380 footerDesc.button.tuneId = tuneId;
1381 footerDesc.button.style = WHITE_BACKGROUND;
1382 return nbgl_layoutAddExtendedFooter(layout, &footerDesc);
1383}
1384
1392int nbgl_layoutAddTouchableBar(nbgl_layout_t *layout, const nbgl_layoutBar_t *barLayout)
1393{
1394 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1395 nbgl_container_t *container;
1396 listItem_t itemDesc = {0};
1397
1398 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddTouchableBar():\n");
1399 if (layout == NULL) {
1400 return -1;
1401 }
1402 // main text is mandatory
1403 if (barLayout->text == NULL) {
1404 LOG_FATAL(LAYOUT_LOGGER, "nbgl_layoutAddTouchableBar(): main text is mandatory\n");
1405 }
1406
1407 itemDesc.iconLeft = barLayout->iconLeft;
1408 itemDesc.iconRight = barLayout->iconRight;
1409 itemDesc.text = barLayout->text;
1410 itemDesc.subText = barLayout->subText;
1411 itemDesc.token = barLayout->token;
1412 itemDesc.tuneId = barLayout->tuneId;
1413 itemDesc.state = (barLayout->inactive) ? OFF_STATE : ON_STATE;
1414 itemDesc.large = barLayout->large;
1415 itemDesc.type = TOUCHABLE_BAR_ITEM;
1416 container = addListItem(layoutInt, &itemDesc);
1417
1418 if (container == NULL) {
1419 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddTouchableBar(): addListItem failed\n");
1420 return -1;
1421 }
1422 return container->obj.area.height;
1423}
1424
1432int nbgl_layoutAddSwitch(nbgl_layout_t *layout, const nbgl_layoutSwitch_t *switchLayout)
1433{
1434 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1435 nbgl_container_t *container;
1436 listItem_t itemDesc = {0};
1437
1438 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddSwitch():\n");
1439 if (layout == NULL) {
1440 return -1;
1441 }
1442 // main text is mandatory
1443 if (switchLayout->text == NULL) {
1444 LOG_FATAL(LAYOUT_LOGGER, "nbgl_layoutAddSwitch(): main text is mandatory\n");
1445 }
1446
1447 itemDesc.text = switchLayout->text;
1448 itemDesc.subText = switchLayout->subText;
1449 itemDesc.token = switchLayout->token;
1450 itemDesc.tuneId = switchLayout->tuneId;
1451 itemDesc.state = switchLayout->initState;
1452 itemDesc.type = SWITCH_ITEM;
1453 container = addListItem(layoutInt, &itemDesc);
1454
1455 if (container == NULL) {
1456 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddSwitch(): addListItem failed\n");
1457 return -1;
1458 }
1459 return container->obj.area.height;
1460}
1461
1470int nbgl_layoutAddText(nbgl_layout_t *layout, const char *text, const char *subText)
1471{
1472 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1473 nbgl_container_t *container;
1474 listItem_t itemDesc = {0};
1475
1476 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddText():\n");
1477 if (layout == NULL) {
1478 return -1;
1479 }
1480
1481 itemDesc.text = text;
1482 itemDesc.subText = subText;
1483 itemDesc.token = NBGL_INVALID_TOKEN;
1484 itemDesc.tuneId = NBGL_NO_TUNE;
1485 itemDesc.type = TEXT_ITEM;
1486 container = addListItem(layoutInt, &itemDesc);
1487
1488 if (container == NULL) {
1489 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddText(): addListItem failed\n");
1490 return -1;
1491 }
1492 return container->obj.area.height;
1493}
1494
1506int nbgl_layoutAddTextWithAlias(nbgl_layout_t *layout,
1507 const char *text,
1508 const char *subText,
1509 uint8_t token,
1510 uint8_t index)
1511{
1512 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1513 nbgl_container_t *container;
1514 listItem_t itemDesc = {0};
1515 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddTextWithAlias():\n");
1516 if (layout == NULL) {
1517 return -1;
1518 }
1519
1520 itemDesc.text = text;
1521 itemDesc.subText = subText;
1522 itemDesc.iconRight = &MINI_PUSH_ICON;
1523 itemDesc.token = token;
1524 itemDesc.tuneId = NBGL_NO_TUNE;
1525 itemDesc.type = TOUCHABLE_BAR_ITEM;
1526 itemDesc.index = index;
1527 itemDesc.state = ON_STATE;
1528 container = addListItem(layoutInt, &itemDesc);
1529
1530 if (container == NULL) {
1531 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddTextWithAlias(): addListItem failed\n");
1532 return -1;
1533 }
1534 return container->obj.area.height;
1535}
1536
1545int nbgl_layoutAddLargeCaseText(nbgl_layout_t *layout, const char *text, bool grayedOut)
1546{
1547 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1548 nbgl_text_area_t *textArea;
1549
1550 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddLargeCaseText():\n");
1551 if (layout == NULL) {
1552 return -1;
1553 }
1554 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1555
1556 textArea->textColor = grayedOut ? INACTIVE_TEXT_COLOR : BLACK;
1557 textArea->text = PIC(text);
1558 textArea->textAlignment = MID_LEFT;
1559 textArea->fontId = LARGE_MEDIUM_FONT;
1560 textArea->obj.area.width = AVAILABLE_WIDTH;
1561 textArea->wrapping = true;
1562 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1563 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1564 textArea->style = NO_STYLE;
1565 textArea->obj.alignment = NO_ALIGNMENT;
1566 textArea->obj.alignmentMarginX = BORDER_MARGIN;
1567 if (layoutInt->container->nbChildren == 0) {
1568 // if first object of container, increase the margin from top
1569 textArea->obj.alignmentMarginY += PRE_FIRST_TEXT_MARGIN;
1570 }
1571 else {
1572 textArea->obj.alignmentMarginY = INTER_PARAGRAPHS_MARGIN; // between paragraphs
1573 }
1574
1575 // set this new obj as child of main container
1576 layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
1577
1578 return 0;
1579}
1580
1591int nbgl_layoutAddTextContent(nbgl_layout_t *layout, nbgl_layoutTextContent_t *content)
1592{
1593 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1594 nbgl_text_area_t *textArea;
1595 uint8_t i;
1596
1597 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddTextContent():\n");
1598 if (layout == NULL) {
1599 return -1;
1600 }
1601
1602 // create title
1603 if (content->title != NULL) {
1604 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1605 textArea->textColor = BLACK;
1606 textArea->text = PIC(content->title);
1607 textArea->textAlignment = MID_LEFT;
1608 textArea->fontId = LARGE_MEDIUM_FONT;
1609 textArea->style = NO_STYLE;
1610 textArea->wrapping = true;
1611 textArea->obj.alignment = NO_ALIGNMENT;
1612 textArea->obj.alignmentMarginX = BORDER_MARGIN;
1613 textArea->obj.alignmentMarginY = PRE_TITLE_MARGIN;
1614 textArea->obj.area.width = AVAILABLE_WIDTH;
1615 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1616 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1617 // set this new obj as child of main container
1618 layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
1619 }
1620
1621 // create descriptions
1622 for (i = 0; i < content->nbDescriptions; i++) {
1623 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1624 textArea->textColor = BLACK;
1625 textArea->text = PIC(content->descriptions[i]);
1626 textArea->fontId = SMALL_REGULAR_FONT;
1627 textArea->style = NO_STYLE;
1628 textArea->wrapping = true;
1629 textArea->obj.area.width = AVAILABLE_WIDTH;
1630 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1631 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1632 textArea->textAlignment = MID_LEFT;
1633 textArea->obj.alignment = NO_ALIGNMENT;
1634 textArea->obj.alignmentMarginX = BORDER_MARGIN;
1635 textArea->obj.alignmentMarginY
1636 = (i == 0) ? PRE_DESCRIPTION_MARGIN : INTER_DESCRIPTIONS_MARGIN;
1637 // set this new obj as child of main container
1638 layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
1639 }
1640
1641 // create info on the bottom
1642 if (content->info != NULL) {
1643 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1644 textArea->textColor = LIGHT_TEXT_COLOR;
1645 textArea->text = PIC(content->info);
1646 textArea->fontId = SMALL_REGULAR_FONT;
1647 textArea->style = NO_STYLE;
1648 textArea->wrapping = true;
1649 textArea->obj.area.width = AVAILABLE_WIDTH;
1650 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1651 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1652 textArea->textAlignment = MID_LEFT;
1653 textArea->obj.alignment = BOTTOM_LEFT;
1654 textArea->obj.alignmentMarginX = BORDER_MARGIN;
1655 textArea->obj.alignmentMarginY = 40;
1656 // set this new obj as child of main container
1657 layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
1658 }
1659
1660 return layoutInt->container->obj.area.height;
1661}
1662
1670int nbgl_layoutAddRadioChoice(nbgl_layout_t *layout, const nbgl_layoutRadioChoice_t *choices)
1671{
1672 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1673 layoutObj_t *obj;
1674 uint8_t i;
1675
1676 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddRadioChoice():\n");
1677 if (layout == NULL) {
1678 return -1;
1679 }
1680 for (i = 0; i < choices->nbChoices; i++) {
1681 nbgl_container_t *container;
1682 nbgl_text_area_t *textArea;
1683 nbgl_radio_t *button;
1684 nbgl_line_t *line;
1685
1686 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
1687 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1688 button = (nbgl_radio_t *) nbgl_objPoolGet(RADIO_BUTTON, layoutInt->layer);
1689
1691 layoutInt, (nbgl_obj_t *) container, choices->token, choices->tuneId);
1692 if (obj == NULL) {
1693 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddRadioChoice(): no more callback obj\n");
1694 return -1;
1695 }
1696
1697 // get container children (max 2)
1698 container->nbChildren = 2;
1699 container->children = nbgl_containerPoolGet(container->nbChildren, layoutInt->layer);
1700 container->obj.area.width = AVAILABLE_WIDTH;
1701 container->obj.area.height = RADIO_CHOICE_HEIGHT;
1702 container->obj.alignment = NO_ALIGNMENT;
1703 container->obj.alignmentMarginX = BORDER_MARGIN;
1704 container->obj.alignTo = (nbgl_obj_t *) NULL;
1705
1706 // init button for this choice
1707 button->activeColor = BLACK;
1708 button->borderColor = LIGHT_GRAY;
1709 button->obj.alignTo = (nbgl_obj_t *) container;
1710 button->obj.alignment = MID_RIGHT;
1711 button->state = OFF_STATE;
1712 container->children[1] = (nbgl_obj_t *) button;
1713
1714 // init text area for this choice
1715 if (choices->localized == true) {
1716#ifdef HAVE_LANGUAGE_PACK
1717 textArea->text = get_ux_loc_string(choices->nameIds[i]);
1718#endif // HAVE_LANGUAGE_PACK
1719 }
1720 else {
1721 textArea->text = PIC(choices->names[i]);
1722 }
1723 textArea->textAlignment = MID_LEFT;
1724 textArea->obj.area.width = container->obj.area.width - RADIO_WIDTH;
1725 textArea->style = NO_STYLE;
1726 textArea->obj.alignment = MID_LEFT;
1727 textArea->obj.alignTo = (nbgl_obj_t *) container;
1728 container->children[0] = (nbgl_obj_t *) textArea;
1729
1730 // whole container should be touchable
1731 container->obj.touchMask = (1 << TOUCHED);
1732 container->obj.touchId = CONTROLS_ID + nbTouchableControls;
1733 nbTouchableControls++;
1734
1735 // highlight init choice
1736 if (i == choices->initChoice) {
1737 button->state = ON_STATE;
1738 textArea->textColor = BLACK;
1739 textArea->fontId = SMALL_BOLD_FONT;
1740 }
1741 else {
1742 button->state = OFF_STATE;
1743 textArea->textColor = LIGHT_TEXT_COLOR;
1744 textArea->fontId = SMALL_REGULAR_FONT;
1745 }
1746 textArea->obj.area.height = nbgl_getFontHeight(textArea->fontId);
1747
1748 line = createHorizontalLine(layoutInt->layer);
1749 line->obj.alignmentMarginY = -1;
1750
1751 // set these new objs as child of main container
1752 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
1753 layoutAddObject(layoutInt, (nbgl_obj_t *) line);
1754 }
1755
1756 return 0;
1757}
1758
1768{
1769 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1770 nbgl_container_t *container;
1771 nbgl_contentCenter_t centeredInfo = {0};
1772
1773 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddCenteredInfo():\n");
1774 if (layout == NULL) {
1775 return -1;
1776 }
1777
1778 centeredInfo.icon = info->icon;
1779 centeredInfo.illustrType = ICON_ILLUSTRATION;
1780
1781 if (info->text1 != NULL) {
1782 if (info->style != NORMAL_INFO) {
1783 centeredInfo.title = info->text1;
1784 }
1785 else {
1786 centeredInfo.smallTitle = info->text1;
1787 }
1788 }
1789 if (info->text2 != NULL) {
1790 if (info->style != LARGE_CASE_BOLD_INFO) {
1791 centeredInfo.description = info->text2;
1792 }
1793 else {
1794 centeredInfo.smallTitle = info->text2;
1795 }
1796 }
1797 if (info->text3 != NULL) {
1798 if (info->style == LARGE_CASE_GRAY_INFO) {
1799 centeredInfo.subText = info->text3;
1800 }
1801 else {
1802 centeredInfo.description = info->text3;
1803 }
1804 }
1805 container = addContentCenter(layoutInt, &centeredInfo);
1806
1807 if (info->onTop) {
1808 container->obj.alignmentMarginX = BORDER_MARGIN;
1809 container->obj.alignmentMarginY = BORDER_MARGIN + info->offsetY;
1810 container->obj.alignment = NO_ALIGNMENT;
1811 }
1812 else {
1813 container->obj.alignmentMarginY = info->offsetY;
1814 }
1815
1816 return container->obj.area.height;
1817}
1818
1828{
1829 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1830 nbgl_container_t *container;
1831
1832 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddContentCenter():\n");
1833 if (layout == NULL) {
1834 return -1;
1835 }
1836
1837 container = addContentCenter(layoutInt, info);
1838
1839 return container->obj.area.height;
1840}
1841
1850{
1851 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1852 nbgl_container_t *container;
1853 nbgl_text_area_t *textArea;
1854 uint8_t row;
1855
1856 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddLeftContent():\n");
1857 if (layout == NULL) {
1858 return -1;
1859 }
1860 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
1861
1862 // get container children
1863 container->nbChildren = info->nbRows + 1;
1864 container->children = nbgl_containerPoolGet(container->nbChildren, layoutInt->layer);
1865 container->layout = VERTICAL;
1866 container->obj.area.width = AVAILABLE_WIDTH;
1867 container->obj.alignmentMarginX = BORDER_MARGIN;
1868
1869 // create title
1870 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1871 textArea->textColor = BLACK;
1872 textArea->text = PIC(info->title);
1873 textArea->textAlignment = MID_LEFT;
1874 textArea->fontId = LARGE_MEDIUM_FONT;
1875 textArea->wrapping = true;
1876#ifdef TARGET_STAX
1877 textArea->obj.alignmentMarginY = 24;
1878#endif
1879 textArea->obj.area.width = AVAILABLE_WIDTH;
1880 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1881 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1882
1883 container->obj.area.height += textArea->obj.area.height + textArea->obj.alignmentMarginY;
1884
1885 container->children[0] = (nbgl_obj_t *) textArea;
1886
1887 for (row = 0; row < info->nbRows; row++) {
1888 nbgl_container_t *rowContainer;
1889 nbgl_image_t *image;
1890
1891 // create a grid with 1 icon on the left column and 1 text on the right one
1892 rowContainer = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, 0);
1893 rowContainer->nbChildren = 2; // 1 icon + 1 text
1894 rowContainer->children = nbgl_containerPoolGet(rowContainer->nbChildren, 0);
1895 rowContainer->obj.area.width = AVAILABLE_WIDTH;
1896
1897 image = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, 0);
1898 image->foregroundColor = BLACK;
1899 image->buffer = PIC(info->rowIcons[row]);
1900 rowContainer->children[0] = (nbgl_obj_t *) image;
1901
1902 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, 0);
1903 textArea->textColor = BLACK;
1904 textArea->text = PIC(info->rowTexts[row]);
1905 textArea->textAlignment = MID_LEFT;
1906 textArea->fontId = SMALL_REGULAR_FONT;
1907 textArea->wrapping = true;
1908 textArea->obj.area.width
1909 = AVAILABLE_WIDTH - image->buffer->width - LEFT_CONTENT_ICON_TEXT_X;
1910 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1911 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1912 textArea->obj.alignment = MID_RIGHT;
1913 rowContainer->children[1] = (nbgl_obj_t *) textArea;
1914 rowContainer->obj.area.height
1915 = MAX(image->buffer->height, textArea->obj.area.height + LEFT_CONTENT_TEXT_PADDING);
1916
1917 if (row == 0) {
1918 rowContainer->obj.alignmentMarginY = PRE_FIRST_ROW_MARGIN;
1919 }
1920 else {
1921 rowContainer->obj.alignmentMarginY = INTER_ROWS_MARGIN;
1922 }
1923 container->children[1 + row] = (nbgl_obj_t *) rowContainer;
1924 container->obj.area.height
1925 += rowContainer->obj.area.height + rowContainer->obj.alignmentMarginY;
1926 }
1927 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
1928
1929 return container->obj.area.height;
1930}
1931
1932#ifdef NBGL_QRCODE
1941int nbgl_layoutAddQRCode(nbgl_layout_t *layout, const nbgl_layoutQRCode_t *info)
1942{
1943 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
1944 nbgl_container_t *container;
1945 nbgl_text_area_t *textArea = NULL;
1946 nbgl_qrcode_t *qrcode;
1947 uint16_t fullHeight = 0;
1948
1949 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddQRCode():\n");
1950 if (layout == NULL) {
1951 return -1;
1952 }
1953
1954 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
1955
1956 // get container children (max 2 (QRCode + text1 + text2))
1957 container->children = nbgl_containerPoolGet(3, layoutInt->layer);
1958 container->nbChildren = 0;
1959
1960 qrcode = (nbgl_qrcode_t *) nbgl_objPoolGet(QR_CODE, layoutInt->layer);
1961 // version is forced to V10 if url is longer than 62 characters
1962 if (strlen(PIC(info->url)) > 62) {
1963 qrcode->version = QRCODE_V10;
1964 }
1965 else {
1966 qrcode->version = QRCODE_V4;
1967 }
1968 qrcode->foregroundColor = BLACK;
1969 // in QR V4, we use:
1970 // - 8*8 screen pixels for one QR pixel on Stax/Flex
1971 // - 5*5 screen pixels for one QR pixel on Apex
1972 // in QR V10, we use 4*4 screen pixels for one QR pixel
1973#ifndef TARGET_APEX
1974 qrcode->obj.area.width
1975 = (qrcode->version == QRCODE_V4) ? (QR_V4_NB_PIX_SIZE * 8) : (QR_V10_NB_PIX_SIZE * 4);
1976#else // TARGET_APEX
1977 qrcode->obj.area.width
1978 = (qrcode->version == QRCODE_V4) ? (QR_V4_NB_PIX_SIZE * 5) : (QR_V10_NB_PIX_SIZE * 4);
1979#endif // TARGET_APEX
1980 qrcode->obj.area.height = qrcode->obj.area.width;
1981 qrcode->text = PIC(info->url);
1982 qrcode->obj.area.bpp = NBGL_BPP_1;
1983 qrcode->obj.alignment = TOP_MIDDLE;
1984
1985 fullHeight += qrcode->obj.area.height;
1986 container->children[container->nbChildren] = (nbgl_obj_t *) qrcode;
1987 container->nbChildren++;
1988
1989 if (info->text1 != NULL) {
1990 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
1991 textArea->textColor = BLACK;
1992 textArea->text = PIC(info->text1);
1993 textArea->textAlignment = CENTER;
1994 textArea->fontId = (info->largeText1 == true) ? LARGE_MEDIUM_FONT : SMALL_REGULAR_FONT;
1995 textArea->wrapping = true;
1996 textArea->obj.area.width = AVAILABLE_WIDTH;
1997 textArea->obj.area.height = nbgl_getTextHeightInWidth(
1998 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
1999 textArea->obj.alignment = BOTTOM_MIDDLE;
2000 textArea->obj.alignTo = (nbgl_obj_t *) container->children[container->nbChildren - 1];
2001 textArea->obj.alignmentMarginY = QR_PRE_TEXT_MARGIN;
2002
2003 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
2004
2005 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
2006 container->nbChildren++;
2007 }
2008 if (info->text2 != NULL) {
2009 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2010 textArea->textColor = LIGHT_TEXT_COLOR;
2011 textArea->text = PIC(info->text2);
2012 textArea->textAlignment = CENTER;
2013 textArea->fontId = SMALL_REGULAR_FONT;
2014 textArea->wrapping = true;
2015 textArea->obj.area.width = AVAILABLE_WIDTH;
2016 textArea->obj.area.height = nbgl_getTextHeightInWidth(
2017 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
2018 textArea->obj.alignment = BOTTOM_MIDDLE;
2019 textArea->obj.alignTo = (nbgl_obj_t *) container->children[container->nbChildren - 1];
2020 if (info->text1 != NULL) {
2021 textArea->obj.alignmentMarginY = QR_INTER_TEXTS_MARGIN;
2022 }
2023 else {
2024 textArea->obj.alignmentMarginY = QR_PRE_TEXT_MARGIN + 8;
2025 }
2026
2027 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY + 8;
2028
2029 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
2030 container->nbChildren++;
2031 }
2032 // ensure that fullHeight is fitting in main container height (with 16 px margin)
2033 if ((fullHeight >= (layoutInt->container->obj.area.height - 16))
2034 && (qrcode->version == QRCODE_V4)) {
2035 qrcode->version = QRCODE_V4_SMALL;
2036 // in QR V4 small, we use 4*4 screen pixels for one QR pixel
2037 qrcode->obj.area.width = QR_V4_NB_PIX_SIZE * 4;
2038 qrcode->obj.area.height = qrcode->obj.area.width;
2039 fullHeight -= QR_V4_NB_PIX_SIZE * 4;
2040 }
2041 container->obj.area.height = fullHeight;
2042 container->layout = VERTICAL;
2043 if (info->centered) {
2044 container->obj.alignment = CENTER;
2045 }
2046 else {
2047 container->obj.alignment = BOTTOM_MIDDLE;
2048 container->obj.alignTo
2049 = layoutInt->container->children[layoutInt->container->nbChildren - 1];
2050 }
2051 container->obj.alignmentMarginY = info->offsetY;
2052
2053 container->obj.area.width = AVAILABLE_WIDTH;
2054
2055 // set this new container as child of main container
2056 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
2057
2058 return fullHeight;
2059}
2060#endif // NBGL_QRCODE
2061
2070int nbgl_layoutAddChoiceButtons(nbgl_layout_t *layout, const nbgl_layoutChoiceButtons_t *info)
2071{
2072 nbgl_layoutFooter_t footerDesc = {0};
2073 footerDesc.type = FOOTER_CHOICE_BUTTONS;
2074 footerDesc.choiceButtons.bottomText = info->bottomText;
2075 footerDesc.choiceButtons.token = info->token;
2076 footerDesc.choiceButtons.topText = info->topText;
2077 footerDesc.choiceButtons.topIcon = info->topIcon;
2078 footerDesc.choiceButtons.style = info->style;
2079 footerDesc.choiceButtons.tuneId = info->tuneId;
2080 return nbgl_layoutAddExtendedFooter(layout, &footerDesc);
2081}
2082
2092int nbgl_layoutAddHorizontalButtons(nbgl_layout_t *layout,
2093 const nbgl_layoutHorizontalButtons_t *info)
2094{
2095 nbgl_layoutUpFooter_t upFooterDesc = {.type = UP_FOOTER_HORIZONTAL_BUTTONS,
2096 .horizontalButtons.leftIcon = info->leftIcon,
2097 .horizontalButtons.leftToken = info->leftToken,
2098 .horizontalButtons.rightText = info->rightText,
2099 .horizontalButtons.rightToken = info->rightToken,
2100 .horizontalButtons.tuneId = info->tuneId};
2101
2102 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddHorizontalButtons():\n");
2103 return nbgl_layoutAddUpFooter(layout, &upFooterDesc);
2104}
2105
2113int nbgl_layoutAddTagValueList(nbgl_layout_t *layout, const nbgl_layoutTagValueList_t *list)
2114{
2115 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
2116 nbgl_container_t *container;
2117 uint8_t i;
2118
2119 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddTagValueList():\n");
2120 if (layout == NULL) {
2121 return -1;
2122 }
2123 if ((list->pairs == NULL) && (list->callback == NULL)) {
2124 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddTagValueList(): pairs and callback are both NULL\n");
2125 return -1;
2126 }
2127 // with callback, all pair indexes (from startIndex) must fit in uint8_t
2128 if ((list->pairs == NULL)
2129 && (((uint16_t) list->startIndex + list->nbPairs) > (UINT8_MAX + 1))) {
2130 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddTagValueList(): pair indexes overflow\n");
2131 return -1;
2132 }
2133
2134 for (i = 0; i < list->nbPairs; i++) {
2135 const nbgl_layoutTagValue_t *pair;
2136 uint16_t fullHeight = 0;
2137 const nbgl_icon_details_t *valueIcon = NULL;
2138 nbgl_text_area_t *itemTextArea;
2139 nbgl_text_area_t *valueTextArea;
2140 uint8_t nbChildren = 2;
2141
2142 // Retrieve pair
2143 if (list->pairs != NULL) {
2144 pair = &list->pairs[i];
2145 }
2146 else {
2147 pair = list->callback(list->startIndex + i);
2148 if (pair == NULL) {
2150 "nbgl_layoutAddTagValueList(): callback returned NULL for index %d\n",
2151 i);
2152 return -1;
2153 }
2154 }
2155
2156 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
2157
2158 // (>) icon for an alias, otherwise the provided icon, if any
2159 valueIcon = layoutGetTagValueIcon(pair);
2160
2161 // tune container number of children (max 4 if a valueIcon and aliasSubName)
2162 if (valueIcon != NULL) {
2163 nbChildren++;
2164 // if it's a alias with a subName, add a child
2165 if ((pair->aliasValue) && (pair->extension != NULL)
2166 && (pair->extension->aliasSubName)) {
2167 nbChildren++;
2168 }
2169 }
2170 // get container children
2171 container->children = nbgl_containerPoolGet(nbChildren, layoutInt->layer);
2172
2173 itemTextArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2174 valueTextArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2175
2176 // init text area for this choice
2177 itemTextArea->textColor = LIGHT_TEXT_COLOR;
2178 itemTextArea->text = PIC(pair->item);
2179 itemTextArea->textAlignment = MID_LEFT;
2180 itemTextArea->fontId = SMALL_REGULAR_FONT;
2181 itemTextArea->wrapping = true;
2182 itemTextArea->obj.area.width = AVAILABLE_WIDTH;
2183 itemTextArea->obj.area.height = nbgl_getTextHeightInWidth(
2184 itemTextArea->fontId, itemTextArea->text, AVAILABLE_WIDTH, itemTextArea->wrapping);
2185 container->children[container->nbChildren] = (nbgl_obj_t *) itemTextArea;
2186 container->nbChildren++;
2187
2188 fullHeight += itemTextArea->obj.area.height;
2189
2190 // init button for this choice
2191 valueTextArea->textColor = BLACK;
2192 valueTextArea->text = PIC(pair->value);
2193 valueTextArea->textAlignment = MID_LEFT;
2194 // the font must match the one used in getNbTagValuesInPage() (nbgl_use_case.c)
2195 valueTextArea->fontId = layoutGetTagValueFont(list->smallCaseForValue);
2196 // the width of value (reduced if there is an icon) must match the one used in
2197 // getNbTagValuesInPage() (nbgl_use_case.c) to compute the number of pairs fitting in a page
2198 valueTextArea->obj.area.width = layoutGetTagValueWidth(valueIcon);
2199
2200 // handle the nbMaxLinesForValue parameters of the list and of the pair, used to
2201 // automatically keep only this number of lines
2202 bool forceEllipsis;
2203 uint8_t nbMaxLines
2204 = layoutGetTagValueMaxLines(list->nbMaxLinesForValue, pair, &forceEllipsis);
2205 uint16_t nbLines = nbgl_getTextNbLinesInWidth(valueTextArea->fontId,
2206 valueTextArea->text,
2207 valueTextArea->obj.area.width,
2208 list->wrapping);
2209 // use this nbMaxLines only if >0
2210 if ((nbMaxLines > 0) && (nbLines > nbMaxLines)) {
2211 nbLines = nbMaxLines;
2212 valueTextArea->nbMaxLines = nbMaxLines;
2213 valueTextArea->hideEndOfLastLine = forceEllipsis || list->hideEndOfLastLine;
2214 }
2215 const nbgl_font_t *font = nbgl_getFont(valueTextArea->fontId);
2216 valueTextArea->obj.area.height = nbLines * font->line_height;
2217 valueTextArea->obj.alignment = BOTTOM_LEFT;
2218 valueTextArea->obj.alignmentMarginY = TAG_VALUE_INTERVALE;
2219 valueTextArea->obj.alignTo = (nbgl_obj_t *) itemTextArea;
2220 valueTextArea->wrapping = list->wrapping;
2221 container->children[container->nbChildren] = (nbgl_obj_t *) valueTextArea;
2222 container->nbChildren++;
2223
2224 fullHeight += valueTextArea->obj.area.height + valueTextArea->obj.alignmentMarginY;
2225 if (valueIcon != NULL) {
2226 nbgl_image_t *image = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
2227 // set the container as touchable, not only the image
2229 layoutInt, (nbgl_obj_t *) container, list->token, TUNE_TAP_CASUAL);
2230 obj->index = i;
2231 image->foregroundColor = BLACK;
2232 image->buffer = valueIcon;
2233 image->obj.alignment = RIGHT_TOP;
2234 image->obj.alignmentMarginX = VALUE_ICON_INTERVALE;
2235 image->obj.alignTo = (nbgl_obj_t *) valueTextArea;
2236 // set the container as touchable, not only the image
2237 container->obj.touchMask = (1 << TOUCHED);
2238 container->obj.touchId = VALUE_BUTTON_1_ID + i;
2239
2240 container->children[container->nbChildren] = (nbgl_obj_t *) image;
2241 container->nbChildren++;
2242
2243 // if an aliasSubName is provided, display it under value
2244 if ((pair->aliasValue) && (pair->extension != NULL)
2245 && (pair->extension->aliasSubName)) {
2246 nbgl_text_area_t *textArea
2248 textArea->textColor = BLACK;
2249 textArea->text = PIC(pair->extension->aliasSubName);
2250 textArea->textAlignment = MID_LEFT;
2251 textArea->nbMaxLines = 1;
2252 textArea->fontId = SMALL_REGULAR_FONT;
2253 textArea->obj.area.height = nbgl_getFontLineHeight(textArea->fontId);
2254 textArea->obj.area.width = valueTextArea->obj.area.width;
2255 textArea->obj.alignment = BOTTOM_LEFT;
2256 textArea->obj.alignmentMarginY = TAG_VALUE_INTERVALE;
2257 textArea->obj.alignTo = (nbgl_obj_t *) valueTextArea;
2258 textArea->wrapping = list->wrapping;
2259 textArea->hideEndOfLastLine
2260 = (nbgl_getSingleLineTextWidth(textArea->fontId, textArea->text)
2261 > textArea->obj.area.width);
2262 container->children[container->nbChildren] = (nbgl_obj_t *) textArea;
2263 container->nbChildren++;
2264 fullHeight += textArea->obj.area.height + textArea->obj.alignmentMarginY;
2265 }
2266 }
2267
2268 container->obj.area.width = AVAILABLE_WIDTH;
2269 container->obj.area.height = fullHeight;
2270 container->layout = VERTICAL;
2271 container->obj.alignmentMarginX = BORDER_MARGIN;
2272 if (i > 0) {
2273 container->obj.alignmentMarginY = INTER_TAG_VALUE_MARGIN;
2274 }
2275 else {
2276 // if there is a header with a separation line, add a margin
2277 if (layoutInt->headerContainer && (layoutInt->headerContainer->nbChildren > 0)
2278 && (layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren - 1]
2279 ->type
2280 == LINE)) {
2281 container->obj.alignmentMarginY = INTER_TAG_VALUE_MARGIN;
2282 }
2283 else {
2284 container->obj.alignmentMarginY = PRE_TAG_VALUE_MARGIN;
2285 }
2286 }
2287 container->obj.alignment = NO_ALIGNMENT;
2288
2289 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
2290 }
2291
2292 return 0;
2293}
2294
2308 const char *text,
2309 const char *subText,
2310 uint8_t percentage)
2311{
2312 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
2313 nbgl_container_t *container;
2314 nbgl_text_area_t *textArea;
2315 nbgl_progress_bar_t *progress;
2316
2317 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddProgressBar():\n");
2318 if (layout == NULL) {
2319 return -1;
2320 }
2321
2322 // First Create Container :
2323 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
2324 // progressbar + text + subText
2325 container->nbChildren = (subText != NULL) ? 3 : 2;
2326 container->children = nbgl_containerPoolGet(container->nbChildren, layoutInt->layer);
2327
2328 container->obj.area.width = AVAILABLE_WIDTH;
2329 container->layout = VERTICAL;
2330 container->obj.alignment = CENTER;
2331
2332 // Create progressbar
2333 progress = (nbgl_progress_bar_t *) nbgl_objPoolGet(PROGRESS_BAR, layoutInt->layer);
2334 progress->foregroundColor = BLACK;
2335 progress->withBorder = true;
2336 progress->state = percentage;
2337 progress->obj.area.width = PROGRESSBAR_WIDTH;
2338 progress->obj.area.height = PROGRESSBAR_HEIGHT;
2339 progress->obj.alignment = TOP_MIDDLE;
2340
2341 // set this new progressbar as child of the container
2342 container->children[0] = (nbgl_obj_t *) progress;
2343
2344 // update container height
2345 container->obj.area.height = progress->obj.alignmentMarginY + progress->obj.area.height;
2346
2347 // create text area
2348 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2349 textArea->textColor = BLACK;
2350 textArea->text = PIC(text);
2351 textArea->textAlignment = CENTER;
2352 textArea->fontId = LARGE_MEDIUM_FONT;
2353 textArea->wrapping = true;
2354 textArea->obj.alignmentMarginY = BAR_TEXT_MARGIN;
2355 textArea->obj.alignTo = (nbgl_obj_t *) progress;
2356 textArea->obj.alignment = BOTTOM_MIDDLE;
2357 textArea->obj.area.width = AVAILABLE_WIDTH;
2358 textArea->obj.area.height = nbgl_getTextHeightInWidth(
2359 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
2360 textArea->style = NO_STYLE;
2361
2362 // update container height
2363 container->obj.area.height += textArea->obj.alignmentMarginY + textArea->obj.area.height;
2364
2365 // set this text as child of the container
2366 container->children[1] = (nbgl_obj_t *) textArea;
2367
2368 if (subText != NULL) {
2369 nbgl_text_area_t *subTextArea;
2370 // create sub-text area
2371 subTextArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2372 subTextArea->textColor = BLACK;
2373 subTextArea->text = PIC(subText);
2374 subTextArea->textAlignment = CENTER;
2375 subTextArea->fontId = SMALL_REGULAR_FONT;
2376 subTextArea->wrapping = true;
2377 subTextArea->obj.alignmentMarginY = BAR_INTER_TEXTS_MARGIN;
2378 subTextArea->obj.alignTo = (nbgl_obj_t *) textArea;
2379 subTextArea->obj.alignment = BOTTOM_MIDDLE;
2380 subTextArea->obj.area.width = AVAILABLE_WIDTH;
2381 subTextArea->obj.area.height = nbgl_getTextHeightInWidth(subTextArea->fontId,
2382 subTextArea->text,
2383 subTextArea->obj.area.width,
2384 subTextArea->wrapping);
2385 subTextArea->style = NO_STYLE;
2386
2387 // update container height
2388 container->obj.area.height
2389 += subTextArea->obj.alignmentMarginY + subTextArea->obj.area.height;
2390
2391 // set thissub-text as child of the container
2392 container->children[2] = (nbgl_obj_t *) subTextArea;
2393 }
2394 // The height of containers must be a multiple of eight
2395 container->obj.area.height = (container->obj.area.height + 7) & 0xFFF8;
2396
2397 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
2398
2399 return 2;
2400}
2401
2408int nbgl_layoutAddSeparationLine(nbgl_layout_t *layout)
2409{
2410 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
2411 nbgl_line_t *line;
2412
2413 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddSeparationLine():\n");
2414 line = createHorizontalLine(layoutInt->layer);
2415 line->obj.alignmentMarginY = -1;
2416 layoutAddObject(layoutInt, (nbgl_obj_t *) line);
2417 return 0;
2418}
2419
2427int nbgl_layoutAddButton(nbgl_layout_t *layout, const nbgl_layoutButton_t *buttonInfo)
2428{
2429 layoutObj_t *obj;
2430 nbgl_button_t *button;
2431 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
2432
2433 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddButton():\n");
2434 if (layout == NULL) {
2435 return -1;
2436 }
2437
2438 // Add in footer if matching
2439 if ((buttonInfo->onBottom) && (!buttonInfo->fittingContent)) {
2440 if (layoutInt->footerContainer == NULL) {
2441 nbgl_layoutFooter_t footerDesc = {0};
2442 footerDesc.type = FOOTER_SIMPLE_BUTTON;
2443 footerDesc.button.text = buttonInfo->text;
2444 footerDesc.button.token = buttonInfo->token;
2445 footerDesc.button.tuneId = buttonInfo->tuneId;
2446 footerDesc.button.icon = buttonInfo->icon;
2447 footerDesc.button.style = buttonInfo->style;
2448 return nbgl_layoutAddExtendedFooter(layout, &footerDesc);
2449 }
2450 else {
2451 nbgl_layoutUpFooter_t upFooterDesc = {0};
2452 upFooterDesc.type = UP_FOOTER_BUTTON;
2453 upFooterDesc.button.text = buttonInfo->text;
2454 upFooterDesc.button.token = buttonInfo->token;
2455 upFooterDesc.button.tuneId = buttonInfo->tuneId;
2456 upFooterDesc.button.icon = buttonInfo->icon;
2457 upFooterDesc.button.style = buttonInfo->style;
2458 return nbgl_layoutAddUpFooter(layout, &upFooterDesc);
2459 }
2460 }
2461
2462 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
2464 layoutInt, (nbgl_obj_t *) button, buttonInfo->token, buttonInfo->tuneId);
2465 if (obj == NULL) {
2466 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddButton(): no more callback obj\n");
2467 return -1;
2468 }
2469
2470 button->obj.alignmentMarginX = BORDER_MARGIN;
2471 button->obj.alignmentMarginY = 12;
2472 button->obj.alignment = NO_ALIGNMENT;
2473 if (buttonInfo->style == BLACK_BACKGROUND) {
2474 button->innerColor = BLACK;
2475 button->foregroundColor = WHITE;
2476 }
2477 else {
2478 button->innerColor = WHITE;
2479 button->foregroundColor = BLACK;
2480 }
2481 if (buttonInfo->style == NO_BORDER) {
2482 button->borderColor = WHITE;
2483 }
2484 else {
2485 if (buttonInfo->style == BLACK_BACKGROUND) {
2486 button->borderColor = BLACK;
2487 }
2488 else {
2489 button->borderColor = LIGHT_GRAY;
2490 }
2491 }
2492 button->text = PIC(buttonInfo->text);
2493 button->fontId = SMALL_BOLD_FONT;
2494 button->icon = PIC(buttonInfo->icon);
2495 if (buttonInfo->fittingContent == true) {
2496 button->obj.area.width = nbgl_getTextWidth(button->fontId, button->text)
2497 + SMALL_BUTTON_HEIGHT
2498 + ((button->icon) ? (button->icon->width + 12) : 0);
2499 button->obj.area.height = SMALL_BUTTON_HEIGHT;
2500 button->radius = SMALL_BUTTON_RADIUS_INDEX;
2501 if (buttonInfo->onBottom != true) {
2502 button->obj.alignmentMarginX += (AVAILABLE_WIDTH - button->obj.area.width) / 2;
2503 }
2504 }
2505 else {
2506 button->obj.area.width = AVAILABLE_WIDTH;
2507 button->obj.area.height = BUTTON_DIAMETER;
2508 button->radius = BUTTON_RADIUS;
2509 }
2510 button->obj.alignTo = NULL;
2511 button->obj.touchMask = (1 << TOUCHED);
2512 button->obj.touchId = (buttonInfo->fittingContent) ? EXTRA_BUTTON_ID : SINGLE_BUTTON_ID;
2513 // set this new button as child of the container
2514 layoutAddObject(layoutInt, (nbgl_obj_t *) button);
2515
2516 return 0;
2517}
2518
2528int nbgl_layoutAddLongPressButton(nbgl_layout_t *layout,
2529 const char *text,
2530 uint8_t token,
2531 tune_index_e tuneId)
2532{
2533 nbgl_layoutUpFooter_t upFooterDesc = {.type = UP_FOOTER_LONG_PRESS,
2534 .longPress.text = text,
2535 .longPress.token = token,
2536 .longPress.tuneId = tuneId};
2537
2538 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddLongPressButton():\n");
2539 if (layout == NULL) {
2540 return -1;
2541 }
2542
2543 return nbgl_layoutAddUpFooter(layout, &upFooterDesc);
2544}
2545
2556int nbgl_layoutAddFooter(nbgl_layout_t *layout,
2557 const char *text,
2558 uint8_t token,
2559 tune_index_e tuneId)
2560{
2561 nbgl_layoutFooter_t footerDesc = {0};
2562 footerDesc.type = FOOTER_SIMPLE_TEXT;
2563 footerDesc.separationLine = true;
2564 footerDesc.simpleText.text = text;
2565 footerDesc.simpleText.token = token;
2566 footerDesc.simpleText.tuneId = tuneId;
2567 return nbgl_layoutAddExtendedFooter(layout, &footerDesc);
2568}
2569
2582int nbgl_layoutAddSplitFooter(nbgl_layout_t *layout,
2583 const char *leftText,
2584 uint8_t leftToken,
2585 const char *rightText,
2586 uint8_t rightToken,
2587 tune_index_e tuneId)
2588{
2589 nbgl_layoutFooter_t footerDesc = {0};
2590 footerDesc.type = FOOTER_DOUBLE_TEXT;
2591 footerDesc.separationLine = true;
2592 footerDesc.doubleText.leftText = leftText;
2593 footerDesc.doubleText.leftToken = leftToken;
2594 footerDesc.doubleText.rightText = rightText;
2595 footerDesc.doubleText.rightToken = rightToken;
2596 footerDesc.doubleText.tuneId = tuneId;
2597 return nbgl_layoutAddExtendedFooter(layout, &footerDesc);
2598}
2599
2608int nbgl_layoutAddHeader(nbgl_layout_t *layout, const nbgl_layoutHeader_t *headerDesc)
2609{
2610 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
2611 layoutObj_t *obj;
2612 nbgl_text_area_t *textArea = NULL;
2613 nbgl_line_t *line = NULL;
2614 nbgl_image_t *image = NULL;
2615 nbgl_button_t *button = NULL;
2616
2617 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddHeader(): type = %d\n", headerDesc->type);
2618 if (layout == NULL) {
2619 return -1;
2620 }
2621 if ((headerDesc == NULL) || (headerDesc->type >= NB_HEADER_TYPES)) {
2622 return -2;
2623 }
2624
2625 layoutInt->headerContainer = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
2626 layoutInt->headerContainer->obj.area.width = SCREEN_WIDTH;
2627 layoutInt->headerContainer->layout = VERTICAL;
2628 layoutInt->headerContainer->children
2629 = (nbgl_obj_t **) nbgl_containerPoolGet(6, layoutInt->layer);
2630 layoutInt->headerContainer->obj.alignment = TOP_MIDDLE;
2631
2632 switch (headerDesc->type) {
2633 case HEADER_EMPTY: {
2634 layoutInt->headerContainer->obj.area.height = headerDesc->emptySpace.height;
2635 break;
2636 }
2637 case HEADER_BACK_AND_TEXT:
2638 case HEADER_BACK_ICON_AND_TEXT:
2639 case HEADER_EXTENDED_BACK: {
2640 const char *text = (headerDesc->type == HEADER_EXTENDED_BACK)
2641 ? PIC(headerDesc->extendedBack.text)
2642 : PIC(headerDesc->backAndText.text);
2643 uint8_t backToken = (headerDesc->type == HEADER_EXTENDED_BACK)
2644 ? headerDesc->extendedBack.backToken
2645 : headerDesc->backAndText.token;
2646 nbgl_button_t *actionButton = NULL;
2647 // add back button only if token is valid
2648 if (backToken != NBGL_INVALID_TOKEN) {
2649 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
2650 obj = layoutAddCallbackObj(layoutInt,
2651 (nbgl_obj_t *) button,
2652 backToken,
2653 (headerDesc->type == HEADER_EXTENDED_BACK)
2654 ? headerDesc->extendedBack.tuneId
2655 : headerDesc->backAndText.tuneId);
2656 if (obj == NULL) {
2658 "nbgl_layoutAddHeader(): no more callback obj for type %d\n",
2659 headerDesc->type);
2660 return -1;
2661 }
2662 button->obj.alignment = MID_LEFT;
2663 button->innerColor = WHITE;
2664 button->foregroundColor = BLACK;
2665 button->borderColor = WHITE;
2666 button->obj.area.width = BACK_KEY_WIDTH;
2667 button->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2668 button->text = NULL;
2669 button->icon = PIC(&LEFT_ARROW_ICON);
2670 button->obj.touchMask = (1 << TOUCHED);
2671 button->obj.touchId = BACK_BUTTON_ID;
2672 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2673 = (nbgl_obj_t *) button;
2674 layoutInt->headerContainer->nbChildren++;
2675 }
2676
2677 // add optional text if needed
2678 if (text != NULL) {
2679 // add optional icon if type is HEADER_BACK_ICON_AND_TEXT
2680 if (headerDesc->type == HEADER_BACK_ICON_AND_TEXT) {
2681 image = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
2682 image->buffer = PIC(headerDesc->backAndText.icon);
2683 image->foregroundColor = BLACK;
2684 image->obj.alignment = CENTER;
2685 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2686 = (nbgl_obj_t *) image;
2687 layoutInt->headerContainer->nbChildren++;
2688 }
2689 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2690 if ((headerDesc->type == HEADER_EXTENDED_BACK)
2691 && (headerDesc->extendedBack.textToken != NBGL_INVALID_TOKEN)) {
2692 obj = layoutAddCallbackObj(layoutInt,
2693 (nbgl_obj_t *) textArea,
2694 headerDesc->extendedBack.textToken,
2695 headerDesc->extendedBack.tuneId);
2696 if (obj == NULL) {
2698 "nbgl_layoutAddHeader(): no more callback obj for type %d\n",
2699 headerDesc->type);
2700 return -1;
2701 }
2702 textArea->obj.touchMask = (1 << TOUCHED);
2703 }
2704 textArea->obj.alignment = CENTER;
2705 textArea->textColor = BLACK;
2706 textArea->obj.area.width
2707 = layoutInt->headerContainer->obj.area.width - 2 * BACK_KEY_WIDTH;
2708 // if icon, reduce to 1 line and fit text width
2709 if (headerDesc->type == HEADER_BACK_ICON_AND_TEXT) {
2710 textArea->obj.area.width -= 16 + image->buffer->width;
2711 }
2712 textArea->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2713 textArea->text = text;
2714 textArea->fontId = SMALL_BOLD_FONT;
2715 textArea->textAlignment = CENTER;
2716 textArea->wrapping = true;
2717 uint8_t nbMaxLines = (headerDesc->type == HEADER_BACK_ICON_AND_TEXT) ? 1 : 2;
2718 // ensure that text fits on 2 lines maximum
2719 if (nbgl_getTextNbLinesInWidth(textArea->fontId,
2720 textArea->text,
2721 textArea->obj.area.width,
2722 textArea->wrapping)
2723 > nbMaxLines) {
2724 textArea->obj.area.height
2725 = nbMaxLines * nbgl_getFontLineHeight(textArea->fontId);
2726#ifndef BUILD_SCREENSHOTS
2728 "nbgl_layoutAddHeader: text [%s] is too long for header\n",
2729 text);
2730#endif // BUILD_SCREENSHOTS
2731 }
2732 if (headerDesc->type == HEADER_BACK_ICON_AND_TEXT) {
2733 textArea->obj.area.width = nbgl_getTextWidth(textArea->fontId, textArea->text);
2734 }
2735 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2736 = (nbgl_obj_t *) textArea;
2737 layoutInt->headerContainer->nbChildren++;
2738 // if icon, realign icon & text
2739 if (headerDesc->type == HEADER_BACK_ICON_AND_TEXT) {
2740 textArea->obj.alignmentMarginX = 8 + image->buffer->width / 2;
2741 image->obj.alignmentMarginX = -8 - textArea->obj.area.width / 2;
2742 }
2743 }
2744 // add action key if the type is HEADER_EXTENDED_BACK
2745 if ((headerDesc->type == HEADER_EXTENDED_BACK)
2746 && (headerDesc->extendedBack.actionIcon)) {
2747 actionButton = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
2748 // if token is valid
2749 if (headerDesc->extendedBack.actionToken != NBGL_INVALID_TOKEN) {
2750 obj = layoutAddCallbackObj(layoutInt,
2751 (nbgl_obj_t *) actionButton,
2752 headerDesc->extendedBack.actionToken,
2753 headerDesc->extendedBack.tuneId);
2754 if (obj == NULL) {
2756 "nbgl_layoutAddHeader(): no more callback obj for type %d\n",
2757 headerDesc->type);
2758 return -1;
2759 }
2760 actionButton->obj.touchMask = (1 << TOUCHED);
2761 }
2762
2763 actionButton->obj.alignment = MID_RIGHT;
2764 actionButton->innerColor = WHITE;
2765 actionButton->foregroundColor
2766 = (headerDesc->extendedBack.actionToken != NBGL_INVALID_TOKEN) ? BLACK
2767 : LIGHT_GRAY;
2768 actionButton->borderColor = WHITE;
2769 actionButton->obj.area.width = BACK_KEY_WIDTH;
2770 actionButton->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2771 actionButton->text = NULL;
2772 actionButton->icon = PIC(headerDesc->extendedBack.actionIcon);
2773 actionButton->obj.touchId = EXTRA_BUTTON_ID;
2774 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2775 = (nbgl_obj_t *) actionButton;
2776 layoutInt->headerContainer->nbChildren++;
2777 }
2778
2779 layoutInt->headerContainer->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2780 // add potential text under the line if the type is HEADER_EXTENDED_BACK
2781 if ((headerDesc->type == HEADER_EXTENDED_BACK)
2782 && (headerDesc->extendedBack.subText != NULL)) {
2783 nbgl_text_area_t *subTextArea;
2784
2785 line = createHorizontalLine(layoutInt->layer);
2786 line->obj.alignment = TOP_MIDDLE;
2787 line->obj.alignmentMarginY = TOUCHABLE_HEADER_BAR_HEIGHT;
2788 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2789 = (nbgl_obj_t *) line;
2790 layoutInt->headerContainer->nbChildren++;
2791
2792 subTextArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2793 subTextArea->textColor = BLACK;
2794 subTextArea->text = PIC(headerDesc->extendedBack.subText);
2795 subTextArea->textAlignment = MID_LEFT;
2796 subTextArea->fontId = SMALL_REGULAR_FONT;
2797 subTextArea->wrapping = true;
2798 subTextArea->obj.alignment = BOTTOM_MIDDLE;
2799 subTextArea->obj.alignmentMarginY = SUB_HEADER_MARGIN;
2800 subTextArea->obj.area.width = AVAILABLE_WIDTH;
2801 subTextArea->obj.area.height
2802 = nbgl_getTextHeightInWidth(subTextArea->fontId,
2803 subTextArea->text,
2804 subTextArea->obj.area.width,
2805 subTextArea->wrapping);
2806 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2807 = (nbgl_obj_t *) subTextArea;
2808 layoutInt->headerContainer->nbChildren++;
2809 layoutInt->headerContainer->obj.area.height
2810 += subTextArea->obj.area.height + 2 * SUB_HEADER_MARGIN;
2812 if (button != NULL) {
2813 button->obj.alignmentMarginY
2814 -= (subTextArea->obj.area.height + 2 * SUB_HEADER_MARGIN) / 2;
2815 }
2816 if (textArea != NULL) {
2817 textArea->obj.alignmentMarginY
2818 -= (subTextArea->obj.area.height + 2 * SUB_HEADER_MARGIN) / 2;
2819 }
2820 if (actionButton != NULL) {
2821 actionButton->obj.alignmentMarginY
2822 -= (subTextArea->obj.area.height + 2 * SUB_HEADER_MARGIN) / 2;
2823 }
2824 }
2825 break;
2826 }
2827 case HEADER_BACK_AND_PROGRESS: {
2828#ifdef TARGET_STAX
2829 // add optional back button
2830 if (headerDesc->progressAndBack.withBack) {
2831 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
2832 obj = layoutAddCallbackObj(layoutInt,
2833 (nbgl_obj_t *) button,
2834 headerDesc->progressAndBack.token,
2835 headerDesc->progressAndBack.tuneId);
2836 if (obj == NULL) {
2838 "nbgl_layoutAddHeader(): no more callback obj for type %d\n",
2839 headerDesc->type);
2840 return -1;
2841 }
2842
2843 button->obj.alignment = MID_LEFT;
2844 button->innerColor = WHITE;
2845 button->foregroundColor = BLACK;
2846 button->borderColor = WHITE;
2847 button->obj.area.width = BACK_KEY_WIDTH;
2848 button->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2849 button->text = NULL;
2850 button->icon = PIC(&LEFT_ARROW_ICON);
2851 button->obj.touchMask = (1 << TOUCHED);
2852 button->obj.touchId = BACK_BUTTON_ID;
2853 // add to container
2854 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2855 = (nbgl_obj_t *) button;
2856 layoutInt->headerContainer->nbChildren++;
2857 }
2858
2859 // add progress indicator
2860 if (headerDesc->progressAndBack.nbPages > 1
2861 && headerDesc->progressAndBack.nbPages != NBGL_NO_PROGRESS_INDICATOR) {
2862 nbgl_page_indicator_t *progress;
2863
2864 progress
2866 progress->activePage = headerDesc->progressAndBack.activePage;
2867 progress->nbPages = headerDesc->progressAndBack.nbPages;
2868 progress->obj.area.width = 224;
2869 progress->obj.alignment = CENTER;
2870 // add to container
2871 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2872 = (nbgl_obj_t *) progress;
2873 layoutInt->headerContainer->nbChildren++;
2874 }
2875 layoutInt->activePage = headerDesc->progressAndBack.activePage;
2876 layoutInt->nbPages = headerDesc->progressAndBack.nbPages;
2877 layoutInt->headerContainer->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2878#endif // TARGET_STAX
2879 break;
2880 }
2881 case HEADER_TITLE: {
2882 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2883 textArea->textColor = BLACK;
2884 textArea->obj.area.width = AVAILABLE_WIDTH;
2885 textArea->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2886 textArea->text = PIC(headerDesc->title.text);
2887 textArea->fontId = SMALL_BOLD_FONT;
2888 textArea->textAlignment = CENTER;
2889 textArea->wrapping = true;
2890 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2891 = (nbgl_obj_t *) textArea;
2892 layoutInt->headerContainer->nbChildren++;
2893 layoutInt->headerContainer->obj.area.height = textArea->obj.area.height;
2894 break;
2895 }
2896 case HEADER_RIGHT_TEXT: {
2897 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2898 obj = layoutAddCallbackObj(layoutInt,
2899 (nbgl_obj_t *) textArea,
2900 headerDesc->rightText.token,
2901 headerDesc->rightText.tuneId);
2902 if (obj == NULL) {
2904 "nbgl_layoutAddHeader(): no more callback obj for type %d\n",
2905 headerDesc->type);
2906 return -1;
2907 }
2908 textArea->obj.alignment = MID_RIGHT;
2909 textArea->obj.alignmentMarginX = BORDER_MARGIN;
2910 textArea->textColor = BLACK;
2911 textArea->obj.area.width = AVAILABLE_WIDTH;
2912 textArea->obj.area.height = TOUCHABLE_HEADER_BAR_HEIGHT;
2913 textArea->text = PIC(headerDesc->rightText.text);
2914 textArea->fontId = SMALL_BOLD_FONT;
2915 textArea->textAlignment = MID_RIGHT;
2916 textArea->obj.touchMask = (1 << TOUCHED);
2917 textArea->obj.touchId = TOP_RIGHT_BUTTON_ID;
2918 // add to bottom container
2919 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2920 = (nbgl_obj_t *) textArea;
2921 layoutInt->headerContainer->nbChildren++;
2922 layoutInt->headerContainer->obj.area.height = textArea->obj.area.height;
2923 break;
2924 }
2925 default:
2926 return -2;
2927 }
2928 // draw separation line at bottom of container
2929 if (headerDesc->separationLine) {
2930 line = createHorizontalLine(layoutInt->layer);
2931 line->obj.alignment = BOTTOM_MIDDLE;
2932 layoutInt->headerContainer->children[layoutInt->headerContainer->nbChildren]
2933 = (nbgl_obj_t *) line;
2934 layoutInt->headerContainer->nbChildren++;
2935 }
2936 // header must be the first child
2937 layoutInt->children[HEADER_INDEX] = (nbgl_obj_t *) layoutInt->headerContainer;
2938
2939 // subtract header height from main container height
2940 layoutInt->container->obj.area.height -= layoutInt->headerContainer->obj.area.height;
2941 layoutInt->container->obj.alignTo = (nbgl_obj_t *) layoutInt->headerContainer;
2942 layoutInt->container->obj.alignment = BOTTOM_LEFT;
2943
2944 layoutInt->headerType = headerDesc->type;
2945
2946 return layoutInt->headerContainer->obj.area.height;
2947}
2948
2957int nbgl_layoutAddExtendedFooter(nbgl_layout_t *layout, const nbgl_layoutFooter_t *footerDesc)
2958{
2959 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
2960 layoutObj_t *obj;
2961 nbgl_text_area_t *textArea;
2962 nbgl_line_t *line, *separationLine = NULL;
2963 nbgl_button_t *button;
2964
2965 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddExtendedFooter():\n");
2966 if (layout == NULL) {
2967 return -1;
2968 }
2969 if ((footerDesc == NULL) || (footerDesc->type >= NB_FOOTER_TYPES)) {
2970 return -2;
2971 }
2972
2973 layoutInt->footerContainer = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
2974 layoutInt->footerContainer->obj.area.width = SCREEN_WIDTH;
2975 layoutInt->footerContainer->layout = VERTICAL;
2976 layoutInt->footerContainer->children
2977 = (nbgl_obj_t **) nbgl_containerPoolGet(5, layoutInt->layer);
2978 layoutInt->footerContainer->obj.alignment = BOTTOM_MIDDLE;
2979
2980 switch (footerDesc->type) {
2981 case FOOTER_EMPTY: {
2982 layoutInt->footerContainer->obj.area.height = footerDesc->emptySpace.height;
2983 break;
2984 }
2985 case FOOTER_SIMPLE_TEXT: {
2986 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
2987 obj = layoutAddCallbackObj(layoutInt,
2988 (nbgl_obj_t *) textArea,
2989 footerDesc->simpleText.token,
2990 footerDesc->simpleText.tuneId);
2991 if (obj == NULL) {
2992 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddFooter(): no more callback obj\n");
2993 return -1;
2994 }
2995
2996 textArea->obj.alignment = BOTTOM_MIDDLE;
2997 textArea->textColor = (footerDesc->simpleText.mutedOut) ? LIGHT_TEXT_COLOR : BLACK;
2998 textArea->obj.area.width = AVAILABLE_WIDTH;
2999 textArea->obj.area.height
3000 = (footerDesc->simpleText.mutedOut) ? SMALL_FOOTER_HEIGHT : SIMPLE_FOOTER_HEIGHT;
3001 textArea->text = PIC(footerDesc->simpleText.text);
3002 textArea->fontId
3003 = (footerDesc->simpleText.mutedOut) ? SMALL_REGULAR_FONT : SMALL_BOLD_FONT;
3004 textArea->textAlignment = CENTER;
3005 textArea->obj.touchMask = (1 << TOUCHED);
3006 textArea->obj.touchId = BOTTOM_BUTTON_ID;
3007 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3008 = (nbgl_obj_t *) textArea;
3009 layoutInt->footerContainer->nbChildren++;
3010 layoutInt->footerContainer->obj.area.height = textArea->obj.area.height;
3011 break;
3012 }
3013 case FOOTER_DOUBLE_TEXT: {
3014 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
3015 obj = layoutAddCallbackObj(layoutInt,
3016 (nbgl_obj_t *) textArea,
3017 footerDesc->doubleText.leftToken,
3018 footerDesc->doubleText.tuneId);
3019 if (obj == NULL) {
3020 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddFooter(): no more callback obj\n");
3021 return -1;
3022 }
3023 textArea->obj.alignment = BOTTOM_LEFT;
3024 textArea->textColor = BLACK;
3025 textArea->obj.area.width = AVAILABLE_WIDTH / 2;
3026 textArea->obj.area.height = SIMPLE_FOOTER_HEIGHT;
3027 textArea->text = PIC(footerDesc->doubleText.leftText);
3028 textArea->fontId = SMALL_BOLD_FONT;
3029 textArea->textAlignment = CENTER;
3030 textArea->obj.touchMask = (1 << TOUCHED);
3031 textArea->obj.touchId = BOTTOM_BUTTON_ID;
3032 // add to bottom container
3033 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3034 = (nbgl_obj_t *) textArea;
3035 layoutInt->footerContainer->nbChildren++;
3036
3037 // create right touchable text
3038 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
3039 obj = layoutAddCallbackObj(layoutInt,
3040 (nbgl_obj_t *) textArea,
3041 footerDesc->doubleText.rightToken,
3042 footerDesc->doubleText.tuneId);
3043 if (obj == NULL) {
3044 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddFooter(): no more callback obj\n");
3045 return -1;
3046 }
3047
3048 textArea->obj.alignment = BOTTOM_RIGHT;
3049 textArea->textColor = BLACK;
3050 textArea->obj.area.width = AVAILABLE_WIDTH / 2;
3051 textArea->obj.area.height = SIMPLE_FOOTER_HEIGHT;
3052 textArea->text = PIC(footerDesc->doubleText.rightText);
3053 textArea->fontId = SMALL_BOLD_FONT;
3054 textArea->textAlignment = CENTER;
3055 textArea->obj.touchMask = (1 << TOUCHED);
3056 textArea->obj.touchId = RIGHT_BUTTON_ID;
3057 // add to bottom container
3058 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3059 = (nbgl_obj_t *) textArea;
3060 layoutInt->footerContainer->nbChildren++;
3061 layoutInt->footerContainer->obj.area.height = textArea->obj.area.height;
3062
3063 // create vertical line separating texts
3064 separationLine = (nbgl_line_t *) nbgl_objPoolGet(LINE, layoutInt->layer);
3065 separationLine->lineColor = LIGHT_GRAY;
3066 separationLine->obj.area.width = 1;
3067 separationLine->obj.area.height = layoutInt->footerContainer->obj.area.height;
3068 separationLine->direction = VERTICAL;
3069 separationLine->thickness = 1;
3070 separationLine->obj.alignment = MID_LEFT;
3071 separationLine->obj.alignTo = (nbgl_obj_t *) textArea;
3072 separationLine->obj.alignmentMarginX = -1;
3073 break;
3074 }
3075 case FOOTER_TEXT_AND_NAV: {
3076 layoutInt->footerContainer->obj.area.height = SIMPLE_FOOTER_HEIGHT;
3077 // add touchable text on the left
3078 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
3079 obj = layoutAddCallbackObj(layoutInt,
3080 (nbgl_obj_t *) textArea,
3081 footerDesc->textAndNav.token,
3082 footerDesc->textAndNav.tuneId);
3083 if (obj == NULL) {
3084 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddFooter(): no more callback obj\n");
3085 return -1;
3086 }
3087 textArea->obj.alignment = BOTTOM_LEFT;
3088 textArea->textColor = BLACK;
3089 textArea->obj.area.width = FOOTER_TEXT_AND_NAV_WIDTH;
3090 textArea->obj.area.height = SIMPLE_FOOTER_HEIGHT;
3091 textArea->text = PIC(footerDesc->textAndNav.text);
3092 textArea->fontId = SMALL_BOLD_FONT;
3093 textArea->textAlignment = CENTER;
3094 textArea->obj.touchMask = (1 << TOUCHED);
3095 textArea->obj.touchId = BOTTOM_BUTTON_ID;
3096 // add to bottom container
3097 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3098 = (nbgl_obj_t *) textArea;
3099 layoutInt->footerContainer->nbChildren++;
3100
3101 // add navigation on the right
3102 nbgl_container_t *navContainer
3104 navContainer->obj.area.width = AVAILABLE_WIDTH;
3105 navContainer->layout = VERTICAL;
3106 navContainer->nbChildren = 4;
3107 navContainer->children
3108 = (nbgl_obj_t **) nbgl_containerPoolGet(navContainer->nbChildren, layoutInt->layer);
3109 navContainer->obj.alignment = BOTTOM_RIGHT;
3110 navContainer->obj.area.width = SCREEN_WIDTH - textArea->obj.area.width;
3111 navContainer->obj.area.height = SIMPLE_FOOTER_HEIGHT;
3112 layoutNavigationPopulate(navContainer, &footerDesc->navigation, layoutInt->layer);
3113 obj = layoutAddCallbackObj(layoutInt,
3114 (nbgl_obj_t *) navContainer,
3115 footerDesc->textAndNav.navigation.token,
3116 footerDesc->textAndNav.navigation.tuneId);
3117 if (obj == NULL) {
3118 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddFooter(): no more callback obj\n");
3119 return -1;
3120 }
3121
3122 // create vertical line separating text from nav
3123 separationLine = (nbgl_line_t *) nbgl_objPoolGet(LINE, layoutInt->layer);
3124 separationLine->lineColor = LIGHT_GRAY;
3125 separationLine->obj.area.width = 1;
3126 separationLine->obj.area.height = layoutInt->footerContainer->obj.area.height;
3127 separationLine->direction = VERTICAL;
3128 separationLine->thickness = 1;
3129 separationLine->obj.alignment = MID_LEFT;
3130 separationLine->obj.alignTo = (nbgl_obj_t *) navContainer;
3131 separationLine->obj.alignmentMarginX = -1;
3132
3133 layoutInt->activePage = footerDesc->textAndNav.navigation.activePage;
3134 layoutInt->nbPages = footerDesc->textAndNav.navigation.nbPages;
3135 // add to bottom container
3136 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3137 = (nbgl_obj_t *) navContainer;
3138 layoutInt->footerContainer->nbChildren++;
3139 break;
3140 }
3141 case FOOTER_NAV: {
3142 layoutInt->footerContainer->obj.area.height = SIMPLE_FOOTER_HEIGHT;
3144 layoutInt->footerContainer, &footerDesc->navigation, layoutInt->layer);
3145 layoutInt->footerContainer->nbChildren = 4;
3146 obj = layoutAddCallbackObj(layoutInt,
3147 (nbgl_obj_t *) layoutInt->footerContainer,
3148 footerDesc->navigation.token,
3149 footerDesc->navigation.tuneId);
3150 if (obj == NULL) {
3151 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddFooter(): no more callback obj\n");
3152 return -1;
3153 }
3154
3155 layoutInt->activePage = footerDesc->navigation.activePage;
3156 layoutInt->nbPages = footerDesc->navigation.nbPages;
3157 break;
3158 }
3159 case FOOTER_SIMPLE_BUTTON: {
3160 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
3161 obj = layoutAddCallbackObj(layoutInt,
3162 (nbgl_obj_t *) button,
3163 footerDesc->button.token,
3164 footerDesc->button.tuneId);
3165 if (obj == NULL) {
3166 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddFooter(): no more callback obj\n");
3167 return -1;
3168 }
3169
3170 button->obj.alignment = BOTTOM_MIDDLE;
3171 button->obj.alignmentMarginY = SINGLE_BUTTON_MARGIN;
3172 if (footerDesc->button.style == BLACK_BACKGROUND) {
3173 button->innerColor = BLACK;
3174 button->foregroundColor = WHITE;
3175 }
3176 else {
3177 button->innerColor = WHITE;
3178 button->foregroundColor = BLACK;
3179 }
3180
3181 if (footerDesc->button.style == NO_BORDER) {
3182 button->borderColor = WHITE;
3183 }
3184 else {
3185 if (footerDesc->button.style == BLACK_BACKGROUND) {
3186 button->borderColor = BLACK;
3187 }
3188 else {
3189 button->borderColor = LIGHT_GRAY;
3190 }
3191 }
3192 button->text = PIC(footerDesc->button.text);
3193 button->fontId = SMALL_BOLD_FONT;
3194 button->icon = PIC(footerDesc->button.icon);
3195 button->radius = BUTTON_RADIUS;
3196 button->obj.area.height = BUTTON_DIAMETER;
3197 layoutInt->footerContainer->obj.area.height = FOOTER_BUTTON_HEIGHT;
3198 if (footerDesc->button.text == NULL) {
3199 button->obj.area.width = BUTTON_DIAMETER;
3200 }
3201 else {
3202 button->obj.area.width = AVAILABLE_WIDTH;
3203 }
3204 button->obj.touchMask = (1 << TOUCHED);
3205 button->obj.touchId = button->text ? SINGLE_BUTTON_ID : BOTTOM_BUTTON_ID;
3206 // add to bottom container
3207 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3208 = (nbgl_obj_t *) button;
3209 layoutInt->footerContainer->nbChildren++;
3210 break;
3211 }
3212 case FOOTER_CHOICE_BUTTONS: {
3213 // texts cannot be NULL
3214 if ((footerDesc->choiceButtons.bottomText == NULL)
3215 || (footerDesc->choiceButtons.topText == NULL)) {
3217 "nbgl_layoutAddFooter(): FOOTER_CHOICE_BUTTONS texts cannot be NULL\n");
3218 return -1;
3219 }
3220
3221 // create bottom button (footer) at first
3222 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
3223 obj = layoutAddCallbackObj(layoutInt,
3224 (nbgl_obj_t *) button,
3225 footerDesc->choiceButtons.token,
3226 footerDesc->choiceButtons.tuneId);
3227 if (obj == NULL) {
3228 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddFooter(): no more callback obj\n");
3229 return -1;
3230 }
3231 // associate with with index 1
3232 obj->index = 1;
3233 // put at the bottom of the container
3234 button->obj.alignment = BOTTOM_MIDDLE;
3235 button->innerColor = WHITE;
3236 if (footerDesc->choiceButtons.style == BOTH_ROUNDED_STYLE) {
3237 button->obj.alignmentMarginY
3238 = SINGLE_BUTTON_MARGIN; // pixels from bottom of container
3239 button->borderColor = LIGHT_GRAY;
3240 button->obj.area.height = BUTTON_DIAMETER;
3241 }
3242 else {
3243 button->obj.alignmentMarginY
3244 = BUTTON_FROM_BOTTOM_MARGIN; // pixels from screen bottom
3245 button->borderColor = WHITE;
3246 button->obj.area.height = FOOTER_IN_PAIR_HEIGHT;
3247 }
3248 button->foregroundColor = BLACK;
3249 button->obj.area.width = AVAILABLE_WIDTH;
3250 button->radius = BUTTON_RADIUS;
3251 button->text = PIC(footerDesc->choiceButtons.bottomText);
3252 button->fontId = SMALL_BOLD_FONT;
3253 button->obj.touchMask = (1 << TOUCHED);
3254 button->obj.touchId = CHOICE_2_ID;
3255 // add to bottom container
3256 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3257 = (nbgl_obj_t *) button;
3258 layoutInt->footerContainer->nbChildren++;
3259
3260 // add line if needed
3261 if ((footerDesc->choiceButtons.style != ROUNDED_AND_FOOTER_STYLE)
3262 && (footerDesc->choiceButtons.style != BOTH_ROUNDED_STYLE)) {
3263 line = createHorizontalLine(layoutInt->layer);
3264 line->obj.alignment = TOP_MIDDLE;
3265 line->obj.alignTo = (nbgl_obj_t *) button;
3266 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3267 = (nbgl_obj_t *) line;
3268 layoutInt->footerContainer->nbChildren++;
3269 }
3270
3271 // then top button, on top of it
3272 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
3273 obj = layoutAddCallbackObj(layoutInt,
3274 (nbgl_obj_t *) button,
3275 footerDesc->choiceButtons.token,
3276 footerDesc->choiceButtons.tuneId);
3277 if (obj == NULL) {
3278 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddFooter(): no more callback obj\n");
3279 return -1;
3280 }
3281 // associate with with index 0
3282 obj->index = 0;
3283 button->obj.alignment = TOP_MIDDLE;
3284 if (footerDesc->choiceButtons.style == ROUNDED_AND_FOOTER_STYLE) {
3285 button->obj.alignmentMarginY = TOP_BUTTON_MARGIN; // pixels from top of container
3286 }
3287 else if (footerDesc->choiceButtons.style == BOTH_ROUNDED_STYLE) {
3288 button->obj.alignmentMarginY
3289 = SINGLE_BUTTON_MARGIN; // pixels from top of container
3290 }
3291 else {
3292 button->obj.alignmentMarginY
3293 = TOP_BUTTON_MARGIN_WITH_ACTION; // pixels from top of container
3294 }
3295 if (footerDesc->choiceButtons.style == SOFT_ACTION_AND_FOOTER_STYLE) {
3296 button->innerColor = WHITE;
3297 button->borderColor = LIGHT_GRAY;
3298 button->foregroundColor = BLACK;
3299 }
3300 else {
3301 button->innerColor = BLACK;
3302 button->borderColor = BLACK;
3303 button->foregroundColor = WHITE;
3304 }
3305 button->obj.area.width = AVAILABLE_WIDTH;
3306 button->obj.area.height = BUTTON_DIAMETER;
3307 button->radius = BUTTON_RADIUS;
3308 button->text = PIC(footerDesc->choiceButtons.topText);
3309 button->icon = (footerDesc->choiceButtons.style != ROUNDED_AND_FOOTER_STYLE)
3310 ? PIC(footerDesc->choiceButtons.topIcon)
3311 : NULL;
3312 button->fontId = SMALL_BOLD_FONT;
3313 button->obj.touchMask = (1 << TOUCHED);
3314 button->obj.touchId = CHOICE_1_ID;
3315 // add to bottom container
3316 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3317 = (nbgl_obj_t *) button;
3318 layoutInt->footerContainer->nbChildren++;
3319
3320 if (footerDesc->choiceButtons.style == ROUNDED_AND_FOOTER_STYLE) {
3321 layoutInt->footerContainer->obj.area.height = ROUNDED_AND_FOOTER_FOOTER_HEIGHT;
3322 }
3323 else if (footerDesc->choiceButtons.style == BOTH_ROUNDED_STYLE) {
3324 layoutInt->footerContainer->obj.area.height = BOTH_ROUNDED_FOOTER_HEIGHT;
3325 }
3326 else {
3327 layoutInt->footerContainer->obj.area.height = ACTION_AND_FOOTER_FOOTER_HEIGHT;
3328 }
3329
3330 break;
3331 }
3332 default:
3333 return -2;
3334 }
3335
3336 // add swipable feature for navigation
3337 if ((footerDesc->type == FOOTER_NAV) || (footerDesc->type == FOOTER_TEXT_AND_NAV)) {
3338 addSwipeInternal(layoutInt,
3339 ((1 << SWIPED_LEFT) | (1 << SWIPED_RIGHT)),
3341 (footerDesc->type == FOOTER_NAV) ? footerDesc->navigation.token
3342 : footerDesc->textAndNav.navigation.token,
3343 (footerDesc->type == FOOTER_NAV)
3344 ? footerDesc->navigation.tuneId
3345 : footerDesc->textAndNav.navigation.tuneId);
3346 }
3347
3348 if (footerDesc->separationLine) {
3349 line = createHorizontalLine(layoutInt->layer);
3350 line->obj.alignment = TOP_MIDDLE;
3351 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3352 = (nbgl_obj_t *) line;
3353 layoutInt->footerContainer->nbChildren++;
3354 }
3355 if (separationLine != NULL) {
3356 layoutInt->footerContainer->children[layoutInt->footerContainer->nbChildren]
3357 = (nbgl_obj_t *) separationLine;
3358 layoutInt->footerContainer->nbChildren++;
3359 }
3360
3361 layoutInt->children[FOOTER_INDEX] = (nbgl_obj_t *) layoutInt->footerContainer;
3362
3363 // subtract footer height from main container height
3364 layoutInt->container->obj.area.height -= layoutInt->footerContainer->obj.area.height;
3365
3366 layoutInt->footerType = footerDesc->type;
3367
3368 return layoutInt->footerContainer->obj.area.height;
3369}
3370
3379int nbgl_layoutAddUpFooter(nbgl_layout_t *layout, const nbgl_layoutUpFooter_t *upFooterDesc)
3380{
3381 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
3382 layoutObj_t *obj;
3383 nbgl_text_area_t *textArea;
3384 nbgl_line_t *line;
3385 nbgl_button_t *button;
3386
3387 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddUpFooter():\n");
3388 if (layout == NULL) {
3389 return -1;
3390 }
3391 if ((upFooterDesc == NULL) || (upFooterDesc->type >= NB_UP_FOOTER_TYPES)) {
3392 return -2;
3393 }
3394
3395 layoutInt->upFooterContainer
3397 layoutInt->upFooterContainer->obj.area.width = SCREEN_WIDTH;
3398 layoutInt->upFooterContainer->layout = VERTICAL;
3399 // maximum 4 children for long press button
3400 layoutInt->upFooterContainer->children
3401 = (nbgl_obj_t **) nbgl_containerPoolGet(4, layoutInt->layer);
3402 layoutInt->upFooterContainer->obj.alignTo = (nbgl_obj_t *) layoutInt->container;
3403 layoutInt->upFooterContainer->obj.alignment = BOTTOM_MIDDLE;
3404
3405 switch (upFooterDesc->type) {
3406 case UP_FOOTER_LONG_PRESS: {
3407 nbgl_progress_bar_t *progressBar;
3408
3409 obj = layoutAddCallbackObj(layoutInt,
3410 (nbgl_obj_t *) layoutInt->upFooterContainer,
3411 upFooterDesc->longPress.token,
3412 upFooterDesc->longPress.tuneId);
3413 if (obj == NULL) {
3414 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddUpFooter(): no more callback obj\n");
3415 return -1;
3416 }
3417 layoutInt->upFooterContainer->nbChildren = 4;
3418 layoutInt->upFooterContainer->obj.area.height = LONG_PRESS_BUTTON_HEIGHT;
3419 layoutInt->upFooterContainer->obj.touchId = LONG_PRESS_BUTTON_ID;
3420 layoutInt->upFooterContainer->obj.touchMask
3421 = ((1 << TOUCHING) | (1 << TOUCH_RELEASED) | (1 << OUT_OF_TOUCH)
3422 | (1 << SWIPED_LEFT) | (1 << SWIPED_RIGHT));
3423
3424 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
3425 button->obj.alignmentMarginX = BORDER_MARGIN;
3426 button->obj.alignment = MID_RIGHT;
3427 button->innerColor = BLACK;
3428 button->foregroundColor = WHITE;
3429 button->borderColor = BLACK;
3430 button->obj.area.width = BUTTON_DIAMETER;
3431 button->obj.area.height = BUTTON_DIAMETER;
3432 button->radius = BUTTON_RADIUS;
3433 button->icon = PIC(&VALIDATE_ICON);
3434 layoutInt->upFooterContainer->children[0] = (nbgl_obj_t *) button;
3435
3436 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
3437 textArea->textColor = BLACK;
3438 textArea->text = PIC(upFooterDesc->longPress.text);
3439 textArea->textAlignment = MID_LEFT;
3440 textArea->fontId = LARGE_MEDIUM_FONT;
3441 textArea->wrapping = true;
3442 textArea->obj.area.width = SCREEN_WIDTH - 3 * BORDER_MARGIN - button->obj.area.width;
3443 textArea->obj.area.height = nbgl_getTextHeightInWidth(
3444 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
3445 textArea->style = NO_STYLE;
3446 textArea->obj.alignment = MID_LEFT;
3447 textArea->obj.alignmentMarginX = BORDER_MARGIN;
3448 layoutInt->upFooterContainer->children[1] = (nbgl_obj_t *) textArea;
3449
3450 line = createHorizontalLine(layoutInt->layer);
3451 line->obj.alignment = TOP_MIDDLE;
3452 layoutInt->upFooterContainer->children[2] = (nbgl_obj_t *) line;
3453
3454 progressBar = (nbgl_progress_bar_t *) nbgl_objPoolGet(PROGRESS_BAR, layoutInt->layer);
3455 progressBar->obj.area.width = SCREEN_WIDTH;
3456 progressBar->obj.area.height = LONG_PRESS_PROGRESS_HEIGHT;
3457 progressBar->obj.alignment = TOP_MIDDLE;
3458 progressBar->obj.alignmentMarginY = LONG_PRESS_PROGRESS_ALIGN;
3459 progressBar->resetIfOverriden = true;
3460 progressBar->partialRedraw = true;
3461 layoutInt->upFooterContainer->children[3] = (nbgl_obj_t *) progressBar;
3462 break;
3463 }
3464 case UP_FOOTER_BUTTON: {
3465 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
3466 obj = layoutAddCallbackObj(layoutInt,
3467 (nbgl_obj_t *) button,
3468 upFooterDesc->button.token,
3469 upFooterDesc->button.tuneId);
3470 if (obj == NULL) {
3471 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddUpFooter(): no more callback obj\n");
3472 return -1;
3473 }
3474
3475 layoutInt->upFooterContainer->nbChildren = 1;
3476 layoutInt->upFooterContainer->obj.area.height = UP_FOOTER_BUTTON_HEIGHT;
3477 button->obj.alignment = CENTER;
3478
3479 if (upFooterDesc->button.style == BLACK_BACKGROUND) {
3480 button->innerColor = BLACK;
3481 button->foregroundColor = WHITE;
3482 }
3483 else {
3484 button->innerColor = WHITE;
3485 button->foregroundColor = BLACK;
3486 }
3487 if (upFooterDesc->button.style == NO_BORDER) {
3488 button->borderColor = WHITE;
3489 }
3490 else {
3491 if (upFooterDesc->button.style == BLACK_BACKGROUND) {
3492 button->borderColor = BLACK;
3493 }
3494 else {
3495 button->borderColor = LIGHT_GRAY;
3496 }
3497 }
3498 button->text = PIC(upFooterDesc->button.text);
3499 button->fontId = SMALL_BOLD_FONT;
3500 button->icon = PIC(upFooterDesc->button.icon);
3501 button->obj.area.width = AVAILABLE_WIDTH;
3502 button->obj.area.height = BUTTON_DIAMETER;
3503 button->radius = BUTTON_RADIUS;
3504
3505 button->obj.alignTo = NULL;
3506 button->obj.touchMask = (1 << TOUCHED);
3507 button->obj.touchId = SINGLE_BUTTON_ID;
3508 layoutInt->upFooterContainer->children[0] = (nbgl_obj_t *) button;
3509 break;
3510 }
3511 case UP_FOOTER_HORIZONTAL_BUTTONS: {
3512 // icon & text cannot be NULL
3513 if ((upFooterDesc->horizontalButtons.leftIcon == NULL)
3514 || (upFooterDesc->horizontalButtons.rightText == NULL)) {
3516 "nbgl_layoutAddUpFooter(): UP_FOOTER_HORIZONTAL_BUTTONS fields cannot be "
3517 "NULL\n");
3518 return -1;
3519 }
3520
3521 layoutInt->upFooterContainer->nbChildren = 2;
3522 layoutInt->upFooterContainer->obj.area.height = UP_FOOTER_BUTTON_HEIGHT;
3523
3524 // create left button (in white) at first
3525 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
3526 obj = layoutAddCallbackObj(layoutInt,
3527 (nbgl_obj_t *) button,
3528 upFooterDesc->horizontalButtons.leftToken,
3529 upFooterDesc->horizontalButtons.tuneId);
3530 if (obj == NULL) {
3531 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddUpFooter(): no more callback obj\n");
3532 return -1;
3533 }
3534 // associate with with index 1
3535 obj->index = 1;
3536 button->obj.alignment = MID_LEFT;
3537 button->obj.alignmentMarginX = BORDER_MARGIN;
3538 button->borderColor = LIGHT_GRAY;
3539 button->innerColor = WHITE;
3540 button->foregroundColor = BLACK;
3541 button->obj.area.width = BUTTON_WIDTH;
3542 button->obj.area.height = BUTTON_DIAMETER;
3543 button->radius = BUTTON_RADIUS;
3544 button->icon = PIC(upFooterDesc->horizontalButtons.leftIcon);
3545 button->fontId = SMALL_BOLD_FONT;
3546 button->obj.touchMask = (1 << TOUCHED);
3547 button->obj.touchId = CHOICE_2_ID;
3548 layoutInt->upFooterContainer->children[0] = (nbgl_obj_t *) button;
3549
3550 // then black button, on right
3551 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layoutInt->layer);
3552 obj = layoutAddCallbackObj(layoutInt,
3553 (nbgl_obj_t *) button,
3554 upFooterDesc->horizontalButtons.rightToken,
3555 upFooterDesc->horizontalButtons.tuneId);
3556 if (obj == NULL) {
3557 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddUpFooter(): no more callback obj\n");
3558 return -1;
3559 }
3560 // associate with with index 0
3561 obj->index = 0;
3562 button->obj.alignment = MID_RIGHT;
3563 button->obj.alignmentMarginX = BORDER_MARGIN;
3564 button->innerColor = BLACK;
3565 button->borderColor = BLACK;
3566 button->foregroundColor = WHITE;
3567 button->obj.area.width = AVAILABLE_WIDTH - BUTTON_WIDTH - LEFT_CONTENT_ICON_TEXT_X;
3568 button->obj.area.height = BUTTON_DIAMETER;
3569 button->radius = BUTTON_RADIUS;
3570 button->text = PIC(upFooterDesc->horizontalButtons.rightText);
3571 button->fontId = SMALL_BOLD_FONT;
3572 button->obj.touchMask = (1 << TOUCHED);
3573 button->obj.touchId = CHOICE_1_ID;
3574 layoutInt->upFooterContainer->children[1] = (nbgl_obj_t *) button;
3575 break;
3576 }
3577 case UP_FOOTER_TIP_BOX: {
3578 // text cannot be NULL
3579 if (upFooterDesc->tipBox.text == NULL) {
3581 "nbgl_layoutAddUpFooter(): UP_FOOTER_TIP_BOX text cannot be NULL\n");
3582 return -1;
3583 }
3584 obj = layoutAddCallbackObj(layoutInt,
3585 (nbgl_obj_t *) layoutInt->upFooterContainer,
3586 upFooterDesc->tipBox.token,
3587 upFooterDesc->tipBox.tuneId);
3588 if (obj == NULL) {
3589 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddUpFooter(): no more callback obj\n");
3590 return -1;
3591 }
3592 layoutInt->upFooterContainer->nbChildren = 3;
3593 layoutInt->upFooterContainer->obj.touchId = TIP_BOX_ID;
3594 layoutInt->upFooterContainer->obj.touchMask = (1 << TOUCHED);
3595
3596 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
3597 textArea->textColor = BLACK;
3598 textArea->text = PIC(upFooterDesc->tipBox.text);
3599 textArea->textAlignment = MID_LEFT;
3600 textArea->fontId = SMALL_REGULAR_FONT;
3601 textArea->wrapping = true;
3602 textArea->obj.area.width = AVAILABLE_WIDTH;
3603 if (upFooterDesc->tipBox.icon != NULL) {
3604 textArea->obj.area.width
3605 -= ((nbgl_icon_details_t *) PIC(upFooterDesc->tipBox.icon))->width
3606 + TIP_BOX_TEXT_ICON_MARGIN;
3607 }
3608 textArea->obj.area.height = nbgl_getTextHeightInWidth(
3609 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
3610 textArea->obj.alignment = MID_LEFT;
3611 textArea->obj.alignmentMarginX = BORDER_MARGIN;
3612 layoutInt->upFooterContainer->children[0] = (nbgl_obj_t *) textArea;
3613 layoutInt->upFooterContainer->obj.area.height = textArea->obj.area.height;
3614
3615 line = createHorizontalLine(layoutInt->layer);
3616 line->obj.alignment = TOP_MIDDLE;
3617 layoutInt->upFooterContainer->children[1] = (nbgl_obj_t *) line;
3618
3619 if (upFooterDesc->tipBox.icon != NULL) {
3620 nbgl_image_t *image = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, layoutInt->layer);
3621 image->obj.alignmentMarginX = BORDER_MARGIN;
3622 image->obj.alignment = MID_RIGHT;
3623 image->foregroundColor = BLACK;
3624 image->buffer = PIC(upFooterDesc->tipBox.icon);
3625 layoutInt->upFooterContainer->children[2] = (nbgl_obj_t *) image;
3626 if (layoutInt->upFooterContainer->obj.area.height < image->buffer->height) {
3627 layoutInt->upFooterContainer->obj.area.height = image->buffer->height;
3628 }
3629 }
3630 layoutInt->upFooterContainer->obj.area.height += 2 * TIP_BOX_MARGIN_Y;
3631
3632 break;
3633 }
3634 case UP_FOOTER_TEXT: {
3635 obj = layoutAddCallbackObj(layoutInt,
3636 (nbgl_obj_t *) layoutInt->upFooterContainer,
3637 upFooterDesc->text.token,
3638 upFooterDesc->text.tuneId);
3639 if (obj == NULL) {
3640 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutAddUpFooter(): no more callback obj\n");
3641 return -1;
3642 }
3643 layoutInt->upFooterContainer->nbChildren = 1;
3644 layoutInt->upFooterContainer->obj.area.height = SMALL_FOOTER_HEIGHT;
3645 layoutInt->upFooterContainer->obj.touchId = WHOLE_SCREEN_ID;
3646 layoutInt->upFooterContainer->obj.touchMask = (1 << TOUCHED);
3647
3648 // only create text_area if text is not empty
3649 if (strlen(PIC(upFooterDesc->text.text))) {
3650 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
3651 textArea->textColor = LIGHT_TEXT_COLOR;
3652 textArea->text = PIC(upFooterDesc->text.text);
3653 textArea->textAlignment = CENTER;
3654 textArea->fontId = SMALL_REGULAR_FONT;
3655 textArea->wrapping = true;
3656 textArea->obj.area.width = AVAILABLE_WIDTH;
3657 textArea->obj.area.height = nbgl_getTextHeightInWidth(
3658 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
3659 textArea->obj.alignment = CENTER;
3660 layoutInt->upFooterContainer->children[0] = (nbgl_obj_t *) textArea;
3661 }
3662 break;
3663 }
3664 default:
3665 return -2;
3666 }
3667
3668 // subtract up footer height from main container height
3669 layoutInt->container->obj.area.height -= layoutInt->upFooterContainer->obj.area.height;
3670
3671 layoutInt->children[UP_FOOTER_INDEX] = (nbgl_obj_t *) layoutInt->upFooterContainer;
3672
3673 layoutInt->upFooterType = upFooterDesc->type;
3674
3675 return layoutInt->upFooterContainer->obj.area.height;
3676}
3677
3691int nbgl_layoutAddProgressIndicator(nbgl_layout_t *layout,
3692 uint8_t activePage,
3693 uint8_t nbPages,
3694 bool withBack,
3695 uint8_t backToken,
3696 tune_index_e tuneId)
3697{
3698 nbgl_layoutHeader_t headerDesc = {.type = HEADER_BACK_AND_PROGRESS,
3699 .separationLine = false,
3700 .progressAndBack.activePage = activePage,
3701 .progressAndBack.nbPages = nbPages,
3702 .progressAndBack.token = backToken,
3703 .progressAndBack.tuneId = tuneId,
3704 .progressAndBack.withBack = withBack,
3705 .progressAndBack.actionIcon = NULL,
3706 .progressAndBack.actionToken = NBGL_INVALID_TOKEN};
3707 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddProgressIndicator():\n");
3708
3709 return nbgl_layoutAddHeader(layout, &headerDesc);
3710}
3711
3722int nbgl_layoutAddSpinner(nbgl_layout_t *layout,
3723 const char *text,
3724 const char *subText,
3725 uint8_t initPosition)
3726{
3727 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
3728 nbgl_container_t *container;
3729 nbgl_text_area_t *textArea;
3730 nbgl_spinner_t *spinner;
3731
3732 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddSpinner():\n");
3733 if (layout == NULL) {
3734 return -1;
3735 }
3736
3737 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
3738 // spinner + text + subText
3739 container->nbChildren = 3;
3740 container->children = nbgl_containerPoolGet(container->nbChildren, layoutInt->layer);
3741
3742 container->obj.area.width = AVAILABLE_WIDTH;
3743 container->layout = VERTICAL;
3744 container->obj.alignment = CENTER;
3745
3746 // create spinner
3747 spinner = (nbgl_spinner_t *) nbgl_objPoolGet(SPINNER, layoutInt->layer);
3748 spinner->position = initPosition;
3749 spinner->obj.alignment = TOP_MIDDLE;
3750 // set this new spinner as child of the container
3751 container->children[0] = (nbgl_obj_t *) spinner;
3752
3753 // update container height
3754 container->obj.area.height += SPINNER_HEIGHT;
3755
3756 // create text area
3757 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
3758 textArea->textColor = BLACK;
3759 textArea->text = PIC(text);
3760 textArea->textAlignment = CENTER;
3761 textArea->fontId = (subText != NULL) ? LARGE_MEDIUM_FONT : SMALL_REGULAR_FONT;
3762 textArea->wrapping = true;
3763 textArea->obj.alignmentMarginY = SPINNER_TEXT_MARGIN;
3764 textArea->obj.alignTo = (nbgl_obj_t *) spinner;
3765 textArea->obj.alignment = BOTTOM_MIDDLE;
3766 textArea->obj.area.width = AVAILABLE_WIDTH;
3767 textArea->obj.area.height = nbgl_getTextHeightInWidth(
3768 textArea->fontId, textArea->text, textArea->obj.area.width, textArea->wrapping);
3769 textArea->style = NO_STYLE;
3770
3771 // update container height
3772 container->obj.area.height += textArea->obj.alignmentMarginY + textArea->obj.area.height;
3773
3774 // set this text as child of the container
3775 container->children[1] = (nbgl_obj_t *) textArea;
3776
3777 if (subText != NULL) {
3778 nbgl_text_area_t *subTextArea;
3779 // create sub-text area
3780 subTextArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
3781 subTextArea->textColor = BLACK;
3782 subTextArea->text = PIC(subText);
3783 subTextArea->textAlignment = CENTER;
3784 subTextArea->fontId = SMALL_REGULAR_FONT;
3785 subTextArea->wrapping = true;
3786 subTextArea->obj.alignmentMarginY = SPINNER_INTER_TEXTS_MARGIN;
3787 subTextArea->obj.alignTo = (nbgl_obj_t *) textArea;
3788 subTextArea->obj.alignment = BOTTOM_MIDDLE;
3789 subTextArea->obj.area.width = AVAILABLE_WIDTH;
3790 subTextArea->obj.area.height = nbgl_getTextHeightInWidth(subTextArea->fontId,
3791 subTextArea->text,
3792 subTextArea->obj.area.width,
3793 subTextArea->wrapping);
3794 subTextArea->style = NO_STYLE;
3795
3796 // update container height
3797 container->obj.area.height
3798 += subTextArea->obj.alignmentMarginY + subTextArea->obj.area.height;
3799
3800 // set thissub-text as child of the container
3801 container->children[2] = (nbgl_obj_t *) subTextArea;
3802 }
3803 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
3804
3805 if (initPosition != SPINNER_FIXED) {
3806 // update ticker to update the spinner periodically
3807 nbgl_screenTickerConfiguration_t tickerCfg = {0};
3808
3809 tickerCfg.tickerIntervale = SPINNER_REFRESH_PERIOD; // ms
3810 tickerCfg.tickerValue = SPINNER_REFRESH_PERIOD; // ms
3811 tickerCfg.tickerCallback = &spinnerTickerCallback;
3812 nbgl_screenUpdateTicker(layoutInt->layer, &tickerCfg);
3813 }
3814
3815 return 0;
3816}
3817
3829int nbgl_layoutUpdateSpinner(nbgl_layout_t *layout,
3830 const char *text,
3831 const char *subText,
3832 uint8_t position)
3833{
3834 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
3835 nbgl_container_t *container;
3836 nbgl_text_area_t *textArea;
3837 nbgl_spinner_t *spinner;
3838 int ret = 0;
3839
3840 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutUpdateSpinner():\n");
3841 if ((layout == NULL) || (layoutInt->container->nbChildren == 0)) {
3842 return -1;
3843 }
3844
3845 container = (nbgl_container_t *) layoutInt->container->children[0];
3846 if ((container->obj.type != CONTAINER) || (container->nbChildren < 2)) {
3847 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutUpdateSpinner(): unexpected container state\n");
3848 return -1;
3849 }
3850
3851 spinner = (nbgl_spinner_t *) container->children[0];
3852 if (spinner->obj.type != SPINNER) {
3854 "nbgl_layoutUpdateSpinner(): expected SPINNER, got type %d\n",
3855 spinner->obj.type);
3856 return -1;
3857 }
3858 // if position is different, redraw
3859 if (spinner->position != position) {
3860 spinner->position = position;
3861 nbgl_objDraw((nbgl_obj_t *) spinner);
3862 ret = 1;
3863 }
3864
3865 // update text area if necessary
3866 textArea = (nbgl_text_area_t *) container->children[1];
3867 if (textArea->obj.type != TEXT_AREA) {
3869 "nbgl_layoutUpdateSpinner(): expected TEXT_AREA, got type %d\n",
3870 textArea->obj.type);
3871 return -1;
3872 }
3873 const char *newText = PIC(text);
3874 size_t newTextLen = strlen(newText);
3875 // if text is different, redraw (don't use strcmp because it crashes with Rust SDK)
3876 if ((newTextLen != strlen(textArea->text)) || memcmp(textArea->text, newText, newTextLen)) {
3877 textArea->text = newText;
3878 nbgl_objDraw((nbgl_obj_t *) textArea);
3879 ret = 2;
3880 }
3881
3882 if (subText != NULL) {
3883 nbgl_text_area_t *subTextArea;
3884
3885 if (container->nbChildren != 3) {
3887 "nbgl_layoutUpdateSpinner(): expected 3 children for subText, got %d\n",
3888 container->nbChildren);
3889 return -1;
3890 }
3891 subTextArea = (nbgl_text_area_t *) container->children[2];
3892 if (subTextArea->obj.type != TEXT_AREA) {
3894 "nbgl_layoutUpdateSpinner(): expected TEXT_AREA for subText, got type %d\n",
3895 subTextArea->obj.type);
3896 return -1;
3897 }
3898 const char *newSubText = PIC(subText);
3899 size_t newSubTextLen = strlen(newSubText);
3900 // if text is different, redraw
3901 if ((newSubTextLen != strlen(subTextArea->text))
3902 || memcmp(subTextArea->text, newSubText, newSubTextLen)) {
3903 subTextArea->text = newSubText;
3904 nbgl_objDraw((nbgl_obj_t *) subTextArea);
3905 ret = 2;
3906 }
3907 }
3908
3909 return ret;
3910}
3911
3918int nbgl_layoutDraw(nbgl_layout_t *layoutParam)
3919{
3920 nbgl_layoutInternal_t *layout = (nbgl_layoutInternal_t *) layoutParam;
3921
3922 if (layout == NULL) {
3923 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutDraw(): layout is NULL\n");
3924 return -1;
3925 }
3926 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutDraw(): layout->isUsed = %d\n", layout->isUsed);
3927 if (layout->tapText) {
3928 // set this new container as child of main container
3929 layoutAddObject(layout, (nbgl_obj_t *) layout->tapText);
3930 }
3931#ifdef TARGET_STAX
3932 if (layout->withLeftBorder == true) {
3933 // draw now the line
3934 nbgl_line_t *line = createLeftVerticalLine(layout->layer);
3935 layout->children[LEFT_BORDER_INDEX] = (nbgl_obj_t *) line;
3936 }
3937#endif // TARGET_STAX
3939
3940 return 0;
3941}
3942
3949int nbgl_layoutRelease(nbgl_layout_t *layoutParam)
3950{
3951 nbgl_layoutInternal_t *layout = (nbgl_layoutInternal_t *) layoutParam;
3952 LOG_DEBUG(PAGE_LOGGER, "nbgl_layoutRelease(): \n");
3953 if ((layout == NULL) || (!layout->isUsed)) {
3954 return -1;
3955 }
3956 // if modal
3957 if (layout->modal) {
3958 nbgl_screenPop(layout->layer);
3959 // if this layout was on top, use its bottom layout as top
3960 if (layout == topLayout) {
3961 topLayout = layout->bottom;
3962 topLayout->top = NULL;
3963 }
3964 else {
3965 // otherwise connect top to bottom
3966 layout->bottom->top = layout->top;
3967 layout->top->bottom = layout->bottom;
3968 }
3969 }
3970 layout->isUsed = false;
3971 return 0;
3972}
3973
3974#endif // HAVE_SE_TOUCH
Random Number Generation.
@ ANIM_ILLUSTRATION
animation
@ ICON_ILLUSTRATION
simple icon
debug traces management
#define LOG_WARN(__logger,...)
Definition nbgl_debug.h:89
@ LAYOUT_LOGGER
Definition nbgl_debug.h:35
@ PAGE_LOGGER
Definition nbgl_debug.h:36
#define LOG_DEBUG(__logger,...)
Definition nbgl_debug.h:88
#define LOG_FATAL(__logger,...)
Definition nbgl_debug.h:90
Middle Level API of the new BOLOS Graphical Library.
#define QR_V10_NB_PIX_SIZE
Definition nbgl_draw.h:26
#define QR_V4_NB_PIX_SIZE
Definition nbgl_draw.h:25
uint16_t nbgl_getSingleLineTextWidth(nbgl_font_id_e fontId, const char *text)
nbgl_font_id_e
Definition nbgl_fonts.h:143
uint8_t nbgl_getFontHeight(nbgl_font_id_e fontId)
uint16_t nbgl_getTextWidth(nbgl_font_id_e fontId, const char *text)
uint16_t nbgl_getTextHeightInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
const nbgl_font_t * nbgl_getFont(nbgl_font_id_e fontId)
uint8_t nbgl_getFontLineHeight(nbgl_font_id_e fontId)
Font screen low-Level driver API, to draw elementary forms.
#define VALIDATE_ICON
Definition nbgl_icons.h:216
int nbgl_layoutAddContentCenter(nbgl_layout_t *layout, const nbgl_contentCenter_t *info)
nbgl_contentRadioChoice_t nbgl_layoutRadioChoice_t
Deprecated, kept for retro compatibility.
int nbgl_layoutAddCenteredInfo(nbgl_layout_t *layout, const nbgl_layoutCenteredInfo_t *info)
Creates an area on the center of the main panel, with a possible icon/image, a possible text in black...
int nbgl_layoutAddText(nbgl_layout_t *layout, const char *text, const char *subText, nbgl_contentCenteredInfoStyle_t style)
Creates an area with given text and sub text, using the given style.
nbgl_contentSwitch_t nbgl_layoutSwitch_t
Deprecated, kept for retro compatibility.
int nbgl_layoutAddProgressBar(nbgl_layout_t *layout, const nbgl_layoutProgressBar_t *barLayout)
Creates an area in main panel to display a progress bar, with a title text and a description under th...
int nbgl_layoutDraw(nbgl_layout_t *layout)
Applies given layout. The screen will be redrawn.
@ WHITE_BACKGROUND
rounded bordered button, with text/icon in black, on white background
#define AVAILABLE_WIDTH
void * nbgl_layout_t
type shared externally
int nbgl_layoutAddSwitch(nbgl_layout_t *layout, const nbgl_layoutSwitch_t *switchLayout)
Creates an area in main panel to display a switch.
#define NBGL_INVALID_TOKEN
Definition nbgl_layout.h:32
int nbgl_layoutAddButton(nbgl_layout_t *layout, const nbgl_layoutButton_t *buttonInfo)
Creates an area in main panel to display a button, with the given style.
nbgl_layout_t * nbgl_layoutGet(const nbgl_layoutDescription_t *description)
returns a layout of the given type. The layout is reset
int nbgl_layoutAddLeftContent(nbgl_layout_t *layout, const nbgl_layoutLeftContent_t *info)
#define SPINNER_FIXED
position to use for a "fixed" spinner
#define NBGL_NO_PROGRESS_INDICATOR
To be used when a control token shall not be used.
Definition nbgl_layout.h:29
struct nbgl_layoutDescription_s nbgl_layoutDescription_t
Structure containing all information when creating a layout. This structure must be passed as argumen...
int nbgl_layoutRelease(nbgl_layout_t *layout)
Release the layout obtained with nbgl_layoutGet().
nbgl_contentTagValueList_t nbgl_layoutTagValueList_t
Deprecated, kept for retro compatibility.
nbgl_contentTagValue_t nbgl_layoutTagValue_t
Deprecated, kept for retro compatibility.
nbgl_contentCenteredInfo_t nbgl_layoutCenteredInfo_t
Deprecated, kept for retro compatibility.
Internal functions/constants of NBGL layout layer.
nbgl_swipe_usage_t
@ SWIPE_USAGE_CUSTOM
@ SWIPE_USAGE_SUGGESTIONS
@ SWIPE_USAGE_NAVIGATION
@ UP_FOOTER_INDEX
@ FOOTER_INDEX
@ HEADER_INDEX
@ TOP_RIGHT_BUTTON_INDEX
@ MAIN_CONTAINER_INDEX
@ LEFT_BORDER_INDEX
static nbgl_font_id_e layoutGetTagValueFont(bool smallCaseForValue)
returns the font used to display the values of a list of tag/value pairs
void layoutNavigationPopulate(nbgl_container_t *navContainer, const nbgl_layoutNavigationBar_t *navConfig, uint8_t layer)
static uint8_t layoutGetTagValueMaxLines(uint8_t listMaxLines, const nbgl_contentTagValue_t *pair, bool *forceEllipsis)
returns the max number of lines of the value of the given tag/value pair, which is the smallest non-z...
static uint16_t layoutGetTagValueWidth(const nbgl_icon_details_t *icon)
returns the width of the value of a tag/value pair. Shared by the layout and the use cases,...
bool keyboardSwipeCallback(nbgl_layoutInternal_t *layoutInt, nbgl_obj_t *obj, nbgl_touchType_t eventType)
static const nbgl_icon_details_t * layoutGetTagValueIcon(const nbgl_contentTagValue_t *pair)
returns the icon displayed on the right of the value of the given tag/value pair
void layoutAddObject(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj)
adds the given obj to the layout
void layoutUpdateCallbackObjToken(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj, uint8_t token)
#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)
struct nbgl_layoutInternal_s nbgl_layoutInternal_t
Structure containing all information about the current layout.
layoutObj_t * layoutAddCallbackObj(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj, uint8_t token, tune_index_e tuneId)
#define NB_MAX_SCREEN_CHILDREN
#define NB_MAX_LAYOUTS
static nbgl_layoutInternal_t gLayout[NB_MAX_LAYOUTS]
array of layouts, if used by modal
void(* nbgl_layoutTouchCallback_t)(int token, uint8_t index)
prototype of function to be called when an object is touched
#define NBGL_NO_TUNE
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 LIGHT_TEXT_COLOR
Definition nbgl_obj.h:166
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:235
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)
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)
#define SWIPE_MASK
Definition nbgl_obj.h:183
nbgl_obj_t * nbgl_objPoolGet(nbgl_obj_type_t type, uint8_t layer)
#define INACTIVE_ARROW_COLOR
Definition nbgl_obj.h:164
void nbgl_refreshSpecial(nbgl_refresh_mode_t mode)
struct PACKED__ nbgl_image_s nbgl_image_t
struct to represent an image (IMAGE type)
#define INACTIVE_SMALL_FONT
Definition nbgl_obj.h:165
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:162
#define INACTIVE_TEXT_COLOR
Definition nbgl_obj.h:163
void nbgl_refreshSpecialWithPostRefresh(nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
@ CHOICE_1_ID
Definition nbgl_obj.h:544
@ TOP_RIGHT_BUTTON_ID
Definition nbgl_obj.h:540
@ LONG_PRESS_BUTTON_ID
Definition nbgl_obj.h:553
@ CONTROLS_ID
Definition nbgl_obj.h:555
@ RIGHT_BUTTON_ID
Definition nbgl_obj.h:538
@ WHOLE_SCREEN_ID
Definition nbgl_obj.h:539
@ BOTTOM_BUTTON_ID
Definition nbgl_obj.h:536
@ SINGLE_BUTTON_ID
Definition nbgl_obj.h:542
@ BACK_BUTTON_ID
Definition nbgl_obj.h:541
@ VALUE_BUTTON_1_ID
Definition nbgl_obj.h:550
@ TIP_BOX_ID
Definition nbgl_obj.h:554
@ EXTRA_BUTTON_ID
Definition nbgl_obj.h:543
@ CHOICE_2_ID
Definition nbgl_obj.h:545
struct PACKED__ nbgl_container_s nbgl_container_t
struct to represent a container (CONTAINER type)
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_screenPush(nbgl_obj_t ***elements, uint8_t nbElements, const nbgl_screenTickerConfiguration_t *ticker, nbgl_buttonCallback_t buttonCallback)
int nbgl_screenSet(nbgl_obj_t ***elements, uint8_t nbElements, const nbgl_screenTickerConfiguration_t *ticker, nbgl_buttonCallback_t buttonCallback)
void nbgl_wait_pipeline(void)
int nbgl_screenUpdateTicker(uint8_t screenIndex, const nbgl_screenTickerConfiguration_t *ticker)
int nbgl_screenPop(uint8_t screenIndex)
struct PACKED__ nbgl_screenTickerConfiguration_s nbgl_screenTickerConfiguration_t
struct to configure a screen layer
int nbgl_screenUpdateBackgroundColor(uint8_t screenIndex, color_t color)
void nbgl_screenRedraw(void)
uint32_t nbgl_touchGetTouchDuration(nbgl_obj_t *obj)
common types for Graphical Library
color_t
Definition nbgl_types.h:153
@ WHITE
Definition nbgl_types.h:157
@ LIGHT_GRAY
Definition nbgl_types.h:156
@ BLACK
Definition nbgl_types.h:154
nbgl_state_t
to represent a boolean state.
Definition nbgl_types.h:212
@ ON_STATE
Definition nbgl_types.h:214
@ OFF_STATE
Definition nbgl_types.h:213
@ POST_REFRESH_FORCE_POWER_OFF
Force screen power off after refresh.
Definition nbgl_types.h:365
@ POST_REFRESH_FORCE_POWER_ON
Force screen power on after refresh.
Definition nbgl_types.h:366
@ POST_REFRESH_FORCE_POWER_ON_WITH_PIPELINE
Force screen power on and enable pipeline.
Definition nbgl_types.h:367
#define SCREEN_WIDTH
Definition nbgl_types.h:90
nbgl_touchType_t
The different types of Touchscreen events.
Definition nbgl_types.h:272
@ SWIPED_LEFT
Definition nbgl_types.h:287
@ SWIPED_UP
Definition nbgl_types.h:284
@ SWIPED_DOWN
Definition nbgl_types.h:285
@ SWIPED_RIGHT
Definition nbgl_types.h:286
@ TOUCH_RELEASED
Definition nbgl_types.h:282
@ TOUCHED
Definition nbgl_types.h:273
@ TOUCHING
corresponding to an object that is currently touched
Definition nbgl_types.h:277
@ OUT_OF_TOUCH
Definition nbgl_types.h:278
@ QRCODE_V10
QRCode V10, can encode text len up to 1500 chars, display size = 228*228.
Definition nbgl_types.h:244
@ QRCODE_V4_SMALL
QRCode V4, can encode text len up to 1500 chars, display size = 132*132.
Definition nbgl_types.h:245
@ QRCODE_V4
QRCode V4, can encode text len up to 62 chars, display size = 264*264.
Definition nbgl_types.h:243
@ VERTICAL
from top to bottom
Definition nbgl_types.h:222
@ HORIZONTAL
from left to right
Definition nbgl_types.h:223
@ LOOP_PARSING
0, 1, 2, 0, 1, 2, ...
Definition nbgl_types.h:421
#define SCREEN_HEIGHT
Definition nbgl_types.h:91
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
@ TOP_MIDDLE
Definition nbgl_types.h:195
@ CENTER
Definition nbgl_types.h:198
@ BOTTOM_RIGHT
Definition nbgl_types.h:202
@ TOP_LEFT
Definition nbgl_types.h:194
@ NO_ALIGNMENT
used when parent container layout is used
Definition nbgl_types.h:193
@ BOTTOM_LEFT
Definition nbgl_types.h:200
@ MID_RIGHT
Definition nbgl_types.h:199
@ RIGHT_TOP
on outside right
Definition nbgl_types.h:205
@ TOP_RIGHT
Definition nbgl_types.h:196
@ MID_LEFT
Definition nbgl_types.h:197
@ BOTTOM_MIDDLE
Definition nbgl_types.h:201
@ IMAGE
Bitmap (y and height must be multiple of 4 on Stax).
Definition nbgl_types.h:170
@ SWITCH
Switch to turn on/off something.
Definition nbgl_types.h:174
@ RADIO_BUTTON
Indicator to inform whether something is on or off.
Definition nbgl_types.h:177
@ SPINNER
Spinner.
Definition nbgl_types.h:181
@ BUTTON
Rounded rectangle button with icon and/or text.
Definition nbgl_types.h:173
@ PROGRESS_BAR
horizontal bar to indicate progression of something (between 0% and 100%)
Definition nbgl_types.h:176
@ QR_CODE
QR Code.
Definition nbgl_types.h:178
@ PAGE_INDICATOR
horizontal bar to indicate position within pages
Definition nbgl_types.h:175
@ LINE
Vertical or Horizontal line.
Definition nbgl_types.h:171
@ CONTAINER
Empty container.
Definition nbgl_types.h:169
@ TEXT_AREA
Area to contain text line(s).
Definition nbgl_types.h:172
#define MAX(x, y)
Definition nbgl_types.h:134
@ NBGL_BPP_1
1 bit per pixel
Definition nbgl_types.h:296
@ NO_STYLE
no border
Definition nbgl_types.h:231
@ BLACK_AND_WHITE_REFRESH
to be used for pure B&W area, when contrast is important
Definition nbgl_types.h:342
@ BLACK_AND_WHITE_FAST_REFRESH
to be used for pure B&W area, when contrast is not priority
Definition nbgl_types.h:343
@ FULL_COLOR_PARTIAL_REFRESH
to be used for small partial refresh (radio buttons, switches)
Definition nbgl_types.h:340
tune_index_e tuneId
uint16_t delayMs
delay between 2 drawings
Definition nbgl_types.h:433
uint8_t nbIcons
number of icons in icons array
Definition nbgl_types.h:431
const nbgl_icon_details_t ** icons
array of nbIcons pointers on icons
Definition nbgl_types.h:430
nbgl_parsingType_t parsing
Definition nbgl_types.h:432
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
const char * text2
second text (can be null)
const char * text1
first text (can be null)
bool onTop
if set to true, align only horizontally
nbgl_contentCenteredInfoStyle_t style
style to apply to this info
const nbgl_icon_details_t * icon
a buffer containing the 1BPP icon
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
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)
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 hideEndOfLastLine
if set to true, replace 3 last chars of last line by "..."
bool wrapping
if set to true, value text will be wrapped on ' ' to avoid cutting words
const nbgl_contentValueExt_t * extension
if not NULL, gives additional info on value field
const char * value
string giving the value name
const char * item
string giving the tag name
const char * aliasSubName
string displayed under alias and in details view
structure defining an ASCII font
Definition nbgl_fonts.h:88
uint8_t line_height
height of a line for all characters in pixels
Definition nbgl_fonts.h:93
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.
const char * text
button text
const nbgl_icon_details_t * icon
a buffer containing the 1BPP icon for button
nbgl_layoutButtonStyle_t style
nbgl_screenTickerConfiguration_t ticker
nbgl_layoutButtonCallback_t onActionCallback
the callback to be called on any action on the 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 for Text content, to be set with nbgl_layoutAddTextContent().
const char * descriptions[NB_MAX_DESCRIPTIONS]
uint8_t nbDescriptions
number of used descriptions in above array
const char * info
description at bottom (in small gray)
const char * title
main text (in large bold font)