Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
nbgl_layout_navigation.c
Go to the documentation of this file.
1
8#ifdef HAVE_SE_TOUCH
9
10/*********************
11 * INCLUDES
12 *********************/
13#include "nbgl_debug.h"
14#include "nbgl_draw.h"
15#include "nbgl_obj.h"
17#include "os_print.h"
18#include "os_helpers.h"
19#include "glyphs.h"
20
21/*********************
22 * DEFINES
23 *********************/
24#define INTERNAL_SMALL_MARGIN 8
25
26#define BORDER_COLOR WHITE
27#if defined(TARGET_STAX)
28#define NAVIGATION_HEIGHT 92
29#define NAV_BUTTON_HEIGHT 80
30#define NAV_BUTTON_WIDTH 80
31#define PAGE_NUMBER_WIDTH 79
32#elif defined(TARGET_FLEX)
33#define NAVIGATION_HEIGHT 96
34#define NAV_BUTTON_HEIGHT NAVIGATION_HEIGHT
35#define NAV_BUTTON_WIDTH 104
36#define PAGE_NUMBER_WIDTH 79
37#endif // TARGETS
38
39/**********************
40 * TYPEDEFS
41 **********************/
42enum {
48};
49
50/**********************
51 * STATIC VARIABLES
52 **********************/
53static char navText[11]; // worst case is "ccc of nnn"
54
55/**********************
56 * VARIABLES
57 **********************/
58
59/**********************
60 * STATIC PROTOTYPES
61 **********************/
62
63static void configButtons(nbgl_container_t *navContainer, uint8_t navNbPages, uint8_t navActivePage)
64{
65 nbgl_button_t *buttonPrevious = (nbgl_button_t *) navContainer->children[PREVIOUS_PAGE_INDEX];
66 nbgl_button_t *buttonNext = (nbgl_button_t *) navContainer->children[NEXT_PAGE_INDEX];
67
68 if (buttonPrevious) {
69 buttonPrevious->foregroundColor = (navActivePage == 0) ? LIGHT_GRAY : BLACK;
70 }
71 if (navNbPages > 1) {
72 buttonNext->foregroundColor = (navActivePage == (navNbPages - 1)) ? LIGHT_GRAY : BLACK;
73 }
74}
75
76/**********************
77 * GLOBAL FUNCTIONS
78 **********************/
79
90 nbgl_touchType_t eventType,
91 uint8_t nbPages,
92 uint8_t *activePage)
93{
94 // if direct touch of buttons within the navigation bar, the given obj is
95 // the touched object
96 if (eventType == TOUCHED) {
97 nbgl_container_t *navContainer = (nbgl_container_t *) obj->parent;
98
99 if (obj == navContainer->children[EXIT_BUTTON_INDEX]) {
100 // fake page when Quit button is touched
101 *activePage = EXIT_PAGE;
102 return true;
103 }
104 else if (obj == navContainer->children[PREVIOUS_PAGE_INDEX]) {
105 if (*activePage > 0) {
106 *activePage = *activePage - 1;
107 configButtons(navContainer, nbPages, *activePage);
108 return true;
109 }
110 }
111 else if (obj == navContainer->children[NEXT_PAGE_INDEX]) {
112 if ((nbPages < 2) || (*activePage < (nbPages - 1))) {
113 *activePage = *activePage + 1;
114 configButtons(navContainer, nbPages, *activePage);
115 return true;
116 }
117 }
118 }
119 // otherwise the given object is the navigation container itself
120 else if (eventType == SWIPED_RIGHT) {
121 if (*activePage > 0) {
122 *activePage = *activePage - 1;
123 configButtons((nbgl_container_t *) obj, nbPages, *activePage);
124 return true;
125 }
126 }
127 else if (eventType == SWIPED_LEFT) {
128 if ((nbPages < 2) || (*activePage < (nbPages - 1))) {
129 *activePage = *activePage + 1;
130 configButtons((nbgl_container_t *) obj, nbPages, *activePage);
131 return true;
132 }
133 }
134 return false;
135}
136
147 const nbgl_layoutNavigationBar_t *navConfig,
148 uint8_t layer)
149{
150 nbgl_button_t *button;
151
152 if (navConfig->withExitKey) {
153 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layer);
154 button->innerColor = WHITE;
155 button->borderColor = BORDER_COLOR;
156 button->obj.area.width = BUTTON_DIAMETER;
157 button->obj.area.height = BUTTON_DIAMETER;
158 button->radius = BUTTON_RADIUS;
159 button->icon = &CLOSE_ICON;
160#ifndef TARGET_STAX
161 button->obj.alignmentMarginX = (navConfig->nbPages > 1) ? 8 : 0;
162#endif // TARGET_STAX
163
164 button->obj.alignment = (navConfig->nbPages > 1) ? MID_LEFT : CENTER;
165 button->obj.touchMask = (1 << TOUCHED);
166 button->obj.touchId = BOTTOM_BUTTON_ID;
167 navContainer->children[EXIT_BUTTON_INDEX] = (nbgl_obj_t *) button;
168 }
169 // create previous page button (back)
170 if (navConfig->withBackKey) {
171 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layer);
172 button->innerColor = WHITE;
173 button->borderColor = BORDER_COLOR;
174 button->obj.area.width = NAV_BUTTON_WIDTH;
175 button->obj.area.height = NAV_BUTTON_HEIGHT;
176 button->radius = BUTTON_RADIUS;
177 button->icon = &CHEVRON_BACK_ICON;
178 // align on the right of the container, leaving space for "Next" button
179 button->obj.alignment = MID_RIGHT;
180 button->obj.alignmentMarginX = NAV_BUTTON_WIDTH;
181 button->obj.touchMask = (1 << TOUCHED);
182 button->obj.touchId = LEFT_BUTTON_ID;
183 navContainer->children[PREVIOUS_PAGE_INDEX] = (nbgl_obj_t *) button;
184 }
185
186 // create next page button
187 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layer);
188 button->innerColor = WHITE;
189 button->borderColor = BORDER_COLOR;
190 button->foregroundColor = BLACK;
191 button->obj.area.width = NAV_BUTTON_WIDTH;
192 button->obj.area.height = NAV_BUTTON_HEIGHT;
193 button->radius = BUTTON_RADIUS;
194 button->icon = &CHEVRON_NEXT_ICON;
195 button->obj.alignment = MID_RIGHT;
196 button->obj.touchMask = (1 << TOUCHED);
197 button->obj.touchId = RIGHT_BUTTON_ID;
198 navContainer->children[NEXT_PAGE_INDEX] = (nbgl_obj_t *) button;
199
200 // potentially create page indicator (with a text area, and "page of nb_page")
201 if (navConfig->withPageIndicator) {
202 if (navConfig->visibleIndicator) {
204 uint16_t marginX = (NAV_BUTTON_WIDTH - CHEVRON_NEXT_ICON.width) / 2;
205
206 SPRINTF(navText, "%d of %d", navConfig->activePage + 1, navConfig->nbPages);
207
208 textArea->textColor = DARK_GRAY;
209 // the max width is the width of the whole container, but not overriding the < and >
210 // icons
211 textArea->obj.area.width
212 = navContainer->obj.area.width - (2 * (marginX + CHEVRON_NEXT_ICON.width));
213 textArea->text = navText;
214 textArea->fontId = SMALL_REGULAR_FONT;
215 textArea->obj.area.height = NAV_BUTTON_HEIGHT;
216 textArea->textAlignment = CENTER;
217 textArea->obj.alignment = CENTER;
218 navContainer->children[PAGE_INDICATOR_INDEX] = (nbgl_obj_t *) textArea;
219 }
220 if (navConfig->withBackKey) {
221 navContainer->children[PREVIOUS_PAGE_INDEX]->alignmentMarginX += PAGE_NUMBER_WIDTH;
222 }
223 }
224
225 // configure enabling/disabling of button
226 configButtons(navContainer, navConfig->nbPages, navConfig->activePage);
227
228 return;
229}
230
231#endif // HAVE_SE_TOUCH
debug traces management
Middle Level API of the new BOLOS Graphical Library.
#define EXIT_PAGE
Definition nbgl_layout.h:38
Internal functions/constants of NBGL layout layer.
@ PAGE_INDICATOR_INDEX
@ NB_MAX_CHILDREN
@ NEXT_PAGE_INDEX
@ EXIT_BUTTON_INDEX
@ PREVIOUS_PAGE_INDEX
void layoutNavigationPopulate(nbgl_container_t *navContainer, const nbgl_layoutNavigationBar_t *navConfig, uint8_t layer)
This function creates a full navigation bar "object", with buttons and returns it as a container.
#define BORDER_COLOR
bool layoutNavigationCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType, uint8_t nbPages, uint8_t *activePage)
function to be called when any of the controls in navigation bar is touched
API to draw all basic graphic objects.
struct PACKED__ nbgl_text_area_s nbgl_text_area_t
struct to represent a text area (TEXT_AREA type)
nbgl_obj_t * nbgl_objPoolGet(nbgl_obj_type_t type, uint8_t layer)
Gets a new graphic object from the pool, with the given type. The type field of the object is set.
struct PACKED__ nbgl_button_s nbgl_button_t
struct to represent a button (BUTTON type) that can contain a text and/or an icon
@ LEFT_BUTTON_ID
Definition nbgl_obj.h:567
@ RIGHT_BUTTON_ID
Definition nbgl_obj.h:568
@ BOTTOM_BUTTON_ID
Definition nbgl_obj.h:566
struct PACKED__ nbgl_container_s nbgl_container_t
struct to represent a container (CONTAINER type)
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
@ WHITE
Definition nbgl_types.h:124
@ DARK_GRAY
Definition nbgl_types.h:122
@ LIGHT_GRAY
Definition nbgl_types.h:123
@ BLACK
Definition nbgl_types.h:121
nbgl_touchType_t
The different types of Touchscreen events.
Definition nbgl_types.h:239
@ SWIPED_LEFT
Definition nbgl_types.h:255
@ SWIPED_RIGHT
Definition nbgl_types.h:254
@ TOUCHED
Definition nbgl_types.h:240
@ CENTER
Definition nbgl_types.h:165
@ MID_RIGHT
Definition nbgl_types.h:166
@ MID_LEFT
Definition nbgl_types.h:164
@ BUTTON
Rounded rectangle button with icon and/or text.
Definition nbgl_types.h:140
@ TEXT_AREA
Area to contain text line(s)
Definition nbgl_types.h:139
This structure contains info to build a navigation bar at the bottom of the screen.
uint8_t activePage
index of active page (from 0 to nbPages-1).
bool withBackKey
if set to true, the "back" key is drawn
bool withExitKey
if set to true, an exit button is drawn (X on the left)
uint8_t nbPages
number of pages. (if 0, no navigation)
unsigned short uint16_t
Definition usbd_conf.h:54
unsigned char uint8_t
Definition usbd_conf.h:53