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"
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 **********************/
41
64
74
85
86/**********************
87 * STATIC VARIABLES
88 **********************/
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);
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
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) {
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
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
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
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
318 false)
319 > 1) {
323 1,
326 }
327 else {
328 if (ctx->textContext.txtStart != NULL) {
329 // simply copy (without reading after the end of a shorter text)
330 strlcpy(
332 }
333 else {
334 ctx->textContext.tmpString[0] = 0;
335 }
336 }
337 }
338 else {
339 SPRINTF(intermediateString,
340 "%s (%d/%d)",
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,
356 }
357 else {
358 // simply copy
359 memcpy(ctx->textContext.tmpString, intermediateString, TMP_STRING_MAX_LEN - 1);
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
368 txt,
369 ctx->textContext.style,
372 }
373 if (navInfo.indication != NO_ARROWS) {
374 nbgl_layoutAddNavigation(ctx->layout, &navInfo);
375 }
377 nbgl_refresh();
378}
379
380// callback on key touch
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) {
392 return;
393 }
394 else if ((ctx->textContext.pos == 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)) {
405 return;
406 }
407 else if ((ctx->textContext.pos == FIRST_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
423{
424 nbgl_layoutDescription_t layoutDescription
425 = {.modal = ctx->modal, .onActionCallback = menuListActionCallback};
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 }
451 nbgl_refresh();
452}
453
454// callback on key touch
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) {
466 displayMenuList(ctx);
467 }
468 }
469 else if (event == BUTTON_RIGHT_PRESSED) {
472 displayMenuList(ctx);
473 }
474 }
475 else if (event == BUTTON_BOTH_PRESSED) {
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
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) {
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
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
647 }
648 ctx->textContext.txtStart = text;
649 ctx->textContext.subTxtStart = subText;
650 // keep only direction part of position
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 };
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);
701
702 ctx->layout = nbgl_layoutGet(&layoutDescription);
704 if (navInfo.indication != NO_ARROWS) {
705 nbgl_layoutAddNavigation(ctx->layout, &navInfo);
706 }
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{
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
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 };
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);
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 }
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 }
843
844 ctx->layout = NULL;
845
846 return ret;
847}
848
849#endif // NBGL_STEP
nbgl_contentCenteredInfoStyle_t
possible styles for Centered Info Area
@ BUTTON_INFO
bold is used for text1 and text2 as a white button
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
#define NB_MAX_LAYERS
< Maximum number of layers for flow, cannot be greater than max number of step layers
Definition nbgl_flow.c:27
static void actionCallback(nbgl_step_t stepCtx, nbgl_buttonEvent_t event)
Definition nbgl_flow.c:133
static FlowContext_t contexts[NB_MAX_LAYERS]
Definition nbgl_flow.c:44
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
int nbgl_layoutAddMenuList(nbgl_layout_t *layout, nbgl_layoutMenuList_t *list)
Creates a menu list (only for nanos) with the given parameters. The navigation (and selection) must b...
@ VERTICAL_NAV
'\/' and '/\' are displayed, to navigate in a list (vertical scrolling)
@ HORIZONTAL_NAV
'<' and '>' are displayed, to navigate between pages and steps
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_layoutAddNavigation(nbgl_layout_t *layout, nbgl_layoutNavigation_t *info)
Creates navigation arrows on side(s) of the screen.
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_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 an area in main panel to display a switch.
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.
Internal functions/constants of NBGL layout layer.
int layoutAddText(nbgl_layout_t *layout, const char *text, const char *subText, nbgl_contentCenteredInfoStyle_t style, uint8_t nbMaxLines, bool ellipsis)
Same as nbgl_layoutAddText(), with the choice of the max number of lines (or buttons in BUTTON_INFO s...
#define NB_MAX_BUTTON_ROWS
Maximum number of buttons used to display the sub text in BUTTON_INFO style.
uint16_t layoutGetButtonRowLen(const char *text, uint16_t *len, uint16_t *width)
computes the part of the given text displayed in a single button in BUTTON_INFO style....
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
static void actionCallback(nbgl_layout_t *layout, nbgl_buttonEvent_t event)
Definition nbgl_step.c:381
static void displayMenuList(StepContext_t *ctx)
Definition nbgl_step.c:422
uint8_t nbgl_stepGetMenuListCurrent(nbgl_step_t step)
Get the index of the currently selected item in the menulist.
Definition nbgl_step.c:760
#define TMP_STRING_MAX_LEN
Maximum number of layers for steps, cannot be greater than max number of layout layers.
Definition nbgl_step.c:25
struct StepContext_s StepContext_t
nbgl_step_t nbgl_stepDrawSwitch(nbgl_stepPosition_t pos, nbgl_stepButtonCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, nbgl_layoutSwitch_t *switchInfo, bool modal)
draw a step page with a switch and navigation arrows to navigate to other pages.
Definition nbgl_step.c:781
static bool getStepLayout(StepContext_t *ctx, const nbgl_layoutDescription_t *layoutDescription)
Definition nbgl_step.c:163
static StepContext_t * getFreeContext(StepStype_t type, bool modal)
Definition nbgl_step.c:110
struct TextContext_s TextContext_t
nbgl_step_t nbgl_stepDrawMenuList(nbgl_stepMenuListCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, nbgl_layoutMenuList_t *list, bool modal)
draw a step page with a menu list and navigation arrows to parse it. This step must be alone
Definition nbgl_step.c:724
static uint16_t getSubTextPageLen(StepContext_t *ctx, const char *subText)
Definition nbgl_step.c:179
static void displayTextPage(StepContext_t *ctx, uint16_t textPage)
Definition nbgl_step.c:268
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)
Same as nbgl_stepDrawText(), with the possibility to truncate subText.
Definition nbgl_step.c:524
static nbgl_layoutNavIndication_t getNavigationInfo(nbgl_stepPosition_t pos, uint16_t nbPages, uint16_t currentPage)
Definition nbgl_step.c:241
int nbgl_stepRelease(nbgl_step_t step)
Release the step obtained with any of the nbgl_stepDrawXXX() functions.
Definition nbgl_step.c:833
StepStype_t
Definition nbgl_step.c:36
@ CENTERED_INFO_STEP
for a centered info step
Definition nbgl_step.c:38
@ MENU_LIST_STEP
for a menu list step
Definition nbgl_step.c:39
@ TEXT_STEP
for a simple text step
Definition nbgl_step.c:37
static void menuListActionCallback(nbgl_layout_t *layout, nbgl_buttonEvent_t event)
Definition nbgl_step.c:455
static const char * getPageAt(StepContext_t *ctx, uint16_t textPage)
Definition nbgl_step.c:226
static uint16_t getPageLen(StepContext_t *ctx, const char *txt)
Definition nbgl_step.c:205
struct MenuListContext_s MenuListContext_t
static StepContext_t * getContextFromLayout(nbgl_layout_t layout)
Definition nbgl_step.c:141
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)
draws a text type step, that can be multi-pages, depending of the length of text and subText....
Definition nbgl_step.c:498
nbgl_step_t nbgl_stepDrawCenteredInfo(nbgl_stepPosition_t pos, nbgl_stepButtonCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, nbgl_layoutCenteredInfo_t *info, bool modal)
draw a step with a centered info (icon + text). This is always a single page step
Definition nbgl_step.c:668
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
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
#define ACTION_ON_ANY_BUTTON
When action callback applies only on both button press.
Definition nbgl_step.h:77
void(* nbgl_stepMenuListCallback_t)(uint8_t choiceIndex)
prototype of chosen menu list item callback
Definition nbgl_step.h:52
#define BACKWARD_DIRECTION
When action callback applies on any button press.
Definition nbgl_step.h:75
Internal functions of NBGL step layer.
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_layoutMenuList_t list
structure to store the number of menu items and the way to select them
Definition nbgl_step.c:72
nbgl_stepMenuListCallback_t selectedCallback
function to call when a menu list item is selected
Definition nbgl_step.c:70
StepStype_t type
type of step
Definition nbgl_step.c:82
TextContext_t textContext
if type is TEXT_STEP or CENTERED_INFO_STEP
Definition nbgl_step.c:77
nbgl_layout_t * layout
handler of the used layout
Definition nbgl_step.c:81
nbgl_screenTickerConfiguration_t ticker
structure containing information about ticker
Definition nbgl_step.c:80
bool modal
true if modal
Definition nbgl_step.c:83
MenuListContext_t menuListContext
if type is MENU_LIST_STEP
Definition nbgl_step.c:78
const char * nextPageStart
pointer on the start point of text at the next page
Definition nbgl_step.c:50
uint16_t currentPage
current page for this text step
Definition nbgl_step.c:48
char tmpString[TMP_STRING_MAX_LEN]
Definition nbgl_step.c:57
uint16_t nbPages
Definition nbgl_step.c:46
nbgl_contentCenteredInfoStyle_t style
style to be used with a CENTERED_INFO_STEP step
Definition nbgl_step.c:60
const char * txtStart
pointer on the start point of text (first page)
Definition nbgl_step.c:49
nbgl_stepPosition_t pos
position of the step within a flow (used for navigation arrows)
Definition nbgl_step.c:53
const char * subTxtStart
pointer on the start point of sub-text (first page)
Definition nbgl_step.c:51
bool actionOnAnyButton
if true, action applies on any button
Definition nbgl_step.c:54
uint8_t nbMaxLinesForSubText
Definition nbgl_step.c:61
nbgl_stepButtonCallback_t onActionCallback
Definition nbgl_step.c:55
nbgl_screenTickerConfiguration_t ticker
nbgl_layoutButtonCallback_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)