Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
nbgl_step.c
Go to the documentation of this file.
1
5
6#ifdef NBGL_STEP
7/*********************
8 * INCLUDES
9 *********************/
10#include <string.h>
11#include "nbgl_debug.h"
12#include "nbgl_step_internal.h"
13#include "nbgl_layout_internal_nanos.h"
14#include "glyphs.h"
15#include "os_pic.h"
16#include "os_print.h"
17#ifdef BUILD_SCREENSHOTS
18#include "json_scenario.h"
19#endif // BUILD_SCREENSHOTS
20
21/*********************
22 * DEFINES
23 *********************/
24// string to store the title for a multi-pages text+subtext
25#define TMP_STRING_MAX_LEN 24
26
28#define NB_MAX_LAYERS 3
29
30/**********************
31 * TYPEDEFS
32 **********************/
36typedef enum {
37 TEXT_STEP = 0,
38 CENTERED_INFO_STEP,
39 MENU_LIST_STEP
40} StepStype_t;
41
45typedef struct TextContext_s {
46 uint16_t nbPages;
48 uint16_t currentPage;
49 const char *txtStart;
50 const char *nextPageStart;
51 const char *subTxtStart;
52
54 bool actionOnAnyButton;
55 nbgl_stepButtonCallback_t onActionCallback;
57 char tmpString[TMP_STRING_MAX_LEN];
60 style;
61 uint8_t nbMaxLinesForSubText;
63} TextContext_t;
64
68typedef struct MenuListContext_s {
70 selectedCallback;
71 nbgl_layoutMenuList_t
72 list;
73} MenuListContext_t;
74
75typedef struct StepContext_s {
76 union {
77 TextContext_t textContext;
78 MenuListContext_t menuListContext;
79 };
81 nbgl_layout_t *layout;
82 StepStype_t type;
83 bool modal;
84} StepContext_t;
85
86/**********************
87 * STATIC VARIABLES
88 **********************/
90static StepContext_t contexts[NB_MAX_LAYERS];
91
92/**********************
93 * VARIABLES
94 **********************/
95#ifdef BUILD_SCREENSHOTS
96// Variables used to store important values (nb lines, bold state etc)
97extern uint16_t last_nb_lines;
98extern uint16_t last_nb_pages;
99extern bool last_bold_state;
100#endif // BUILD_SCREENSHOTS
101
102/**********************
103 * STATIC PROTOTYPES
104 **********************/
105
106static void actionCallback(nbgl_layout_t *layout, nbgl_buttonEvent_t event);
107static void menuListActionCallback(nbgl_layout_t *layout, nbgl_buttonEvent_t event);
108
109// returns a non-used step context from the contexts[] array, or NULL if not found
110static StepContext_t *getFreeContext(StepStype_t type, bool modal)
111{
112 StepContext_t *ctx = NULL;
113
114 if (!modal) {
115 // Index 0 is reserved for background
116 ctx = &contexts[0];
117 }
118 else {
119 uint32_t i = 1;
120 while (i < NB_MAX_LAYERS) {
121 if (contexts[i].layout == NULL) {
122 ctx = &contexts[i];
123 break;
124 }
125 i++;
126 }
127 }
128 if (ctx == NULL) {
129 LOG_FATAL(STEP_LOGGER, "getFreeContext(): no available context\n");
130 }
131 else {
132 memset(ctx, 0, sizeof(StepContext_t));
133 ctx->type = type;
134 ctx->modal = modal;
135 }
136 return ctx;
137}
138
139// returns the step context from the contexts[] array matching with the given layout handler, or
140// NULL if not found
141static StepContext_t *getContextFromLayout(nbgl_layout_t layout)
142{
143 StepContext_t *ctx = NULL;
144 uint32_t i = 0;
145 while (i < NB_MAX_LAYERS) {
146 if (contexts[i].layout == layout) {
147 ctx = &contexts[i];
148 break;
149 }
150 i++;
151 }
152 if (ctx == NULL) {
153 LOG_WARN(STEP_LOGGER, "getContextFromLayout(): no matching context\n");
154 }
155 return ctx;
156}
157
158// (re)acquires the layout of the given step context. When re-rendering a step (internal page
159// navigation in a text step, selection change in a menu list), the layout currently held by the
160// context must be released first: for a modal step, nbgl_layoutGet() pushes a new screen and
161// consumes one of the few modal layout slots, so not releasing it would leak a screen layer on
162// every page, until the pool is exhausted.
163static bool getStepLayout(StepContext_t *ctx, const nbgl_layoutDescription_t *layoutDescription)
164{
165 if (ctx->layout != NULL) {
166 nbgl_layoutRelease((nbgl_layout_t *) ctx->layout);
167 ctx->layout = NULL;
168 }
169 ctx->layout = nbgl_layoutGet(layoutDescription);
170 if (ctx->layout == NULL) {
171 LOG_WARN(STEP_LOGGER, "getStepLayout(): impossible to get a layout\n");
172 return false;
173 }
174 return true;
175}
176
177// from the current details context, return the number of bytes of the given subText displayed in
178// a page
179static uint16_t getSubTextPageLen(StepContext_t *ctx, const char *subText)
180{
181 uint16_t len = 0;
182 if (ctx->textContext.style == BUTTON_INFO) {
183 // use exactly the same split as the buttons drawn by the layout
184 uint8_t row = 0;
185 while ((row < NB_MAX_BUTTON_ROWS) && (subText[len] != '\0')) {
186 uint16_t rowLen, rowWidth;
187 len += layoutGetButtonRowLen(&subText[len], &rowLen, &rowWidth);
188 row++;
189 }
190 }
191 else {
193 subText,
195 NB_MAX_LINES - 1,
196 &len,
197 true);
198 }
199 return len;
200}
201
202// from the current details context, return the number of bytes of the given page start of text (or
203// of subText if any) displayed in this page, plus the '\n' ending it if any. Used both to move
204// forward and to recompute the pages from the beginning, so that they always start at the same char
205static uint16_t getPageLen(StepContext_t *ctx, const char *txt)
206{
207 uint16_t len;
208 if (ctx->textContext.subTxtStart == NULL) {
211 }
212 else {
213 len = getSubTextPageLen(ctx, txt);
214 }
215 // if the next char is '\n', skip it to avoid starting the next page with an empty line
216 // (not for the buttons of subText, for which getSubTextPageLen() already handles '\n')
217 if (((ctx->textContext.subTxtStart == NULL) || (ctx->textContext.style != BUTTON_INFO))
218 && (txt[len] == '\n')) {
219 len++;
220 }
221 return len;
222}
223
224// from the current details context, return a pointer on the text (or on subText if any) at the
225// given page
226static const char *getPageAt(StepContext_t *ctx, uint16_t textPage)
227{
228 uint16_t page = 0;
229 const char *currentChar = (ctx->textContext.subTxtStart == NULL) ? ctx->textContext.txtStart
230 : ctx->textContext.subTxtStart;
231 while (page < textPage) {
232 if (page < (ctx->textContext.nbPages - 1)) {
233 currentChar = currentChar + getPageLen(ctx, currentChar);
234 }
235 page++;
236 }
237 return currentChar;
238}
239
240// utility function to compute navigation arrows
241static nbgl_layoutNavIndication_t getNavigationInfo(nbgl_stepPosition_t pos,
242 uint16_t nbPages,
243 uint16_t currentPage)
244{
246
247 if (nbPages > 1) {
248 if (currentPage > 0) {
249 indication |= LEFT_ARROW;
250 }
251 if (currentPage < (nbPages - 1)) {
252 indication |= RIGHT_ARROW;
253 }
254 }
255 if (pos == FIRST_STEP) {
256 indication |= RIGHT_ARROW;
257 }
258 else if (pos == LAST_STEP) {
259 indication |= LEFT_ARROW;
260 }
261 else if (pos == NEITHER_FIRST_NOR_LAST_STEP) {
262 indication |= RIGHT_ARROW | LEFT_ARROW;
263 }
264 return indication;
265}
266
267// function used to display the current page in details review mode
268static void displayTextPage(StepContext_t *ctx, uint16_t textPage)
269{
270 const char *txt;
271 char intermediateString[36]; // a bit bigger but we know that one line cannot contain
272 // more than 23 chars
273
274 // if move backward or first page
275 if (textPage <= ctx->textContext.currentPage) {
276 // recompute current start from beginning
277 txt = getPageAt(ctx, textPage);
278 }
279 // else move forward
280 else {
281 txt = ctx->textContext.nextPageStart;
282 }
283 ctx->textContext.currentPage = textPage;
284
285 if (ctx->textContext.currentPage < (ctx->textContext.nbPages - 1)) {
286 // memorize next position to save processing
287 ctx->textContext.nextPageStart = txt + getPageLen(ctx, txt);
288 }
289 else {
290 ctx->textContext.nextPageStart = NULL;
291 }
292 nbgl_layoutDescription_t layoutDescription = {0};
293 nbgl_layoutNavigation_t navInfo = {
294 .direction = HORIZONTAL_NAV,
295 };
296
297 layoutDescription.modal = ctx->modal;
298 layoutDescription.onActionCallback = actionCallback;
299 layoutDescription.ticker.tickerCallback = ctx->ticker.tickerCallback;
300 layoutDescription.ticker.tickerIntervale = ctx->ticker.tickerIntervale;
301 layoutDescription.ticker.tickerValue = ctx->ticker.tickerValue;
302 if (!getStepLayout(ctx, &layoutDescription)) {
303 return;
304 }
305
306 navInfo.indication = getNavigationInfo(
307 ctx->textContext.pos, ctx->textContext.nbPages, ctx->textContext.currentPage);
308
309 if (ctx->textContext.subTxtStart == NULL) {
310 nbgl_layoutAddText(ctx->layout, txt, NULL, ctx->textContext.style);
311 }
312 else {
313 if (ctx->textContext.nbPages == 1) {
314 // truncate title to fit in one line, if necessary
316 ctx->textContext.txtStart,
318 false)
319 > 1) {
321 ctx->textContext.txtStart,
323 1,
324 ctx->textContext.tmpString,
325 TMP_STRING_MAX_LEN);
326 }
327 else {
328 if (ctx->textContext.txtStart != NULL) {
329 // simply copy (without reading after the end of a shorter text)
330 strlcpy(
331 ctx->textContext.tmpString, ctx->textContext.txtStart, TMP_STRING_MAX_LEN);
332 }
333 else {
334 ctx->textContext.tmpString[0] = 0;
335 }
336 }
337 }
338 else {
339 SPRINTF(intermediateString,
340 "%s (%d/%d)",
341 ctx->textContext.txtStart,
342 (int) (ctx->textContext.currentPage + 1),
343 (int) ctx->textContext.nbPages);
344 // truncate title to fit in one line, if necessary
346 intermediateString,
348 false)
349 > 1) {
351 intermediateString,
353 1,
354 ctx->textContext.tmpString,
355 TMP_STRING_MAX_LEN);
356 }
357 else {
358 // simply copy
359 memcpy(ctx->textContext.tmpString, intermediateString, TMP_STRING_MAX_LEN - 1);
360 ctx->textContext.tmpString[TMP_STRING_MAX_LEN - 1] = 0;
361 }
362 }
363 // if the sub text has a max number of lines, it is displayed in a single page, truncated
364 // with an ellipsis if it doesn't fit. Otherwise, the text of the current page fills the
365 // lines (or buttons), the remaining text is displayed in the next pages, so no ellipsis
366 layoutAddText(ctx->layout,
367 ctx->textContext.tmpString,
368 txt,
369 ctx->textContext.style,
370 ctx->textContext.nbMaxLinesForSubText,
371 ctx->textContext.nbMaxLinesForSubText > 0);
372 }
373 if (navInfo.indication != NO_ARROWS) {
374 nbgl_layoutAddNavigation(ctx->layout, &navInfo);
375 }
376 nbgl_layoutDraw(ctx->layout);
377 nbgl_refresh();
378}
379
380// callback on key touch
381static void actionCallback(nbgl_layout_t *layout, nbgl_buttonEvent_t event)
382{
383 StepContext_t *ctx = getContextFromLayout(layout);
384
385 if (!ctx) {
386 LOG_WARN(STEP_LOGGER, "actionCallback(): ctx not found\n");
387 return;
388 }
389 if (event == BUTTON_LEFT_PRESSED) {
390 if (ctx->textContext.currentPage > 0) {
391 displayTextPage(ctx, ctx->textContext.currentPage - 1);
392 return;
393 }
394 else if ((ctx->textContext.pos == LAST_STEP)
395 || (ctx->textContext.pos == NEITHER_FIRST_NOR_LAST_STEP)
396 || (ctx->textContext.actionOnAnyButton)) {
397 if (ctx->textContext.onActionCallback != NULL) {
398 ctx->textContext.onActionCallback((nbgl_step_t) ctx, event);
399 }
400 }
401 }
402 else if (event == BUTTON_RIGHT_PRESSED) {
403 if (ctx->textContext.currentPage < (ctx->textContext.nbPages - 1)) {
404 displayTextPage(ctx, ctx->textContext.currentPage + 1);
405 return;
406 }
407 else if ((ctx->textContext.pos == FIRST_STEP)
408 || (ctx->textContext.pos == NEITHER_FIRST_NOR_LAST_STEP)
409 || (ctx->textContext.actionOnAnyButton)) {
410 if (ctx->textContext.onActionCallback != NULL) {
411 ctx->textContext.onActionCallback((nbgl_step_t) ctx, event);
412 }
413 }
414 }
415 else if (event == BUTTON_BOTH_PRESSED) {
416 if (ctx->textContext.onActionCallback != NULL) {
417 ctx->textContext.onActionCallback((nbgl_step_t) ctx, event);
418 }
419 }
420}
421
422static void displayMenuList(StepContext_t *ctx)
423{
424 nbgl_layoutDescription_t layoutDescription
425 = {.modal = ctx->modal, .onActionCallback = menuListActionCallback};
426 nbgl_layoutMenuList_t *list = &ctx->menuListContext.list;
427
428 layoutDescription.ticker.tickerCallback = ctx->ticker.tickerCallback;
429 layoutDescription.ticker.tickerIntervale = ctx->ticker.tickerIntervale;
430 layoutDescription.ticker.tickerValue = ctx->ticker.tickerValue;
431
432 if (!getStepLayout(ctx, &layoutDescription)) {
433 return;
434 }
435 nbgl_layoutAddMenuList(ctx->layout, list);
436 if (list->nbChoices > 1) {
437 nbgl_layoutNavigation_t navInfo = {.direction = VERTICAL_NAV};
438 navInfo.indication = 0;
439 if (list->selectedChoice > 0) {
440 navInfo.indication |= LEFT_ARROW;
441 }
442 if (list->selectedChoice < (list->nbChoices - 1)) {
443 navInfo.indication |= RIGHT_ARROW;
444 }
445
446 if (navInfo.indication != NO_ARROWS) {
447 nbgl_layoutAddNavigation(ctx->layout, &navInfo);
448 }
449 }
450 nbgl_layoutDraw(ctx->layout);
451 nbgl_refresh();
452}
453
454// callback on key touch
455static void menuListActionCallback(nbgl_layout_t *layout, nbgl_buttonEvent_t event)
456{
457 StepContext_t *ctx = getContextFromLayout(layout);
458 if (!ctx) {
459 LOG_WARN(STEP_LOGGER, "menuListActionCallback(): ctx not found\n");
460 return;
461 }
462
463 if (event == BUTTON_LEFT_PRESSED) {
464 if (ctx->menuListContext.list.selectedChoice > 0) {
465 ctx->menuListContext.list.selectedChoice--;
466 displayMenuList(ctx);
467 }
468 }
469 else if (event == BUTTON_RIGHT_PRESSED) {
470 if (ctx->menuListContext.list.selectedChoice < (ctx->menuListContext.list.nbChoices - 1)) {
471 ctx->menuListContext.list.selectedChoice++;
472 displayMenuList(ctx);
473 }
474 }
475 else if (event == BUTTON_BOTH_PRESSED) {
476 ctx->menuListContext.selectedCallback(ctx->menuListContext.list.selectedChoice);
477 }
478}
479
480/**********************
481 * GLOBAL FUNCTIONS
482 **********************/
483
499 nbgl_stepButtonCallback_t onActionCallback,
501 const char *text,
502 const char *subText,
504 bool modal)
505{
506 return stepDrawText(pos, onActionCallback, ticker, text, subText, style, modal, 0);
507}
508
525 nbgl_stepButtonCallback_t onActionCallback,
527 const char *text,
528 const char *subText,
530 bool modal,
531 uint8_t nbMaxLinesForSubText)
532{
533#ifdef BUILD_SCREENSHOTS
534 // Initialize a default area
535 nbgl_area_t area = {0};
536 area.x0 = area.y0 = 0;
537 area.width = AVAILABLE_WIDTH;
539#endif // BUILD_SCREENSHOTS
540 StepContext_t *ctx = getFreeContext(TEXT_STEP, modal);
541 if (!ctx) {
542 LOG_WARN(STEP_LOGGER, "nbgl_stepDrawText(): no free context\n");
543 return NULL;
544 }
545 // the texts are read here (to count and split the pages) and when displaying the pages, so
546 // they must always be accessed with the same (PIC) address (PIC(NULL) is NULL)
547 text = PIC(text);
548 subText = PIC(subText);
549 // initialize context (already set to 0 by getFreeContext())
550 ctx->textContext.onActionCallback = onActionCallback;
551 // style is needed to compute the number of pages of subText
552 ctx->textContext.style = style;
553 if (ticker) {
554 ctx->ticker.tickerCallback = ticker->tickerCallback;
555 ctx->ticker.tickerIntervale = ticker->tickerIntervale;
556 ctx->ticker.tickerValue = ticker->tickerValue;
557 }
558
559 // if no subText, get the number of pages for main text
560 if (subText == NULL) {
561 ctx->textContext.nbPages = nbgl_getTextNbPagesInWidth(
563#ifdef BUILD_SCREENSHOTS
564 store_string_infos(text,
566 &area,
567 true,
568 last_nb_lines,
569 last_nb_pages,
570 last_bold_state);
571#endif // BUILD_SCREENSHOTS
572 }
573 else {
574#ifdef BUILD_SCREENSHOTS
575 uint16_t nb_lines_title;
576 // Call this function to get correct nb_lines/nb_pages for text field.
579 nb_lines_title = last_nb_lines;
580 // There is a sub text, so no more than 3 lines for title...
581 if (nb_lines_title > 3) {
582 nb_lines_title = 3;
583 }
584 area.height
586 store_string_infos(text,
588 &area,
589 true,
590 last_nb_lines,
591 last_nb_pages,
592 last_bold_state);
593#endif // BUILD_SCREENSHOTS
594 if (nbMaxLinesForSubText > 0) {
595 // subText is truncated to fit in a single page
596 ctx->textContext.nbMaxLinesForSubText = nbMaxLinesForSubText;
597 ctx->textContext.nbPages = 1;
598 }
599 else if (style == BUTTON_INFO) {
600 // count the pages with exactly the same split as the one used to display them. Each
601 // page contains at least one char, so all the text is always reachable
602 const char *pageStart = subText;
603 do {
604 pageStart += getSubTextPageLen(ctx, pageStart);
605 ctx->textContext.nbPages++;
606 } while (*pageStart != '\0');
607 }
608 else {
609 // NB_MAX_LINES-1 because first line is for main text
610 ctx->textContext.nbPages = nbgl_getTextNbPagesInWidth(
612 }
613#ifdef BUILD_SCREENSHOTS
614 if ((nbMaxLinesForSubText > 0) || (style == BUTTON_INFO)) {
615 // Call this function to get correct nb_lines for subText (its pages are counted above)
618 }
619 area.height = (NB_MAX_LINES - nb_lines_title)
621 // If subTxtid is not valid, we'll use txtId for nb_lines/nb_pages values
622 // (in BUTTON_INFO style or if truncated, the pages are the ones really displayed, and if
623 // truncated in a text style, only nbMaxLinesForSubText lines are displayed. In
624 // BUTTON_INFO style, nbMaxLinesForSubText is a number of buttons, not of lines)
625 store_string_infos(subText,
627 &area,
628 true,
629 ((style != BUTTON_INFO) && (nbMaxLinesForSubText > 0)
630 && (last_nb_lines > nbMaxLinesForSubText))
631 ? nbMaxLinesForSubText
632 : last_nb_lines,
633 ((style == BUTTON_INFO) || (nbMaxLinesForSubText > 0))
634 ? ctx->textContext.nbPages
635 : last_nb_pages,
636 last_bold_state);
637#endif // BUILD_SCREENSHOTS
638 }
640 "nbgl_stepDrawText: ctx = %p, nbPages = %d, pos = 0x%X\n",
641 ctx,
642 (int) ctx->textContext.nbPages,
643 pos);
644 if (pos & BACKWARD_DIRECTION) {
645 // start with last page
646 ctx->textContext.currentPage = ctx->textContext.nbPages - 1;
647 }
648 ctx->textContext.txtStart = text;
649 ctx->textContext.subTxtStart = subText;
650 // keep only direction part of position
651 ctx->textContext.pos = pos & STEP_POSITION_MASK;
652 ctx->textContext.actionOnAnyButton = (pos & ACTION_ON_ANY_BUTTON) != 0;
653 displayTextPage(ctx, ctx->textContext.currentPage);
654
655 return (nbgl_step_t) ctx;
656}
657
669 nbgl_stepButtonCallback_t onActionCallback,
672 bool modal)
673{
674 nbgl_layoutDescription_t layoutDescription
675 = {.modal = modal, .onActionCallback = (nbgl_layoutButtonCallback_t) actionCallback};
676 nbgl_layoutNavigation_t navInfo = {
677 .direction = HORIZONTAL_NAV,
678 };
679 StepContext_t *ctx = getFreeContext(CENTERED_INFO_STEP, modal);
680 if (!ctx) {
681 LOG_WARN(STEP_LOGGER, "nbgl_stepDrawCenteredInfo(): no free context\n");
682 return NULL;
683 }
684
685 // initialize context (already set to 0 by getFreeContext())
686 ctx->textContext.onActionCallback = onActionCallback;
687 if (ticker) {
688 ctx->ticker.tickerCallback = ticker->tickerCallback;
689 ctx->ticker.tickerIntervale = ticker->tickerIntervale;
690 ctx->ticker.tickerValue = ticker->tickerValue;
691 layoutDescription.ticker.tickerCallback = ticker->tickerCallback;
692 layoutDescription.ticker.tickerIntervale = ticker->tickerIntervale;
693 layoutDescription.ticker.tickerValue = ticker->tickerValue;
694 }
695
696 ctx->textContext.nbPages = 1;
697 // keep only direction part of position
698 ctx->textContext.pos = pos & (RIGHT_ARROW | LEFT_ARROW);
699 navInfo.indication = getNavigationInfo(
700 ctx->textContext.pos, ctx->textContext.nbPages, ctx->textContext.currentPage);
701
702 ctx->layout = nbgl_layoutGet(&layoutDescription);
703 nbgl_layoutAddCenteredInfo(ctx->layout, info);
704 if (navInfo.indication != NO_ARROWS) {
705 nbgl_layoutAddNavigation(ctx->layout, &navInfo);
706 }
707 nbgl_layoutDraw(ctx->layout);
708 nbgl_refresh();
709
710 LOG_DEBUG(STEP_LOGGER, "nbgl_stepDrawCenteredInfo(): step = %p\n", ctx);
711 return (nbgl_step_t) ctx;
712}
713
727 bool modal)
728{
729 StepContext_t *ctx = getFreeContext(MENU_LIST_STEP, modal);
730 if (!ctx) {
731 LOG_WARN(STEP_LOGGER, "nbgl_stepDrawMenuList(): no free context\n");
732 return NULL;
733 }
734
735 // initialize context (already set to 0 by getFreeContext())
736 if (ticker) {
737 ctx->ticker.tickerCallback = ticker->tickerCallback;
738 ctx->ticker.tickerIntervale = ticker->tickerIntervale;
739 ctx->ticker.tickerValue = ticker->tickerValue;
740 }
741
742 ctx->menuListContext.list.nbChoices = list->nbChoices;
743 ctx->menuListContext.list.selectedChoice = list->selectedChoice;
744 ctx->menuListContext.list.callback = list->callback;
745 ctx->menuListContext.selectedCallback = onActionCallback;
746
747 displayMenuList(ctx);
748
749 LOG_DEBUG(STEP_LOGGER, "nbgl_stepDrawMenuList(): step = %p\n", ctx);
750
751 return (nbgl_step_t) ctx;
752}
753
761{
762 StepContext_t *ctx = (StepContext_t *) step;
763 if (!ctx) {
764 return 0;
765 }
766 return (ctx->menuListContext.list.selectedChoice);
767}
768
782 nbgl_stepButtonCallback_t onActionCallback,
784 nbgl_layoutSwitch_t *switchInfo,
785 bool modal)
786{
787 nbgl_layoutDescription_t layoutDescription
788 = {.modal = modal, .onActionCallback = (nbgl_layoutButtonCallback_t) actionCallback};
789 nbgl_layoutNavigation_t navInfo = {
790 .direction = HORIZONTAL_NAV,
791 };
792 StepContext_t *ctx = getFreeContext(CENTERED_INFO_STEP, modal);
793 if (!ctx) {
794 LOG_WARN(STEP_LOGGER, "nbgl_stepDrawSwitch(): no free context\n");
795 return NULL;
796 }
797
798 // initialize context (already set to 0 by getFreeContext())
799 ctx->textContext.onActionCallback = onActionCallback;
800 if (ticker) {
801 ctx->ticker.tickerCallback = ticker->tickerCallback;
802 ctx->ticker.tickerIntervale = ticker->tickerIntervale;
803 ctx->ticker.tickerValue = ticker->tickerValue;
804 layoutDescription.ticker.tickerCallback = ticker->tickerCallback;
805 layoutDescription.ticker.tickerIntervale = ticker->tickerIntervale;
806 layoutDescription.ticker.tickerValue = ticker->tickerValue;
807 }
808
809 ctx->textContext.nbPages = 1;
810 // keep only direction part of position
811 ctx->textContext.pos = pos & (RIGHT_ARROW | LEFT_ARROW);
812 navInfo.indication = getNavigationInfo(
813 ctx->textContext.pos, ctx->textContext.nbPages, ctx->textContext.currentPage);
814
815 ctx->layout = nbgl_layoutGet(&layoutDescription);
816 nbgl_layoutAddSwitch(ctx->layout, switchInfo);
817 if (navInfo.indication != NO_ARROWS) {
818 nbgl_layoutAddNavigation(ctx->layout, &navInfo);
819 }
820 nbgl_layoutDraw(ctx->layout);
821 nbgl_refresh();
822
823 LOG_DEBUG(STEP_LOGGER, "nbgl_stepDrawSwitch(): ctx = %p\n", ctx);
824 return (nbgl_step_t) ctx;
825}
826
834{
835 StepContext_t *ctx = (StepContext_t *) step;
836 int ret;
837
838 LOG_DEBUG(STEP_LOGGER, "nbgl_stepRelease(): ctx = %p\n", ctx);
839 if (!ctx) {
840 return -1;
841 }
842 ret = nbgl_layoutRelease((nbgl_layout_t *) ctx->layout);
843
844 ctx->layout = NULL;
845
846 return ret;
847}
848
849#endif // NBGL_STEP
nbgl_contentCenteredInfoStyle_t
possible styles for Centered Info Area
debug traces management
#define LOG_WARN(__logger,...)
Definition nbgl_debug.h:89
@ STEP_LOGGER
Definition nbgl_debug.h:42
#define LOG_DEBUG(__logger,...)
Definition nbgl_debug.h:88
#define LOG_FATAL(__logger,...)
Definition nbgl_debug.h:90
uint8_t nbgl_getTextNbPagesInWidth(nbgl_font_id_e fontId, const char *text, uint8_t nbLinesPerPage, uint16_t maxWidth)
bool nbgl_getTextMaxLenInNbLines(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t maxNbLines, uint16_t *len, bool wrapping)
@ BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp
Definition nbgl_fonts.h:152
@ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp
Definition nbgl_fonts.h:150
void nbgl_textReduceOnNbLines(nbgl_font_id_e fontId, const char *origText, uint16_t maxWidth, uint8_t nbLines, char *reducedText, uint16_t reducedTextLen)
uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
uint8_t nbgl_getFontLineHeight(nbgl_font_id_e fontId)
#define NB_MAX_LINES
@ VERTICAL_NAV
'\/' and '/\' are displayed, to navigate in a list (vertical scrolling)
@ HORIZONTAL_NAV
'<' and '>' are displayed, to navigate between pages and steps
int nbgl_layoutAddText(nbgl_layout_t *layout, const char *text, const char *subText)
Creates an area with given text (in bold) and sub text (in regular).
nbgl_layoutNavIndication_t
possible styles for Navigation arrows (it's a bit field)
@ NO_ARROWS
@ LEFT_ARROW
left arrow is used
@ RIGHT_ARROW
right arrow is used
int nbgl_layoutAddCenteredInfo(nbgl_layout_t *layout, const nbgl_layoutCenteredInfo_t *info)
Creates an area on the center of the main panel, with a possible icon/image, a possible text in black...
nbgl_contentSwitch_t nbgl_layoutSwitch_t
Deprecated, kept for retro compatibility.
int nbgl_layoutDraw(nbgl_layout_t *layout)
Applies given layout. The screen will be redrawn.
#define AVAILABLE_WIDTH
void * nbgl_layout_t
type shared externally
int nbgl_layoutAddSwitch(nbgl_layout_t *layout, const nbgl_layoutSwitch_t *switchLayout)
Creates a switch with the given text and its state.
nbgl_layout_t * nbgl_layoutGet(const nbgl_layoutDescription_t *description)
returns a layout of the given type. The layout is reset
struct nbgl_layoutDescription_s nbgl_layoutDescription_t
Structure containing all information when creating a layout. This structure must be passed as argumen...
void(* nbgl_layoutButtonCallback_t)(nbgl_layout_t *layout, nbgl_buttonEvent_t event)
prototype of function to be called when buttons are touched on a screen
int nbgl_layoutRelease(nbgl_layout_t *layout)
Release the layout obtained with nbgl_layoutGet().
nbgl_contentCenteredInfo_t nbgl_layoutCenteredInfo_t
Deprecated, kept for retro compatibility.
void nbgl_refresh(void)
nbgl_buttonEvent_t
Definition nbgl_obj.h:196
@ BUTTON_BOTH_PRESSED
Sent when both buttons are released.
Definition nbgl_obj.h:203
@ BUTTON_LEFT_PRESSED
Sent when Left button is released.
Definition nbgl_obj.h:197
@ BUTTON_RIGHT_PRESSED
Send when Right button is released.
Definition nbgl_obj.h:198
struct PACKED__ nbgl_screenTickerConfiguration_s nbgl_screenTickerConfiguration_t
struct to configure a screen layer
void(* nbgl_stepButtonCallback_t)(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
prototype of function to be called when buttons are touched on a screen
Definition nbgl_step.h:59
uint8_t nbgl_stepGetMenuListCurrent(nbgl_step_t step)
nbgl_step_t nbgl_stepDrawSwitch(nbgl_stepPosition_t pos, nbgl_stepButtonCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, nbgl_layoutSwitch_t *switchInfo, bool modal)
void * nbgl_step_t
type shared externally
Definition nbgl_step.h:46
uint8_t nbgl_stepPosition_t
this type is a bitfield containing:
Definition nbgl_step.h:90
#define STEP_POSITION_MASK
Definition nbgl_step.h:81
@ NEITHER_FIRST_NOR_LAST_STEP
neither first nor last in a multiple steps flow
Definition nbgl_step.h:69
@ LAST_STEP
last in a multiple steps flow
Definition nbgl_step.h:68
@ FIRST_STEP
first in a multiple steps flow
Definition nbgl_step.h:67
nbgl_step_t nbgl_stepDrawMenuList(nbgl_stepMenuListCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, nbgl_layoutMenuList_t *list, bool modal)
#define ACTION_ON_ANY_BUTTON
When action callback applies only on both button press.
Definition nbgl_step.h:77
int nbgl_stepRelease(nbgl_step_t step)
void(* nbgl_stepMenuListCallback_t)(uint8_t choiceIndex)
prototype of chosen menu list item callback
Definition nbgl_step.h:52
nbgl_step_t nbgl_stepDrawText(nbgl_stepPosition_t pos, nbgl_stepButtonCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, const char *text, const char *subText, nbgl_contentCenteredInfoStyle_t style, bool modal)
nbgl_step_t nbgl_stepDrawCenteredInfo(nbgl_stepPosition_t pos, nbgl_stepButtonCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, nbgl_layoutCenteredInfo_t *info, bool modal)
#define BACKWARD_DIRECTION
When action callback applies on any button press.
Definition nbgl_step.h:75
Internal functions of NBGL step layer.
nbgl_step_t stepDrawText(nbgl_stepPosition_t pos, nbgl_stepButtonCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, const char *text, const char *subText, nbgl_contentCenteredInfoStyle_t style, bool modal, uint8_t nbMaxLinesForSubText)
struct PACKED__ nbgl_area_s nbgl_area_t
Represents a rectangle area of the screen.
size_t strlcpy(char *dst, const char *src, size_t size)
nbgl_screenTickerConfiguration_t ticker
nbgl_layoutTouchCallback_t onActionCallback
the callback to be called on any action on the layout
This structure contains a list of names to build a menu list on Nanos, with for each item a descripti...
nbgl_menuListCallback_t callback
function to call to retrieve a menu list item text
uint8_t nbChoices
total number of choices in the menu list
uint8_t selectedChoice
index of the selected choice (centered, in bold)
This structure contains info to build a navigation bar at the bottom of the screen.
nbgl_layoutNavIndication_t indication
specifies which arrows to use (left or right)
static nbgl_touchStatePosition_t pos
Definition ux.c:56