Skip to content

Commit

Permalink
Truncate title when drawing multi-pages step
Browse files Browse the repository at this point in the history
  • Loading branch information
nroggeman-ledger committed Feb 21, 2025
1 parent 61b4d94 commit 277e938
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib_nbgl/src/nbgl_step.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,31 @@ static void displayTextPage(StepContext_t *ctx, uint8_t textPage)
nbgl_layoutAddText(ctx->layout, ctx->textContext.txtStart, txt, ctx->textContext.style);
}
else {
SPRINTF(ctx->textContext.tmpString,
char intermediateString[36]; // a bit bigger but we know that one line cannot contain
// more than 23 chars
SPRINTF(intermediateString,
"%s (%d/%d)",
ctx->textContext.txtStart,
ctx->textContext.currentPage + 1,
ctx->textContext.nbPages);
// truncate title to fit in one line, if necessary
if (nbgl_getTextNbLinesInWidth(BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp,
intermediateString,
AVAILABLE_WIDTH,
false)
> 1) {
nbgl_textReduceOnNbLines(BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp,
intermediateString,
AVAILABLE_WIDTH,
1,
ctx->textContext.tmpString,
TMP_STRING_MAX_LEN);
}
else {
// simply copy
memcpy(ctx->textContext.tmpString, intermediateString, TMP_STRING_MAX_LEN - 1);
ctx->textContext.tmpString[TMP_STRING_MAX_LEN - 1] = 0;
}
nbgl_layoutAddText(
ctx->layout, ctx->textContext.tmpString, txt, ctx->textContext.style);
}
Expand Down

0 comments on commit 277e938

Please sign in to comment.