Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep pointer for nbgl_layoutAddKeypad (LNX/LNS+) #634

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib_nbgl/include/nbgl_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,11 +666,14 @@ int nbgl_layoutUpdateKeypadContent(nbgl_layout_t *layout,
uint8_t nbActiveDigits,
const char *text);

#else // HAVE_SE_TOUCH
#else // HAVE_SE_TOUCH
/* layout objects for pages with keypad (nanos) */
int nbgl_layoutAddKeypad(nbgl_layout_t *layout,
keyboardCallback_t callback,
const char *text,
#ifdef BUILD_SCREENSHOTS
UX_LOC_STRINGS_INDEX textId,
#endif // BUILD_SCREENSHOTS
bool shuffled);
int nbgl_layoutUpdateKeypad(nbgl_layout_t *layout,
uint8_t index,
Expand Down
79 changes: 46 additions & 33 deletions lib_nbgl/src/nbgl_fonts.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,7 @@ bool nbgl_getTextMaxLenInNbLines(nbgl_font_id_e fontId,

// if \n, reset width
if (unicode == '\n') {
if (width != 0) {
maxNbLines--;
}
maxNbLines--;
width = 0;
continue;
}
Expand Down Expand Up @@ -713,13 +711,17 @@ uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId,
uint16_t maxWidth,
bool wrapping)
{
const nbgl_font_t *font = nbgl_getFont(fontId);
uint16_t width = 0;
uint16_t nbLines = 0;
uint16_t textLen = strlen(text);
const char *lastDelimiter = NULL;
uint32_t lenAtLastDelimiter = 0;
const char *prevText = NULL;
const nbgl_font_t *font = nbgl_getFont(fontId);
uint16_t width = 0;
#ifdef SCREEN_SIZE_NANO
uint16_t nbLines = 0;
#else // SCREEN_SIZE_NANO
uint16_t nbLines = 1;
#endif // SCREEN_SIZE_NANO
uint16_t textLen = strlen(text);
const char *lastDelimiter = NULL;
uint32_t lenAtLastDelimiter = 0;
const char *prevText = NULL;

#ifdef BUILD_SCREENSHOTS
last_nb_lines = 0;
Expand Down Expand Up @@ -751,9 +753,13 @@ uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId,
#ifdef BUILD_SCREENSHOTS
// Continue parsing the string, to find the real nb_lines & nb_pages!
++last_nb_pages;
#ifdef SCREEN_SIZE_NANO
if (width != 0) {
#endif // SCREEN_SIZE_NANO
++nbLines;
#ifdef SCREEN_SIZE_NANO
}
#endif // SCREEN_SIZE_NANO
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
Expand All @@ -766,18 +772,18 @@ uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId,
}
// if \n, increment the number of lines
else if (unicode == '\n') {
if (width != 0) {
nbLines++;
nbLines++;
#ifdef BUILD_SCREENSHOTS
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
if (nbLines == 4) {
++last_nb_pages;
nbLines = 0;
}
#endif // BUILD_SCREENSHOTS
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
#ifdef SCREEN_SIZE_NANO
if (nbLines == 4) {
++last_nb_pages;
nbLines = 0;
}
#endif // SCREEN_SIZE_NANO
#endif // BUILD_SCREENSHOTS
width = 0;
lastDelimiter = NULL;
continue;
Expand Down Expand Up @@ -832,16 +838,19 @@ uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId,
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
#ifdef SCREEN_SIZE_NANO
if (nbLines == 4) {
++last_nb_pages;
nbLines = 0;
}
#endif // SCREEN_SIZE_NANO
#endif // BUILD_SCREENSHOTS
}
else {
width += char_width;
}
}
#ifdef SCREEN_SIZE_NANO
if (width != 0) {
++nbLines;
}
Expand All @@ -850,6 +859,7 @@ uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId,
last_nb_lines = nbLines;
}
#endif // BUILD_SCREENSHOTS
#endif // SCREEN_SIZE_NANO
return nbLines;
}

