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) {
358#ifdef BUILD_SCREENSHOTS
359 obj->area.width = SCREEN_WIDTH - obj->area.x0;
360 // Be sure the area is not empty
361 if (!obj->area.width) {
362 obj->area.width = 1;
363 obj->area.x0 -= 1;
364 }
365#else // BUILD_SCREENSHOTS
367 "compute_position(), forbidden width, obj->type = %d, x0=%d, width=%d\n",
368 obj->type,
369 obj->area.x0,
370 obj->area.width);
371#endif // BUILD_SCREENSHOTS
372 }
373#ifdef HAVE_SE_TOUCH
374 if ((obj->area.y0 + obj->area.height) > SCREEN_HEIGHT) {
375#ifdef BUILD_SCREENSHOTS
376 obj->area.height = SCREEN_HEIGHT - obj->area.y0;
377 // Be sure the area is not empty
378 if (!obj->area.height) {
379 obj->area.height = 1;
380 obj->area.y0 -= 1;
381 }
382#else // BUILD_SCREENSHOTS
384 "compute_position(), forbidden height, obj->type = %d, y0=%d, height=%d\n",
385 obj->type,
386 obj->area.y0,
387 obj->area.height);
388#endif // BUILD_SCREENSHOTS
389 }
390#endif // HAVE_SE_TOUCH
391}
392
393static void draw_screen(nbgl_container_t *obj, nbgl_obj_t *prevObj, bool computePosition)
394{
395 nbgl_area_t rectArea;
396
397 UNUSED(prevObj);
398 UNUSED(computePosition);
399
400 rectArea.backgroundColor = obj->obj.area.backgroundColor;
401 rectArea.x0 = obj->obj.area.x0;
402 rectArea.y0 = obj->obj.area.y0;
403 rectArea.width = obj->obj.area.width;
404 rectArea.height = obj->obj.area.height;
405 nbgl_frontDrawRect(&rectArea);
406}
407
408static void draw_container(nbgl_container_t *obj, nbgl_obj_t *prevObj, bool computePosition)
409{
410 if (computePosition) {
411 compute_position((nbgl_obj_t *) obj, prevObj);
412 }
414 "draw_container(), x0 = %d, y0 = %d, width = %d, height = %d\n",
415 obj->obj.area.x0,
416 obj->obj.area.y0,
417 obj->obj.area.width,
418 obj->obj.area.height);
419 // inherit background from parent
420 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
421 if (obj->forceClean) {
423 }
424}
425
426#ifdef HAVE_SE_TOUCH
435static void draw_button(nbgl_button_t *obj, nbgl_obj_t *prevObj, bool computePosition)
436{
437 uint16_t textWidth = 0;
438 const char *text = NULL;
439#define ICON_TEXT_SPACE 12
440
441 if (computePosition) {
442 compute_position((nbgl_obj_t *) obj, prevObj);
443 }
445 "draw_button(), x0 = %d, y0 = %d, width = %d, height = %d\n",
446 obj->obj.area.x0,
447 obj->obj.area.y0,
448 obj->obj.area.width,
449 obj->obj.area.height);
450
451 // inherit background from parent
452 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
453 // draw the rounded corner rectangle if necessary
454 if ((obj->innerColor == obj->borderColor)
455 && (obj->innerColor != obj->obj.area.backgroundColor)) {
456 nbgl_drawRoundedRect((nbgl_area_t *) obj, obj->radius, obj->innerColor);
457 }
458 else {
459#ifdef TARGET_APEX
460 // on Apex, top-right button (54x56) is drawned as an icon
461 if ((obj->radius == RADIUS_28_PIXELS) && (obj->obj.area.width == BUTTON_WIDTH)) {
462 nbgl_drawIcon(&obj->obj.area, NO_TRANSFORMATION, BLACK, &C_dashed_button_56px);
463 }
464 else {
466 (nbgl_area_t *) obj, obj->radius, BUTTON_STROKE, obj->innerColor, obj->borderColor);
467 }
468#else // TARGET_APEX
470 (nbgl_area_t *) obj, obj->radius, BUTTON_STROKE, obj->innerColor, obj->borderColor);
471#endif // TARGET_APEX
472 }
473 // get the text of the button from the callback if not NULL
474 if (obj->onDrawCallback != NULL) {
475 obj->text = obj->onDrawCallback(obj->token);
476 }
477 text = obj->text;
478 // draw the text (right of the icon, with 8 pixels between them)
479 if (text != NULL) {
480 nbgl_area_t rectArea;
481 // Compute available with & height to display the text
482 rectArea.x0 = obj->obj.area.x0;
483 rectArea.y0 = obj->obj.area.y0;
484 // Only one line of text
485 rectArea.height = nbgl_getFontHeight(obj->fontId);
486 rectArea.y0 += (obj->obj.area.height - rectArea.height) / 2;
487 rectArea.width = obj->obj.area.width;
488 if (obj->icon != NULL) {
489 rectArea.x0 += obj->icon->width + ICON_TEXT_SPACE;
490 rectArea.width -= obj->icon->width + ICON_TEXT_SPACE;
491 }
492 // Compute the width & number of characters displayed on first line
493 uint16_t textLen;
494 nbgl_getTextMaxLenAndWidth(obj->fontId, text, rectArea.width, &textLen, &textWidth, true);
495
496#ifdef BUILD_SCREENSHOTS
497 store_string_infos(text, obj->fontId, &rectArea, true, 1, 1, false);
498#endif // BUILD_SCREENSHOTS
499
500 // Center the text, horizontally
501 if (textWidth < rectArea.width) {
502 rectArea.x0 += (rectArea.width - textWidth) / 2;
503 }
504 LOG_DEBUG(OBJ_LOGGER, "draw_button(), text = %s\n", text);
505 rectArea.backgroundColor = obj->innerColor;
506 nbgl_drawText(&rectArea, text, textLen, obj->fontId, obj->foregroundColor);
507 }
508 // draw the icon, if any
509 if (obj->icon != NULL) {
510 uint16_t iconX0, iconY0;
511 nbgl_area_t rectArea;
512
513 if (text != NULL) {
514 iconX0 = obj->obj.area.x0
515 + (obj->obj.area.width - (textWidth + obj->icon->width + ICON_TEXT_SPACE)) / 2;
516 }
517 else {
518 iconX0 = obj->obj.area.x0 + (obj->obj.area.width - obj->icon->width) / 2;
519 }
521 "draw_button(), obj->obj.area.height = %d, obj->iconHeight = %d\n",
522 obj->obj.area.height,
523 obj->icon->height);
524 iconY0 = obj->obj.area.y0 + (obj->obj.area.height - obj->icon->height) / 2;
525
526 rectArea.backgroundColor = obj->innerColor;
527 rectArea.x0 = iconX0;
528 rectArea.y0 = iconY0;
529 rectArea.width = obj->icon->width;
530 rectArea.height = obj->icon->height;
531 rectArea.bpp = obj->icon->bpp;
532
533 nbgl_drawIcon(&rectArea, NO_TRANSFORMATION, obj->foregroundColor, obj->icon);
534 }
535}
536
545static void draw_line(nbgl_line_t *obj, nbgl_obj_t *prevObj, bool computePosition)
546{
547 nbgl_area_t rectArea;
548 if (computePosition) {
549 compute_position((nbgl_obj_t *) obj, prevObj);
550 }
551 LOG_DEBUG(OBJ_LOGGER, "draw_line(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
552 // inherit background from parent
553 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
555 "draw_line(), backgroundColor = %d, lineColor = %d\n",
556 obj->obj.area.backgroundColor,
557 obj->lineColor);
558 rectArea.x0 = obj->obj.area.x0;
559 rectArea.y0 = obj->obj.area.y0;
560 rectArea.backgroundColor = obj->obj.area.backgroundColor;
561 if (obj->direction == VERTICAL) {
562 rectArea.width = obj->obj.area.width = obj->thickness;
563 rectArea.height = obj->obj.area.height;
564 nbgl_frontDrawLine(&rectArea, 0, obj->lineColor);
565 }
566 else {
567 rectArea.width = obj->obj.area.width;
568 rectArea.height = obj->obj.area.height = obj->thickness;
569 nbgl_frontDrawLine(&rectArea, 0, obj->lineColor);
570 }
571}
572#else // HAVE_SE_TOUCH
581static void draw_button(nbgl_button_t *obj, nbgl_obj_t *prevObj, bool computePosition)
582{
583 uint16_t textWidth = 0;
584 const char *text = NULL;
585#define ICON_TEXT_SPACE 2
586
587 if (computePosition) {
588 compute_position((nbgl_obj_t *) obj, prevObj);
589 }
591 "draw_button(), x0 = %d, y0 = %d, width = %d, height = %d\n",
592 obj->obj.area.x0,
593 obj->obj.area.y0,
594 obj->obj.area.width,
595 obj->obj.area.height);
596
597 // inherit background from parent
598 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
599 // draw the rounded corner rectangle if necessary
600 nbgl_drawRoundedRect((nbgl_area_t *) obj, obj->radius, obj->innerColor);
601
602 // get the text of the button from the callback if not NULL
603 if (obj->onDrawCallback != NULL) {
604 obj->text = obj->onDrawCallback(obj->token);
605 }
606 text = obj->text;
607 // draw the text (right of the icon, with ICON_TEXT_SPACE pixels between them)
608 if (text != NULL) {
609 nbgl_area_t rectArea;
610 // Compute available with & height to display the text
611 rectArea.x0 = obj->obj.area.x0;
612 rectArea.y0 = obj->obj.area.y0;
613 // Only one line of text is allowed
614 rectArea.height = nbgl_getFontHeight(obj->fontId);
615 rectArea.y0 += (obj->obj.area.height - rectArea.height) / 2;
616 rectArea.width = obj->obj.area.width;
617 if (obj->icon != NULL) {
618 rectArea.x0 += obj->icon->width + ICON_TEXT_SPACE;
619 rectArea.width -= obj->icon->width + ICON_TEXT_SPACE;
620 }
621 // Compute the width & number of characters displayed on first line
622 uint16_t textLen;
623 nbgl_getTextMaxLenAndWidth(obj->fontId, text, rectArea.width, &textLen, &textWidth, true);
624
625 // Center the text, horizontally
626 if (textWidth < rectArea.width) {
627 rectArea.x0 += (rectArea.width - textWidth) / 2;
628 }
629 LOG_DEBUG(OBJ_LOGGER, "draw_button(), text = %s\n", text);
630 rectArea.backgroundColor = obj->innerColor;
631 nbgl_drawText(&rectArea, text, textLen, obj->fontId, obj->foregroundColor);
632 }
633 // draw the icon, if any
634 if (obj->icon != NULL) {
635 uint16_t iconX0, iconY0;
636 nbgl_area_t rectArea;
637
638 if (text != NULL) {
639 iconX0 = obj->obj.area.x0
640 + (obj->obj.area.width - (textWidth + obj->icon->width + ICON_TEXT_SPACE)) / 2;
641 }
642 else {
643 iconX0 = obj->obj.area.x0 + (obj->obj.area.width - obj->icon->width) / 2;
644 }
646 "draw_button(), obj->obj.area.height = %d, obj->iconHeight = %d\n",
647 obj->obj.area.height,
648 obj->icon->height);
649 iconY0 = obj->obj.area.y0 + (obj->obj.area.height - obj->icon->height) / 2;
650
651 rectArea.backgroundColor = obj->innerColor;
652 rectArea.x0 = iconX0;
653 rectArea.y0 = iconY0;
654 rectArea.width = obj->icon->width;
655 rectArea.height = obj->icon->height;
656 rectArea.bpp = obj->icon->bpp;
657
658 nbgl_drawIcon(&rectArea, NO_TRANSFORMATION, obj->foregroundColor, obj->icon);
659 }
660}
661#endif // HAVE_SE_TOUCH
662
663static void draw_image(nbgl_image_t *obj, nbgl_obj_t *prevObj, bool computePosition)
664{
665 const nbgl_icon_details_t *iconDetails;
666 nbgl_color_map_t colorMap;
667
668 // if buffer is NULL, let's try to call onDrawCallback, if not NULL, to get it
669 if (obj->buffer == NULL) {
670 if (obj->onDrawCallback != NULL) {
671 iconDetails = obj->onDrawCallback(obj->token);
672 }
673 else {
674 return;
675 }
676 }
677 else {
678 iconDetails = obj->buffer;
679 }
680 if (iconDetails == NULL) {
681 return;
682 }
683
684 // use dimension and bpp from the icon details
685 obj->obj.area.width = iconDetails->width;
686 obj->obj.area.height = iconDetails->height;
687 obj->obj.area.bpp = iconDetails->bpp;
688 if (computePosition) {
689 compute_position((nbgl_obj_t *) obj, prevObj);
690 }
691 LOG_DEBUG(OBJ_LOGGER, "draw_image(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
692 // inherit background from parent
693 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
694 if (obj->obj.area.bpp == NBGL_BPP_1) {
695 colorMap = obj->foregroundColor;
696 }
697 else if (obj->obj.area.bpp == NBGL_BPP_2) {
698 colorMap = ((WHITE << 6) | (LIGHT_GRAY << 4) | (DARK_GRAY << 2) | BLACK);
699 }
700 else {
701 colorMap = obj->foregroundColor;
702 }
703
704 nbgl_drawIcon((nbgl_area_t *) obj, obj->transformation, colorMap, iconDetails);
705}
706
707#ifdef HAVE_SE_TOUCH
708static void draw_switch(nbgl_switch_t *obj, nbgl_obj_t *prevObj, bool computePosition)
709{
710 nbgl_area_t rectArea;
711
712 // force dimensions
713 obj->obj.area.width = SWITCH_ICON.width;
714 obj->obj.area.height = SWITCH_ICON.height;
715 if (computePosition) {
716 compute_position((nbgl_obj_t *) obj, prevObj);
717 }
718 LOG_DEBUG(OBJ_LOGGER, "draw_switch(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
719
720 // inherit background from parent
721 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
722
723 rectArea.x0 = obj->obj.area.x0;
724 rectArea.y0 = obj->obj.area.y0;
725 rectArea.width = obj->obj.area.width;
726 rectArea.height = obj->obj.area.height;
727 rectArea.backgroundColor = obj->obj.area.backgroundColor;
728 rectArea.bpp = NBGL_BPP_1;
729 if (obj->state == OFF_STATE) {
730#if NB_COLOR_BITS == 1
731 nbgl_drawIcon(&rectArea, NO_TRANSFORMATION, obj->onColor, &C_switch_off_24px);
732#else
733 nbgl_frontDrawImage(&rectArea, SWITCH_ICON.bitmap, NO_TRANSFORMATION, obj->offColor);
734#endif
735 }
736 else {
737#if NB_COLOR_BITS == 1
738 nbgl_drawIcon(&rectArea, NO_TRANSFORMATION, obj->onColor, &C_switch_on_24px);
739#else
740 nbgl_frontDrawImage(&rectArea, SWITCH_ICON.bitmap, VERTICAL_MIRROR, obj->onColor);
741#endif
742 }
743}
744
745static void draw_radioButton(nbgl_radio_t *obj, nbgl_obj_t *prevObj, bool computePosition)
746{
747 nbgl_area_t rectArea;
748 const nbgl_icon_details_t *icon;
749 nbgl_color_map_t color_map;
750
751 // force dimensions
752 obj->obj.area.width = RADIO_WIDTH;
753 obj->obj.area.height = RADIO_HEIGHT;
754 if (computePosition) {
755 compute_position((nbgl_obj_t *) obj, prevObj);
756 }
758 "draw_radioButton(), x0 = %d, y0 = %d, state = %d\n",
759 obj->obj.area.x0,
760 obj->obj.area.y0,
761 obj->state);
762
763 // inherit background from parent
764 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
765
766 if (obj->state == OFF_STATE) {
767 icon = &RADIO_OFF_ICON;
768#if NB_COLOR_BITS == 1
769 color_map = obj->activeColor;
770#else
771 color_map = obj->borderColor;
772#endif
773 }
774 else {
775 icon = &RADIO_ON_ICON;
776 color_map = obj->activeColor;
777 }
778 rectArea.x0 = obj->obj.area.x0;
779 rectArea.y0 = obj->obj.area.y0;
780 rectArea.width = obj->obj.area.width;
781 rectArea.height = obj->obj.area.height;
782 rectArea.backgroundColor = obj->obj.area.backgroundColor;
783 rectArea.bpp = icon->bpp;
784 nbgl_drawIcon(&rectArea, NO_TRANSFORMATION, color_map, icon);
785}
786#endif // HAVE_SE_TOUCH
787
795static void draw_progressBar(nbgl_progress_bar_t *obj, nbgl_obj_t *prevObj, bool computePosition)
796{
797#ifdef HAVE_SE_TOUCH
798
799 uint8_t stroke = PROGRESS_STROKE; // pixels for border
800 nbgl_area_t barArea;
801 uint16_t barWidth = ((obj->state * obj->obj.area.width)) / 100;
802
803 if (computePosition) {
804 compute_position((nbgl_obj_t *) obj, prevObj);
805 }
807 "draw_progressBar(), x0 = %d, y0 = %d, level = %d %%\n",
808 obj->obj.area.x0,
809 obj->obj.area.y0,
810 obj->state);
811 memcpy(&barArea, &obj->obj.area, sizeof(nbgl_area_t));
812
813 // inherit background from parent
814 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
815
816 if (obj->partialRedraw == false) {
817 // Case of progress bar full draw
818 if (obj->withBorder) {
821 stroke,
822 obj->obj.area.backgroundColor,
823 obj->foregroundColor);
824 }
825 else {
827 (nbgl_area_t *) obj, RADIUS_0_PIXELS, obj->obj.area.backgroundColor);
828 }
829 // also reset previous width to be sure to clean up everything
830 obj->previousWidth = 0;
831 if (obj->state == 0) {
832 goto end;
833 }
834 }
835 // Setup bar draw
836 int barDiffWith = barWidth - obj->previousWidth;
837 color_t barColor;
838
839 if (barDiffWith > 0) {
840 // Drawing "forward"
841 barArea.x0 = obj->obj.area.x0 + obj->previousWidth;
842 barArea.width = barDiffWith;
843 barColor = obj->foregroundColor;
844 }
845 else if (barDiffWith < 0) {
846 // Drawing "backward"
847 barArea.x0 = obj->obj.area.x0 + obj->previousWidth + barDiffWith;
848 barArea.width = -barDiffWith;
849 barColor = obj->obj.area.backgroundColor;
850 }
851
852 if (barDiffWith != 0) {
853 nbgl_drawRoundedRect((nbgl_area_t *) &barArea, RADIUS_0_PIXELS, barColor);
854 }
855
856 // reset partialRedraw to be sure that in case of full redraw of the screen we redraw the
857 // full bar
858 if (obj->partialRedraw == true) {
859 obj->partialRedraw = false;
860 }
861 obj->previousWidth = barWidth;
862
863end:
864 extendRefreshArea(&barArea);
865 objRefreshAreaDone = true;
866#else // HAVE_SE_TOUCH
867 uint8_t stroke = 1; // 1 pixels for border
868 uint16_t levelWidth;
869
870 if (computePosition) {
871 compute_position((nbgl_obj_t *) obj, prevObj);
872 }
874 "draw_progressBar(), x0 = %d, y0 = %d, level = %d %%\n",
875 obj->obj.area.x0,
876 obj->obj.area.y0,
877 obj->state);
878
879 // inherit background from parent
880 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
881
882 // draw external part if necessary
883 if (obj->withBorder) {
885 RADIUS_3_PIXELS,
886 stroke,
887 obj->obj.area.backgroundColor,
888 obj->foregroundColor);
889 }
890 else {
891 nbgl_drawRoundedRect((nbgl_area_t *) obj, RADIUS_3_PIXELS, obj->obj.area.backgroundColor);
892 }
893 // draw level
894 levelWidth = MIN((obj->obj.area.width - 2) * obj->state / 100, (obj->obj.area.width - 2));
895 if (levelWidth > 0) {
896 nbgl_area_t rectArea;
897 rectArea.width = levelWidth;
898 rectArea.height = obj->obj.area.height - 2;
899 rectArea.backgroundColor = obj->foregroundColor;
900 rectArea.bpp = NBGL_BPP_1;
901 rectArea.x0 = obj->obj.area.x0 + 1;
902 rectArea.y0 = obj->obj.area.y0 + 1;
903
904 nbgl_frontDrawRect(&rectArea);
905 }
906#endif // HAVE_SE_TOUCH
907}
908
909#ifdef HAVE_SE_TOUCH
918static void draw_pageIndicator(nbgl_page_indicator_t *obj,
919 nbgl_obj_t *prevObj,
920 bool computePosition)
921{
922 nbgl_area_t rectArea;
923 uint16_t dashWidth;
924
925 // display nothing if less than two pages
926 if (obj->nbPages < 2) {
927 return;
928 }
929
930 if (obj->nbPages <= NB_MAX_PAGES_WITH_DASHES) {
931 int i;
932 // force height
933 obj->obj.area.height = 4;
934
935 if (computePosition) {
936 compute_position((nbgl_obj_t *) obj, prevObj);
937 }
939 "draw_pageIndicator(), x0 = %d, y0 = %d, page = %d/%d\n",
940 obj->obj.area.x0,
941 obj->obj.area.y0,
942 obj->activePage,
943 obj->nbPages);
944
945 // inherit background from parent
946 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
947
948 dashWidth = (obj->obj.area.width - ((obj->nbPages - 1) * INTER_DASHES)) / obj->nbPages;
949 rectArea.x0 = obj->obj.area.x0;
950 rectArea.y0 = obj->obj.area.y0;
951 rectArea.width = dashWidth;
952 rectArea.height = 4;
953 rectArea.backgroundColor = obj->obj.area.backgroundColor;
954 rectArea.bpp = NBGL_BPP_1;
955 // draw dashes
956 for (i = 0; i < obj->activePage; i++) {
958 &rectArea, 0, (obj->style == PROGRESSIVE_INDICATOR) ? BLACK : LIGHT_GRAY);
959 rectArea.x0 += dashWidth + INTER_DASHES;
960 }
961 nbgl_frontDrawLine(&rectArea, 0, BLACK);
962 rectArea.x0 += dashWidth + INTER_DASHES;
963 i++;
964
965 for (; i < obj->nbPages; i++) {
966 nbgl_frontDrawLine(&rectArea, 0, LIGHT_GRAY);
967 rectArea.x0 += dashWidth + INTER_DASHES;
968 }
969 }
970 else {
971 char navText[11]; // worst case is "ccc of nnn"
972
973 SPRINTF(navText, "%d of %d", obj->activePage + 1, obj->nbPages);
974 // force height
975 obj->obj.area.height = nbgl_getFontHeight(SMALL_REGULAR_FONT);
976 // the width must be at least 80
977 obj->obj.area.width = nbgl_getTextWidth(SMALL_REGULAR_FONT, navText);
978
979 if (computePosition) {
980 compute_position((nbgl_obj_t *) obj, prevObj);
981 }
983 "draw_pageIndicator(), x0 = %d, y0 = %d, page = %d/%d\n",
984 obj->obj.area.x0,
985 obj->obj.area.y0,
986 obj->activePage,
987 obj->nbPages);
988
989 // inherit background from parent
990 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
991
992 // draw active page
993 rectArea.x0 = obj->obj.area.x0;
994 rectArea.y0 = obj->obj.area.y0;
995 rectArea.width = obj->obj.area.width;
996 rectArea.height = obj->obj.area.height;
997 rectArea.backgroundColor = obj->obj.area.backgroundColor;
998 rectArea.bpp = NBGL_BPP_1;
999 nbgl_drawText(&rectArea, navText, strlen(navText), SMALL_REGULAR_FONT, LIGHT_TEXT_COLOR);
1000 }
1001}
1002#endif // HAVE_SE_TOUCH
1003
1012static void draw_textArea(nbgl_text_area_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1013{
1014 nbgl_area_t rectArea;
1015 uint16_t textWidth, fontHeight, lineHeight, textHeight, midHeight;
1016 uint8_t line, nbLines;
1017 const char *text;
1018 nbgl_font_id_e fontId = obj->fontId;
1019
1020 if (computePosition) {
1021 compute_position((nbgl_obj_t *) obj, prevObj);
1022 }
1023 // get the text of the button from the callback if not NULL
1024 if (obj->onDrawCallback != NULL) {
1025 obj->text = obj->onDrawCallback(obj->token);
1026 }
1027 text = obj->text;
1028 if (text == NULL) {
1029 return;
1030 }
1031
1032 LOG_DEBUG(
1033 OBJ_LOGGER,
1034 "draw_textArea(), wrapping = %d, x0 = %d, y0 = %d, width = %d, height = %d, text = %s\n",
1035 obj->wrapping,
1036 obj->obj.area.x0,
1037 obj->obj.area.y0,
1038 obj->obj.area.width,
1039 obj->obj.area.height,
1040 text);
1041
1042 // inherit background from parent
1043 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1044
1045 // draw background to make sure it's clean
1046#ifdef SCREEN_SIZE_NANO
1047 if (obj->style == INVERTED_COLORS) {
1048 obj->obj.area.backgroundColor = WHITE;
1049 rectArea.backgroundColor = BLACK;
1050 }
1051 else
1052#endif // SCREEN_SIZE_NANO
1053 {
1054 // inherit background from parent
1055 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1056 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1057 }
1058 rectArea.x0 = obj->obj.area.x0;
1059 rectArea.y0 = obj->obj.area.y0;
1060 rectArea.width = obj->obj.area.width;
1061 rectArea.height = obj->obj.area.height;
1062#ifdef SCREEN_SIZE_NANO
1063 if (obj->style == INVERTED_COLORS) {
1064 nbgl_drawRoundedRect(&rectArea, RADIUS_1_PIXEL, WHITE);
1065 }
1066 else
1067#endif // SCREEN_SIZE_NANO
1068 {
1069 nbgl_frontDrawRect(&rectArea);
1070 }
1071
1072 fontHeight = nbgl_getFontHeight(fontId);
1073 lineHeight = nbgl_getFontLineHeight(fontId);
1074 // special case of autoHideLongLine, when the text is too long for a line, draw '...' at the
1075 // beginning
1076 if (obj->autoHideLongLine == true) {
1077#ifdef BUILD_SCREENSHOTS
1078 nbgl_getTextNbLinesInWidth(fontId, text, obj->obj.area.width, obj->wrapping);
1079 store_string_infos(text,
1080 fontId,
1081 &obj->obj.area,
1082 obj->wrapping,
1083 last_nb_lines,
1084 last_nb_pages,
1085 last_bold_state);
1086#endif // BUILD_SCREENSHOTS
1087 textWidth = nbgl_getSingleLineTextWidth(fontId, text);
1088 if (textWidth > obj->obj.area.width) {
1089 uint16_t lineWidth, lineLen;
1090 uint16_t dotsWidth;
1091
1092 dotsWidth = nbgl_getTextWidth(fontId, "...");
1093 rectArea.x0 = obj->obj.area.x0;
1094 rectArea.y0 = obj->obj.area.y0 + (obj->obj.area.height - fontHeight) / 2;
1095 rectArea.width = dotsWidth;
1096 nbgl_drawText(&rectArea, "...", 3, fontId, obj->textColor);
1097 // then draw the end of text
1099 fontId, text, obj->obj.area.width - dotsWidth, &lineLen, &lineWidth);
1100 rectArea.x0 += dotsWidth;
1101 rectArea.width = lineWidth;
1102 nbgl_drawText(&rectArea,
1103 &text[nbgl_getTextLength(text) - lineLen],
1104 lineLen,
1105 obj->fontId,
1106 obj->textColor);
1107 return;
1108 }
1109 }
1110
1111 // get nb lines in the given width (depending of wrapping)
1112 nbLines = nbgl_getTextNbLinesInWidth(fontId, text, obj->obj.area.width, obj->wrapping);
1113#ifdef BUILD_SCREENSHOTS
1114 store_string_infos(
1115 text, fontId, &obj->obj.area, obj->wrapping, last_nb_lines, last_nb_pages, last_bold_state);
1116#endif // BUILD_SCREENSHOTS
1117 // saturate nb lines if nbMaxLines is greater than 0
1118 if ((obj->nbMaxLines > 0) && (obj->nbMaxLines < nbLines)) {
1119 nbLines = obj->nbMaxLines;
1120 }
1121
1122 textHeight = (nbLines - 1) * lineHeight + fontHeight;
1123
1124 midHeight = (obj->obj.area.height - textHeight) / 2;
1125#ifdef SCREEN_SIZE_NANO
1126 if (obj->style == INVERTED_COLORS) {
1127 midHeight--;
1128 }
1129#endif // SCREEN_SIZE_NANO
1130
1131 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1132 rectArea.height = fontHeight;
1133 // draw each line
1134 for (line = 0; line < nbLines; line++) {
1135 uint16_t lineWidth, lineLen;
1136
1138 fontId, text, obj->obj.area.width, &lineLen, &lineWidth, obj->wrapping);
1139 if (obj->textAlignment == MID_LEFT) {
1140 rectArea.x0 = obj->obj.area.x0;
1141 }
1142 else if (obj->textAlignment == CENTER) {
1143 rectArea.x0 = obj->obj.area.x0 + (obj->obj.area.width - lineWidth) / 2;
1144 }
1145 else if (obj->textAlignment == MID_RIGHT) {
1146 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - lineWidth;
1147 }
1148 else {
1149 LOG_FATAL(OBJ_LOGGER, "Forbidden obj->textAlignment = %d\n", obj->textAlignment);
1150 }
1151 rectArea.y0 = obj->obj.area.y0 + midHeight + line * lineHeight;
1152 rectArea.width = lineWidth;
1153
1155 "draw_textArea(), [%s] line %d, lineLen %d lineWidth = %d, obj.area.height = %d, "
1156 "textHeight = %d, nbMaxLines = %d, wrapping = %d\n",
1157 text,
1158 line,
1159 lineLen,
1160 lineWidth,
1161 obj->obj.area.height,
1162 textHeight,
1163 obj->nbMaxLines,
1164 obj->wrapping);
1165 if ((obj->nbMaxLines == 0) || (line < (obj->nbMaxLines - 1))) {
1166 fontId = nbgl_drawText(&rectArea, text, lineLen, fontId, obj->textColor);
1167 }
1168 else {
1169#ifdef HAVE_SE_TOUCH
1170 uint16_t dotsWidth = nbgl_getSingleLineTextWidth(obj->fontId, "...");
1171 // for last chunk, if nbMaxLines is used, replace the 3 last chars by "..."
1172 // draw line except 3 last chars
1173 if ((lineWidth + dotsWidth) >= obj->obj.area.width) {
1174 lineLen -= 3;
1175 }
1176 nbgl_drawText(&rectArea, text, lineLen, obj->fontId, obj->textColor);
1177 rectArea.x0 += nbgl_getSingleLineTextWidthInLen(obj->fontId, text, lineLen);
1178
1179 // draw "..." after the other chars
1180 rectArea.width = dotsWidth;
1181 nbgl_drawText(&rectArea, "...", 3, obj->fontId, obj->textColor);
1182#else // HAVE_SE_TOUCH
1183 nbgl_drawText(&rectArea, text, lineLen, fontId, obj->textColor);
1184#endif // HAVE_SE_TOUCH
1185 return;
1186 }
1187 text += lineLen;
1188 /* skip trailing \n */
1189 if (*text == '\n') {
1190 text++;
1191 }
1192 }
1193}
1194
1195#ifdef NBGL_QRCODE
1204static void draw_qrCode(nbgl_qrcode_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1205{
1206 nbgl_area_t rectArea;
1207
1208 if (computePosition) {
1209 compute_position((nbgl_obj_t *) obj, prevObj);
1210 }
1211 // be sure to align vertical position on multiple of 4
1212 obj->obj.area.y0 &= ~0x3;
1214 "draw_qrCode(), x0 = %d, y0 = %d, width = %d, height = %d, text = %s\n",
1215 obj->obj.area.x0,
1216 obj->obj.area.y0,
1217 obj->obj.area.width,
1218 obj->obj.area.height,
1219 obj->text);
1220
1221 // inherit background from parent
1222 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1223
1224 rectArea.x0 = obj->obj.area.x0;
1225 rectArea.y0 = obj->obj.area.y0;
1226 rectArea.width = obj->obj.area.width;
1227 rectArea.height = obj->obj.area.height;
1228 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1229 nbgl_drawQrCode(&rectArea, obj->version, obj->text, obj->foregroundColor);
1230}
1231#endif // NBGL_QRCODE
1232
1233#ifdef NBGL_KEYBOARD
1241static void draw_keyboard(nbgl_keyboard_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1242{
1243#ifndef HAVE_SE_TOUCH
1244 obj->obj.area.width = KEYBOARD_WIDTH;
1245 obj->obj.area.height = KEYBOARD_KEY_HEIGHT;
1246#endif // HAVE_SE_TOUCH
1247
1248 if (computePosition) {
1249 compute_position((nbgl_obj_t *) obj, prevObj);
1250 }
1251 LOG_DEBUG(
1252 OBJ_LOGGER, "draw_keyboard(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1253
1254 // inherit background from parent
1255 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1256
1258}
1259#endif // NBGL_KEYBOARD
1260
1261#ifdef NBGL_KEYPAD
1269static void draw_keypad(nbgl_keypad_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1270{
1271#ifndef HAVE_SE_TOUCH
1272 obj->obj.area.height = KEYPAD_HEIGHT;
1273 obj->obj.area.width = KEYPAD_WIDTH;
1274#endif // HAVE_SE_TOUCH
1275
1276 if (computePosition) {
1277 compute_position((nbgl_obj_t *) obj, prevObj);
1278 }
1279 obj->obj.area.y0 &= ~0x3;
1280 LOG_DEBUG(OBJ_LOGGER, "draw_keypad(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1281
1282 // inherit background from parent
1283 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1284
1285 nbgl_objDrawKeypad(obj);
1286}
1287#endif // NBGL_KEYPAD
1288
1289#ifdef HAVE_SE_TOUCH
1297static void draw_spinner(nbgl_spinner_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1298{
1299 nbgl_area_t rectArea;
1300 color_t foreColor;
1301
1302 obj->obj.area.width = SPINNER_WIDTH;
1303 obj->obj.area.height = SPINNER_HEIGHT;
1304
1305 if (computePosition) {
1306 compute_position((nbgl_obj_t *) obj, prevObj);
1307 }
1308 LOG_DEBUG(OBJ_LOGGER, "draw_spinner(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1309
1310 // inherit background from parent
1311 obj->obj.area.backgroundColor = obj->obj.parent->area.backgroundColor;
1312 // foreground color is the opposite of background one
1313 foreColor = (obj->obj.area.backgroundColor == WHITE) ? BLACK : WHITE;
1314
1315 rectArea.bpp = NBGL_BPP_1;
1316 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1317 // if position is OxFF, it means "fixed" so draw 4 corners
1318 if (obj->position == 0xFF) {
1319 // draw horizontal segments
1320 rectArea.x0 = obj->obj.area.x0;
1321 rectArea.y0 = obj->obj.area.y0;
1322 rectArea.width = SPINNER_DASH_WIDTH;
1323 rectArea.height = SPINNER_DASH_STROKE;
1324 nbgl_frontDrawLine(&rectArea, 0, foreColor); // top left
1325 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1326 nbgl_frontDrawLine(&rectArea, 0, foreColor); // top right
1327 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1328 nbgl_frontDrawLine(&rectArea, 0, foreColor); // bottom right
1329 rectArea.x0 = obj->obj.area.x0;
1330 nbgl_frontDrawLine(&rectArea, 0, foreColor); // bottom left
1331 // draw vertical segments
1332 rectArea.x0 = obj->obj.area.x0;
1333 rectArea.y0 = obj->obj.area.y0;
1334 rectArea.width = SPINNER_DASH_STROKE;
1335 rectArea.height = SPINNER_DASH_HEIGHT;
1336 nbgl_frontDrawLine(&rectArea, 0, foreColor); // top left
1337 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1338 nbgl_frontDrawLine(&rectArea, 0, foreColor); // top right
1339 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1340 nbgl_frontDrawLine(&rectArea, 0, foreColor); // bottom right
1341 rectArea.x0 = obj->obj.area.x0;
1342 nbgl_frontDrawLine(&rectArea, 0, foreColor); // bottom left
1343 }
1344 else {
1345 // clean up full rectangle
1346 rectArea.x0 = obj->obj.area.x0;
1347 rectArea.y0 = obj->obj.area.y0;
1348 rectArea.width = obj->obj.area.width;
1349 rectArea.height = obj->obj.area.height;
1350 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1351 nbgl_frontDrawRect(&rectArea); // top left
1352
1353 // draw horizontal segment in foreColor
1354 rectArea.width = SPINNER_DASH_WIDTH;
1355 rectArea.height = SPINNER_DASH_STROKE;
1356 switch (obj->position) {
1357 case 0: // top left corner
1358 rectArea.x0 = obj->obj.area.x0;
1359 rectArea.y0 = obj->obj.area.y0;
1360 break;
1361 case 1: // top right
1362 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1363 rectArea.y0 = obj->obj.area.y0;
1364 break;
1365 case 2: // bottom right
1366 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1367 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 3;
1368 break;
1369 case 3: // bottom left
1370 rectArea.x0 = obj->obj.area.x0;
1371 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - 3;
1372 break;
1373 default:
1374 return;
1375 }
1376 nbgl_frontDrawLine(&rectArea, 0, foreColor);
1377
1378 // draw vertical segment in foreColor
1379 rectArea.width = SPINNER_DASH_STROKE;
1380 rectArea.height = SPINNER_DASH_HEIGHT;
1381 rectArea.backgroundColor = foreColor;
1382 switch (obj->position) {
1383 case 0: // top left corner
1384 rectArea.x0 = obj->obj.area.x0;
1385 rectArea.y0 = obj->obj.area.y0;
1386 break;
1387 case 1: // top right corner
1388 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1389 rectArea.y0 = obj->obj.area.y0;
1390 break;
1391 case 2: // bottom right corner
1392 rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width - rectArea.width;
1393 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1394 break;
1395 case 3: // bottom left corner
1396 rectArea.x0 = obj->obj.area.x0;
1397 rectArea.y0 = obj->obj.area.y0 + obj->obj.area.height - rectArea.height;
1398 break;
1399 default:
1400 return;
1401 }
1402 nbgl_frontDrawRect(&rectArea);
1403 }
1404}
1405
1406#else // HAVE_SE_TOUCH
1407
1415static void draw_textEntry(nbgl_text_entry_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1416{
1417 nbgl_area_t rectArea;
1418 int textLen = strlen(obj->text);
1419 uint32_t offsetX;
1420
1421 if (computePosition) {
1422 compute_position((nbgl_obj_t *) obj, prevObj);
1423 }
1424
1426 "draw_textEntry(), x0 = %d, y0 = %d, width = %d, height = %d\n",
1427 obj->obj.area.x0,
1428 obj->obj.area.y0,
1429 obj->obj.area.width,
1430 obj->obj.area.height);
1431
1432 // draw background to make sure it's clean
1433 obj->obj.area.backgroundColor = WHITE;
1434 rectArea.backgroundColor = BLACK;
1435 rectArea.x0 = obj->obj.area.x0;
1436 rectArea.y0 = obj->obj.area.y0;
1437 rectArea.width = obj->obj.area.width;
1438 rectArea.height = obj->obj.area.height;
1439 rectArea.bpp = NBGL_BPP_1;
1440 nbgl_drawRoundedRect(&rectArea, RADIUS_3_PIXELS, WHITE);
1441
1442 rectArea.backgroundColor = obj->obj.area.backgroundColor;
1443 rectArea.height = nbgl_getFontHeight(obj->fontId);
1444 if (obj->nbChars > NB_MAX_LETTERS) {
1445 return;
1446 }
1447 offsetX = (obj->obj.area.width - (obj->nbChars * 10)) / 2;
1448 // draw each of the nb chars
1449 for (int i = 0; i < obj->nbChars; i++) {
1450 char digit;
1451 rectArea.x0 = obj->obj.area.x0 + offsetX + (i * 10);
1452 rectArea.y0 = obj->obj.area.y0 - 2;
1453 rectArea.width = 8;
1454 if (textLen < obj->nbChars) {
1455 if (i < textLen) {
1456 digit = obj->text[i];
1457 }
1458 else {
1459 digit = '_';
1460 }
1461 }
1462 else {
1463 // first char is '..' to notify continuing
1464 if (i == 0) {
1466 continue;
1467 }
1468 else if (i < (obj->nbChars - 1)) {
1469 digit = obj->text[textLen - obj->nbChars + 1 + i];
1470 }
1471 else {
1472 digit = '_';
1473 }
1474 }
1476 }
1477}
1478#endif // HAVE_SE_TOUCH
1479
1487static void draw_image_file(nbgl_image_file_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1488{
1489 if (obj->buffer == NULL) {
1490 return;
1491 }
1492 if (computePosition) {
1493 compute_position((nbgl_obj_t *) obj, prevObj);
1494 }
1495
1496 LOG_DEBUG(
1497 OBJ_LOGGER, "draw_image_file(), x0 = %d, y0 = %d\n", obj->obj.area.x0, obj->obj.area.y0);
1498 obj->obj.area.backgroundColor = WHITE;
1499 nbgl_frontDrawImageFile((nbgl_area_t *) obj, obj->buffer, BLACK, ramBuffer);
1500}
1501
1502#ifdef NBGL_MASKING
1503static void draw_mask_control(nbgl_mask_control_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1504{
1505 if (computePosition) {
1506 compute_position((nbgl_obj_t *) obj, prevObj);
1507 }
1508
1509 if (obj->enableMasking) {
1510 nbgl_frontControlAreaMasking(obj->maskIndex, &obj->obj.area);
1511 }
1512 else {
1513 nbgl_frontControlAreaMasking(obj->maskIndex, NULL);
1514 }
1515}
1516#endif // NBGL_MASKING
1517
1525static void draw_object(nbgl_obj_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1526{
1527 LOG_DEBUG(OBJ_LOGGER, "draw_object() obj->type = %d, prevObj = %p\n", obj->type, prevObj);
1528 objRefreshAreaDone = false;
1529 if ((obj->type < NB_OBJ_TYPES) && (draw_functions[obj->type] != NULL)) {
1530 if ((obj->type != SCREEN) && (obj->parent == NULL)) {
1531 LOG_WARN(OBJ_LOGGER, "object with type [%d] has not parent\n", obj->type);
1532 return;
1533 }
1534 draw_function_t func = (draw_function_t) PIC(draw_functions[obj->type]);
1535 func(obj, prevObj, computePosition);
1536 }
1537 else {
1538 LOG_WARN(OBJ_LOGGER, "Not existing object type [%d]\n", obj->type);
1539 return;
1540 }
1541
1542#ifdef HAVE_SERIALIZED_NBGL
1543 io_seph_ux_send_nbgl_serialized(NBGL_DRAW_OBJ, obj);
1544#endif
1545 if (!objRefreshAreaDone) {
1546 extendRefreshArea(&obj->area);
1547 }
1548}
1549
1559static void draw_obj_and_chidren(nbgl_obj_t *obj, nbgl_obj_t *prevObj, bool computePosition)
1560{
1561 uint8_t i = 0;
1562 LOG_DEBUG(OBJ_LOGGER, "draw_obj_and_chidren(): obj = %p\n", obj);
1563 // draw the object itself
1564 draw_object(obj, prevObj, computePosition);
1565
1566 if ((obj->type == SCREEN) || (obj->type == CONTAINER)) {
1567 nbgl_container_t *container = (nbgl_container_t *) obj;
1568 nbgl_obj_t *prev = NULL;
1569 LOG_DEBUG(
1570 OBJ_LOGGER, "draw_obj_and_chidren(): container->children = %p\n", container->children);
1571 // draw the children, if any
1572 if (container->children != NULL) {
1573 for (i = 0; i < container->nbChildren; i++) {
1574 nbgl_obj_t *current = container->children[i];
1575 if (current != NULL) {
1576 current->parent = (nbgl_obj_t *) container;
1577 draw_obj_and_chidren(current, prev, true);
1578 if (current->alignTo == NULL) {
1579 prev = current;
1580 }
1581 }
1582 }
1583 }
1584 }
1585}
1586
1593static void extendRefreshArea(nbgl_area_t *area)
1594{
1595 int16_t x1, y1; // bottom right corner
1596 x1 = refreshArea.x0 + refreshArea.width;
1597 y1 = refreshArea.y0 + refreshArea.height;
1598
1599 // if obj top-left is on left of current top-left corner, move top-left corner
1600 if (area->x0 < refreshArea.x0) {
1601 // No negative coordinates
1602 refreshArea.x0 = MAX(0, area->x0);
1603 }
1604 // if obj bottom-right is on right of current bottom-right corner, move bottom-right corner
1605 if (((area->x0 + area->width) > x1) || (refreshArea.width == 0)) {
1606 // Not beyond width
1607 x1 = MIN(SCREEN_WIDTH, area->x0 + area->width);
1608 }
1609 // if obj top-left is on top of current top-left corner, move top-left corner
1610 if (area->y0 < refreshArea.y0) {
1611 // No negative coordinates and align on lower multiple of alignment
1612 refreshArea.y0 = MAX(0, area->y0) & ~(VERTICAL_ALIGNMENT - 1);
1613 }
1614 // if obj bottom-right is on bottom of current bottom-right corner, move bottom-right corner
1615 if (((area->y0 + area->height) > y1) || (refreshArea.height == 0)) {
1616 // Not beyond height
1617 y1 = MIN(SCREEN_HEIGHT, area->y0 + area->height);
1618 // align on upper multiple of alignment
1619 y1 = (y1 + (VERTICAL_ALIGNMENT - 1)) & ~(VERTICAL_ALIGNMENT - 1);
1620 }
1621
1622 // sanity check
1623 if (x1 > SCREEN_WIDTH) {
1625 "extendRefreshArea: Impossible area x0 = %d width %d\n",
1626 refreshArea.x0,
1627 refreshArea.width);
1628 }
1629 if (y1 > SCREEN_HEIGHT) {
1630#ifdef HAVE_SE_TOUCH
1632 "extendRefreshArea: Impossible area y0 = %d height %d\n",
1633 refreshArea.y0,
1634 refreshArea.height);
1635#else // HAVE_SE_TOUCH
1636 y1 = SCREEN_HEIGHT;
1637#endif // HAVE_SE_TOUCH
1638 }
1639 // recompute width and height
1640 refreshArea.width = x1 - refreshArea.x0;
1641 refreshArea.height = y1 - refreshArea.y0;
1642
1643 // revaluate area bpp
1644 if (area->bpp > refreshArea.bpp) {
1645 refreshArea.bpp = area->bpp;
1646 }
1647}
1648
1655{
1656 bool computePosition = false;
1657 bool fromApp = false;
1658
1659 LOG_DEBUG(OBJ_LOGGER, "nbgl_objDraw(): obj = %p\n", obj);
1660 // check whether it's necessary to compute position, and if this object belongs to
1661 // an Application screen
1662 if (obj->type == SCREEN) {
1663 // always compute position for screen and all sub-objects
1664 computePosition = true;
1665 fromApp = !(((nbgl_screen_t *) obj)->isUxScreen);
1666 }
1667 else {
1668 nbgl_obj_t *parent = obj;
1669 // search screen in parenthood
1670 while (parent->parent != NULL) {
1671 parent = parent->parent;
1672 }
1673 if (parent->type == SCREEN) {
1674 fromApp = !(((nbgl_screen_t *) parent)->isUxScreen);
1675 }
1676 else {
1677 // should never happen
1678 fromApp = false;
1679 }
1680 }
1681 // forbid redrawing App screens by UX or vice versa
1682 if ((os_sched_current_task() == TASK_BOLOS_UX) == fromApp) {
1683 return;
1684 }
1685 // actually draw the object and its children, if it is allowed
1686 if (objDrawingDisabled && fromApp) {
1687 return;
1688 }
1689 draw_obj_and_chidren(obj, NULL, computePosition);
1690}
1691
1701
1708{
1709 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1710 return;
1711 }
1712
1715 "nbgl_refreshSpecial(), x0,y0 = [%d, %d], w,h = [%d, %d]\n",
1716 refreshArea.x0,
1717 refreshArea.y0,
1718 refreshArea.width,
1719 refreshArea.height);
1721}
1722
1724{
1725 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1726 return;
1727 }
1728
1729 nbgl_frontRefreshArea(&refreshArea, mode, post_refresh);
1731 "nbgl_refreshSpecialNoPoff(), x0,y0 = [%d, %d], w,h = [%d, %d]\n",
1732 refreshArea.x0,
1733 refreshArea.y0,
1734 refreshArea.width,
1735 refreshArea.height);
1737}
1738
1744{
1745 if ((refreshArea.width == 0) || (refreshArea.height == 0)) {
1746 return false;
1747 }
1748 return true;
1749}
1750
1756{
1757#ifdef HAVE_SERIALIZED_NBGL
1758 io_seph_ux_send_nbgl_serialized(NBGL_REFRESH_AREA, (nbgl_obj_t *) &refreshArea);
1759#endif
1760 refreshArea.x0 = SCREEN_WIDTH - 1;
1761 refreshArea.width = 0;
1762 refreshArea.y0 = SCREEN_HEIGHT - 1;
1763 refreshArea.height = 0;
1764 refreshArea.bpp = NBGL_BPP_2;
1765}
1766
1773{
1774 // init area to the smallest size
1776 objDrawingDisabled = false;
1777#ifdef HAVE_SE_TOUCH
1778 nbgl_touchInit(false);
1779#endif
1780}
1781
1787void nbgl_objAllowDrawing(bool enable)
1788{
1789 objDrawingDisabled = !enable;
1790}
1791
1798{
1799 return ramBuffer;
1800}
1801
1808{
1809 nbgl_obj_t *parent = obj;
1810 // search screen in parenthood
1811 while (parent->parent != NULL) {
1812 parent = parent->parent;
1813 }
1814 if (parent->type == SCREEN) {
1815 return (((nbgl_screen_t *) parent)->isUxScreen);
1816 }
1817 else {
1818 // should never happen
1819 return true;
1820 }
1821}
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:535
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:584
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:369
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:857
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:270
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:1654
void nbgl_refresh(void)
This functions refreshes the actual screen on display with what has changed since the last refresh.
Definition nbgl_obj.c:1697
void nbgl_refreshReset(void)
This functions resets all changes since the last refresh.
Definition nbgl_obj.c:1755
void nbgl_objAllowDrawing(bool enable)
This functions enables or disables drawing/refresh for all further calls.
Definition nbgl_obj.c:1787
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:1707
bool nbgl_objIsUx(nbgl_obj_t *obj)
This function returns true if the object belongs to a UxScreen.
Definition nbgl_obj.c:1807
void nbgl_refreshSpecialWithPostRefresh(nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
Definition nbgl_obj.c:1723
uint8_t * nbgl_objGetRAMBuffer(void)
This function is used to get the all purpose RAM buffer.
Definition nbgl_obj.c:1797
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:1743
void nbgl_objInit(void)
This functions inits all internal of nbgl objects layer.
Definition nbgl_obj.c:1772
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
#define BUTTON_WIDTH
Definition nbgl_obj.h:104
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
@ RADIUS_28_PIXELS
Definition nbgl_types.h:366
@ 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