From 3d23aa7dc2aaeeee1bae4908f4aa3a04df15e329 Mon Sep 17 00:00:00 2001 From: tdejoigny-ledger Date: Thu, 26 Sep 2024 18:29:48 +0200 Subject: [PATCH] =?UTF-8?q?nbgl=5FuseCasePlugInHome=20removed=20nbgl=5Fuse?= =?UTF-8?q?CaseForwardOnlyReview=20removed=20nbgl=5FuseCaseViewDetails=20r?= =?UTF-8?q?enamed=20=E2=86=92=20displayDetails=20and=20removed=20from=20AP?= =?UTF-8?q?I=20nbgl=5FuseCaseKeypad=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib_nbgl/doc/nbgl_use_case.dox | 4 - lib_nbgl/doc/nbgl_use_case_nanos.dox | 75 ----------- lib_nbgl/include/nbgl_use_case.h | 35 ----- lib_nbgl/src/nbgl_use_case.c | 191 ++++++--------------------- 4 files changed, 43 insertions(+), 262 deletions(-) diff --git a/lib_nbgl/doc/nbgl_use_case.dox b/lib_nbgl/doc/nbgl_use_case.dox index 78391eaa0..d2a9151a7 100644 --- a/lib_nbgl/doc/nbgl_use_case.dox +++ b/lib_nbgl/doc/nbgl_use_case.dox @@ -61,7 +61,6 @@ Some APIs have also been kept for backward compatibility, and for some rare case - for Home Screen: - @ref nbgl_useCaseHome() to draw the home screen of an application. - @ref nbgl_useCaseHomeExt() to draw an extended version of home screen of an application (with action button) - - @ref nbgl_useCasePlugInHome() to draw the home screen of a Plug-In application - for Settings: - @ref nbgl_useCaseSettings() to draw a level of settings pages - for most used reviews: @@ -71,9 +70,6 @@ Some APIs have also been kept for backward compatibility, and for some rare case - for address verification: - @ref nbgl_useCaseAddressConfirmation() to draw an address confirmation page, with a possibility to see it as QR Code - @ref nbgl_useCaseAddressConfirmationExt() to draw an address confirmation page, with a possibility to see it as QR Code and some extra tag/value pairs -- for rare reviews: - - @ref nbgl_useCaseForwardOnlyReview() to draw the pages of a forward-only review (without back key) - - @ref nbgl_useCaseViewDetails() to draw the pages displaying the full value of a given long data of a review @subsection use_case_home_settings Home & Settings screen Use Case diff --git a/lib_nbgl/doc/nbgl_use_case_nanos.dox b/lib_nbgl/doc/nbgl_use_case_nanos.dox index 1ad53d45d..eff34c383 100644 --- a/lib_nbgl/doc/nbgl_use_case_nanos.dox +++ b/lib_nbgl/doc/nbgl_use_case_nanos.dox @@ -46,8 +46,6 @@ A few APIs are available to draw typical Use-Cases, such as: - for most used reviews: - @ref nbgl_useCaseStaticReview() to draw the pages of a regular review, when all info are available from the beginning (see @subpage use_case_static_review) - @ref nbgl_useCaseRegularReview() to draw the pages of a regular review (all pages but the cover one) (see @subpage use_case_regular_review) -- for rare reviews: - - @ref nbgl_useCaseForwardOnlyReview() to draw the pages of a forward-only review (without back) (see @subpage use_case_forward_only_review) - for address verification: - @ref nbgl_useCaseAddressConfirmation() to draw an address confirmation page (see @subpage use_case_addr_confirm) - @ref nbgl_useCaseAddressConfirmationExt() to draw an address confirmation page, with some extra tag/value pairs (see @subpage use_case_addr_confirm_ext) @@ -247,79 +245,6 @@ void startReview(void) { } @endcode -@subsection use_case_forward_only_review Forward only Review Use Case - -Some message/transaction reviews may be too long to be memorized, so it is only possible to move forward. - -In this case, no backward navigation is possible, and the number of pages cannot be defined at start-up. - -The API to initiate the display of the series of forward-only review pages is @ref nbgl_useCaseForwardOnlyReview(), providing: - -- a navigation callback called when to retrieve the content of the next page. It is also called to fill the initial page. - -Here is an example code: - -@code - -static uint8_t last_transaction_page; - -static void onApprove(void) { - // confirm transaction - - // and go back to main - appMain(); -} - -static void onReject(void) { - // reject transaction - - // and go back to main - appMain(); -} - -// called to get the content of the given page -static bool navCallback(uint8_t page, nbgl_pageContent_t *content) { - memset(content, 0, sizeof(nbgl_pageContent_t)); - if (page == 0) { - // the first page is used to display the title of the review - content->text = "Review\ntransaction"; - content->icon = &C_icon_eye; - } - else if (page == (last_transaction+1)) { - // try to get a new tag/value pair in this transaction - char *tag; - char *value; - if (getNextTagValuePair(&tag, &value)) { - content->text = tag; - content->subText = value; - last_transaction_page = page; - } - else { - // this page is for approval - content->text = "Approve"; - content->icon = &C_icon_validate; - content->callback = onApprove; - } - } - else if (page == (last_transaction+2)) { - // this page is for rejection - content->text = "Reject"; - content->icon = &C_icon_crossmark; - content->callback = onReject; - } - else { - return false; - } - // valid page so return true - return true; -} - -void startForwardOnlyTransaction(void) { - last_transaction_page = 0; - nbgl_useCaseForwardOnlyReview(navCallback); -} -@endcode - @subsection use_case_static_review Static Review Use Case \image{inline} html UseCase-Nano-Review1.png "caption" width=1000 diff --git a/lib_nbgl/include/nbgl_use_case.h b/lib_nbgl/include/nbgl_use_case.h index 653fcaa12..f001c470a 100644 --- a/lib_nbgl/include/nbgl_use_case.h +++ b/lib_nbgl/include/nbgl_use_case.h @@ -374,14 +374,6 @@ void nbgl_useCaseHomeExt(const char *appName, nbgl_callback_t actionCallback, nbgl_callback_t topRightCallback, nbgl_callback_t quitCallback); -void nbgl_useCasePlugInHome(const char *plugInName, - const char *appName, - const nbgl_icon_details_t *appIcon, - const char *tagline, - const char *subTagline, - bool withSettings, - nbgl_callback_t topRightCallback, - nbgl_callback_t quitCallback); void nbgl_useCaseSettings(const char *settingsTitle, uint8_t initPage, uint8_t nbPages, @@ -411,10 +403,6 @@ void nbgl_useCaseRegularReview(uint8_t initPage, nbgl_layoutTouchCallback_t buttonCallback, nbgl_navCallback_t navCallback, nbgl_choiceCallback_t choiceCallback); -void nbgl_useCaseForwardOnlyReview(const char *rejectText, - nbgl_layoutTouchCallback_t buttonCallback, - nbgl_navCallback_t navCallback, - nbgl_choiceCallback_t choiceCallback); void nbgl_useCaseForwardOnlyReviewNoSkip(const char *rejectText, nbgl_layoutTouchCallback_t buttonCallback, nbgl_navCallback_t navCallback, @@ -427,7 +415,6 @@ void nbgl_useCaseStaticReviewLight(const nbgl_contentTagValueList_t *tagValueLis const nbgl_pageInfoLongPress_t *infoLongPress, const char *rejectText, nbgl_choiceCallback_t callback); -void nbgl_useCaseViewDetails(const char *tag, const char *value, bool wrapping); void nbgl_useCaseAddressConfirmation(const char *address, nbgl_choiceCallback_t callback); void nbgl_useCaseAddressConfirmationExt(const char *address, nbgl_choiceCallback_t callback, @@ -449,28 +436,6 @@ void nbgl_useCaseKeypadPIN(const char *title, tune_index_e tuneId, nbgl_pinValidCallback_t validatePinCallback, nbgl_layoutTouchCallback_t actionCallback); -/** - * @deprecated - * See #nbgl_useCaseKeypadPIN - */ -DEPRECATED static inline void nbgl_useCaseKeypad(const char *title, - uint8_t minDigits, - uint8_t maxDigits, - uint8_t backToken, - bool shuffled, - tune_index_e tuneId, - nbgl_pinValidCallback_t validatePinCallback, - nbgl_layoutTouchCallback_t actionCallback) -{ - nbgl_useCaseKeypadPIN(title, - minDigits, - maxDigits, - backToken, - shuffled, - tuneId, - validatePinCallback, - actionCallback); -} #endif // NBGL_KEYPAD #endif // HAVE_SE_TOUCH diff --git a/lib_nbgl/src/nbgl_use_case.c b/lib_nbgl/src/nbgl_use_case.c index 16f32a41f..c5fe111e7 100644 --- a/lib_nbgl/src/nbgl_use_case.c +++ b/lib_nbgl/src/nbgl_use_case.c @@ -181,7 +181,6 @@ typedef union { // char buffers to build some strings static char appDescription[APP_DESCRIPTION_MAX_LEN]; -static char plugInDescription[APP_DESCRIPTION_MAX_LEN]; // multi-purposes callbacks static nbgl_callback_t onQuit; @@ -298,6 +297,7 @@ static uint8_t useCaseGetNbTagValuesInPage(uint8_t nbP uint8_t startIndex, bool isSkippable, bool *requireSpecificDisplay); +static void displayDetails(const char *tag, const char *value, bool wrapping); static void reset_callbacks(void) { @@ -533,9 +533,9 @@ static void pageCallback(int token, uint8_t index) } } else if (token == DETAILS_BUTTON_TOKEN) { - nbgl_useCaseViewDetails(genericContext.detailsItem, - genericContext.detailsvalue, - genericContext.detailsWrapping); + displayDetails(genericContext.detailsItem, + genericContext.detailsvalue, + genericContext.detailsWrapping); } else if (token == NAV_TOKEN) { if (index == EXIT_PAGE) { @@ -2045,6 +2045,45 @@ static uint8_t useCaseGetNbTagValuesInPage(uint8_t nbP return nbPairsInPage; } +/** + * @brief Draws a flow of pages to view details on a given tag/value pair that doesn't fit in a + * single page + * + * @param tag tag name (in gray) + * @param value full value string, that will be split in multiple pages + * @param wrapping if set to true, value text is wrapped on ' ' characters + */ +static void displayDetails(const char *tag, const char *value, bool wrapping) +{ + memset(&detailsContext, 0, sizeof(detailsContext)); + + uint16_t nbLines + = nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT, value, AVAILABLE_WIDTH, wrapping); + + // initialize context + detailsContext.tag = tag; + detailsContext.value = value; + detailsContext.nbPages = (nbLines + NB_MAX_LINES_IN_DETAILS - 1) / NB_MAX_LINES_IN_DETAILS; + detailsContext.currentPage = 0; + detailsContext.wrapping = wrapping; + // add some spare for room lost with "..." substitution + if (detailsContext.nbPages > 1) { + uint16_t nbLostChars = (detailsContext.nbPages - 1) * 3; + uint16_t nbLostLines = (nbLostChars + ((AVAILABLE_WIDTH) / 16) - 1) + / ((AVAILABLE_WIDTH) / 16); // 16 for average char width + uint8_t nbLinesInLastPage + = nbLines - ((detailsContext.nbPages - 1) * NB_MAX_LINES_IN_DETAILS); + + detailsContext.nbPages += nbLostLines / NB_MAX_LINES_IN_DETAILS; + if ((nbLinesInLastPage + (nbLostLines % NB_MAX_LINES_IN_DETAILS)) + > NB_MAX_LINES_IN_DETAILS) { + detailsContext.nbPages++; + } + } + + displayDetailsPage(0, true); +} + /********************** * GLOBAL FUNCTIONS **********************/ @@ -2337,70 +2376,6 @@ void nbgl_useCaseHomeExt(const char *appName, appName, appIcon, tagline, withSettings, &homeAction, topRightCallback, quitCallback); } -/** - * @brief draws the home page of a plug-in app (page on which we land when launching it from - * dashboard) - * - * @param plugInName plug-in app name - * @param appName master app name (app used by plug-in) - * @param appIcon master app icon - * @param tagline text under plug-in name (if NULL, it will be "This app confirms actions - * for\n.") - * @param subTagline text under master app icon (if NULL, it will be "This app relies - * on\n") - * @param withSettings if true, use a "settings" (wheel) icon in bottom button, otherwise a "info" - * (i) - * @param topRightCallback callback called when top-right button is touched - * @param quitCallback callback called when quit button is touched - */ -void nbgl_useCasePlugInHome(const char *plugInName, - const char *appName, - const nbgl_icon_details_t *appIcon, - const char *tagline, - const char *subTagline, - bool withSettings, - nbgl_callback_t topRightCallback, - nbgl_callback_t quitCallback) -{ - reset_callbacks(); - - nbgl_pageInfoDescription_t info = {.centeredInfo.icon = appIcon, - .centeredInfo.text1 = plugInName, - .centeredInfo.style = PLUGIN_INFO, - .centeredInfo.offsetY = -16, - .footerText = NULL, - .bottomButtonStyle = QUIT_APP_TEXT, - .tapActionText = NULL, - .topRightStyle = withSettings ? SETTINGS_ICON : INFO_ICON, - .topRightToken = CONTINUE_TOKEN, - .actionButtonText = NULL, - .tuneId = TUNE_TAP_CASUAL}; - info.bottomButtonsToken = QUIT_TOKEN; - onAction = NULL; - if (tagline == NULL) { - snprintf(appDescription, - APP_DESCRIPTION_MAX_LEN, - "This app confirms actions for\n%s.", - plugInName); - info.centeredInfo.text2 = appDescription; - } - else { - info.centeredInfo.text2 = tagline; - } - if (subTagline == NULL) { - snprintf(plugInDescription, APP_DESCRIPTION_MAX_LEN, "This app relies on\n%s", appName); - info.centeredInfo.text3 = plugInDescription; - } - else { - info.centeredInfo.text3 = subTagline; - } - - onContinue = topRightCallback; - onQuit = quitCallback; - pageContext = nbgl_pageDrawInfo(&pageCallback, NULL, &info); - nbgl_refresh(); -} - /** * @brief Draws the settings pages of an app with as many pages as given * For each page, the given navCallback will be called to get the content. Only 'type' and @@ -2813,47 +2788,6 @@ void nbgl_useCaseRegularReview(uint8_t initPage, displayReviewPage(initPage, true); } -/** - * @brief Draws a flow of pages of a review, without back key. - * It is possible to go to next page thanks to "tap to continue". - * For each page, the given navCallback will be called to get the content. Only 'type' and - * union has to be set in this content. - * Note that this is not a standard use case, it should only be used on very specific - * situations. - * - * @param rejectText text to use in footer - * @param buttonCallback callback called when a potential button (details or long press) in the - * content is touched - * @param navCallback callback called when navigation "tap to continue" is touched, to get the - * content of next page - * @param choiceCallback callback called when either long_press or footer is called (param is true - * for long press) - */ -void nbgl_useCaseForwardOnlyReview(const char *rejectText, - nbgl_layoutTouchCallback_t buttonCallback, - nbgl_navCallback_t navCallback, - nbgl_choiceCallback_t choiceCallback) -{ - reset_callbacks(); - - // memorize context - onChoice = choiceCallback; - onNav = navCallback; - onControls = buttonCallback; - forwardNavOnly = true; - navType = REVIEW_NAV; - - // fill navigation structure - UNUSED(rejectText); - prepareNavInfo(true, NBGL_NO_PROGRESS_INDICATOR, getRejectReviewText(TYPE_OPERATION)); - - navInfo.progressIndicator = false; - navInfo.skipText = "Skip"; - navInfo.skipToken = SKIP_TOKEN; - - displayReviewPage(0, true); -} - /** * @brief Draws a flow of pages of a review, without back key. * It is possible to go to next page thanks to "tap to continue". @@ -3357,45 +3291,6 @@ void nbgl_useCaseReviewStreamingFinish(const char *finishTitle, displayGenericContextPage(0, true); } -/** - * @brief Draws a flow of pages to view details on a given tag/value pair that doesn't fit in a - * single page - * - * @param tag tag name (in gray) - * @param value full value string, that will be split in multiple pages - * @param wrapping if set to true, value text is wrapped on ' ' characters - */ -void nbgl_useCaseViewDetails(const char *tag, const char *value, bool wrapping) -{ - memset(&detailsContext, 0, sizeof(detailsContext)); - - uint16_t nbLines - = nbgl_getTextNbLinesInWidth(SMALL_REGULAR_FONT, value, AVAILABLE_WIDTH, wrapping); - - // initialize context - detailsContext.tag = tag; - detailsContext.value = value; - detailsContext.nbPages = (nbLines + NB_MAX_LINES_IN_DETAILS - 1) / NB_MAX_LINES_IN_DETAILS; - detailsContext.currentPage = 0; - detailsContext.wrapping = wrapping; - // add some spare for room lost with "..." substitution - if (detailsContext.nbPages > 1) { - uint16_t nbLostChars = (detailsContext.nbPages - 1) * 3; - uint16_t nbLostLines = (nbLostChars + ((AVAILABLE_WIDTH) / 16) - 1) - / ((AVAILABLE_WIDTH) / 16); // 16 for average char width - uint8_t nbLinesInLastPage - = nbLines - ((detailsContext.nbPages - 1) * NB_MAX_LINES_IN_DETAILS); - - detailsContext.nbPages += nbLostLines / NB_MAX_LINES_IN_DETAILS; - if ((nbLinesInLastPage + (nbLostLines % NB_MAX_LINES_IN_DETAILS)) - > NB_MAX_LINES_IN_DETAILS) { - detailsContext.nbPages++; - } - } - - displayDetailsPage(0, true); -} - /** * @brief draws an address confirmation page. This page contains the given address in a tag/value * layout, with a button to open a modal to see address as a QR Code, and at the bottom a button to