13#include "nbgl_layout_internal_nanos.h"
17#ifdef BUILD_SCREENSHOTS
18#include "json_scenario.h"
25#define TMP_STRING_MAX_LEN 24
28#define NB_MAX_LAYERS 3
45typedef struct TextContext_s {
50 const char *nextPageStart;
51 const char *subTxtStart;
54 bool actionOnAnyButton;
57 char tmpString[TMP_STRING_MAX_LEN];
61 uint8_t nbMaxLinesForSubText;
68typedef struct MenuListContext_s {
75typedef struct StepContext_s {
77 TextContext_t textContext;
78 MenuListContext_t menuListContext;
90static StepContext_t contexts[NB_MAX_LAYERS];
95#ifdef BUILD_SCREENSHOTS
97extern uint16_t last_nb_lines;
98extern uint16_t last_nb_pages;
99extern bool last_bold_state;
110static StepContext_t *getFreeContext(StepStype_t type,
bool modal)
112 StepContext_t *ctx = NULL;
120 while (i < NB_MAX_LAYERS) {
121 if (contexts[i].layout == NULL) {
132 memset(ctx, 0,
sizeof(StepContext_t));
141static StepContext_t *getContextFromLayout(
nbgl_layout_t layout)
143 StepContext_t *ctx = NULL;
145 while (i < NB_MAX_LAYERS) {
146 if (contexts[i].layout == layout) {
165 if (ctx->layout != NULL) {
170 if (ctx->layout == NULL) {
179static uint16_t getSubTextPageLen(StepContext_t *ctx,
const char *subText)
182 if (ctx->textContext.style == BUTTON_INFO) {
185 while ((row < NB_MAX_BUTTON_ROWS) && (subText[len] !=
'\0')) {
186 uint16_t rowLen, rowWidth;
187 len += layoutGetButtonRowLen(&subText[len], &rowLen, &rowWidth);
205static uint16_t getPageLen(StepContext_t *ctx,
const char *txt)
208 if (ctx->textContext.subTxtStart == NULL) {
213 len = getSubTextPageLen(ctx, txt);
217 if (((ctx->textContext.subTxtStart == NULL) || (ctx->textContext.style != BUTTON_INFO))
218 && (txt[len] ==
'\n')) {
226static const char *getPageAt(StepContext_t *ctx, uint16_t textPage)
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);
243 uint16_t currentPage)
248 if (currentPage > 0) {
251 if (currentPage < (nbPages - 1)) {
268static void displayTextPage(StepContext_t *ctx, uint16_t textPage)
271 char intermediateString[36];
275 if (textPage <= ctx->textContext.currentPage) {
277 txt = getPageAt(ctx, textPage);
281 txt = ctx->textContext.nextPageStart;
283 ctx->textContext.currentPage = textPage;
285 if (ctx->textContext.currentPage < (ctx->textContext.nbPages - 1)) {
287 ctx->textContext.nextPageStart = txt + getPageLen(ctx, txt);
290 ctx->textContext.nextPageStart = NULL;
297 layoutDescription.
modal = ctx->modal;
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)) {
307 ctx->textContext.pos, ctx->textContext.nbPages, ctx->textContext.currentPage);
309 if (ctx->textContext.subTxtStart == NULL) {
313 if (ctx->textContext.nbPages == 1) {
316 ctx->textContext.txtStart,
321 ctx->textContext.txtStart,
324 ctx->textContext.tmpString,
328 if (ctx->textContext.txtStart != NULL) {
331 ctx->textContext.tmpString, ctx->textContext.txtStart, TMP_STRING_MAX_LEN);
334 ctx->textContext.tmpString[0] = 0;
339 SPRINTF(intermediateString,
341 ctx->textContext.txtStart,
342 (
int) (ctx->textContext.currentPage + 1),
343 (
int) ctx->textContext.nbPages);
354 ctx->textContext.tmpString,
359 memcpy(ctx->textContext.tmpString, intermediateString, TMP_STRING_MAX_LEN - 1);
360 ctx->textContext.tmpString[TMP_STRING_MAX_LEN - 1] = 0;
366 layoutAddText(ctx->layout,
367 ctx->textContext.tmpString,
369 ctx->textContext.style,
370 ctx->textContext.nbMaxLinesForSubText,
371 ctx->textContext.nbMaxLinesForSubText > 0);
374 nbgl_layoutAddNavigation(ctx->layout, &navInfo);
383 StepContext_t *ctx = getContextFromLayout(layout);
390 if (ctx->textContext.currentPage > 0) {
391 displayTextPage(ctx, ctx->textContext.currentPage - 1);
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);
403 if (ctx->textContext.currentPage < (ctx->textContext.nbPages - 1)) {
404 displayTextPage(ctx, ctx->textContext.currentPage + 1);
409 || (ctx->textContext.actionOnAnyButton)) {
410 if (ctx->textContext.onActionCallback != NULL) {
411 ctx->textContext.onActionCallback((
nbgl_step_t) ctx, event);
416 if (ctx->textContext.onActionCallback != NULL) {
417 ctx->textContext.onActionCallback((
nbgl_step_t) ctx, event);
422static void displayMenuList(StepContext_t *ctx)
425 = {.modal = ctx->modal, .onActionCallback = menuListActionCallback};
428 layoutDescription.
ticker.tickerCallback = ctx->ticker.tickerCallback;
429 layoutDescription.
ticker.tickerIntervale = ctx->ticker.tickerIntervale;
430 layoutDescription.
ticker.tickerValue = ctx->ticker.tickerValue;
432 if (!getStepLayout(ctx, &layoutDescription)) {
435 nbgl_layoutAddMenuList(ctx->layout, list);
447 nbgl_layoutAddNavigation(ctx->layout, &navInfo);
457 StepContext_t *ctx = getContextFromLayout(layout);
464 if (ctx->menuListContext.list.selectedChoice > 0) {
465 ctx->menuListContext.list.selectedChoice--;
466 displayMenuList(ctx);
470 if (ctx->menuListContext.list.selectedChoice < (ctx->menuListContext.list.nbChoices - 1)) {
471 ctx->menuListContext.list.selectedChoice++;
472 displayMenuList(ctx);
476 ctx->menuListContext.selectedCallback(ctx->menuListContext.list.selectedChoice);
506 return stepDrawText(
pos, onActionCallback, ticker, text, subText, style, modal, 0);
531 uint8_t nbMaxLinesForSubText)
533#ifdef BUILD_SCREENSHOTS
536 area.x0 = area.y0 = 0;
540 StepContext_t *ctx = getFreeContext(TEXT_STEP, modal);
548 subText = PIC(subText);
550 ctx->textContext.onActionCallback = onActionCallback;
552 ctx->textContext.style = style;
554 ctx->ticker.tickerCallback = ticker->tickerCallback;
555 ctx->ticker.tickerIntervale = ticker->tickerIntervale;
556 ctx->ticker.tickerValue = ticker->tickerValue;
560 if (subText == NULL) {
563#ifdef BUILD_SCREENSHOTS
564 store_string_infos(text,
574#ifdef BUILD_SCREENSHOTS
575 uint16_t nb_lines_title;
579 nb_lines_title = last_nb_lines;
581 if (nb_lines_title > 3) {
586 store_string_infos(text,
594 if (nbMaxLinesForSubText > 0) {
596 ctx->textContext.nbMaxLinesForSubText = nbMaxLinesForSubText;
597 ctx->textContext.nbPages = 1;
599 else if (style == BUTTON_INFO) {
602 const char *pageStart = subText;
604 pageStart += getSubTextPageLen(ctx, pageStart);
605 ctx->textContext.nbPages++;
606 }
while (*pageStart !=
'\0');
613#ifdef BUILD_SCREENSHOTS
614 if ((nbMaxLinesForSubText > 0) || (style == BUTTON_INFO)) {
625 store_string_infos(subText,
629 ((style != BUTTON_INFO) && (nbMaxLinesForSubText > 0)
630 && (last_nb_lines > nbMaxLinesForSubText))
631 ? nbMaxLinesForSubText
633 ((style == BUTTON_INFO) || (nbMaxLinesForSubText > 0))
634 ? ctx->textContext.nbPages
640 "nbgl_stepDrawText: ctx = %p, nbPages = %d, pos = 0x%X\n",
642 (
int) ctx->textContext.nbPages,
646 ctx->textContext.currentPage = ctx->textContext.nbPages - 1;
648 ctx->textContext.txtStart = text;
649 ctx->textContext.subTxtStart = subText;
653 displayTextPage(ctx, ctx->textContext.currentPage);
679 StepContext_t *ctx = getFreeContext(CENTERED_INFO_STEP, modal);
686 ctx->textContext.onActionCallback = onActionCallback;
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;
696 ctx->textContext.nbPages = 1;
700 ctx->textContext.pos, ctx->textContext.nbPages, ctx->textContext.currentPage);
705 nbgl_layoutAddNavigation(ctx->layout, &navInfo);
729 StepContext_t *ctx = getFreeContext(MENU_LIST_STEP, modal);
737 ctx->ticker.tickerCallback = ticker->tickerCallback;
738 ctx->ticker.tickerIntervale = ticker->tickerIntervale;
739 ctx->ticker.tickerValue = ticker->tickerValue;
742 ctx->menuListContext.list.nbChoices = list->
nbChoices;
744 ctx->menuListContext.list.callback = list->
callback;
745 ctx->menuListContext.selectedCallback = onActionCallback;
747 displayMenuList(ctx);
762 StepContext_t *ctx = (StepContext_t *) step;
766 return (ctx->menuListContext.list.selectedChoice);
792 StepContext_t *ctx = getFreeContext(CENTERED_INFO_STEP, modal);
799 ctx->textContext.onActionCallback = onActionCallback;
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;
809 ctx->textContext.nbPages = 1;
813 ctx->textContext.pos, ctx->textContext.nbPages, ctx->textContext.currentPage);
818 nbgl_layoutAddNavigation(ctx->layout, &navInfo);
835 StepContext_t *ctx = (StepContext_t *) step;
nbgl_contentCenteredInfoStyle_t
possible styles for Centered Info Area
#define LOG_WARN(__logger,...)
#define LOG_DEBUG(__logger,...)
#define LOG_FATAL(__logger,...)
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
@ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp
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)
@ 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)
@ 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.
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.
@ BUTTON_BOTH_PRESSED
Sent when both buttons are released.
@ BUTTON_LEFT_PRESSED
Sent when Left button is released.
@ BUTTON_RIGHT_PRESSED
Send when Right button is released.
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
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
uint8_t nbgl_stepPosition_t
this type is a bitfield containing:
#define STEP_POSITION_MASK
@ NEITHER_FIRST_NOR_LAST_STEP
neither first nor last in a multiple steps flow
@ LAST_STEP
last in a multiple steps flow
@ FIRST_STEP
first in a multiple steps flow
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.
int nbgl_stepRelease(nbgl_step_t step)
void(* nbgl_stepMenuListCallback_t)(uint8_t choiceIndex)
prototype of chosen menu list item callback
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.
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 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