From 55680e3bd68d7455746ebf142a2f8e91a9615040 Mon Sep 17 00:00:00 2001 From: Charles-Edouard de la Vergne Date: Mon, 26 Feb 2024 13:37:19 +0100 Subject: [PATCH] Define new content type BARS_LIST_ICONS --- lib_nbgl/include/nbgl_content.h | 20 +++++++++++++++++++- lib_nbgl/include/nbgl_page.h | 4 ++++ lib_nbgl/src/nbgl_page.c | 16 ++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib_nbgl/include/nbgl_content.h b/lib_nbgl/include/nbgl_content.h index 60929909f..c7b5a1c36 100644 --- a/lib_nbgl/include/nbgl_content.h +++ b/lib_nbgl/include/nbgl_content.h @@ -241,6 +241,19 @@ typedef struct { #endif // HAVE_PIEZO_SOUND } nbgl_contentBarsList_t; +/** + * @brief This structure contains data to build a @ref BARS_LIST_ICONS content + */ +typedef struct nbgl_contentBarsListIcons_s { + const char *const *barTexts; ///< array of texts for each bar (nbBars items, in black/bold) + const nbgl_icon_details_t *const *barIcons; ///< a buffer containing the 1BPP icons + const uint8_t *tokens; ///< array of tokens, one for each bar (nbBars items) + uint8_t nbBars; ///< number of elements in barTexts and tokens array +#ifdef HAVE_PIEZO_SOUND + tune_index_e tuneId; ///< if not @ref NBGL_NO_TUNE, a tune will be played when a bar is touched +#endif // HAVE_PIEZO_SOUND +} nbgl_contentBarsListIcons_t; + /** * @brief The different types of predefined contents * @@ -255,11 +268,15 @@ typedef enum { SWITCHES_LIST, ///< list of switches with descriptions INFOS_LIST, ///< list of infos with titles CHOICES_LIST, ///< list of choices through radio buttons - BARS_LIST ///< list of touchable bars (with > on the right to go to sub-pages) + BARS_LIST, ///< list of touchable bars (with > on the right to go to sub-pages) + BARS_LIST_ICONS ///< list of touchable bars (with > on the right and icon on the left) } nbgl_contentType_t; /** * @brief Union of the different type of contents + * + * @note This union is duplicated in nbgl_page.h: @ref nbgl_pageContent_t + * */ typedef union { nbgl_contentCenteredInfo_t centeredInfo; ///< @ref CENTERED_INFO type @@ -272,6 +289,7 @@ typedef union { nbgl_contentInfoList_t infosList; ///< @ref INFOS_LIST type nbgl_contentRadioChoice_t choicesList; ///< @ref CHOICES_LIST type nbgl_contentBarsList_t barsList; ///< @ref BARS_LIST type + nbgl_contentBarsListIcons_t barsListIcons; ///< @ref BARS_LIST_ICONS type } nbgl_content_u; /** diff --git a/lib_nbgl/include/nbgl_page.h b/lib_nbgl/include/nbgl_page.h index 93299c79c..cb63d9310 100644 --- a/lib_nbgl/include/nbgl_page.h +++ b/lib_nbgl/include/nbgl_page.h @@ -48,6 +48,9 @@ typedef nbgl_contentInfoLongPress_t nbgl_pageInfoLongPress_t; /** * @brief This structure contains data to build a page in multi-pages mode (@ref * nbgl_pageDrawGenericContent) + * + * @note This union is duplicated in nbgl_content.h: @ref nbgl_content_u + * */ typedef struct nbgl_pageContent_s { const char *title; ///< text for the title of the page (if NULL, no title) @@ -67,6 +70,7 @@ typedef struct nbgl_pageContent_s { nbgl_contentInfoList_t infosList; ///< @ref INFOS_LIST type nbgl_contentRadioChoice_t choicesList; ///< @ref CHOICES_LIST type nbgl_contentBarsList_t barsList; ///< @ref BARS_LIST type + nbgl_contentBarsListIcons_t barsListIcons; ///< @ref BARS_LIST_ICONS type }; } nbgl_pageContent_t; diff --git a/lib_nbgl/src/nbgl_page.c b/lib_nbgl/src/nbgl_page.c index c1372c96d..1ced3756e 100644 --- a/lib_nbgl/src/nbgl_page.c +++ b/lib_nbgl/src/nbgl_page.c @@ -176,6 +176,22 @@ static void addContent(nbgl_pageContent_t *content, nbgl_layout_t *layout) } break; } + case BARS_LIST_ICONS: { + uint8_t i; + for (i = 0; i < content->barsListIcons.nbBars; i++) { + nbgl_layoutBar_t bar; + bar.text = content->barsListIcons.barTexts[i]; + bar.subText = NULL; + bar.iconRight = &C_Next32px; + bar.iconLeft = content->barsListIcons.barIcons[i]; + bar.token = content->barsListIcons.tokens[i]; + bar.centered = false; + bar.tuneId = content->barsListIcons.tuneId; + nbgl_layoutAddTouchableBar(layout, &bar); + nbgl_layoutAddSeparationLine(layout); + } + break; + } } }