Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
nbgl_obj.c
Go to the documentation of this file.
1
6/*********************
7 * INCLUDES
8 *********************/
9#include <string.h>
10
11#include "app_config.h"
12#include "nbgl_obj.h"
13#include "nbgl_draw.h"
14#include "nbgl_front.h"
15#include "nbgl_debug.h"
16#include "nbgl_screen.h"
17#include "nbgl_touch.h"
18#include "os_print.h"
19#include "os_helpers.h"
20#include "os_pic.h"
21#include "os_task.h"
22#include "glyphs.h"
23#include "os_io_seph_ux.h"
24#ifdef HAVE_SERIALIZED_NBGL
25#include "nbgl_serialize.h"
26#endif
27#ifdef BUILD_SCREENSHOTS
28#include "json_scenario.h"
29#endif // BUILD_SCREENSHOTS
30
31/*********************
32 * DEFINES
33 *********************/
34// max number of letters in TEXT_ENTRY
35#define NB_MAX_LETTERS 9
36
37#if defined(TARGET_STAX)
38#define INTER_DASHES 10
39#define SPINNER_DASH_WIDTH 22
40#define SPINNER_DASH_HEIGHT 14
41#define SPINNER_DASH_STROKE 4
42#define PROGRESS_STROKE 3
43#elif defined(TARGET_FLEX)
44#define INTER_DASHES 8
45#define SPINNER_DASH_WIDTH 24
46#define SPINNER_DASH_HEIGHT 16
47#define SPINNER_DASH_STROKE 4
48#define PROGRESS_STROKE 3
49#elif defined(TARGET_APEX)
50#define INTER_DASHES 8
51#define SPINNER_DASH_WIDTH 15
52#define SPINNER_DASH_HEIGHT 10
53#define SPINNER_DASH_STROKE 2
54#define PROGRESS_STROKE 2
55#endif // TARGETS
56
57/**********************
58 * TYPEDEFS
59 **********************/
60typedef void (*draw_function_t)(nbgl_obj_t *obj, nbgl_obj_t *prevObj, bool computePosition);
61
62/**********************
63 * STATIC PROTOTYPES
64 **********************/
65static void draw_screen(nbgl_container_t *obj, nbgl_obj_t *prevObj, bool computePosition);
66static void draw_container(nbgl_container_t *obj, nbgl_obj_t *prevObj, bool computePosition);
67static void draw_image(nbgl_image_t *obj, nbgl_obj_t *prevObj, bool computePosition);
68static void draw_button(nbgl_button_t *obj, nbgl_obj_t *prevObj, bool computePosition);
69#ifdef HAVE_SE_TOUCH
70static void draw_line(nbgl_line_t *obj, nbgl_obj_t *prevObj, bool computePosition);
71static void draw_switch(nbgl_switch_t *obj, nbgl_obj_t *prevObj, bool computePosition);
72static void draw_radioButton(nbgl_radio_t *obj, nbgl_obj_t *prevObj, bool computePosition);
73static void draw_pageIndicator(nbgl_page_indicator_t *obj,
74 nbgl_obj_t *prevObj,
75 bool computePosition);
76static void draw_spinner(nbgl_spinner_t *obj, nbgl_obj_t *prevObj, bool computePosition);
77#else // HAVE_SE_TOUCH
78static void draw_textEntry(nbgl_text_entry_t *obj, nbgl_obj_t *prevObj, bool computePosition);
79#endif // HAVE_SE_TOUCH
80static void draw_progressBar(nbgl_progress_bar_t *obj, nbgl_obj_t *prevObj, bool computePosition);
81static void draw_textArea(nbgl_text_area_t *obj, nbgl_obj_t *prevObj, bool computePosition);
82#ifdef NBGL_QRCODE
83static void draw_qrCode(nbgl_qrcode_t *obj, nbgl_obj_t *prevObj, bool computePosition);
84#endif // NBGL_QRCODE
85#ifdef NBGL_KEYBOARD
86static void draw_keyboard(nbgl_keyboard_t *obj, nbgl_obj_t *prevObj, bool computePosition);
87#endif // NBGL_KEYBOARD
88#ifdef NBGL_KEYPAD
89static void draw_keypad(nbgl_keypad_t *obj, nbgl_obj_t *prevObj, bool computePosition);
90#endif // NBGL_KEYPAD
91static void draw_image_file(nbgl_image_file_t *obj, nbgl_obj_t *prevObj, bool computePosition);
92#ifdef NBGL_MASKING
93static void draw_mask_control(nbgl_mask_control_t *obj, nbgl_obj_t *prevObj, bool computePosition);
94#endif // NBGL_MASKING
95
96static void extendRefreshArea(nbgl_area_t *obj);
97
98/**********************
99 * STATIC VARIABLES
100 **********************/
101// area to resfresh
102static nbgl_area_t refreshArea;
103
104// boolean used to enable/forbid drawing/refresh by Application
105static bool objDrawingDisabled;
106
107// boolean used to indicate a manual refresh area extension
108static bool objRefreshAreaDone;
109
110// indexed by nbgl_obj_type_t
111static const draw_function_t draw_functions[NB_OBJ_TYPES] = {
112 [SCREEN] = (draw_function_t) draw_screen,
113 [CONTAINER] = (draw_function_t) draw_container,
114 [IMAGE] = (draw_function_t) draw_image,
115 [TEXT_AREA] = (draw_function_t) draw_textArea,
116 [BUTTON] = (draw_function_t) draw_button,
117#ifdef HAVE_SE_TOUCH
118 [LINE] = (draw_function_t) draw_line,
119 [SWITCH] = (draw_function_t) draw_switch,
120 [PAGE_INDICATOR] = (draw_function_t) draw_pageIndicator,
121 [RADIO_BUTTON] = (draw_function_t) draw_radioButton,
122#ifdef NBGL_QRCODE
123 [QR_CODE] = (draw_function_t) draw_qrCode,
124#endif // NBGL_QRCODE
125 [SPINNER] = (draw_function_t) draw_spinner,
126#endif // HAVE_SE_TOUCH
127 [PROGRESS_BAR] = (draw_function_t) draw_progressBar,
128#ifdef NBGL_KEYBOARD
129 [KEYBOARD] = (draw_function_t) draw_keyboard,
130#endif // NBGL_KEYBOARD
131#ifdef NBGL_KEYPAD
132 [KEYPAD] = (draw_function_t) draw_keypad,
133#endif // NBGL_KEYPAD
134 [IMAGE_FILE] = (draw_function_t) draw_image_file,
135#ifndef HAVE_SE_TOUCH
136 [TEXT_ENTRY] = (draw_function_t) draw_textEntry,
137#endif // HAVE_SE_TOUCH
138#ifdef NBGL_MASKING
139 [MASK_CONTROL] = (draw_function_t) draw_mask_control,
140#endif // NBGL_MASKING
141};
142/**********************
143 * VARIABLES
144 **********************/
145// buffer used either for image file uncompression and side screen string drawing
147
148#ifdef BUILD_SCREENSHOTS
149// Variables used to store important values (nb lines, bold state etc)
150extern uint16_t last_nb_lines, last_nb_pages;
151extern bool last_bold_state, verbose;
152#endif // BUILD_SCREENSHOTS
153
154/**********************
155 * STATIC PROTOTYPES
156 **********************/
157
158/**********************
159 * GLOBAL FUNCTIONS
160 **********************/
161
162static void compute_relativePosition(nbgl_obj_t *obj, nbgl_obj_t *prevObj)
163{
164 nbgl_container_t *parent = (nbgl_container_t *) (obj->parent);
165 // LOG_DEBUG(OBJ_LOGGER,"compute_relativePosition()\n");
166 // compute object absolute position thanks to layout/alignment
167 if (obj->alignment == NO_ALIGNMENT) {
168 LOG_DEBUG(
170 "compute_relativePosition() without align to, parent->layout = %d, prevObj = %p\n",
171 parent->layout,
172 prevObj);
173 // align to parent, depending of layout
174 if (parent->layout == VERTICAL) {
175 obj->rel_x0 = obj->alignmentMarginX;
176 if (prevObj != NULL) {
177 obj->rel_y0 = prevObj->rel_y0 + prevObj->area.height + obj->alignmentMarginY;
178 }
179 else {
180 obj->rel_y0 = obj->alignmentMarginY;
181 }
182 }
183 else { // HORIZONTAL
184 if (prevObj != NULL) {
185 obj->rel_x0 = prevObj->rel_x0 + prevObj->area.width + obj->alignmentMarginX;
186 }
187 else {
188 obj->rel_x0 = obj->alignmentMarginX;
189 }
190 obj->rel_y0 = obj->alignmentMarginY;
191 }
192 }
193 else {
194 nbgl_obj_t *alignToObj = obj->alignTo;
195 if (alignToObj == NULL) {
196 alignToObj = obj->parent;
197 LOG_DEBUG(OBJ_LOGGER, "compute_relativePosition() with align to parent\n");
198 }
199 else {
200 LOG_DEBUG(OBJ_LOGGER, "compute_relativePosition() with align to = %p\n", alignToObj);
201 }
202 // align to the given object, with the given constraints
203 if (alignToObj == obj->parent) {
204 // align inside if the reference is the parent
205 switch (obj->alignment) {
206 case TOP_LEFT:
207 obj->rel_x0 = obj->alignmentMarginX;
208 obj->rel_y0 = obj->alignmentMarginY;
209 break;
210 case TOP_MIDDLE:
211 obj->rel_x0
212 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
213 obj->rel_y0 = obj->alignmentMarginY;
214 break;
215 case TOP_RIGHT:
216 obj->rel_x0
217 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
218 obj->rel_y0 = obj->alignmentMarginY;
219 break;
220 case MID_LEFT:
221 obj->rel_x0 = obj->alignmentMarginX;
222 obj->rel_y0
223 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
224 break;
225 case CENTER:
226 obj->rel_x0
227 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
228 obj->rel_y0
229 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
230 break;
231 case MID_RIGHT:
232 obj->rel_x0
233 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
234 obj->rel_y0
235 = (parent->obj.area.height - obj->area.height) / 2 + obj->alignmentMarginY;
236 break;
237 case BOTTOM_LEFT:
238 obj->rel_x0 = obj->alignmentMarginX;
239 obj->rel_y0
240 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
241 break;
242 case BOTTOM_MIDDLE:
243 obj->rel_x0
244 = (parent->obj.area.width - obj->area.width) / 2 + obj->alignmentMarginX;
245 obj->rel_y0
246 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
247 break;
248 case BOTTOM_RIGHT:
249 obj->rel_x0
250 = (parent->obj.area.width - obj->area.width) - obj->alignmentMarginX;
251 obj->rel_y0
252 = (parent->obj.area.height - obj->area.height) - obj->alignmentMarginY;
253 break;
254 default:
255 // not supported
256 break;
257 }
258 }
259 else {
260 // align outside if the reference is a "brother"
261 switch (obj->alignment) {
262 case TOP_LEFT:
263 obj->rel_x0 = alignToObj->rel_x0 + obj->alignmentMarginX;
264 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
265 break;
266 case TOP_MIDDLE:
267 obj->rel_x0 = alignToObj->rel_x0
268 + (alignToObj->area.width - obj->area.width) / 2
269 + obj->alignmentMarginX;
270 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
271 break;
272 case TOP_RIGHT:
273 obj->rel_x0 = alignToObj->rel_x0 + (alignToObj->area.width - obj->area.width)
274 - obj->alignmentMarginX;
275 obj->rel_y0 = alignToObj->rel_y0 - obj->area.height - obj->alignmentMarginY;
276 break;
277
278 case LEFT_TOP:
279 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
280 obj->rel_y0 = alignToObj->rel_y0 + obj->alignmentMarginY;
281 break;
282 case MID_LEFT:
283 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
284 obj->rel_y0 = alignToObj->rel_y0
285 + (alignToObj->area.height - obj->area.height) / 2
286 + obj->alignmentMarginY;
287 break;
288 case LEFT_BOTTOM:
289 obj->rel_x0 = alignToObj->rel_x0 - obj->area.width - obj->alignmentMarginX;
290 obj->rel_y0 = alignToObj->rel_y0 + (alignToObj->area.height - obj->area.height)
291 + obj->alignmentMarginY;
292 break;
293
294 case RIGHT_TOP:
295 obj->rel_x0
296 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
297 obj->rel_y0 = alignToObj->rel_y0 + obj->alignmentMarginY;
298 break;
299 case MID_RIGHT:
300 obj->rel_x0
301 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
302 obj->rel_y0 = alignToObj->rel_y0
303 + (alignToObj->area.height - obj->area.height) / 2
304 + obj->alignmentMarginY;
305 break;
306 case RIGHT_BOTTOM:
307 obj->rel_x0
308 = alignToObj->rel_x0 + alignToObj->area.width + obj->alignmentMarginX;
309 obj->rel_y0 = alignToObj->rel_y0 + (alignToObj->area.height - obj->area.height)
310 + obj->alignmentMarginY;
311 break;
312
313 case BOTTOM_LEFT:
314 obj->rel_x0 = alignToObj->rel_x0 + obj->alignmentMarginX;
315 obj->rel_y0
316 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
317 break;
318 case BOTTOM_MIDDLE:
319 obj->rel_x0 = alignToObj->rel_x0
320 + (alignToObj->area.width - obj->area.width) / 2
321 + obj->alignmentMarginX;
322 obj->rel_y0
323 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
324 break;
325 case BOTTOM_RIGHT:
326 obj->rel_x0 = alignToObj->rel_x0 + (alignToObj->area.width - obj->area.width)
327 - obj->alignmentMarginX;
328 obj->rel_y0
329 = alignToObj->rel_y0 + alignToObj->area.height + obj->alignmentMarginY;
330 break;
331 default:
332 // not supported
333 break;
334 }
335 }
336 }
337}
338
339static void compute_position(nbgl_obj_t *obj, nbgl_obj_t *prevObj)
340{
341 nbgl_container_t *parent = (nbgl_container_t *) (obj->parent);
342
343 compute_relativePosition(obj, prevObj);
344
345 if (parent == NULL) {
346 // HUGE issue
347 return;
348 }
349 // LOG_DEBUG(OBJ_LOGGER,"compute_position(), parent.type = %d, parent->obj.area.x0 = %d,
350 // obj->rel_x0=%d\n",parent->type,parent->obj.area.x0,obj->rel_x0);
351 // LOG_DEBUG(OBJ_LOGGER,"compute_position(), parent->obj.area.y0 = %d,
352 // obj->rel_y0=%d\n",parent->obj.area.y0,obj->rel_y0);
353
354 obj->area.x0 = parent->obj.area.x0 + obj->rel_x0;
355 obj->area.y0 = parent->obj.area.y0 + obj->rel_y0;
356
357 if ((obj->area.x0 + obj->area.width) > SCREEN_WIDTH) {
359 "compute_position(), forbidden width, obj->type = %d, x0=%d, width=%d\n",
360 obj->type,
361 obj->area.x0,
362 obj->area.width);
363 }
364#ifdef HAVE_SE_TOUCH
365 if ((obj->area.y0 + obj->area.height) > SCREEN_HEIGHT) {
367 "compute_position(), forbidden height, obj->type = %d, y0=%d, height=%d\n",
368 obj->type,
369 obj->area.y0,
370 obj->area.height);
371 }
372#endif // HAVE_SE_TOUCH
373}
374
375static void draw_screen(nbgl_container_t *obj, nbgl_obj_t *prevObj, bool computePosition)
376{
377 nbgl_area_t rectArea;
378
379 UNUSED(prevObj);
380 UNUSED(computePosition);
381
382 rectArea.backgroundColor = obj->obj.area.backgroundColor;
383 rectArea.x0 = obj->obj.area.x0;
384 rectArea.y0 = obj->obj.area.y0;
385 rectArea.width = obj->obj.area.width;
386 rectArea.height = obj->obj.area.height;
387 nbgl_frontDrawRect(&rectArea);
388}
389
390static void draw_container(nbgl_container_t *obj, nbgl_obj_t *prevObj, bool computePosition)
391{
392 if (computePosition) {
393 compute_position((nbgl_obj_t *) obj, prevObj);
394 }
396 "draw_container(), x0 = %d, y0 = %d, width = %d, height = %d\n",
397 obj->obj.area.x0,
398 obj->obj.area.y0,
399 obj->obj.area.width,
400 obj->obj.area.height);
401 // inherit background from parent
402 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
403 if (obj->forceClean) {
405 }
406}
407
408#ifdef HAVE_SE_TOUCH
417static void draw_button(nbgl_button_t *obj, nbgl_obj_t *prevObj, bool computePosition)
418{
419 uint16_t textWidth = 0;
420 const char *text = NULL;
421#define ICON_TEXT_SPACE 12
422
423 if (computePosition) {
424 compute_position((nbgl_obj_t *) obj, prevObj);
425 }
427 "draw_button(), x0 = %d, y0 = %d, width = %d, height = %d\n",
428 obj->obj.area.x0,
429 obj->obj.area.y0,
430 obj->obj.area.width,
431 obj->obj.area.height);
432
433 // inherit background from parent
434 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
435 // draw the rounded corner rectangle if necessary
436 if ((obj->innerColor == obj->borderColor)
437 && (obj->innerColor != obj->obj.area.backgroundColor)) {
438 nbgl_drawRoundedRect((nbgl_area_t *) obj, obj->radius, obj->innerColor);
439 }
440 else {
442 (nbgl_area_t *) obj, obj->radius, BUTTON_STROKE, obj->innerColor, obj->borderColor);
443 }
444 // get the text of the button from the callback if not NULL
445 if (obj->onDrawCallback != NULL) {
446 obj->text = obj->onDrawCallback(obj->token);
447 }
448 text = obj->text;
449 // draw the text (right of the icon, with 8 pixels between them)
450 if (text != NULL) {
451 nbgl_area_t rectArea;
452 // Compute available with & height to display the text
453 rectArea.x0 = obj->obj.area.x0;
454 rectArea.y0 = obj->obj.area.y0;
455 // Only one line of text
456 rectArea.height = nbgl_getFontHeight(obj->fontId);
457 rectArea.y0 += (obj->obj.area.height - rectArea.height) / 2;
458 rectArea.width = obj->obj.area.width;
459 if (obj->icon != NULL) {
460 rectArea.x0 += obj->icon->width + ICON_TEXT_SPACE;
461 rectArea.width -= obj->icon->width + ICON_TEXT_SPACE;
462 }
463 // Compute the width & number of characters displayed on first line
464 uint16_t textLen;
465 nbgl_getTextMaxLenAndWidth(obj->fontId, text, rectArea.width, &textLen, &textWidth, true);
466
467#ifdef BUILD_SCREENSHOTS
468 store_string_infos(text, obj->fontId, &rectArea, true, 1, 1, false);
469#endif // BUILD_SCREENSHOTS
470
471 // Center the text, horizontally
472 if (textWidth < rectArea.width) {
473 rectArea.x0 += (rectArea.width - textWidth) / 2;
474 }
475 LOG_DEBUG(OBJ_LOGGER, "draw_button(), text = %s\n", text);
476 rectArea.backgroundColor = obj->innerColor;
477 nbgl_drawText(&rectArea, text, textLen, obj->fontId, obj->foregroundColor);
478 }
479 // draw the icon, if any
480 if (obj->icon != NULL) {
481 uint16_t iconX0, iconY0;
482 nbgl_area_t rectArea;
483
484 if (text != NULL) {
485 iconX0 = obj->obj.area.x0
486 + (obj->obj.area.width - (textWidth + obj->icon->width + ICON_TEXT_SPACE)) / 2;
487 }
488 else {
489 iconX0 = obj->obj.area.x0 + (obj->obj.area.width - obj->icon->width) / 2;
490 }
492 "draw_button(), obj->obj.area.height = %d, obj->iconHeight = %d\n",
493 obj->obj.area.height,
494 obj->icon->height);
495 iconY0 = obj->obj.area.y0 + (obj->obj.area.height - obj->icon->height) / 2;
496
497 rectArea.backgroundColor = obj->innerColor;
498 rectArea.x0 = iconX0;
499 rectArea.y0 = iconY0;
500 rectArea.width = obj->icon->width;
501 rectArea.height = obj->icon->height;
502 rectArea.bpp = obj->icon->bpp;
503
504 nbgl_drawIcon(&rectArea, NO_TRANSFORMATION, obj->foregroundColor, obj->icon);
505 }
506}
507
516static void draw_line(nbgl_line_t *obj, nbgl_obj_t *prevObj, bool computePosition)
517{
518 nbgl_area_t rectArea;
519 if (computePosition) {
520 compute_position((nbgl_obj_t *) obj, prevObj);
521 }
522 LOG_DEBUG(OBJ_LOGGER, "draw_line(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
523 // inherit background from parent
524 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
526 "draw_line(), backgroundColor = %d, lineColor = %d\n",
527 obj->obj.area.backgroundColor,
528 obj->lineColor);
529 rectArea.x0 = obj->obj.area.x0;
530 rectArea.y0 = obj->obj.area.y0;
531 rectArea.backgroundColor = obj->obj.area.backgroundColor;
532 if (obj->direction == VERTICAL) {
533 rectArea.width = obj->obj.area.width = obj->thickness;
534 rectArea.height = obj->obj.area.height;
535 nbgl_frontDrawLine(&rectArea, 0, obj->lineColor);
536 }
537 else {
538 rectArea.width = obj->obj.area.width;
539 rectArea.height = obj->obj.area.height = obj->thickness;
540 nbgl_frontDrawLine(&rectArea, 0, obj->lineColor);
541 }
542}
543#else // HAVE_SE_TOUCH
552static void draw_button(nbgl_button_t *obj, nbgl_obj_t *prevObj, bool computePosition)
553{
554 uint16_t textWidth = 0;
555 const char *text = NULL;
556#define ICON_TEXT_SPACE 2
557
558 if (computePosition) {
559 compute_position((nbgl_obj_t *) obj, prevObj);
560 }
562 "draw_button(), x0 = %d, y0 = %d, width = %d, height = %d\n",
563 obj->obj.area.x0,
564 obj->obj.area.y0,
565 obj->obj.area.width,
566 obj->obj.area.height);
567
568 // inherit background from parent
569 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
570 // draw the rounded corner rectangle if necessary
571 nbgl_drawRoundedRect((nbgl_area_t *) obj, obj->radius, obj->innerColor);
572
573 // get the text of the button from the callback if not NULL
574 if (obj->onDrawCallback != NULL) {
575 obj->text = obj->onDrawCallback(obj->token);
576 }
577 text = obj->text;
578 // draw the text (right of the icon, with ICON_TEXT_SPACE pixels between them)
579 if (text != NULL) {
580 nbgl_area_t rectArea;
581 // Compute available with & height to display the text
582 rectArea.x0 = obj->obj.area.x0;
583 rectArea.y0 = obj->obj.area.y0;
584 // Only one line of text is allowed
585 rectArea.height = nbgl_getFontHeight(obj->fontId);
586 rectArea.y0 += (obj->obj.area.height - rectArea.height) / 2;
587 rectArea.width = obj->obj.area.width;
588 if (obj->icon != NULL) {
589 rectArea.x0 += obj->icon->width + ICON_TEXT_SPACE;
590 rectArea.width -= obj->icon->width + ICON_TEXT_SPACE;
591 }
592 // Compute the width & number of characters displayed on first line
593 uint16_t textLen;
594 nbgl_getTextMaxLenAndWidth(obj->fontId, text, rectArea.width, &textLen, &textWidth, true);
595
596 // Center the text, horizontally
597 if (textWidth < rectArea.width) {
598 rectArea.x0 += (rectArea.width - textWidth) / 2;
599 }
600 LOG_DEBUG(OBJ_LOGGER, "draw_button(), text = %s\n", text);
601 rectArea.backgroundColor = obj->innerColor;
602 nbgl_drawText(&rectArea, text, textLen, obj->fontId, obj->foregroundColor);
603 }
604 // draw the icon, if any
605 if (obj->icon != NULL) {
606 uint16_t iconX0, iconY0;
607 nbgl_area_t rectArea;
608
609 if (text != NULL) {
610 iconX0 = obj->obj.area.x0
611 + (obj->obj.area.width - (textWidth + obj->icon->width + ICON_TEXT_SPACE)) / 2;
612 }
613 else {
614 iconX0 = obj->obj.area.x0 + (obj->obj.area.width - obj->icon->width) / 2;
615 }
617 "draw_button(), obj->obj.area.height = %d, obj->iconHeight = %d\n",
618 obj->obj.area.height,
619 obj->icon->height);
620 iconY0 = obj->obj.area.y0 + (obj->obj.area.height - obj->icon->height) / 2;
621
622 rectArea.backgroundColor = obj->innerColor;
623 rectArea.x0 = iconX0;
624 rectArea.y0 = iconY0;
625 rectArea.width = obj->icon->width;
626 rectArea.height = obj->icon->height;
627 rectArea.bpp = obj->icon->bpp;
628
629 nbgl_drawIcon(&rectArea, NO_TRANSFORMATION, obj->foregroundColor, obj->icon);
630 }
631}
632#endif // HAVE_SE_TOUCH
633
634static void draw_image(nbgl_image_t *obj, nbgl_obj_t *prevObj, bool computePosition)
635{
636 const nbgl_icon_details_t *iconDetails;
637 nbgl_color_map_t colorMap;
638
639 // if buffer is NULL, let's try to call onDrawCallback, if not NULL, to get it
640 if (obj->buffer == NULL) {
641 if (obj->onDrawCallback != NULL) {
642 iconDetails = obj->onDrawCallback(obj->token);
643 }
644 else {
645 return;
646 }
647 }
648 else {
649 iconDetails = obj->buffer;
650 }
651 if (iconDetails == NULL) {
652 return;
653 }
654
655 // use dimension and bpp from the icon details
656 obj->obj.area.width = iconDetails->width;
657 obj->obj.area.height = iconDetails->height;
658 obj->obj.area.bpp = iconDetails->bpp;
659 if (computePosition) {
660 compute_position((nbgl_obj_t *) obj, prevObj);
661 }
662 LOG_DEBUG(OBJ_LOGGER, "draw_image(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
663 // inherit background from parent
664 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
665 if (obj->obj.area.bpp == NBGL_BPP_1) {
666 colorMap = obj->foregroundColor;
667 }
668 else if (obj->obj.area.bpp == NBGL_BPP_2) {
669 colorMap = ((WHITE << 6) | (LIGHT_GRAY << 4) | (DARK_GRAY << 2) | BLACK);
670 }
671 else {
672 colorMap = obj->foregroundColor;
673 }
674
675 nbgl_drawIcon((nbgl_area_t *) obj, obj->transformation, colorMap, iconDetails);
676}
677
678#ifdef HAVE_SE_TOUCH
679static void draw_switch(nbgl_switch_t *obj, nbgl_obj_t *prevObj, bool computePosition)
680{
681 nbgl_area_t rectArea;
682
683 // force dimensions
684 obj->obj.area.width = SWITCH_ICON.width;
685 obj->obj.area.height = SWITCH_ICON.height;
686 if (computePosition) {
687 compute_position((nbgl_obj_t *) obj, prevObj);
688 }
689 LOG_DEBUG(OBJ_LOGGER, "draw_switch(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
690
691 // inherit background from parent
692 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
693
694 rectArea.x0 = obj->obj.area.x0;
695 rectArea.y0 = obj->obj.area.y0;
696 rectArea.width = obj->obj.area.width;
697 rectArea.height = obj->obj.area.height;
698 rectArea.backgroundColor = obj->obj.area.backgroundColor;
699 rectArea.bpp = NBGL_BPP_1;
700 if (obj->state == OFF_STATE) {
701#if NB_COLOR_BITS == 1
702 nbgl_drawIcon(&rectArea, NO_TRANSFORMATION, obj->onColor, &C_switch_off_24px);
703#else
704 nbgl_frontDrawImage(&rectArea, SWITCH_ICON.bitmap, NO_TRANSFORMATION, obj->offColor);
705#endif
706 }
707 else {
708#if NB_COLOR_BITS == 1
709 nbgl_drawIcon(&rectArea, NO_TRANSFORMATION, obj->onColor, &C_switch_on_24px);
710#else
711 nbgl_frontDrawImage(&rectArea, SWITCH_ICON.bitmap, VERTICAL_MIRROR, obj->onColor);
712#endif
713 }
714}
715
716static void draw_radioButton(nbgl_radio_t *obj, nbgl_obj_t *prevObj, bool computePosition)
717{
718 nbgl_area_t rectArea;
719 const nbgl_icon_details_t *icon;
720 nbgl_color_map_t color_map;
721
722 // force dimensions
723 obj->obj.area.width = RADIO_WIDTH;
724 obj->obj.area.height = RADIO_HEIGHT;
725 if (computePosition) {
726 compute_position((nbgl_obj_t *) obj, prevObj);
727 }
729 "draw_radioButton(), x0 = %d, y0 = %d, state = %d\n",
730 obj->obj.area.x0,
731 obj->obj.area.y0,
732 obj->state);
733
734 // inherit background from parent
735 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
736
737 if (obj->state == OFF_STATE) {
738 icon = &RADIO_OFF_ICON;
739#if NB_COLOR_BITS == 1
740 color_map = obj->activeColor;
741#else
742 color_map = obj->borderColor;
743#endif
744 }
745 else {
746 icon = &RADIO_ON_ICON;
747 color_map = obj->activeColor;
748 }
749 rectArea.x0 = obj->obj.area.x0;
750 rectArea.y0 = obj->obj.area.y0;
751 rectArea.width = obj->obj.area.width;
752 rectArea.height = obj->obj.area.height;
753 rectArea.backgroundColor = obj->obj.area.backgroundColor;
754 rectArea.bpp = icon->bpp;
755 nbgl_drawIcon(&rectArea, NO_TRANSFORMATION, color_map, icon);
756}
757#endif // HAVE_SE_TOUCH
758
766static void draw_progressBar(nbgl_progress_bar_t *obj, nbgl_obj_t *prevObj, bool computePosition)
767{
768#ifdef HAVE_SE_TOUCH
769
770 uint8_t stroke = PROGRESS_STROKE; // pixels for border
771 nbgl_area_t barArea;
772 uint16_t barWidth = ((obj->state * obj->obj.area.width)) / 100;
773
774 if (computePosition) {
775 compute_position((nbgl_obj_t *) obj, prevObj);
776 }
778 "draw_progressBar(), x0 = %d, y0 = %d, level = %d %%\n",
779 obj->obj.area.x0,
780 obj->obj.area.y0,
781 obj->state);
782 memcpy(&barArea, &obj->obj.area, sizeof(nbgl_area_t));
783
784 // inherit background from parent
785 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
786
787 if (obj->partialRedraw == false) {
788 // Case of progress bar full draw
789 if (obj->withBorder) {
792 stroke,
793 obj->obj.area.backgroundColor,
794 obj->foregroundColor);
795 }
796 else {
798 (nbgl_area_t *) obj, RADIUS_0_PIXELS, obj->obj.area.backgroundColor);
799 }
800 // also reset previous width to be sure to clean up everything
801 obj->previousWidth = 0;
802 if (obj->state == 0) {
803 goto end;
804 }
805 }
806 // Setup bar draw
807 int barDiffWith = barWidth - obj->previousWidth;
808 color_t barColor;
809
810 if (barDiffWith > 0) {
811 // Drawing "forward"
812 barArea.x0 = obj->obj.area.x0 + obj->previousWidth;
813 barArea.width = barDiffWith;
814 barColor = obj->foregroundColor;
815 }
816 else if (barDiffWith < 0) {
817 // Drawing "backward"
818 barArea.x0 = obj->obj.area.x0 + obj->previousWidth + barDiffWith;
819 barArea.width = -barDiffWith;
820 barColor = obj->obj.area.backgroundColor;
821 }
822
823 if (barDiffWith != 0) {
824 nbgl_drawRoundedRect((nbgl_area_t *) &barArea, RADIUS_0_PIXELS, barColor);
825 }
826
827 // reset partialRedraw to be sure that in case of full redraw of the screen we redraw the
828 // full bar
829 if (obj->partialRedraw == true) {
830 obj->partialRedraw = false;
831 }
832 obj->previousWidth = barWidth;
833
834end:
835 extendRefreshArea(&barArea);
836 objRefreshAreaDone = true;
837#else // HAVE_SE_TOUCH
838 uint8_t stroke = 1; // 1 pixels for border
839 uint16_t levelWidth;
840
841 if (computePosition) {
842 compute_position((nbgl_obj_t *) obj, prevObj);
843 }
845 "draw_progressBar(), x0 = %d, y0 = %d, level = %d %%\n",
846 obj->obj.area.x0,
847 obj->obj.area.y0,
848 obj->state);
849
850 // inherit background from parent
851 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
852
853 // draw external part if necessary
854 if (obj->withBorder) {
856 RADIUS_3_PIXELS,
857 stroke,
858 obj->obj.area.backgroundColor,
859 obj->foregroundColor);
860 }
861 else {
862 nbgl_drawRoundedRect((nbgl_area_t *) obj, RADIUS_3_PIXELS, obj->obj.area.backgroundColor);
863 }
864 // draw level
865 levelWidth = MIN((obj->obj.area.width - 2) * obj->state / 100, (obj->obj.area.width - 2));
866 if (levelWidth > 0) {
867 nbgl_area_t rectArea;
868 rectArea.width = levelWidth;
869 rectArea.height = obj->obj.area.height - 2;
870 rectArea.backgroundColor = obj->foregroundColor;
871 rectArea.bpp = NBGL_BPP_1;
872 rectArea.x0 = obj->obj.area.x0 + 1;
873 rectArea.y0 = obj->obj.area.y0 + 1;
874
875 nbgl_frontDrawRect(&rectArea);
876 }
877#endif // HAVE_SE_TOUCH
878}
879
880#ifdef HAVE_SE_TOUCH
889static void draw_pageIndicator(nbgl_page_indicator_t *obj,
890 nbgl_obj_t *prevObj,
891 bool computePosition)
892{
893 nbgl_area_t rectArea;
894 uint16_t dashWidth;
895
896 // display nothing if less than two pages
897 if (obj->nbPages < 2) {
898 return;
899 }
900
901 if (obj->nbPages <= NB_MAX_PAGES_WITH_DASHES) {
902 int i;
903 // force height
904 obj->obj.area.height = 4;
905
906 if (computePosition) {
907 compute_position((nbgl_obj_t *) obj, prevObj);
908 }
910 "draw_pageIndicator(), x0 = %d, y0 = %d, page = %d/%d\n",
911 obj->obj.area.x0,
912 obj->obj.area.y0,
913 obj->activePage,
914 obj->nbPages);
915
916 // inherit background from parent
917 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
918
919 dashWidth = (obj->obj.area.width - ((obj->nbPages - 1) * INTER_DASHES)) / obj->nbPages;
920 rectArea.x0 = obj->obj.area.x0;
921 rectArea.y0 = obj->obj.area.y0;
922 rectArea.width = dashWidth;
923 rectArea.height = 4;
924 rectArea.backgroundColor = obj->obj.area.backgroundColor;
925 rectArea.bpp = NBGL_BPP_1;
926 // draw dashes
927 for (i = 0; i < obj->activePage; i++) {
929 &rectArea, 0, (obj->style == PROGRESSIVE_INDICATOR) ? BLACK : LIGHT_GRAY);
930 rectArea.x0 += dashWidth + INTER_DASHES;
931 }
932 nbgl_frontDrawLine(&rectArea, 0, BLACK);
933 rectArea.x0 += dashWidth + INTER_DASHES;
934 i++;
935
936 for (; i < obj->nbPages; i++) {
937 nbgl_frontDrawLine(&rectArea, 0, LIGHT_GRAY);
938 rectArea.x0 += dashWidth + INTER_DASHES;
939 }
940 }
941 else {
942 char navText[11]; // worst case is "ccc of nnn"
943
944 SPRINTF(navText, "%d of %d", obj->activePage + 1, obj->nbPages);
945 // force height
946 obj->obj.area.height = nbgl_getFontHeight(SMALL_REGULAR_FONT);
947 // the width must be at least 80
948 obj->obj.area.width = nbgl_getTextWidth(SMALL_REGULAR_FONT, navText);
949
950 if (computePosition) {
951 compute_position((nbgl_obj_t *) obj, prevObj);
952 }
954 "draw_pageIndicator(), x0 = %d, y0 = %d, page = %d/%d\n",
955 obj->obj.area.x0,
956 obj->obj.area.y0,
957 obj->activePage,
958 obj->nbPages);
959
960 // inherit background from parent
961 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
962
963 // draw active page
964 rectArea.x0 = obj->obj.area.x0;
965 rectArea.y0 = obj->obj.area.y0;
966 rectArea.width = obj->obj.area.width;
967 rectArea.height = obj->obj.area.height;
968 rectArea.backgroundColor = obj->obj.area.backgroundColor;
969 rectArea.bpp = NBGL_BPP_1;
970 nbgl_drawText(&rectArea, navText, strlen(navText), SMALL_REGULAR_FONT, LIGHT_TEXT_COLOR);
971 }
972}
973#endif // HAVE_SE_TOUCH
974
983static void draw_textArea(nbgl_text_area_t *obj, nbgl_obj_t *prevObj, bool computePosition)
984{
985 nbgl_area_t rectArea;
986 uint16_t textWidth, fontHeight, lineHeight, textHeight, midHeight;
987 uint8_t line, nbLines;
988 const char *text;
989 nbgl_font_id_e fontId = obj->fontId;
990
991 if (computePosition) {
992 compute_position((nbgl_obj_t *) obj, prevObj);
993 }
994 // get the text of the button from the callback if not NULL
995 if (obj->onDrawCallback != NULL) {
996 obj->text = obj->onDrawCallback(obj->token);
997 }
998 text = obj->text;
999 if (text == NULL) {
1000 return;
1001 }
1002
1003 LOG_DEBUG(
1004 OBJ_LOGGER,
1005 "draw_textArea(), wrapping = %d, x0 = %d, y0 = %d, width = %d, height = %d, text = %s\n",
1006 obj->wrapping,
1007 obj->obj.area.x0,
1008 obj->obj.area.y0,
1009 obj->obj.area.width,
1010 obj->obj.area.height,
1011 text);
1012
1013 // inherit background from parent
1014 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1015
1016 // draw background to make sure it's clean
1017#ifdef SCREEN_SIZE_NANO
1018 if (obj->style == INVERTED_COLORS) {
1019 obj->obj.area.backgroundColor = WHITE;
1020 rectArea.backgroundColor = BLACK;
1021 }
1022 else
1023#endif // SCREEN_SIZE_NANO
1024 {
1025 // inherit background from parent
1026 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1027 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1028 }
1029 rectArea.x0 = obj->obj.area.x0;
1030 rectArea.y0 = obj->obj.area.y0;
1031 rectArea.width = obj->obj.area.width;
1032 rectArea.height = obj->obj.area.height;
1033#ifdef SCREEN_SIZE_NANO
1034 if (obj->style == INVERTED_COLORS) {
1035 nbgl_drawRoundedRect(&rectArea, RADIUS_1_PIXEL, WHITE);
1036 }
1037 else
1038#endif // SCREEN_SIZE_NANO
1039 {
1040 nbgl_frontDrawRect(&rectArea);
1041 }
1042
1043 fontHeight = nbgl_getFontHeight(fontId);
1044 lineHeight = nbgl_getFontLineHeight(fontId);
1045 // special case of autoHideLongLine, when the text is too long for a line, draw '...' at the
1046 // beginning
1047 if (obj->autoHideLongLine == true) {
1048#ifdef BUILD_SCREENSHOTS
1049 nbgl_getTextNbLinesInWidth(fontId, text, obj->obj.area.width, obj->wrapping);
1050 store_string_infos(text,
1051 fontId,
1052 &obj->obj.area,
1053 obj->wrapping,
1054 last_nb_lines,
1055 last_nb_pages,
1056 last_bold_state);
1057#endif // BUILD_SCREENSHOTS
1058 textWidth = nbgl_getSingleLineTextWidth(fontId, text);
1059 if (textWidth > obj->obj.area.width) {
1060 uint16_t lineWidth, lineLen;
1061 uint16_t dotsWidth;
1062
1063 dotsWidth = nbgl_getTextWidth(fontId, "...");
1064 rectArea.x0 = obj->obj.area.x0;
1065 rectArea.y0 = obj->obj.area.y0 + (obj->obj.area.height - fontHeight) / 2;
1066 rectArea.width = dotsWidth;
1067 nbgl_drawText(&rectArea, "...", 3, fontId, obj->textColor);
1068 // then draw the end of text
1070 fontId, text, obj->obj.area.width - dotsWidth, &lineLen, &lineWidth);
1071 rectArea.x0 += dotsWidth;
1072 rectArea.width = lineWidth;
1073 nbgl_drawText(&rectArea,
1074 &text[nbgl_getTextLength(text) - lineLen],
1075 lineLen,
1076 obj->fontId,
1077 obj->textColor);
1078 return;
1079 }
1080 }
1081
1082 // get nb lines in the given width (depending of wrapping)
1083 nbLines = nbgl_getTextNbLinesInWidth(fontId, text, obj->obj.area.width, obj->wrapping);
1084#ifdef BUILD_SCREENSHOTS
1085 store_string_infos(
1086 text, fontId, &obj->obj.area, obj->wrapping, last_nb_lines, last_nb_pages, last_bold_state);
1087#endif // BUILD_SCREENSHOTS
1088 // saturate nb lines if nbMaxLines is greater than 0
1089 if ((obj->nbMaxLines > 0) && (obj->nbMaxLines < nbLines)) {
1090 nbLines = obj->nbMaxLines;
1091 }
1092
1093 textHeight = (nbLines - 1) * lineHeight + fontHeight;
1094
1095 midHeight = (obj->obj.area.height - textHeight) / 2;
1096#ifdef SCREEN_SIZE_NANO
1097 if (obj->style == INVERTED_COLORS) {
1098 midHeight--;
1099 }
1100#endif // SCREEN_SIZE_NANO
1101
1102 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1103 rectArea.height = fontHeight;
1104 // draw each line
1105 for (line = 0; line < nbLines; line++) {
1106 uint16_t lineWidth, lineLen;
1107
1109 fontId, text, obj->obj.area.width, &lineLen, &lineWidth, obj->wrapping);
1110 if (obj->textAlignment == MID_LEFT) {
1111 rectArea.x0 = obj->obj.area.x0;
1112 }
1113 else if (obj->textAlignment == CENTER) {
1114 rectArea.x0 = obj->obj.area.x0 + (obj->obj.area.width - lineWidth) / 2;
1115 }
1116 else if (obj->textAlignment == MID_RIGHT) {
1117 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - lineWidth;
1118 }
1119 else {
1120 LOG_FATAL(OBJ_LOGGER, "Forbidden obj->textAlignment = %d\n", obj->textAlignment);
1121 }
1122 rectArea.y0 = obj->obj.area.y0 + midHeight + line * lineHeight;
1123 rectArea.width = lineWidth;
1124
1126 "draw_textArea(), [%s] line %d, lineLen %d lineWidth = %d, obj.area.height = %d, "
1127 "textHeight = %d, nbMaxLines = %d, wrapping = %d\n",
1128 text,
1129 line,
1130 lineLen,
1131 lineWidth,
1132 obj->obj.area.height,
1133 textHeight,
1134 obj->nbMaxLines,
1135 obj->wrapping);
1136 if ((obj->nbMaxLines == 0) || (line < (obj->nbMaxLines - 1))) {
1137 fontId = nbgl_drawText(&rectArea, text, lineLen, fontId, obj->textColor);
1138 }
1139 else {
1140#ifdef HAVE_SE_TOUCH
1141 uint16_t dotsWidth = nbgl_getSingleLineTextWidth(obj->fontId, "...");
1142 // for last chunk, if nbMaxLines is used, replace the 3 last chars by "..."
1143 // draw line except 3 last chars
1144 if ((lineWidth + dotsWidth) >= obj->obj.area.width) {
1145 lineLen -= 3;
1146 }
1147 nbgl_drawText(&rectArea, text, lineLen, obj->fontId, obj->textColor);
1148 rectArea.x0 += nbgl_getSingleLineTextWidthInLen(obj->fontId, text, lineLen);
1149
1150 // draw "..." after the other chars
1151 rectArea.width = dotsWidth;
1152 nbgl_drawText(&rectArea, "...", 3, obj->fontId, obj->textColor);
1153#else // HAVE_SE_TOUCH
1154 nbgl_drawText(&rectArea, text, lineLen, fontId, obj->textColor);
1155#endif // HAVE_SE_TOUCH
1156 return;
1157 }
1158 text += lineLen;
1159 /* skip trailing \n */
1160 if (*text == '\n') {
1161 text++;
1162 }
1163 }
1164}
1165
1166#ifdef NBGL_QRCODE
1175static void draw_qrCode(nbgl_qrcode_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1176{
1177 nbgl_area_t rectArea;
1178
1179 if (computePosition) {
1180 compute_position((nbgl_obj_t *) obj, prevObj);
1181 }
1182 // be sure to align vertical position on multiple of 4
1183 obj->obj.area.y0 &= ~0x3;
1185 "draw_qrCode(), x0 = %d, y0 = %d, width = %d, height = %d, text = %s\n",
1186 obj->obj.area.x0,
1187 obj->obj.area.y0,
1188 obj->obj.area.width,
1189 obj->obj.area.height,
1190 obj->text);
1191
1192 // inherit background from parent
1193 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1194
1195 rectArea.x0 = obj->obj.area.x0;
1196 rectArea.y0 = obj->obj.area.y0;
1197 rectArea.width = obj->obj.area.width;
1198 rectArea.height = obj->obj.area.height;
1199 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1200 nbgl_drawQrCode(&rectArea, obj->version, obj->text, obj->foregroundColor);
1201}
1202#endif // NBGL_QRCODE
1203
1204#ifdef NBGL_KEYBOARD
1212static void draw_keyboard(nbgl_keyboard_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1213{
1214#ifndef HAVE_SE_TOUCH
1215 obj->obj.area.width = KEYBOARD_WIDTH;
1216 obj->obj.area.height = KEYBOARD_KEY_HEIGHT;
1217#endif // HAVE_SE_TOUCH
1218
1219 if (computePosition) {
1220 compute_position((nbgl_obj_t *) obj, prevObj);
1221 }
1222 LOG_DEBUG(
1223 OBJ_LOGGER, "draw_keyboard(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1224
1225 // inherit background from parent
1226 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1227
1229}
1230#endif // NBGL_KEYBOARD
1231
1232#ifdef NBGL_KEYPAD
1240static void draw_keypad(nbgl_keypad_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1241{
1242#ifndef HAVE_SE_TOUCH
1243 obj->obj.area.height = KEYPAD_HEIGHT;
1244 obj->obj.area.width = KEYPAD_WIDTH;
1245#endif // HAVE_SE_TOUCH
1246
1247 if (computePosition) {
1248 compute_position((nbgl_obj_t *) obj, prevObj);
1249 }
1250 obj->obj.area.y0 &= ~0x3;
1251 LOG_DEBUG(OBJ_LOGGER, "draw_keypad(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1252
1253 // inherit background from parent
1254 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1255
1256 nbgl_objDrawKeypad(obj);
1257}
1258#endif // NBGL_KEYPAD
1259
1260#ifdef HAVE_SE_TOUCH
1268static void draw_spinner(nbgl_spinner_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1269{
1270 nbgl_area_t rectArea;
1271 color_t foreColor;
1272
1273 obj->obj.area.width = SPINNER_WIDTH;
1274 obj->obj.area.height = SPINNER_HEIGHT;
1275
1276 if (computePosition) {
1277 compute_position((nbgl_obj_t *) obj, prevObj);
1278 }
1279 LOG_DEBUG(OBJ_LOGGER, "draw_spinner(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1280
1281 // inherit background from parent
1282 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1283 // foreground color is the opposite of background one
1284 foreColor = (obj->obj.area.backgroundColor == WHITE) ? BLACK : WHITE;
1285
1286 rectArea.bpp = NBGL_BPP_1;
1287 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1288 // if position is OxFF, it means "fixed" so draw 4 corners
1289 if (obj->position == 0xFF) {
1290 // draw horizontal segments
1291 rectArea.x0 = obj->obj.area.x0;
1292 rectArea.y0 = obj->obj.area.y0;
1293 rectArea.width = SPINNER_DASH_WIDTH;
1294 rectArea.height = SPINNER_DASH_STROKE;
1295 nbgl_frontDrawLine(&rectArea, 0, foreColor); // top left
1296 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1297 nbgl_frontDrawLine(&rectArea, 0, foreColor); // top right
1298 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 3;
1299 nbgl_frontDrawLine(&rectArea, 0, foreColor); // bottom right
1300 rectArea.x0 = obj->obj.area.x0;
1301 nbgl_frontDrawLine(&rectArea, 0, foreColor); // bottom left
1302 // draw vertical segments
1303 rectArea.x0 = obj->obj.area.x0;
1304 rectArea.y0 = obj->obj.area.y0;
1305 rectArea.width = SPINNER_DASH_STROKE;
1306 rectArea.height = SPINNER_DASH_HEIGHT;
1307 rectArea.backgroundColor = foreColor;
1308 nbgl_frontDrawRect(&rectArea); // top left
1309 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1310 nbgl_frontDrawRect(&rectArea); // top right
1311 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1312 nbgl_frontDrawRect(&rectArea); // bottom right
1313 rectArea.x0 = obj->obj.area.x0;
1314 nbgl_frontDrawRect(&rectArea); // bottom left
1315 }
1316 else {
1317 // clean up full rectangle
1318 rectArea.x0 = obj->obj.area.x0;
1319 rectArea.y0 = obj->obj.area.y0;
1320 rectArea.width = obj->obj.area.width;
1321 rectArea.height = obj->obj.area.height;
1322 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1323 nbgl_frontDrawRect(&rectArea); // top left
1324
1325 // draw horizontal segment in foreColor
1326 rectArea.width = SPINNER_DASH_WIDTH;
1327 rectArea.height = SPINNER_DASH_STROKE;
1328 switch (obj->position) {
1329 case 0: // top left corner
1330 rectArea.x0 = obj->obj.area.x0;
1331 rectArea.y0 = obj->obj.area.y0;
1332 break;
1333 case 1: // top right
1334 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1335 rectArea.y0 = obj->obj.area.y0;
1336 break;
1337 case 2: // bottom right
1338 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1339 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 3;
1340 break;
1341 case 3: // bottom left
1342 rectArea.x0 = obj->obj.area.x0;
1343 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 3;
1344 break;
1345 default:
1346 return;
1347 }
1348 nbgl_frontDrawLine(&rectArea, 0, foreColor);
1349
1350 // draw vertical segment in foreColor
1351 rectArea.width = SPINNER_DASH_STROKE;
1352 rectArea.height = SPINNER_DASH_HEIGHT;
1353 rectArea.backgroundColor = foreColor;
1354 switch (obj->position) {
1355 case 0: // top left corner
1356 rectArea.x0 = obj->obj.area.x0;
1357 rectArea.y0 = obj->obj.area.y0;
1358 break;
1359 case 1: // top right corner
1360 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1361 rectArea.y0 = obj->obj.area.y0;
1362 break;
1363 case 2: // bottom right corner
1364 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1365 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1366 break;
1367 case 3: // bottom left corner
1368 rectArea.x0 = obj->obj.area.x0;
1369 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1370 break;
1371 default:
1372 return;
1373 }
1374 nbgl_frontDrawRect(&rectArea);
1375 }
1376}
1377
1378#else // HAVE_SE_TOUCH
1379
1387static void draw_textEntry(nbgl_text_entry_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1388{
1389 nbgl_area_t rectArea;
1390 int textLen = strlen(obj->text);
1391 uint32_t offsetX;
1392
1393 if (computePosition) {
1394 compute_position((nbgl_obj_t *) obj, prevObj);
1395 }
1396
1398 "draw_textEntry(), x0 = %d, y0 = %d, width = %d, height = %d\n",
1399 obj->obj.area.x0,
1400 obj->obj.area.y0,
1401 obj->obj.area.width,
1402 obj->obj.area.height);
1403
1404 // draw background to make sure it's clean
1405 obj->obj.area.backgroundColor = WHITE;
1406 rectArea.backgroundColor = BLACK;
1407 rectArea.x0 = obj->obj.area.x0;
1408 rectArea.y0 = obj->obj.area.y0;
1409 rectArea.width = obj->obj.area.width;
1410 rectArea.height = obj->obj.area.height;
1411 rectArea.bpp = NBGL_BPP_1;
1412 nbgl_drawRoundedRect(&rectArea, RADIUS_3_PIXELS, WHITE);
1413
1414 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1415 rectArea.height = nbgl_getFontHeight(obj->fontId);
1416 if (obj->nbChars > NB_MAX_LETTERS) {
1417 return;
1418 }
1419 offsetX = (obj->obj.area.width - (obj->nbChars * 10)) / 2;
1420 // draw each of the nb chars
1421 for (int i = 0; i < obj->nbChars; i++) {
1422 char digit;
1423 rectArea.x0 = obj->obj.area.x0 + offsetX + (i * 10);
1424 rectArea.y0 = obj->obj.area.y0 - 2;
1425 rectArea.width = 8;
1426 if (textLen < obj->nbChars) {
1427 if (i < textLen) {
1428 digit = obj->text[i];
1429 }
1430 else {
1431 digit = '_';
1432 }
1433 }
1434 else {
1435 // first char is '..' to notify continuing
1436 if (i == 0) {
1438 continue;
1439 }
1440 else if (i < (obj->nbChars - 1)) {
1441 digit = obj->text[textLen - obj->nbChars + 1 + i];
1442 }
1443 else {
1444 digit = '_';
1445 }
1446 }
1448 }
1449}
1450#endif // HAVE_SE_TOUCH
1451
1459static void draw_image_file(nbgl_image_file_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1460{
1461 if (obj->buffer == NULL) {
1462 return;
1463 }
1464 if (computePosition) {
1465 compute_position((nbgl_obj_t *) obj, prevObj);
1466 }
1467
1468 LOG_DEBUG(
1469 OBJ_LOGGER, "draw_image_file(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1470 obj->obj.area.backgroundColor = WHITE;
1471 nbgl_frontDrawImageFile((nbgl_area_t *) obj, obj->buffer, BLACK, ramBuffer);
1472}
1473
1474#ifdef NBGL_MASKING
1475static void draw_mask_control(nbgl_mask_control_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1476{
1477 if (computePosition) {
1478 compute_position((nbgl_obj_t *) obj, prevObj);
1479 }
1480
1481 if (obj->enableMasking) {
1482 nbgl_frontControlAreaMasking(obj->maskIndex, &obj->obj.area);
1483 }
1484 else {
1485 nbgl_frontControlAreaMasking(obj->maskIndex, NULL);
1486 }
1487}
1488#endif // NBGL_MASKING
1489
1497static void draw_object(nbgl_obj_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1498{
1499 LOG_DEBUG(OBJ_LOGGER, "draw_object() obj->type = %d, prevObj = %p\n", obj->type, prevObj);
1500 objRefreshAreaDone = false;
1501 if ((obj->type < NB_OBJ_TYPES) && (draw_functions[obj->type] != NULL)) {
1502 if ((obj->type != SCREEN) && (obj->parent == NULL)) {
1503 LOG_WARN(OBJ_LOGGER, "object with type [%d] has not parent\n", obj->type);
1504 return;
1505 }
1506 draw_function_t func = (draw_function_t) PIC(draw_functions[obj->type]);
1507 func(obj, prevObj, computePosition);
1508 }
1509 else {
1510 LOG_WARN(OBJ_LOGGER, "Not existing object type [%d]\n", obj->type);
1511 return;
1512 }
1513
1514#ifdef HAVE_SERIALIZED_NBGL
1515 io_seph_ux_send_nbgl_serialized(NBGL_DRAW_OBJ, obj);
1516#endif
1517 if (!objRefreshAreaDone) {
1518 extendRefreshArea(&obj->area);
1519 }
1520}
1521
1531static void draw_obj_and_chidren(nbgl_obj_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1532{
1533 uint8_t i = 0;
1534 LOG_DEBUG(OBJ_LOGGER, "draw_obj_and_chidren(): obj = %p\n", obj);
1535 // draw the object itself
1536 draw_object(obj, prevObj, computePosition);
1537
1538 if ((obj->type == SCREEN) || (obj->type == CONTAINER)) {
1539 nbgl_container_t *container = (nbgl_container_t *) obj;
1540 nbgl_obj_t *prev = NULL;
1541 LOG_DEBUG(
1542 OBJ_LOGGER, "draw_obj_and_chidren(): container->children = %p\n", container->children);
1543 // draw the children, if any
1544 if (container->children != NULL) {
1545 for (i = 0; i < container->nbChildren; i++) {
1546 nbgl_obj_t *current = container->children[i];
1547 if (current != NULL) {
1548 current->parent = (nbgl_obj_t *) container;
1549 draw_obj_and_chidren(current, prev, true);
1550 if (current->alignTo == NULL) {
1551 prev = current;
1552 }
1553 }
1554 }
1555 }
1556 }
1557}
1558
1565static void extendRefreshArea(nbgl_area_t *area)
1566{
1567 int16_t x1, y1; // bottom right corner
1568 x1 = refreshArea.x0 + refreshArea.width;
1569 y1 = refreshArea.y0 + refreshArea.height;
1570
1571 // if obj top-left is on left of current top-left corner, move top-left corner
1572 if (area->x0 < refreshArea.x0) {
1573 // No negative coordinates
1574 refreshArea.x0 = MAX(0, area->x0);
1575 }
1576 // if obj bottom-right is on right of current bottom-right corner, move bottom-right corner
1577 if (((area->x0 + area->width) > x1) || (refreshArea.width == 0)) {
1578 // Not beyond width
1579 x1 = MIN(SCREEN_WIDTH, area->x0 + area->width);
1580 }
1581 // if obj top-left is on top of current top-left corner, move top-left corner
1582 if (area->y0 < refreshArea.y0) {
1583 // No negative coordinates and align on lower multiple of alignment
1584 refreshArea.y0 = MAX(0, area->y0) & ~(VERTICAL_ALIGNMENT - 1);
1585 }
1586 // if obj bottom-right is on bottom of current bottom-right corner, move bottom-right corner
1587 if (((area->y0 + area->height) > y1) || (refreshArea.height == 0)) {
1588 // Not beyond height
1589 y1 = MIN(SCREEN_HEIGHT, area->y0 + area->height);
1590 // align on upper multiple of alignment
1591 y1 = (y1 + (VERTICAL_ALIGNMENT - 1)) & ~(VERTICAL_ALIGNMENT - 1);
1592 }
1593
1594 // sanity check
1595 if (x1 > SCREEN_WIDTH) {
1597 "extendRefreshArea: Impossible area x0 = %d width %d\n",
1598 refreshArea.x0,
1599 refreshArea.width);
1600 }
1601 if (y1 > SCREEN_HEIGHT) {
1602#ifdef HAVE_SE_TOUCH
1604 "extendRefreshArea: Impossible area y0 = %d height %d\n",
1605 refreshArea.y0,
1606 refreshArea.height);
1607#else // HAVE_SE_TOUCH
1608 y1 = SCREEN_HEIGHT;
1609#endif // HAVE_SE_TOUCH
1610 }
1611 // recompute width and height
1612 refreshArea.width = x1 - refreshArea.x0;
1613 refreshArea.height = y1 - refreshArea.y0;
1614
1615 // revaluate area bpp
1616 if (area->bpp > refreshArea.bpp) {
1617 refreshArea.bpp = area->bpp;
1618 }
1619}
1620
1627{
1628 bool computePosition = false;
1629 bool fromApp = false;
1630
1631 LOG_DEBUG(OBJ_LOGGER, "nbgl_objDraw(): obj = %p\n", obj);
1632 // check whether it's necessary to compute position, and if this object belongs to
1633 // an Application screen
1634 if (obj->type == SCREEN) {
1635 // always compute position for screen and all sub-objects
1636 computePosition = true;
1637 fromApp = !(((nbgl_screen_t *) obj)->isUxScreen);
1638 }
1639 else {
1640 nbgl_obj_t *parent = obj;
1641 // search screen in parenthood
1642 while (parent->parent != NULL) {
1643 parent = parent->parent;
1644 }
1645 if (parent->type == SCREEN) {
1646 fromApp = !(((nbgl_screen_t *) parent)->isUxScreen);
1647 }
1648 else {
1649 // should never happen
1650 fromApp = false;
1651 }
1652 }
1653 // forbid redrawing App screens by UX or vice versa
1654 if ((os_sched_current_task() == TASK_BOLOS_UX) == fromApp) {
1655 return;
1656 }
1657 // actually draw the object and its children, if it is allowed
1658 if (objDrawingDisabled && fromApp) {
1659 return;
1660 }
1661 draw_obj_and_chidren(obj, NULL, computePosition);
1662}
1663
1673
1680{
1681 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1682 return;
1683 }
1684
1687 "nbgl_refreshSpecial(), x0,y0 = [%d, %d], w,h = [%d, %d]\n",
1688 refreshArea.x0,
1689 refreshArea.y0,
1690 refreshArea.width,
1691 refreshArea.height);
1693}
1694
1696{
1697 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1698 return;
1699 }
1700
1701 nbgl_frontRefreshArea(&refreshArea, mode, post_refresh);
1703 "nbgl_refreshSpecialNoPoff(), x0,y0 = [%d, %d], w,h = [%d, %d]\n",
1704 refreshArea.x0,
1705 refreshArea.y0,
1706 refreshArea.width,
1707 refreshArea.height);
1709}
1710
1716{
1717 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1718 return false;
1719 }
1720 return true;
1721}
1722
1728{
1729#ifdef HAVE_SERIALIZED_NBGL
1730 io_seph_ux_send_nbgl_serialized(NBGL_REFRESH_AREA, (nbgl_obj_t *) &refreshArea);
1731#endif
1732 refreshArea.x0 = SCREEN_WIDTH - 1;
1733 refreshArea.width = 0;
1734 refreshArea.y0 = SCREEN_HEIGHT - 1;
1735 refreshArea.height = 0;
1736 refreshArea.bpp = NBGL_BPP_2;
1737}
1738
1745{
1746 // init area to the smallest size
1748 objDrawingDisabled = false;
1749#ifdef HAVE_SE_TOUCH
1750 nbgl_touchInit(false);
1751#endif
1752}
1753
1759void nbgl_objAllowDrawing(bool enable)
1760{
1761 objDrawingDisabled = !enable;
1762}
1763
1770{
1771 return ramBuffer;
1772}
1773
1780{
1781 nbgl_obj_t *parent = obj;
1782 // search screen in parenthood
1783 while (parent->parent != NULL) {
1784 parent = parent->parent;
1785 }
1786 if (parent->type == SCREEN) {
1787 return (((nbgl_screen_t *) parent)->isUxScreen);
1788 }
1789 else {
1790 // should never happen
1791 return true;
1792 }
1793}
debug traces management
#define LOG_WARN(__logger,...)
Definition nbgl_debug.h:87
#define LOG_DEBUG(__logger,...)
Definition nbgl_debug.h:86
#define LOG_FATAL(__logger,...)
Definition nbgl_debug.h:88
@ OBJ_LOGGER
Definition nbgl_debug.h:30
Middle Level API of the new BOLOS Graphical Library.
void nbgl_drawIcon(nbgl_area_t *area, nbgl_transformation_t transformation, nbgl_color_map_t color_map, const nbgl_icon_details_t *icon)
Helper function to render an icon directly from its nbgl_icon_details_t structure.
Definition nbgl_draw.c:531
nbgl_font_id_e nbgl_drawText(const nbgl_area_t *area, const char *text, uint16_t textLen, nbgl_font_id_e fontId, color_t fontColor)
This function draws the given single-line text, with the given parameters.
Definition nbgl_draw.c:580
void nbgl_drawRoundedBorderedRect(const nbgl_area_t *area, nbgl_radius_t radius, uint8_t stroke, color_t innerColor, color_t borderColor)
This functions draws a rounded corners rectangle with a border, with the given parameters.
Definition nbgl_draw.c:368
void nbgl_drawQrCode(const nbgl_area_t *area, nbgl_qrcode_version_t version, const char *text, color_t backgroundColor)
Draws the given text into a V10 QR code (QR code version is fixed using qrcodegen_VERSION_MIN/qrcodeg...
Definition nbgl_draw.c:853
void nbgl_drawRoundedRect(const nbgl_area_t *area, nbgl_radius_t radius, color_t innerColor)
This functions draws a rounded corners rectangle (without border), with the given parameters.
Definition nbgl_draw.c:269
void nbgl_getTextMaxLenAndWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t *len, uint16_t *width, bool wrapping)
compute the max width of the first line of the given text fitting in maxWidth
Definition nbgl_fonts.c:476
uint16_t nbgl_getSingleLineTextWidth(nbgl_font_id_e fontId, const char *text)
return the max width in pixels of the given text until the first or \0 is encountered
Definition nbgl_fonts.c:328
nbgl_font_id_e
Definition nbgl_fonts.h:143
@ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp
Definition nbgl_fonts.h:150
bool nbgl_getTextMaxLenAndWidthFromEnd(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t *len, uint16_t *width)
compute the len and width of the given text fitting in the maxWidth, starting from end of text
Definition nbgl_fonts.c:675
uint8_t nbgl_getFontHeight(nbgl_font_id_e fontId)
return the height in pixels of the font with the given font ID
Definition nbgl_fonts.c:392
uint16_t nbgl_getTextWidth(nbgl_font_id_e fontId, const char *text)
return the max width in pixels of the given text (can be multiline)
Definition nbgl_fonts.c:354
uint16_t nbgl_getTextLength(const char *text)
return the number of bytes of the given text, excluding final ' ' or '\0'
Definition nbgl_fonts.c:448
uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
compute the number of lines of the given text fitting in the given maxWidth
Definition nbgl_fonts.c:725
uint8_t nbgl_getFontLineHeight(nbgl_font_id_e fontId)
return the height in pixels of the line of font with the given font ID
Definition nbgl_fonts.c:404
uint16_t nbgl_getSingleLineTextWidthInLen(nbgl_font_id_e fontId, const char *text, uint16_t maxLen)
return the max width in pixels of the given text until the first or \0 is encountered,...
Definition nbgl_fonts.c:342
Font screen low-Level driver API, to draw elementary forms.
void nbgl_frontDrawLine(const nbgl_area_t *area, uint8_t dotStartIdx, color_t lineColor)
void nbgl_frontControlAreaMasking(uint8_t mask_index, nbgl_area_t *masked_area_or_null)
void nbgl_frontDrawImage(const nbgl_area_t *area, const uint8_t *buffer, nbgl_transformation_t transformation, nbgl_color_map_t colorMap)
void nbgl_frontDrawImageFile(const nbgl_area_t *area, const uint8_t *buffer, nbgl_color_map_t colorMap, const uint8_t *uzlib_chunk_buffer)
void nbgl_frontRefreshArea(const nbgl_area_t *area, nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
void nbgl_frontDrawRect(const nbgl_area_t *area)
#define ICON_TEXT_SPACE
#define NB_MAX_LETTERS
Definition nbgl_obj.c:35
void nbgl_objDraw(nbgl_obj_t *obj)
This function draws or redraws the given object and its children (recursive version)
Definition nbgl_obj.c:1626
void nbgl_refresh(void)
This functions refreshes the actual screen on display with what has changed since the last refresh.
Definition nbgl_obj.c:1669
void nbgl_refreshReset(void)
This functions resets all changes since the last refresh.
Definition nbgl_obj.c:1727
void nbgl_objAllowDrawing(bool enable)
This functions enables or disables drawing/refresh for all further calls.
Definition nbgl_obj.c:1759
void(* draw_function_t)(nbgl_obj_t *obj, nbgl_obj_t *prevObj, bool computePosition)
Definition nbgl_obj.c:60
void nbgl_refreshSpecial(nbgl_refresh_mode_t mode)
This functions refreshes the actual screen on display with what has changed since the last refresh,...
Definition nbgl_obj.c:1679
bool nbgl_objIsUx(nbgl_obj_t *obj)
This function returns true if the object belongs to a UxScreen.
Definition nbgl_obj.c:1779
void nbgl_refreshSpecialWithPostRefresh(nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
Definition nbgl_obj.c:1695
uint8_t * nbgl_objGetRAMBuffer(void)
This function is used to get the all purpose RAM buffer.
Definition nbgl_obj.c:1769
uint8_t ramBuffer[GZLIB_UNCOMPRESSED_CHUNK]
Definition nbgl_obj.c:146
bool nbgl_refreshIsNeeded(void)
This functions returns true if there is something to refresh.
Definition nbgl_obj.c:1715
void nbgl_objInit(void)
This functions inits all internal of nbgl objects layer.
Definition nbgl_obj.c:1744
API to draw all basic graphic objects.
struct PACKED__ nbgl_line_s nbgl_line_t
struct to represent a vertical or horizontal line
struct PACKED__ nbgl_navigation_bar_s nbgl_page_indicator_t
struct to represent a navigation bar (PAGE_INDICATOR type) There can be up to 5 page indicators,...
struct PACKED__ nbgl_radio_s nbgl_radio_t
struct to represent a radio button (RADIO_BUTTON type)
#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)
struct PACKED__ nbgl_progress_bar_s nbgl_progress_bar_t
struct to represent a progress bar (PROGRESS_BAR type)
struct PACKED__ nbgl_keypad_s nbgl_keypad_t
struct to represent a keypad (KEYPAD type)
struct PACKED__ nbgl_mask_control_s nbgl_mask_control_t
struct PACKED__ nbgl_text_entry_s nbgl_text_entry_t
struct to represent a text entry area (TEXT_ENTRY type)
struct PACKED__ nbgl_keyboard_s nbgl_keyboard_t
struct to represent a keyboard (KEYBOARD type)
struct PACKED__ nbgl_image_s nbgl_image_t
struct to represent an image (IMAGE type)
struct PACKED__ nbgl_button_s nbgl_button_t
struct to represent a button (BUTTON type) that can contain a text and/or an icon
void nbgl_objDrawKeyboard(nbgl_keyboard_t *kbd)
This function draws a keyboard object.
#define NB_MAX_PAGES_WITH_DASHES
Definition nbgl_obj.h:261
void nbgl_objDrawKeypad(nbgl_keypad_t *kbd)
This function draws a keypad object.
struct PACKED__ nbgl_container_s nbgl_container_t
struct to represent a container (CONTAINER type)
@ PROGRESSIVE_INDICATOR
all dashes before active page are black
Definition nbgl_obj.h:490
#define BUTTON_STROKE
Definition nbgl_obj.h:283
struct PACKED__ nbgl_switch_s nbgl_switch_t
struct to represent a switch (size is fixed) (SWITCH type)
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
struct PACKED__ nbgl_spinner_s nbgl_spinner_t
struct to represent a "spinner", represented by the Ledger corners, in gray, with one of the corners ...
struct PACKED__ nbgl_image_file_s nbgl_image_file_t
struct to represent an image file object (IMAGE_FILE type) The source of the data is an image file wi...
struct PACKED__ nbgl_qrcode_s nbgl_qrcode_t
struct to represent a QR code (QR_CODE type), whose size is fixed
API to manage screens.
struct PACKED__ nbgl_screen_s nbgl_screen_t
struct to represent a screen (SCREEN type)
@ NBGL_DRAW_OBJ
@ NBGL_REFRESH_AREA
void nbgl_touchInit(bool fromUx)
Function to initialize the touch context.
Definition nbgl_touch.c:273
color_t
Definition nbgl_types.h:140
@ WHITE
Definition nbgl_types.h:144
@ DARK_GRAY
Definition nbgl_types.h:142
@ LIGHT_GRAY
Definition nbgl_types.h:143
@ BLACK
Definition nbgl_types.h:141
@ OFF_STATE
Definition nbgl_types.h:200
nbgl_post_refresh_t
Post refresh modes.
Definition nbgl_types.h:352
@ POST_REFRESH_FORCE_POWER_OFF
Force screen power off after refresh.
Definition nbgl_types.h:353
#define VERTICAL_MIRROR
Definition nbgl_types.h:97
uint8_t nbgl_color_map_t
Represents the color_map to be used for 2BPP image, or the foreground color for 1BPP image.
Definition nbgl_types.h:390
@ RADIUS_0_PIXELS
no radius (square angle)
Definition nbgl_types.h:376
@ VERTICAL
from top to bottom
Definition nbgl_types.h:209
#define MIN(x, y)
Definition nbgl_types.h:118
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
#define GZLIB_UNCOMPRESSED_CHUNK
size of gzlib uncompression buffer in bytes
Definition nbgl_types.h:305
@ TOP_MIDDLE
Definition nbgl_types.h:182
@ CENTER
Definition nbgl_types.h:185
@ BOTTOM_RIGHT
Definition nbgl_types.h:189
@ TOP_LEFT
Definition nbgl_types.h:181
@ NO_ALIGNMENT
used when parent container layout is used
Definition nbgl_types.h:180
@ BOTTOM_LEFT
Definition nbgl_types.h:187
@ LEFT_TOP
on outside left
Definition nbgl_types.h:190
@ LEFT_BOTTOM
on outside left
Definition nbgl_types.h:191
@ MID_RIGHT
Definition nbgl_types.h:186
@ RIGHT_TOP
on outside right
Definition nbgl_types.h:192
@ TOP_RIGHT
Definition nbgl_types.h:183
@ MID_LEFT
Definition nbgl_types.h:184
@ BOTTOM_MIDDLE
Definition nbgl_types.h:188
@ RIGHT_BOTTOM
on outside right
Definition nbgl_types.h:193
@ KEYPAD
Keypad.
Definition nbgl_types.h:167
@ IMAGE
Bitmap (y and height must be multiple of 4 on Stax)
Definition nbgl_types.h:157
@ IMAGE_FILE
Image file (with Ledger compression)
Definition nbgl_types.h:169
@ TEXT_ENTRY
area for entered text, only for Nanos
Definition nbgl_types.h:170
@ NB_OBJ_TYPES
Definition nbgl_types.h:172
@ SWITCH
Switch to turn on/off something.
Definition nbgl_types.h:161
@ RADIO_BUTTON
Indicator to inform whether something is on or off.
Definition nbgl_types.h:164
@ SPINNER
Spinner.
Definition nbgl_types.h:168
@ BUTTON
Rounded rectangle button with icon and/or text.
Definition nbgl_types.h:160
@ PROGRESS_BAR
horizontal bar to indicate progression of something (between 0% and 100%)
Definition nbgl_types.h:163
@ QR_CODE
QR Code.
Definition nbgl_types.h:165
@ PAGE_INDICATOR
horizontal bar to indicate position within pages
Definition nbgl_types.h:162
@ LINE
Vertical or Horizontal line.
Definition nbgl_types.h:158
@ KEYBOARD
Keyboard.
Definition nbgl_types.h:166
@ MASK_CONTROL
OS-specific object to enable/disable masked area.
Definition nbgl_types.h:171
@ CONTAINER
Empty container.
Definition nbgl_types.h:156
@ TEXT_AREA
Area to contain text line(s)
Definition nbgl_types.h:159
@ SCREEN
Main screen.
Definition nbgl_types.h:155
#define MAX(x, y)
Definition nbgl_types.h:121
#define NO_TRANSFORMATION
Definition nbgl_types.h:91
@ NBGL_BPP_1
1 bit per pixel
Definition nbgl_types.h:284
@ NBGL_BPP_2
2 bits per pixel
Definition nbgl_types.h:285
struct PACKED__ nbgl_area_s nbgl_area_t
Represents a rectangle area of the screen.
nbgl_refresh_mode_t
different modes of refresh for nbgl_refreshSpecial()
Definition nbgl_types.h:326
@ FULL_COLOR_CLEAN_REFRESH
to be used for lock screen display (cleaner but longer refresh)
Definition nbgl_types.h:329