Skip to content

Commit

Permalink
Rename and simplify object drawing API
Browse files Browse the repository at this point in the history
  • Loading branch information
nroggeman-ledger committed Aug 23, 2024
1 parent c9649ec commit f3ae979
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 121 deletions.
4 changes: 2 additions & 2 deletions lib_nbgl/doc/nbgl_api.dox
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ Once defined and set as children (or sub-children) of the main @ref SCREEN, all
with a simple call to @ref nbgl_screenRedraw().

But if only a given object has been modified since the last redraw, for example by changing its text or its color, it can be redrawn
(with all of its children and sub-children, if any) with a call to @ref nbgl_redrawObject().
(with all of its children and sub-children, if any) with a call to @ref nbgl_objDraw().

The only properties that should not have changed for this object are its dimensions and position.

Except in some specific cases, the previousObj parameter of @ref nbgl_redrawObject() can be set to NULL and computeDimensions set to false.
Except in some specific cases, the previousObj parameter of @ref nbgl_objDraw() can be set to NULL and computeDimensions set to false.

@subsection refresh Refreshing screen

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 @@ -567,7 +567,6 @@ enum {
/**********************
* GLOBAL PROTOTYPES
**********************/
void nbgl_redrawObject(nbgl_obj_t *obj, nbgl_obj_t *prevObj, bool computePosition);

void nbgl_refresh(void);
void nbgl_refreshSpecial(nbgl_refresh_mode_t mode);
Expand All @@ -576,6 +575,7 @@ bool nbgl_refreshIsNeeded(void);
void nbgl_refreshReset(void);

void nbgl_objInit(void);
void nbgl_objDraw(nbgl_obj_t *obj);
void nbgl_objAllowDrawing(bool enable);

void nbgl_objPoolRelease(uint8_t layer);
Expand Down
2 changes: 2 additions & 0 deletions lib_nbgl/include/nbgl_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ typedef struct PACKED__ nbgl_screen_s {
struct nbgl_screen_s *previous; ///< pointer to screen on bottom of this one (or NULL is this
///< screen is bottom of stack)
uint8_t index; ///< index in screenStack array
bool isUxScreen; ///< set to TRUE if allocated by Bolos-UX
} nbgl_screen_t;

/**********************
Expand All @@ -84,6 +85,7 @@ void nbgl_screenRedraw(void);
nbgl_obj_t *nbgl_screenGetAt(uint8_t screenIndex);
nbgl_obj_t *nbgl_screenGetTop(void);
uint8_t nbgl_screenGetCurrentStackSize(void);
uint8_t nbgl_screenGetUxStackSize(void);
bool nbgl_screenContainsObj(nbgl_obj_t *obj);
nbgl_obj_t *nbgl_screenContainsObjType(nbgl_screen_t *screen, nbgl_obj_type_t type);

Expand Down
12 changes: 6 additions & 6 deletions lib_nbgl/src/nbgl_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ static void touchCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType)
&& (((nbgl_container_t *) obj)->children[1]->type == SWITCH)) {
nbgl_switch_t *lSwitch = (nbgl_switch_t *) ((nbgl_container_t *) obj)->children[1];
lSwitch->state = (lSwitch->state == ON_STATE) ? OFF_STATE : ON_STATE;
nbgl_redrawObject((nbgl_obj_t *) lSwitch, false, false);
nbgl_objDraw((nbgl_obj_t *) lSwitch);
// refresh will be done after tune playback
needRefresh = true;
// index is used for state
Expand Down Expand Up @@ -333,7 +333,7 @@ static void longTouchCallback(nbgl_obj_t *obj,
progressBar->previousState = progressBar->state;
progressBar->state = new_state;

nbgl_redrawObject((nbgl_obj_t *) progressBar, false, false);
nbgl_objDraw((nbgl_obj_t *) progressBar);
// Ensure progress bar is fully drawn
// before calling the callback.
nbgl_refreshSpecialWithPostRefresh(BLACK_AND_WHITE_FAST_REFRESH,
Expand All @@ -352,7 +352,7 @@ static void longTouchCallback(nbgl_obj_t *obj,
|| (eventType == SWIPED_LEFT) || (eventType == SWIPED_RIGHT)) {
nbgl_wait_pipeline();
progressBar->state = 0;
nbgl_redrawObject((nbgl_obj_t *) progressBar, false, false);
nbgl_objDraw((nbgl_obj_t *) progressBar);
nbgl_refreshSpecialWithPostRefresh(BLACK_AND_WHITE_REFRESH, POST_REFRESH_FORCE_POWER_OFF);
}
}
Expand Down Expand Up @@ -387,7 +387,7 @@ static void radioTouchCallback(nbgl_obj_t *obj,
// ensure that radio button is ON
radio->state = ON_STATE;
// redraw container
nbgl_redrawObject((nbgl_obj_t *) obj, NULL, false);
nbgl_objDraw((nbgl_obj_t *) obj);
}
else if ((layout->callbackObjPool[i].obj->type == CONTAINER)
&& (((nbgl_container_t *) layout->callbackObjPool[i].obj)->nbChildren == 2)
Expand All @@ -407,7 +407,7 @@ static void radioTouchCallback(nbgl_obj_t *obj,
textArea->textColor = DARK_GRAY;
textArea->fontId = SMALL_REGULAR_FONT;
// redraw container
nbgl_redrawObject((nbgl_obj_t *) layout->callbackObjPool[i].obj, NULL, false);
nbgl_objDraw((nbgl_obj_t *) layout->callbackObjPool[i].obj);
}
}
i++;
Expand Down Expand Up @@ -447,7 +447,7 @@ static void spinnerTickerCallback(void)
spinner = (nbgl_spinner_t *) layout->container->children[i];
spinner->position++;
spinner->position &= 3; // modulo 4
nbgl_redrawObject((nbgl_obj_t *) spinner, NULL, false);
nbgl_objDraw((nbgl_obj_t *) spinner);
nbgl_refreshSpecial(BLACK_AND_WHITE_FAST_REFRESH);
return;
}
Expand Down
20 changes: 10 additions & 10 deletions lib_nbgl/src/nbgl_layout_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ bool keyboardSwipeCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType)
if (i < (uint32_t) nbActiveButtons) {
if (updateSuggestionButtons(suggestionsContainer, eventType, i)) {
io_seproxyhal_play_tune(TUNE_TAP_CASUAL);
nbgl_redrawObject((nbgl_obj_t *) suggestionsContainer, NULL, false);
nbgl_objDraw((nbgl_obj_t *) suggestionsContainer);
nbgl_refreshSpecial(FULL_COLOR_PARTIAL_REFRESH);
}

Expand Down Expand Up @@ -565,7 +565,7 @@ int nbgl_layoutUpdateKeyboard(nbgl_layout_t *layout,
keyboard->casing = casing;
}

nbgl_redrawObject((nbgl_obj_t *) keyboard, NULL, false);
nbgl_objDraw((nbgl_obj_t *) keyboard);

return 0;
}
Expand Down Expand Up @@ -728,7 +728,7 @@ int nbgl_layoutUpdateSuggestionButtons(nbgl_layout_t *layout,
updateSuggestionButtons(container, 0, 0);
#endif // TARGET_STAX

nbgl_redrawObject((nbgl_obj_t *) container, NULL, false);
nbgl_objDraw((nbgl_obj_t *) container);

return 0;
}
Expand Down Expand Up @@ -848,15 +848,15 @@ int nbgl_layoutUpdateEnteredText(nbgl_layout_t *layout,
textArea->text = text;
textArea->textColor = grayedOut ? LIGHT_GRAY : BLACK;
textArea->textAlignment = MID_LEFT;
nbgl_redrawObject((nbgl_obj_t *) textArea, NULL, false);
nbgl_objDraw((nbgl_obj_t *) textArea);

// update number text area
if (numbered) {
// it is the previously created object
textArea = (nbgl_text_area_t *) layoutInt->container->children[1];
snprintf(numText, sizeof(numText), "%d.", number);
textArea->text = numText;
nbgl_redrawObject((nbgl_obj_t *) textArea, NULL, false);
nbgl_objDraw((nbgl_obj_t *) textArea);
}
// if the text doesn't fit, indicate it by returning 1 instead of 0, for different refresh
if (nbgl_getSingleLineTextWidth(textArea->fontId, text) > textArea->obj.area.width) {
Expand Down Expand Up @@ -950,7 +950,7 @@ int nbgl_layoutUpdateConfirmationButton(nbgl_layout_t *layout,
button->borderColor = LIGHT_GRAY;
button->innerColor = LIGHT_GRAY;
}
nbgl_redrawObject((nbgl_obj_t *) button, NULL, false);
nbgl_objDraw((nbgl_obj_t *) button);
return 0;
}

Expand Down Expand Up @@ -1054,14 +1054,14 @@ int nbgl_layoutUpdateKeyboardContent(nbgl_layout_t *layout, nbgl_layoutKeyboardC
// get Word number typed text
textArea = (nbgl_text_area_t *) container->children[1];
snprintf(numText, sizeof(numText), "%d.", content->number);
nbgl_redrawObject((nbgl_obj_t *) textArea, NULL, false);
nbgl_objDraw((nbgl_obj_t *) textArea);
}

// get text area for entered text
textArea = (nbgl_text_area_t *) container->children[2];
textArea->textColor = content->grayedOut ? LIGHT_GRAY : BLACK;
textArea->text = content->text;
nbgl_redrawObject((nbgl_obj_t *) textArea, NULL, false);
nbgl_objDraw((nbgl_obj_t *) textArea);

if (content->type == KEYBOARD_WITH_SUGGESTIONS) {
nbActiveButtons = content->suggestionButtons.nbUsedButtons;
Expand Down Expand Up @@ -1091,7 +1091,7 @@ int nbgl_layoutUpdateKeyboardContent(nbgl_layout_t *layout, nbgl_layoutKeyboardC
indicator->activePage = 0;
updateSuggestionButtons(suggestionsContainer, 0, 0);

nbgl_redrawObject((nbgl_obj_t *) suggestionsContainer, NULL, false);
nbgl_objDraw((nbgl_obj_t *) suggestionsContainer);
}
else if (content->type == KEYBOARD_WITH_BUTTON) {
// update main text area
Expand All @@ -1111,7 +1111,7 @@ int nbgl_layoutUpdateKeyboardContent(nbgl_layout_t *layout, nbgl_layoutKeyboardC
button->borderColor = LIGHT_GRAY;
button->innerColor = LIGHT_GRAY;
}
nbgl_redrawObject((nbgl_obj_t *) button, NULL, false);
nbgl_objDraw((nbgl_obj_t *) button);
}

// if the entered text doesn't fit, indicate it by returning 1 instead of 0, for different
Expand Down
4 changes: 2 additions & 2 deletions lib_nbgl/src/nbgl_layout_keyboard_nanos.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int nbgl_layoutUpdateKeyboard(nbgl_layout_t *layout, uint8_t index, uint32_t key
}
}

nbgl_redrawObject((nbgl_obj_t *) keyboard, NULL, false);
nbgl_objDraw((nbgl_obj_t *) keyboard);

return 0;
}
Expand Down Expand Up @@ -182,7 +182,7 @@ int nbgl_layoutUpdateEnteredText(nbgl_layout_t *layout, uint8_t index, const cha
return -1;
}
textEntry->text = text;
nbgl_redrawObject((nbgl_obj_t *) textEntry, NULL, false);
nbgl_objDraw((nbgl_obj_t *) textEntry);

return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions lib_nbgl/src/nbgl_layout_keypad.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ int nbgl_layoutUpdateKeypad(nbgl_layout_t *layout,
keypad->enableBackspace = enableBackspace;
keypad->enableDigits = enableDigits;

nbgl_redrawObject((nbgl_obj_t *) keypad, NULL, false);
nbgl_objDraw((nbgl_obj_t *) keypad);

return 0;
}
Expand Down Expand Up @@ -313,7 +313,7 @@ int nbgl_layoutUpdateHiddenDigits(nbgl_layout_t *layout, uint8_t index, uint8_t
}
}

nbgl_redrawObject((nbgl_obj_t *) image, NULL, false);
nbgl_objDraw((nbgl_obj_t *) image);

return 0;
}
Expand Down Expand Up @@ -538,7 +538,7 @@ int nbgl_layoutUpdateKeypadContent(nbgl_layout_t *layout,
}
}

nbgl_redrawObject((nbgl_obj_t *) image, NULL, false);
nbgl_objDraw((nbgl_obj_t *) image);
}
else {
// update main text area (second child of the main container)
Expand All @@ -551,7 +551,7 @@ int nbgl_layoutUpdateKeypadContent(nbgl_layout_t *layout,
textArea->text = text;
textArea->textColor = BLACK;
textArea->textAlignment = MID_LEFT;
nbgl_redrawObject((nbgl_obj_t *) textArea, NULL, false);
nbgl_objDraw((nbgl_obj_t *) textArea);

// if the text doesn't fit, indicate it by returning 1 instead of 0, for different refresh
if (nbgl_getSingleLineTextWidth(textArea->fontId, text) > textArea->obj.area.width) {
Expand Down
4 changes: 2 additions & 2 deletions lib_nbgl/src/nbgl_layout_keypad_nanos.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int nbgl_layoutUpdateKeypad(nbgl_layout_t *layout,
keypad->enableValidate = enableValidate;
keypad->enableBackspace = enableBackspace;

nbgl_redrawObject((nbgl_obj_t *) keypad, NULL, false);
nbgl_objDraw((nbgl_obj_t *) keypad);

return 0;
}
Expand Down Expand Up @@ -260,7 +260,7 @@ int nbgl_layoutUpdateHiddenDigits(nbgl_layout_t *layout, uint8_t index, uint8_t
}
}

nbgl_redrawObject((nbgl_obj_t *) image, NULL, false);
nbgl_objDraw((nbgl_obj_t *) image);

return 0;
}
Expand Down
Loading

0 comments on commit f3ae979

Please sign in to comment.