Skip to content

Commit

Permalink
Stax - Use IDs for touchable objects to ease tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nroggeman-ledger committed Sep 12, 2023
1 parent a5e2d10 commit 76503a3
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 97 deletions.
29 changes: 27 additions & 2 deletions lib_nbgl/include/nbgl_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,16 @@ typedef void (*nbgl_touchCallback_t)(void *obj, nbgl_touchType_t eventType) ;
*/
typedef struct PACKED__ nbgl_obj_s {
nbgl_area_t area; ///< absolute position, backGround color and size of the object. DO NOT MOVE THIS FIELD
nbgl_obj_type_t type; ///< type of the graphical object, must be explicitly set
int16_t rel_x0; ///< horizontal position of top-left corner relative to parent's top-left corner
int16_t rel_y0; ///< vertical position of top-left corner relative to parent's top-left corner, must be multiple of 4
struct nbgl_obj_s *parent; ///< parent of this object
struct nbgl_obj_s *alignTo; ///< object to align to (parent by default)
nbgl_aligment_t alignment; ///< type of alignment
int16_t alignmentMarginX; ///< horizontal margin when aligning
int16_t alignmentMarginY; ///< vertical margin when aligning
nbgl_obj_type_t type; ///< type of the graphical object, must be explicitly set
uint8_t touchMask; ///< bit mask to tell engine which touch events are handled by this object
uint8_t touchId; ///< a unique identifier (by screen) to be used by external test environnement (TTYT or Screenshots)
} nbgl_obj_t;

/**
Expand Down Expand Up @@ -431,6 +432,28 @@ typedef struct PACKED__ nbgl_keypad_s {
keyboardCallback_t callback; ///< function called when an active key is pressed
} nbgl_keypad_t;

/**
* @brief ids of touchable objects, for external stimulus (by Testing environment)
*
*/
enum {
BOTTOM_BUTTON_ID = 1,
LEFT_BUTTON_ID,
RIGHT_BUTTON_ID,
WHOLE_SCREEN_ID,
TOP_RIGHT_BUTTON_ID,
BACK_BUTTON_ID,
SINGLE_BUTTON_ID,
CHOICE_1_ID,
CHOICE_2_ID,
KEYPAD_ID,
KEYBOARD_ID,
ENTERED_TEXT_ID,
CONTROLS_ID, // when multiple controls in the same pages (buttons, switches, radios)
NB_CONTROL_IDS
};


/**********************
* GLOBAL PROTOTYPES
**********************/
Expand All @@ -456,14 +479,16 @@ uint8_t nbgl_containerPoolGetNbUsed(uint8_t layer);

nbgl_container_t *nbgl_navigationPopulate(uint8_t nbPages, uint8_t activePage, bool withExitKey, uint8_t layer);
bool nbgl_navigationCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType, uint8_t nbPages, uint8_t *activePage);
nbgl_container_t *nbgl_bottomButtonPopulate(const nbgl_icon_details_t *icon, bool separationLine, uint8_t layer);

// for internal use
void nbgl_objDrawKeyboard(nbgl_keyboard_t *kbd);
void nbgl_objDrawKeypad(nbgl_keypad_t *kbd);
void nbgl_keyboardTouchCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType);
void nbgl_keypadTouchCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType);

bool nbgl_keyboardGetPosition(nbgl_keyboard_t *kbd, char index, uint16_t *x, uint16_t *y);
bool nbgl_keypadGetPosition(nbgl_keypad_t *kbd, char index, uint16_t *x, uint16_t *y);

