16 #ifdef BUILD_SCREENSHOTS
17 #include "json_scenario.h"
24 #define TMP_STRING_MAX_LEN 24
27 #define NB_MAX_LAYERS 3
44 typedef struct TextContext_s {
48 const char *nextPageStart;
49 const char *subTxtStart;
54 char tmpString[TMP_STRING_MAX_LEN];
63 typedef struct MenuListContext_s {
70 typedef struct StepContext_s {
72 TextContext_t textContext;
73 MenuListContext_t menuListContext;
85 static StepContext_t contexts[NB_MAX_LAYERS];
90 #ifdef BUILD_SCREENSHOTS
97 extern bool last_bold_state;
108 static StepContext_t *getFreeContext(StepStype_t type,
bool modal)
110 StepContext_t *ctx = NULL;
118 while (i < NB_MAX_LAYERS) {
119 if (contexts[i].layout == NULL) {
130 memset(ctx, 0,
sizeof(StepContext_t));
139 static StepContext_t *getContextFromLayout(
nbgl_layout_t layout)
141 StepContext_t *ctx = NULL;
143 while (i < NB_MAX_LAYERS) {
144 if (contexts[i].layout == layout) {
157 static const char *getTextPageAt(StepContext_t *ctx,
uint8_t textPage)
160 const char *currentChar = ctx->textContext.txtStart;
161 while (page < textPage) {
162 if (page < (ctx->textContext.nbPages - 1)) {
170 currentChar = currentChar + len;
178 static const char *getSubTextPageAt(StepContext_t *ctx,
uint8_t textPage)
181 const char *currentChar = ctx->textContext.subTxtStart;
182 while (page < textPage) {
183 if (page < (ctx->textContext.nbPages - 1)) {
191 currentChar = currentChar + len;
206 if (currentPage > 0) {
209 if (currentPage < (nbPages - 1)) {
226 static void displayTextPage(StepContext_t *ctx,
uint8_t textPage)
231 if (textPage <= ctx->textContext.currentPage) {
233 if (ctx->textContext.subTxtStart == NULL) {
234 txt = getTextPageAt(ctx, textPage);
237 txt = getSubTextPageAt(ctx, textPage);
242 txt = ctx->textContext.nextPageStart;
244 ctx->textContext.currentPage = textPage;
246 if (ctx->textContext.currentPage < (ctx->textContext.nbPages - 1)) {
253 ctx->textContext.nextPageStart = txt + len;
256 ctx->textContext.nextPageStart = NULL;
263 layoutDescription.
modal = ctx->modal;
265 layoutDescription.
ticker.tickerCallback = ctx->ticker.tickerCallback;
266 layoutDescription.
ticker.tickerIntervale = ctx->ticker.tickerIntervale;
267 layoutDescription.
ticker.tickerValue = ctx->ticker.tickerValue;
271 ctx->textContext.pos, ctx->textContext.nbPages, ctx->textContext.currentPage);
273 if (ctx->textContext.subTxtStart == NULL) {
277 if (ctx->textContext.nbPages == 1) {
278 nbgl_layoutAddText(ctx->layout, ctx->textContext.txtStart, txt, ctx->textContext.style);
281 SPRINTF(ctx->textContext.tmpString,
283 ctx->textContext.txtStart,
284 ctx->textContext.currentPage + 1,
285 ctx->textContext.nbPages);
287 ctx->layout, ctx->textContext.tmpString, txt, ctx->textContext.style);
291 nbgl_layoutAddNavigation(ctx->layout, &navInfo);
300 StepContext_t *ctx = getContextFromLayout(layout);
306 if (ctx->textContext.currentPage > 0) {
307 displayTextPage(ctx, ctx->textContext.currentPage - 1);
310 else if ((ctx->textContext.pos ==
LAST_STEP)
312 if (ctx->textContext.onActionCallback != NULL) {
313 ctx->textContext.onActionCallback((
nbgl_step_t) ctx, event);
318 if (ctx->textContext.currentPage < (ctx->textContext.nbPages - 1)) {
319 displayTextPage(ctx, ctx->textContext.currentPage + 1);
324 if (ctx->textContext.onActionCallback != NULL) {
325 ctx->textContext.onActionCallback((
nbgl_step_t) ctx, event);
330 if (ctx->textContext.onActionCallback != NULL) {
331 ctx->textContext.onActionCallback((
nbgl_step_t) ctx, event);
336 static void displayMenuList(StepContext_t *ctx)
339 = {.
modal = ctx->modal, .onActionCallback = menuListActionCallback};
342 layoutDescription.
ticker.tickerCallback = ctx->ticker.tickerCallback;
343 layoutDescription.
ticker.tickerIntervale = ctx->ticker.tickerIntervale;
344 layoutDescription.
ticker.tickerValue = ctx->ticker.tickerValue;
347 nbgl_layoutAddMenuList(ctx->layout, list);
359 nbgl_layoutAddNavigation(ctx->layout, &navInfo);
369 StepContext_t *ctx = getContextFromLayout(layout);
375 if (ctx->menuListContext.list.selectedChoice > 0) {
376 ctx->menuListContext.list.selectedChoice--;
377 displayMenuList(ctx);
381 if (ctx->menuListContext.list.selectedChoice < (ctx->menuListContext.list.nbChoices - 1)) {
382 ctx->menuListContext.list.selectedChoice++;
383 displayMenuList(ctx);
387 ctx->menuListContext.selectedCallback(ctx->menuListContext.list.selectedChoice);
417 #ifdef BUILD_SCREENSHOTS
420 area.x0 = area.y0 = 0;
424 StepContext_t *ctx = getFreeContext(TEXT_STEP, modal);
429 ctx->textContext.onActionCallback = onActionCallback;
431 ctx->ticker.tickerCallback = ticker->tickerCallback;
432 ctx->ticker.tickerIntervale = ticker->tickerIntervale;
433 ctx->ticker.tickerValue = ticker->tickerValue;
437 if (subText == NULL) {
440 #ifdef BUILD_SCREENSHOTS
441 store_string_infos(text,
451 #ifdef BUILD_SCREENSHOTS
456 nb_lines_title = last_nb_lines;
458 if (nb_lines_title > 3) {
463 store_string_infos(text,
474 #ifdef BUILD_SCREENSHOTS
478 store_string_infos(subText,
488 "nbgl_stepDrawText: ctx = %p, nbPages = %d, pos = 0x%X\n",
490 ctx->textContext.nbPages,
494 ctx->textContext.currentPage = ctx->textContext.nbPages - 1;
496 ctx->textContext.txtStart = text;
497 ctx->textContext.subTxtStart = subText;
500 ctx->textContext.style = style;
501 displayTextPage(ctx, ctx->textContext.currentPage);
527 StepContext_t *ctx = getFreeContext(CENTERED_INFO_STEP, modal);
533 ctx->textContext.onActionCallback = onActionCallback;
535 ctx->ticker.tickerCallback = ticker->tickerCallback;
536 ctx->ticker.tickerIntervale = ticker->tickerIntervale;
537 ctx->ticker.tickerValue = ticker->tickerValue;
538 layoutDescription.
ticker.tickerCallback = ticker->tickerCallback;
539 layoutDescription.
ticker.tickerIntervale = ticker->tickerIntervale;
540 layoutDescription.
ticker.tickerValue = ticker->tickerValue;
543 ctx->textContext.nbPages = 1;
547 ctx->textContext.pos, ctx->textContext.nbPages, ctx->textContext.currentPage);
552 nbgl_layoutAddNavigation(ctx->layout, &navInfo);
576 StepContext_t *ctx = getFreeContext(MENU_LIST_STEP, modal);
583 ctx->ticker.tickerCallback = ticker->tickerCallback;
584 ctx->ticker.tickerIntervale = ticker->tickerIntervale;
585 ctx->ticker.tickerValue = ticker->tickerValue;
588 ctx->menuListContext.list.nbChoices = list->
nbChoices;
590 ctx->menuListContext.list.callback = list->
callback;
591 ctx->menuListContext.selectedCallback = onActionCallback;
593 displayMenuList(ctx);
608 StepContext_t *ctx = (StepContext_t *) step;
612 return (ctx->menuListContext.list.selectedChoice);
623 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)
compute the number of pages of nbLinesPerPage lines per page of the given text fitting in the given m...
bool nbgl_getTextMaxLenInNbLines(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t maxNbLines, uint16_t *len, bool wrapping)
compute the len of the given text (in bytes) fitting in the given maximum nb lines,...
@ BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp
uint8_t nbgl_getFontLineHeight(nbgl_font_id_e fontId)
return the height in pixels of the line of font with the given font ID
@ 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...
int nbgl_layoutDraw(nbgl_layout_t *layout)
Applies given layout. The screen will be redrawn.
void * nbgl_layout_t
type shared externally
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_layout_t * nbgl_layoutGet(const nbgl_layoutDescription_t *description)
returns a layout of the given type. The layout is reset
void nbgl_refresh(void)
This functions refreshes the actual screen on display with what has changed since the last refresh.
@ 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
Step construction API of NBGL.
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
@ 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
uint8_t nbgl_stepGetMenuListCurrent(nbgl_step_t step)
void * nbgl_step_t
type shared externally
uint8_t nbgl_stepPosition_t
this type contains nbgl_layoutNavIndication_t in its LSBs and direction in its MSB (using FORWARD_DIR...
nbgl_step_t nbgl_stepDrawMenuList(nbgl_stepMenuListCallback_t onActionCallback, nbgl_screenTickerConfiguration_t *ticker, nbgl_layoutMenuList_t *list, bool modal)
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
struct PACKED__ nbgl_area_s nbgl_area_t
Represents a rectangle area of the screen.
This structure contains info to build a centered (vertically and horizontally) area,...
Structure containing all information when creating a layout. This structure must be passed as argumen...
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_layoutNavDirection_t direction
vertical or horizontal navigation
nbgl_layoutNavIndication_t indication
specifies which arrows to use (left or right)
BOLOS_UX_LOC_STRINGS UX_LOC_STRINGS_INDEX