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 60
41#define PAGE_NUMBER_WIDTH 60
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}
80
81/**********************
82 * GLOBAL FUNCTIONS
83 **********************/
84
95 nbgl_touchType_t eventType,
96 uint8_t nbPages,
97 uint8_t *activePage)
98{
99 // if direct touch of buttons within the navigation bar, the given obj is
100 // the touched object
101 if (eventType == TOUCHED) {
102 nbgl_container_t *navContainer = (nbgl_container_t *) obj->parent;
103
104 if (obj == navContainer->children[EXIT_BUTTON_INDEX]) {
105 // fake page when Quit button is touched
106 *activePage = EXIT_PAGE;
107 return true;
108 }
109 else if (obj == navContainer->children[PREVIOUS_PAGE_INDEX]) {
110 if (*activePage > 0) {
111 *activePage = *activePage - 1;
112 configButtons(navContainer, nbPages, *activePage);
113 return true;
114 }
115 }
116 else if (obj == navContainer->children[NEXT_PAGE_INDEX]) {
117 if ((nbPages < 2) || (*activePage < (nbPages - 1))) {
118 *activePage = *activePage + 1;
119 configButtons(navContainer, nbPages, *activePage);
120 return true;
121 }
122 }
123 }
124 // otherwise the given object is the navigation container itself
125 else if (eventType == SWIPED_RIGHT) {
126 if (*activePage > 0) {
127 *activePage = *activePage - 1;
128 configButtons((nbgl_container_t *) obj, nbPages, *activePage);
129 return true;
130 }
131 }
132 else if (eventType == SWIPED_LEFT) {
133 if ((nbPages < 2) || (*activePage < (nbPages - 1))) {
134 *activePage = *activePage + 1;
135 configButtons((nbgl_container_t *) obj, nbPages, *activePage);
136 return true;
137 }
138 }
139 return false;
140}
141
152 const nbgl_layoutNavigationBar_t *navConfig,
153 uint8_t layer)
154{
155 nbgl_button_t *button;
156
157 if (navConfig->withExitKey) {
158 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layer);
159 button->innerColor = WHITE;
160 button->borderColor = BORDER_COLOR;
161 button->obj.area.width = BUTTON_DIAMETER;
162 button->obj.area.height = BUTTON_DIAMETER;
163 button->radius = BUTTON_RADIUS;
164 button->icon = &CLOSE_ICON;
165#ifndef TARGET_STAX
166 button->obj.alignmentMarginX = (navConfig->nbPages > 1) ? 8 : 0;
167#endif // TARGET_STAX
168
169 button->obj.alignment = (navConfig->nbPages > 1) ? MID_LEFT : CENTER;
170 button->obj.touchMask = (1 << TOUCHED);
171 button->obj.touchId = BOTTOM_BUTTON_ID;
172 navContainer->children[EXIT_BUTTON_INDEX] = (nbgl_obj_t *) button;
173 }
174 // create previous page button (back)
175 if (navConfig->withBackKey) {
176 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layer);
177 button->innerColor = WHITE;
178 button->borderColor = BORDER_COLOR;
179 button->obj.area.width = NAV_BUTTON_WIDTH;
180 button->obj.area.height = NAV_BUTTON_HEIGHT;
181 button->radius = BUTTON_RADIUS;
182 button->icon = &CHEVRON_BACK_ICON;
183 // align on the right of the container, leaving space for "Next" button
184 button->obj.alignment = MID_RIGHT;
185 button->obj.alignmentMarginX = NAV_BUTTON_WIDTH;
186 button->obj.touchMask = (1 << TOUCHED);
187 button->obj.touchId = LEFT_BUTTON_ID;
188 navContainer->children[PREVIOUS_PAGE_INDEX] = (nbgl_obj_t *) button;
189 }
190
191 // create next page button
192 button = (nbgl_button_t *) nbgl_objPoolGet(BUTTON, layer);
193 button->innerColor = WHITE;
194 button->borderColor = BORDER_COLOR;
195 button->foregroundColor = BLACK;
196 button->obj.area.width = NAV_BUTTON_WIDTH;
197 button->obj.area.height = NAV_BUTTON_HEIGHT;
198 button->radius = BUTTON_RADIUS;
199 button->icon = &CHEVRON_NEXT_ICON;
200 button->obj.alignment = MID_RIGHT;
201 button->obj.touchMask = (1 << TOUCHED);
202 button->obj.touchId = RIGHT_BUTTON_ID;
203 navContainer->children[NEXT_PAGE_INDEX] = (nbgl_obj_t *) button;
204
205 // potentially create page indicator (with a text area, and "page of nb_page")
206 if (navConfig->withPageIndicator) {
207 if (navConfig->visibleIndicator) {
209 uint16_t marginX = (NAV_BUTTON_WIDTH - CHEVRON_NEXT_ICON.width) / 2;
210
211 SPRINTF(navText, "%d of %d", navConfig->activePage + 1, navConfig->nbPages);
212
213 textArea->textColor = LIGHT_TEXT_COLOR;
214 // the max width is the width of the whole container, but not overriding the < and >
215 // icons
216 textArea->obj.area.width
217 = navContainer->obj.area.width - (2 * (marginX + CHEVRON_NEXT_ICON.width));
218 textArea->text = navText;
219 textArea->fontId = SMALL_REGULAR_FONT;
220 textArea->obj.area.height = NAV_BUTTON_HEIGHT;
221 textArea->textAlignment = CENTER;
222 textArea->obj.alignment = CENTER;
223 navContainer->children[PAGE_INDICATOR_INDEX] = (nbgl_obj_t *) textArea;
224 }
225 if (navConfig->withBackKey) {
226 navContainer->children[PREVIOUS_PAGE_INDEX]->alignmentMarginX += PAGE_NUMBER_WIDTH;
227 }
228 }
229
230 // configure enabling/disabling of button
231 configButtons(navContainer, navConfig->nbPages, navConfig->activePage);
232
233 return;
234}
235
236#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:271
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
#define INACTIVE_COLOR
Definition nbgl_obj.h:268
@ LEFT_BUTTON_ID
Definition nbgl_obj.h:665
@ RIGHT_BUTTON_ID
Definition nbgl_obj.h:666
@ BOTTOM_BUTTON_ID
Definition nbgl_obj.h:664
#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:275
@ SWIPED_RIGHT
Definition nbgl_types.h:274
@ 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)