/**********************
* MACROS
**********************/
Expand Down
1 change: 1 addition & 0 deletions lib_nbgl/include/nbgl_touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern "C" {
void nbgl_touchHandler(nbgl_touchStatePosition_t *touchEvent, uint32_t currentTimeMs);
bool nbgl_touchGetTouchedPosition(nbgl_obj_t *obj, nbgl_touchStatePosition_t **firstPos, nbgl_touchStatePosition_t **lastPos);
uint32_t nbgl_touchGetTouchDuration(nbgl_obj_t *obj);
nbgl_obj_t* nbgl_touchGetObjectFromId(nbgl_obj_t *obj, uint8_t id);

/**********************
* MACROS
Expand Down
93 changes: 0 additions & 93 deletions lib_nbgl/src/nbgl_bottom_button.c

This file was deleted.

76 changes: 75 additions & 1 deletion lib_nbgl/src/nbgl_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ static nbgl_button_t *choiceButtons[NB_MAX_SUGGESTION_BUTTONS];
static char numText[5];
#endif

// numbers of touchable controls for the whole page
static uint8_t nbTouchableControls = 0;

/**********************
* STATIC PROTOTYPES
**********************/
Expand Down Expand Up @@ -392,6 +395,56 @@ static nbgl_line_t* createLeftVerticalLine(uint8_t layer) {
return line;
}

/**
* @brief This function creates a bottom area with a centered button and a top line. Returns it as a container
*
* @param icon icon to place in centered button
* @param separationLine if set to true, adds a light gray separation line on top of the container
* @param layer screen layer to use
* @return the created container object
*/
static nbgl_container_t *createBottomButton(const nbgl_icon_details_t *icon, bool separationLine, uint8_t layer) {
nbgl_button_t *button;
nbgl_container_t *container;

container = (nbgl_container_t *)nbgl_objPoolGet(CONTAINER, layer);
container->obj.area.width = SCREEN_WIDTH;
container->obj.area.height = BUTTON_DIAMETER+2*BORDER_MARGIN;
container->layout = HORIZONTAL ;
container->nbChildren = 2;
container->children = (nbgl_obj_t**)nbgl_containerPoolGet(container->nbChildren, layer);
container->obj.alignment = NO_ALIGNMENT;

button = (nbgl_button_t*)nbgl_objPoolGet(BUTTON,layer);
button->innerColor = WHITE;
button->borderColor = LIGHT_GRAY;
button->obj.area.width = BUTTON_DIAMETER;
button->obj.area.height = BUTTON_DIAMETER;
button->radius = BUTTON_RADIUS;
button->icon = icon;
button->obj.alignment = CENTER;
button->obj.touchMask = (1<<TOUCHED);
button->obj.touchId = BOTTOM_BUTTON_ID;
container->children[0] = (nbgl_obj_t*)button;

if (separationLine) {
nbgl_line_t *line;
// create horizontal line
line = (nbgl_line_t*)nbgl_objPoolGet(LINE,0);
line->lineColor = LIGHT_GRAY;
line->obj.area.width = SCREEN_WIDTH;
line->obj.area.height = 4;
line->direction = HORIZONTAL;
line->thickness = 1;
line->obj.alignmentMarginY = BORDER_MARGIN-4;
line->obj.alignTo = (nbgl_obj_t*)button;
line->obj.alignment = TOP_MIDDLE;
container->children[1] = (nbgl_obj_t*)line;
}

return container;
}

// function adding a layout object in the callbackObjPool array for the given layout, and configuring it
static layoutObj_t *addCallbackObj(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj, uint8_t token, tune_index_e tuneId) {
layoutObj_t *layoutObj = NULL;
Expand Down Expand Up @@ -453,6 +506,8 @@ nbgl_layout_t *nbgl_layoutGet(const nbgl_layoutDescription_t *description) {
// reset globals
memset(layout,0,sizeof(nbgl_layoutInternal_t));

nbTouchableControls = 0;

layout->callback = (nbgl_layoutTouchCallback_t)PIC(description->onActionCallback);
layout->modal = description->modal;
layout->withLeftBorder = description->withLeftBorder;
Expand Down Expand Up @@ -481,6 +536,7 @@ nbgl_layout_t *nbgl_layoutGet(const nbgl_layoutDescription_t *description) {
obj->token = description->tapActionToken;
obj->tuneId = description->tapTuneId;
layout->container->obj.touchMask = (1<<TOUCHED);
layout->container->obj.touchId = WHOLE_SCREEN_ID;

// create 'tap to continue' text area
layout->tapText = (nbgl_text_area_t*)nbgl_objPoolGet(TEXT_AREA, 0);
Expand Down Expand Up @@ -530,6 +586,7 @@ int nbgl_layoutAddTopRightButton(nbgl_layout_t *layout, const nbgl_icon_details_
button->innerColor = WHITE;
button->borderColor = LIGHT_GRAY;
button->obj.touchMask = (1<<TOUCHED);
button->obj.touchId = TOP_RIGHT_BUTTON_ID;
button->icon = PIC(icon);
button->obj.alignment = TOP_RIGHT;

Expand Down Expand Up @@ -598,7 +655,7 @@ int nbgl_layoutAddBottomButton(nbgl_layout_t *layout, const nbgl_icon_details_t
if (layout == NULL)
return -1;

layoutInt->bottomContainer = nbgl_bottomButtonPopulate(icon,separationLine,layoutInt->layer);
layoutInt->bottomContainer = createBottomButton(icon,separationLine,layoutInt->layer);
obj = addCallbackObj(layoutInt,(nbgl_obj_t*)layoutInt->bottomContainer,token,tuneId);
if (obj == NULL)
return -1;
Expand Down Expand Up @@ -650,6 +707,8 @@ int nbgl_layoutAddTouchableBar(nbgl_layout_t *layout, const nbgl_layoutBar_t *ba
// otherwise it is seen as a title
if ((barLayout->inactive != true) && ((barLayout->iconLeft != NULL)||(barLayout->iconRight != NULL))) {
container->obj.touchMask = (1<<TOUCHED);
container->obj.touchId = CONTROLS_ID + nbTouchableControls;
nbTouchableControls++;
}

if (barLayout->iconLeft != NULL) {
Expand Down Expand Up @@ -763,6 +822,8 @@ int nbgl_layoutAddSwitch(nbgl_layout_t *layout, const nbgl_layoutSwitch_t *switc
container->obj.alignmentMarginX = BORDER_MARGIN;
container->obj.alignment = NO_ALIGNMENT;
container->obj.touchMask = (1<<TOUCHED);
container->obj.touchId = CONTROLS_ID + nbTouchableControls;
nbTouchableControls++;

textArea = (nbgl_text_area_t *)nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
textArea->textColor = BLACK;
Expand Down Expand Up @@ -992,6 +1053,8 @@ int nbgl_layoutAddRadioChoice(nbgl_layout_t *layout, const nbgl_layoutRadioChoic
container->obj.alignTo = (nbgl_obj_t*)NULL;
// whole container should be touchable
container->obj.touchMask = (1<<TOUCHED);
container->obj.touchId = CONTROLS_ID + nbTouchableControls;
nbTouchableControls++;

// highlight init choice
if (i == choices->initChoice) {
Expand Down Expand Up @@ -1352,6 +1415,7 @@ int nbgl_layoutAddChoiceButtons(nbgl_layout_t *layout, const nbgl_layoutChoiceBu
bottomButton->text = PIC(info->bottomText);
bottomButton->fontId = BAGL_FONT_INTER_SEMIBOLD_24px;
bottomButton->obj.touchMask = (1 << TOUCHED);
bottomButton->obj.touchId = CHOICE_2_ID;
// set this new button as child of the container
addObjectToLayout(layoutInt,(nbgl_obj_t*)bottomButton);

Expand Down Expand Up @@ -1379,6 +1443,7 @@ int nbgl_layoutAddChoiceButtons(nbgl_layout_t *layout, const nbgl_layoutChoiceBu
topButton->text = PIC(info->topText);
topButton->fontId = BAGL_FONT_INTER_SEMIBOLD_24px;
topButton->obj.touchMask = (1 << TOUCHED);
topButton->obj.touchId = CHOICE_1_ID;
// set this new button as child of the container
addObjectToLayout(layoutInt,(nbgl_obj_t*)topButton);

Expand Down Expand Up @@ -1652,6 +1717,7 @@ int nbgl_layoutAddButton(nbgl_layout_t *layout, const nbgl_layoutButton_t *butto
}
button->obj.alignTo = NULL;
button->obj.touchMask = (1 << TOUCHED);
button->obj.touchId = SINGLE_BUTTON_ID;
// set this new button as child of the container
addObjectToLayout(layoutInt,(nbgl_obj_t*)button);

Expand Down Expand Up @@ -1770,6 +1836,7 @@ int nbgl_layoutAddFooter(nbgl_layout_t *layout, const char *text, uint8_t token,
textArea->fontId = BAGL_FONT_INTER_SEMIBOLD_24px;
textArea->textAlignment = CENTER;
textArea->obj.touchMask = (1 << TOUCHED);
textArea->obj.touchId = BOTTOM_BUTTON_ID;
layoutInt->children[layoutInt->nbChildren] = (nbgl_obj_t*)textArea;
layoutInt->nbChildren++;

Expand Down Expand Up @@ -1819,6 +1886,7 @@ int nbgl_layoutAddSplitFooter(nbgl_layout_t *layout, const char *leftText, uint8
textArea->fontId = BAGL_FONT_INTER_SEMIBOLD_24px;
textArea->textAlignment = CENTER;
textArea->obj.touchMask = (1 << TOUCHED);
textArea->obj.touchId = BOTTOM_BUTTON_ID;
layoutInt->children[layoutInt->nbChildren] = (nbgl_obj_t*)textArea;
layoutInt->nbChildren++;

Expand All @@ -1836,6 +1904,7 @@ int nbgl_layoutAddSplitFooter(nbgl_layout_t *layout, const char *leftText, uint8
textArea->fontId = BAGL_FONT_INTER_SEMIBOLD_24px;
textArea->textAlignment = CENTER;
textArea->obj.touchMask = (1 << TOUCHED);
textArea->obj.touchId = RIGHT_BUTTON_ID;
layoutInt->children[layoutInt->nbChildren] = (nbgl_obj_t*)textArea;
layoutInt->nbChildren++;

Expand Down Expand Up @@ -1920,6 +1989,7 @@ int nbgl_layoutAddProgressIndicator(nbgl_layout_t *layout, uint8_t activePage, u
button->text = NULL;
button->icon = PIC(&C_leftArrow32px);
button->obj.touchMask = (1<<TOUCHED);
button->obj.touchId = BACK_BUTTON_ID;
container->children[1] = (nbgl_obj_t*)button;
}

Expand Down Expand Up @@ -2138,6 +2208,7 @@ int nbgl_layoutAddSuggestionButtons(nbgl_layout_t *layout, uint8_t nbUsedButtons
}
choiceButtons[i]->text = buttonTexts[i];
choiceButtons[i]->obj.touchMask = (1<<TOUCHED);
choiceButtons[i]->obj.touchId = CONTROLS_ID + i;
// some buttons may not be visible
if (i<nbUsedButtons)
container->children[i] = (nbgl_obj_t*)choiceButtons[i];
Expand Down Expand Up @@ -2271,6 +2342,7 @@ int nbgl_layoutAddEnteredText(nbgl_layout_t *layout, bool numbered, uint8_t numb
return -1;
textArea->token = token;
textArea->obj.touchMask = (1<<TOUCHED);
textArea->obj.touchId = ENTERED_TEXT_ID;

// set this new text area as child of the container
addObjectToLayout(layoutInt,(nbgl_obj_t*)textArea);
Expand Down Expand Up @@ -2356,6 +2428,7 @@ int nbgl_layoutAddConfirmationButton(nbgl_layout_t *layout, bool active, const c
button->innerColor = BLACK;
button->borderColor = BLACK;
button->obj.touchMask = (1 << TOUCHED);
button->obj.touchId = BOTTOM_BUTTON_ID;
}
else {
button->borderColor = LIGHT_GRAY;
Expand Down Expand Up @@ -2402,6 +2475,7 @@ int nbgl_layoutUpdateConfirmationButton(nbgl_layout_t *layout, uint8_t index, bo
button->innerColor = BLACK;
button->borderColor = BLACK;
button->obj.touchMask = (1 << TOUCHED);
button->obj.touchId = BOTTOM_BUTTON_ID;
}
else {
button->borderColor = LIGHT_GRAY;
Expand Down
Loading

0 comments on commit 76503a3

Please sign in to comment.