Expand Down Expand Up @@ -905,9 +915,13 @@ uint8_t nbgl_getTextNbPagesInWidth(nbgl_font_id_e fontId,
if (unicode == '\f') {
nbPages++;
#ifdef BUILD_SCREENSHOTS
#ifdef SCREEN_SIZE_NANO
if (width != 0) {
#endif // SCREEN_SIZE_NANO
++nbLines;
#ifdef SCREEN_SIZE_NANO
}
#endif // SCREEN_SIZE_NANO
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
Expand All @@ -918,18 +932,17 @@ uint8_t nbgl_getTextNbPagesInWidth(nbgl_font_id_e fontId,
}
// if \n, increment the number of lines
else if (unicode == '\n') {
if (width != 0) {
nbLines++;
nbLines++;
#ifdef BUILD_SCREENSHOTS
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
#endif // BUILD_SCREENSHOTS
if (nbLines == nbLinesPerPage && textLen) {
nbPages++;
nbLines = 0;
}
if (nbLines == nbLinesPerPage && textLen) {
nbPages++;
nbLines = 0;
}

width = 0;
lastDelimiter = NULL;
continue;
Expand Down Expand Up @@ -996,9 +1009,11 @@ uint8_t nbgl_getTextNbPagesInWidth(nbgl_font_id_e fontId,
}
}
#ifdef BUILD_SCREENSHOTS
#ifdef SCREEN_SIZE_NANO
if (width != 0) {
++nbLines;
}
#endif // SCREEN_SIZE_NANO
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
Expand Down Expand Up @@ -1062,10 +1077,8 @@ void nbgl_textWrapOnNbLines(nbgl_font_id_e fontId, char *text, uint16_t maxWidth
unicode = nbgl_popUnicodeChar((const uint8_t **) &text, &textLen, &is_unicode);
// if \n, reset width
if (unicode == '\n') {
if (width != 0) {
currentNbLines++;
}
width = 0;
width = 0;
currentNbLines++;
lastDelimiter = NULL;
continue;
}
Expand Down
19 changes: 11 additions & 8 deletions lib_nbgl/src/nbgl_layout_keypad_nanos.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
* PROTOTYPES
**********************/

// #ifdef BUILD_SCREENSHOTS
#ifdef BUILD_SCREENSHOTS
extern const char *get_ux_loc_string(uint32_t index);
// #endif // BUILD_SCREENSHOTS
#endif // BUILD_SCREENSHOTS

/**********************
* GLOBAL FUNCTIONS
Expand All @@ -56,19 +56,22 @@ extern const char *get_ux_loc_string(uint32_t index);
*
* @param layout the current layout
* @param callback function called when any of the key is touched
* @param text text to use as title for the keypad
* @param textId ID of the text to use as title for the keypad
* @param shuffled if set to true, digits are shuffled in keypad
* @return the index of keypad in layout, to use in @ref nbgl_layoutUpdateKeypad()
*/
int nbgl_layoutAddKeypad(nbgl_layout_t *layout,
keyboardCallback_t callback,
int nbgl_layoutAddKeypad(nbgl_layout_t *layout,
keyboardCallback_t callback,
const char *text,
#ifdef BUILD_SCREENSHOTS
UX_LOC_STRINGS_INDEX textId,
bool shuffled)
#endif // BUILD_SCREENSHOTS
bool shuffled)
{
nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
nbgl_keypad_t *keypad;
nbgl_text_area_t *textArea;
const char *text = get_ux_loc_string(textId);

LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddKeypad():\n");
if (layout == NULL) {
Expand All @@ -78,9 +81,9 @@ int nbgl_layoutAddKeypad(nbgl_layout_t *layout,
textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
textArea->textColor = WHITE;
textArea->text = PIC(text);
#if (defined(HAVE_LANGUAGE_PACK) || defined(BUILD_SCREENSHOTS))
#ifdef BUILD_SCREENSHOTS
textArea->textId = textId;
#endif //(defined(HAVE_LANGUAGE_PACK)||defined(BUILD_SCREENSHOTS))
#endif // BUILD_SCREENSHOTS
textArea->textAlignment = CENTER;
textArea->fontId = BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp;
textArea->obj.area.width = AVAILABLE_WIDTH;
Expand Down
Loading