Skip to content

Commit

Permalink
Add ability to change validation icon type in PinPad with arrow inste…
Browse files Browse the repository at this point in the history
…ad of check
  • Loading branch information
nroggeman-ledger committed Nov 28, 2024
1 parent 76c8ed1 commit 8976ff9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib_nbgl/include/nbgl_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ int nbgl_layoutUpdateKeypad(nbgl_layout_t *layout,
bool enableValidate,
bool enableBackspace,
bool enableDigits);
int nbgl_layoutUpdateKeypadValidation(nbgl_layout_t *layout, bool softValidation);
DEPRECATED int nbgl_layoutAddHiddenDigits(nbgl_layout_t *layout, uint8_t nbDigits);
DEPRECATED int nbgl_layoutUpdateHiddenDigits(nbgl_layout_t *layout,
uint8_t index,
Expand Down
2 changes: 1 addition & 1 deletion lib_nbgl/include/nbgl_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ typedef struct PACKED__ nbgl_keyboard_s {
typedef struct PACKED__ nbgl_keypad_s {
nbgl_obj_t obj; ///< common part
#ifdef HAVE_SE_TOUCH
color_t textColor; ///< color set to digits.
color_t borderColor; ///< color set to key borders
bool softValidation; ///< if true, the "check icon" is replaced by an arrow
bool enableDigits; ///< if true, Digit keys are enabled
bool partial; ///< if true, means that only some keys have changed
uint8_t digitIndexes[5]; ///< array of digits indexes, 4 bits per digit
Expand Down
3 changes: 2 additions & 1 deletion lib_nbgl/src/nbgl_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,8 @@ static nbgl_container_t *addContentCenter(nbgl_layoutInternal_t *layoutInt,

// get container children
container->nbChildren = 0;
container->children = nbgl_containerPoolGet(6, layoutInt->layer);
// the max number is: icon + anim + title + small title + description + sub-text
container->children = nbgl_containerPoolGet(6, layoutInt->layer);

// add icon or animation if present
if (info->icon != NULL) {
Expand Down
29 changes: 29 additions & 0 deletions lib_nbgl/src/nbgl_layout_keypad.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,35 @@ int nbgl_layoutUpdateKeypad(nbgl_layout_t *layout,
return 0;
}

/**
* @brief Updates an existing keypad on bottom of the screen, with the given configuration, without
* redraw
*
* @param layout the current layout
* @param softValidation if true, the "check icon" is replaced by an arrow
* @return >=0 if OK
*/
int nbgl_layoutUpdateKeypadValidation(nbgl_layout_t *layout, bool softValidation)
{
nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
nbgl_keypad_t *keypad;

LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutUpdateKeypad(): softValidation = %d,\n", softValidation);
if (layout == NULL) {
return -1;
}
UNUSED(index);

// get existing keypad (in the footer container)
keypad = (nbgl_keypad_t *) layoutInt->footerContainer->children[0];
if ((keypad == NULL) || (keypad->obj.type != KEYPAD)) {
return -1;
}
keypad->softValidation = softValidation;

return 0;
}

/**
* @brief Adds a placeholder for hidden digits on top of a keypad, to represent the entered digits,
* as full circles The placeholder is "underligned" with a thin horizontal line of the expected full
Expand Down
19 changes: 13 additions & 6 deletions lib_nbgl/src/nbgl_obj_keypad.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,25 +221,32 @@ static void keypadDrawDigits(nbgl_keypad_t *keypad)
nbgl_frontDrawRect(&rectArea); // 1st full line, on the left
}
else {
const nbgl_icon_details_t *icon;

if (keypad->softValidation) {
icon = &RIGHT_ARROW_ICON;
}
else {
icon = &VALIDATE_ICON;
}
// if enabled, draw icon in white on a black background
rectArea.backgroundColor = BLACK;
rectArea.x0 = keypad->obj.area.x0 + 2 * KEY_WIDTH;
rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3;
rectArea.width = KEY_WIDTH;
rectArea.height = KEYPAD_KEY_HEIGHT;
nbgl_frontDrawRect(&rectArea);
rectArea.width = VALIDATE_ICON.width;
rectArea.height = VALIDATE_ICON.height;
rectArea.width = icon->width;
rectArea.height = icon->height;
rectArea.bpp = NBGL_BPP_1;
rectArea.x0 = keypad->obj.area.x0 + 2 * KEY_WIDTH + (KEY_WIDTH - rectArea.width) / 2;
rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3
+ (KEYPAD_KEY_HEIGHT - rectArea.height) / 2;
if (VALIDATE_ICON.isFile) {
nbgl_frontDrawImageFile(&rectArea, (uint8_t *) VALIDATE_ICON.bitmap, WHITE, ramBuffer);
if (icon->isFile) {
nbgl_frontDrawImageFile(&rectArea, (uint8_t *) icon->bitmap, WHITE, ramBuffer);
}
else {
nbgl_frontDrawImage(
&rectArea, (uint8_t *) VALIDATE_ICON.bitmap, NO_TRANSFORMATION, WHITE);
nbgl_frontDrawImage(&rectArea, (uint8_t *) icon->bitmap, NO_TRANSFORMATION, WHITE);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib_nbgl/src/nbgl_serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static void nbgl_serializeKeypad(nbgl_keypad_t *obj, uint8_t *out, size_t *w_cnt
nbgl_serializeObj((nbgl_obj_t *) &obj->obj, out, w_cnt, max_len);

#ifdef HAVE_SE_TOUCH
nbgl_appendU8((uint8_t) obj->textColor, out, w_cnt, max_len);
nbgl_appendU8((uint8_t) obj->softValidation, out, w_cnt, max_len);
nbgl_appendU8((uint8_t) obj->borderColor, out, w_cnt, max_len);
#endif // HAVE_SE_TOUCH
nbgl_appendU8((uint8_t) obj->enableBackspace, out, w_cnt, max_len);
Expand Down

0 comments on commit 8976ff9

Please sign in to comment.