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#elif defined(TARGET_APEX)
38#define NAVIGATION_HEIGHT 60
39#define NAV_BUTTON_HEIGHT 60
40#define NAV_BUTTON_WIDTH 56
41#define PAGE_NUMBER_WIDTH 68
42#endif // TARGETS
43
44/**********************
45 * TYPEDEFS
46 **********************/
47enum {
53};
54
55/**********************
56 * STATIC VARIABLES
57 **********************/
58static char navText[11]; // worst case is "ccc of nnn"
59
60/**********************
61 * VARIABLES
62 **********************/
63
64/**********************
65 * STATIC PROTOTYPES
66 **********************/
67
68static void configButtons(nbgl_container_t *navContainer, uint8_t navNbPages, uint8_t navActivePage)
69{
70 nbgl_button_t *buttonPrevious = (nbgl_button_t *) navContainer->children[PREVIOUS_PAGE_INDEX];
71 nbgl_button_t *buttonNext = (nbgl_button_t *) navContainer->children[NEXT_PAGE_INDEX];
72
73 if (buttonPrevious) {
74 buttonPrevious->foregroundColor = (navActivePage == 0) ? INACTIVE_COLOR : BLACK;
75 }
76 if (navNbPages > 1) {
77 buttonNext->foregroundColor = (navActivePage == (navNbPages - 1)) ? INACTIVE_COLOR : BLACK;
78 }
79 else {
80 buttonNext->foregroundColor = INACTIVE_COLOR;
81 }
82}
83
84/**********************
85 * GLOBAL FUNCTIONS
86 **********************/
87
98 nbgl_touchType_t eventType,
99 uint8_t nbPages,
100 uint8_t *activePage)
101{
102 // if direct touch of buttons within the navigation bar, the given obj is
103 // the touched object
104 if (eventType == TOUCHED) {
105 nbgl_container_t *navContainer = (nbgl_container_t *) obj->parent;
106
107 if (obj == navContainer->children[EXIT_BUTTON_INDEX]) {
108 // fake page when Quit button is touched
109 *activePage = EXIT_PAGE;
110 return true;
111 }
112 else if (obj == navContainer->children[PREVIOUS_PAGE_INDEX]) {
113 if (*activePage > 0) {
114 *activePage = *activePage - 1;
115 configButtons(navContainer, nbPages, *activePage);
116 return true;
117 }
118 }
119 else if (obj == navContainer->children[NEXT_PAGE_INDEX]) {
120 if ((nbPages >= 2) && (*activePage < (nbPages - 1))) {
121 *activePage = *activePage + 1;
122 configButtons(navContainer, nbPages, *activePage);
123 return true;
124 }
125 }
126 }
127 // otherwise the given object is the navigation container itself
128 else if (eventType == SWIPED_RIGHT) {
129 if (*activePage > 0) {
130 *activePage = *activePage - 1;
131 configButtons((nbgl_container_t *) obj, nbPages, *activePage);
132 return true;
133 }
134 }
135 else if (eventType == SWIPED_LEFT) {
136 if ((nbPages >= 2) && (*activePage < (nbPages - 1))) {
137 *activePage = *activePage + 1;
138 configButtons((nbgl_container_t *) obj, nbPages, *activePage);
139 return true;
140 }
141 }
142 return false;
143}
144
155 const nbgl_layoutNavigationBar_t *navConfig,
156 uint8_t layer)
157{
158 nbgl_button_t *button;
159
160 if (navConfig->withExitKey) {
161 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layer);
162 button->innerColor = WHITE;
163 button->borderColor = BORDER_COLOR;
164 button->obj.area.width = BUTTON_DIAMETER;
165 button->obj.area.height = BUTTON_DIAMETER;
166 button->radius = BUTTON_RADIUS;
167 button->icon = &CLOSE_ICON;
168#ifdef TARGET_FLEX
169 button->obj.alignmentMarginX = (navConfig->nbPages > 1) ? 8 : 0;
170#endif // TARGET_STAX
171
172 button->obj.alignment = (navConfig->nbPages > 1) ? MID_LEFT : CENTER;
173 button->obj.touchMask = (1 << TOUCHED);
174 button->obj.touchId = BOTTOM_BUTTON_ID;
175 navContainer->children[EXIT_BUTTON_INDEX] = (nbgl_obj_t *) button;
176 }
177 // create previous page button (back)
178 if (navConfig->withBackKey) {
179 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layer);
180 button->innerColor = WHITE;
181 button->borderColor = BORDER_COLOR;
182 button->obj.area.width = NAV_BUTTON_WIDTH;
183 button->obj.area.height = NAV_BUTTON_HEIGHT;
184 button->radius = BUTTON_RADIUS;
185 button->icon = &CHEVRON_BACK_ICON;
186 // align on the right of the container, leaving space for "Next" button
187 button->obj.alignment = MID_RIGHT;
188 button->obj.alignmentMarginX = NAV_BUTTON_WIDTH;
189 button->obj.touchMask = (1 << TOUCHED);
190 button->obj.touchId = LEFT_BUTTON_ID;
191 navContainer->children[PREVIOUS_PAGE_INDEX] = (nbgl_obj_t *) button;
192 }
193
194 // create next page button
195 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layer);
196 button->innerColor = WHITE;
197 button->borderColor = BORDER_COLOR;
198 button->foregroundColor = BLACK;
199 button->obj.area.width = NAV_BUTTON_WIDTH;
200 button->obj.area.height = NAV_BUTTON_HEIGHT;
201 button->radius = BUTTON_RADIUS;
202 button->icon = &CHEVRON_NEXT_ICON;
203 button->obj.alignment = MID_RIGHT;
204 button->obj.touchMask = (1 << TOUCHED);
205 button->obj.touchId = RIGHT_BUTTON_ID;
206 navContainer->children[NEXT_PAGE_INDEX] = (nbgl_obj_t *) button;
207
208 // potentially create page indicator (with a text area, and "page of nb_page")
209 if (navConfig->withPageIndicator) {
210 if (navConfig->visibleIndicator) {
212 uint16_t marginX = (NAV_BUTTON_WIDTH - CHEVRON_NEXT_ICON.width) / 2;
213
214 SPRINTF(navText, "%d of %d", navConfig->activePage + 1, navConfig->nbPages);
215
216 textArea->textColor = LIGHT_TEXT_COLOR;
217 // the max width is the width of the whole container, but not overriding the < and >
218 // icons
219 textArea->obj.area.width
220 = navContainer->obj.area.width - (2 * (marginX + CHEVRON_NEXT_ICON.width));
221 textArea->text = navText;
222 textArea->fontId = SMALL_REGULAR_FONT;
223 textArea->obj.area.height = NAV_BUTTON_HEIGHT;
224 textArea->textAlignment = CENTER;
225 textArea->obj.alignment = CENTER;
226 navContainer->children[PAGE_INDICATOR_INDEX] = (nbgl_obj_t *) textArea;
227 }
228 if (navConfig->withBackKey) {
229 navContainer->children[PREVIOUS_PAGE_INDEX]->alignmentMarginX += PAGE_NUMBER_WIDTH;
230 }
231 }
232
233 // configure enabling/disabling of button
234 configButtons(navContainer, navConfig->nbPages, navConfig->activePage);
235
236 return;
237}
238
239#endif // HAVE_SE_TOUCH
debug traces management
Middle Level API of the new BOLOS Graphical Library.
#define EXIT_PAGE
Definition nbgl_layout.h:35
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.
#define LIGHT_TEXT_COLOR
Definition nbgl_obj.h:282
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)
struct PACKED__ nbgl_button_s nbgl_button_t
struct to represent a button (BUTTON type) that can contain a text and/or an icon
#define INACTIVE_COLOR
Definition nbgl_obj.h:279
@ LEFT_BUTTON_ID
Definition nbgl_obj.h:673
@ RIGHT_BUTTON_ID
Definition nbgl_obj.h:674
@ BOTTOM_BUTTON_ID
Definition nbgl_obj.h:672
#define BUTTON_DIAMETER
Definition nbgl_obj.h:99
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:144
@ BLACK
Definition nbgl_types.h:141
nbgl_touchType_t
The different types of Touchscreen events.
Definition nbgl_types.h:259
@ SWIPED_LEFT
Definition nbgl_types.h:274
@ SWIPED_RIGHT
Definition nbgl_types.h:273
@ TOUCHED
Definition nbgl_types.h:260
@ CENTER
Definition nbgl_types.h:185
@ MID_RIGHT
Definition nbgl_types.h:186
@ MID_LEFT
Definition nbgl_types.h:184
@ BUTTON
Rounded rectangle button with icon and/or text.
Definition nbgl_types.h:160
@ TEXT_AREA
Area to contain text line(s)
Definition nbgl_types.h:159
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)