9 #include "app_config.h"
39 #define SCREEN_STACK_SIZE 4
50 static uint8_t nbScreensOnStack = 0;
68 if (nbScreensOnStack == 0) {
76 touch_exclude_borders(LEFT_BORDER);
90 if (screenIndex < nbScreensOnStack) {
91 return (
nbgl_obj_t *) &screenStack[screenIndex];
104 if (nbScreensOnStack > 0) {
118 if ((nbScreensOnStack == 1) && (screenStack[0].container.nbChildren == 0)) {
121 return nbScreensOnStack;
136 while (screen != NULL) {
137 if (screen->isUxScreen) {
140 screen = screen->previous;
161 static int nbgl_screenSetAt(
uint8_t screenIndex,
177 screenStack[screenIndex].container.obj.type =
SCREEN;
179 screenStack[screenIndex].container.obj.area.backgroundColor =
WHITE;
181 screenStack[screenIndex].container.obj.area.backgroundColor =
BLACK;
183 screenStack[screenIndex].container.obj.area.height =
SCREEN_HEIGHT;
184 screenStack[screenIndex].container.obj.area.width =
SCREEN_WIDTH;
185 screenStack[screenIndex].container.obj.area.x0 = 0;
186 screenStack[screenIndex].container.obj.area.y0 = 0;
187 screenStack[screenIndex].container.obj.rel_x0 = 0;
188 screenStack[screenIndex].container.obj.rel_y0 = 0;
189 screenStack[screenIndex].index = screenIndex;
190 screenStack[screenIndex].container.layout =
VERTICAL;
191 screenStack[screenIndex].container.children = *children;
192 screenStack[screenIndex].container.nbChildren = nbChildren;
194 screenStack[screenIndex].touchCallback = callback;
196 screenStack[screenIndex].buttonCallback = callback;
198 if (ticker != NULL) {
199 screenStack[screenIndex].ticker.tickerCallback
201 screenStack[screenIndex].ticker.tickerIntervale = ticker->tickerIntervale;
202 screenStack[screenIndex].ticker.tickerValue = ticker->tickerValue;
205 screenStack[screenIndex].ticker.tickerCallback = NULL;
207 screenStack[screenIndex].isUxScreen = (os_sched_current_task() == TASK_BOLOS_UX);
236 if (nbScreensOnStack == 0) {
238 topOfStack = &screenStack[0];
244 return nbgl_screenSetAt(0, elements, nbElements, ticker, callback);
259 screenStack[screenIndex].container.nbChildren = nbElements;
275 screenStack[screenIndex].container.obj.area.backgroundColor = color;
291 if (ticker != NULL) {
292 screenStack[screenIndex].ticker.tickerCallback
294 screenStack[screenIndex].ticker.tickerIntervale = ticker->tickerIntervale;
295 screenStack[screenIndex].ticker.tickerValue = ticker->tickerValue;
298 screenStack[screenIndex].ticker.tickerCallback = NULL;
314 return screenStack[screenIndex].container.children;
343 "nbgl_screenPush(): already in highest index in the stack(%d)\n",
344 nbScreensOnStack - 1);
348 if (nbScreensOnStack == 0) {
350 topOfStack = &screenStack[screenIndex];
351 topOfStack->next = NULL;
353 topOfStack->previous = &screenStack[0];
354 screenStack[0].next = topOfStack;
355 screenStack[0].container.nbChildren = 0;
362 if (screenStack[screenIndex].previous == NULL) {
365 topOfStack->next = &screenStack[screenIndex];
366 screenStack[screenIndex].previous = topOfStack;
374 topOfStack = &screenStack[screenIndex];
375 topOfStack->next = NULL;
384 if (nbgl_screenSetAt(screenIndex, elements, nbElements, ticker, callback) >= 0) {
405 if (nbScreensOnStack == 0) {
412 if (&screenStack[screenIndex] == topOfStack) {
413 if (nbScreensOnStack == 0) {
417 topOfStack = topOfStack->previous;
422 if (screenStack[screenIndex].previous != NULL) {
423 screenStack[screenIndex].previous->next = screenStack[screenIndex].next;
425 if (screenStack[screenIndex].next != NULL) {
426 screenStack[screenIndex].next->previous = screenStack[screenIndex].previous;
430 screenStack[screenIndex].previous = NULL;
431 screenStack[screenIndex].next = NULL;
432 screenStack[screenIndex].container.nbChildren = 0;
433 screenStack[screenIndex].container.children = NULL;
439 if ((nbScreensOnStack == 1) && (screenStack[0].container.nbChildren == 0)) {
440 nbScreensOnStack = 0;
456 if ((screenStack[screenIndex].previous != NULL)
457 || (screenStack[screenIndex].next != NULL)) {
462 screenStack[screenIndex].container.children = NULL;
463 screenStack[screenIndex].container.nbChildren = 0;
465 nbScreensOnStack = 0;
478 if (nbScreensOnStack == 0) {
482 if ((topOfStack->ticker.tickerCallback != NULL) && (topOfStack->ticker.tickerValue != 0)) {
483 topOfStack->ticker.tickerValue -=
MIN(topOfStack->ticker.tickerValue, intervaleMs);
484 if (topOfStack->ticker.tickerValue == 0) {
486 topOfStack->ticker.tickerValue = topOfStack->ticker.tickerIntervale;
487 topOfStack->ticker.tickerCallback();
514 if (container->children != NULL) {
515 for (i = 0; i < container->nbChildren; i++) {
517 if (current != NULL) {
518 if (objIsIn(current, obj) ==
true) {
539 if (refObj->type == type) {
547 if (container->children != NULL) {
548 for (i = 0; i < container->nbChildren; i++) {
550 if (current != NULL) {
551 nbgl_obj_t *found = objIsOfType(current, type);
570 if (nbScreensOnStack == 0) {
573 return objIsIn((
nbgl_obj_t *) topOfStack, obj);
585 if (nbScreensOnStack == 0) {
589 return objIsOfType((
nbgl_obj_t *) screen, type);
#define LOG_WARN(__logger,...)
#define LOG_DEBUG(__logger,...)
Font screen low-Level driver API, to draw elementary forms.
void(* nbgl_touchCallback_t)(void *obj, nbgl_touchType_t eventType)
prototype of function to be called when a touch event is received by an object
void nbgl_objDraw(nbgl_obj_t *obj)
This function draws or redraws the given object and its children (recursive version)
nbgl_obj_t ** nbgl_containerPoolGet(uint8_t nbObjs, uint8_t layer)
Gets a new container from the pool, with the given number of obj pointers.
void nbgl_containerPoolRelease(uint8_t layer)
Release the objects pointers from the pool for the given layer.
void(* nbgl_buttonCallback_t)(void *obj, nbgl_buttonEvent_t buttonEvent)
prototype of function to be called when a button event is received by an object (TODO: change to scre...
struct PACKED__ nbgl_container_s nbgl_container_t
struct to represent a container (CONTAINER type)
void nbgl_objPoolRelease(uint8_t layer)
Release the objects from the pool for the given layer.
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
#define SCREEN_STACK_SIZE
Max number of stackable screens.
nbgl_obj_t * nbgl_screenGetTop(void)
Returns the screen on top layer, as a generic object.
int nbgl_screenSet(nbgl_obj_t ***elements, uint8_t nbElements, const nbgl_screenTickerConfiguration_t *ticker, nbgl_touchCallback_t callback)
Configures the lowest layer screen. To be used by applications A nbgl_screenRedraw() can be called af...
int nbgl_screenPush(nbgl_obj_t ***elements, uint8_t nbElements, const nbgl_screenTickerConfiguration_t *ticker, nbgl_touchCallback_t callback)
Pushes a screen on top of the stack, with the given number of elements, if possible....
int nbgl_screenUpdateNbElements(uint8_t screenIndex, uint8_t nbElements)
Updates the number of children on given layer. can only be smaller than the number given in nbgl_scre...
int nbgl_screenUpdateTicker(uint8_t screenIndex, const nbgl_screenTickerConfiguration_t *ticker)
Updates the ticker configuration of the screen at the given screenIndex, always set at WHITE in.
bool nbgl_screenContainsObj(nbgl_obj_t *obj)
return true if the given obj can be found in refObj or any of its children
int nbgl_screenReset(void)
Releases all screens and objects and resets the screen stack. It is supposed to be called before runn...
nbgl_obj_t ** nbgl_screenGetElements(uint8_t screenIndex)
Returns the array of elements (children) of the screen at the given index (return value of nbgl_scree...
uint8_t nbgl_screenGetUxStackSize(void)
Returns the number of used UX screens on stack.
int nbgl_screenPop(uint8_t screenIndex)
Release the screen at the given index in screen array (index returned by nbgl_screenPush())....
uint8_t nbgl_screenGetCurrentStackSize(void)
Returns the number of used screens on stack.
nbgl_obj_t * nbgl_screenContainsObjType(nbgl_screen_t *screen, nbgl_obj_type_t type)
return an object of the given type in the given screen
nbgl_obj_t * nbgl_screenGetAt(uint8_t screenIndex)
Returns the screen on the given layer index, as a generic object.
int nbgl_screenUpdateBackgroundColor(uint8_t screenIndex, color_t color)
Updates the background color of the screen at the given screenIndex, always set at WHITE in.
void nbgl_screenRedraw(void)
This function redraws the whole screen on top of stack and its children.
void nbgl_screenHandler(uint32_t intervaleMs)
Function to be called periodically by system to enable using ticker.
struct PACKED__ nbgl_screen_s nbgl_screen_t
struct to represent a screen (SCREEN type)
void(* nbgl_tickerCallback_t)(void)
prototype of function to be called when a timer on screen is fired
struct PACKED__ nbgl_screenTickerConfiguration_s nbgl_screenTickerConfiguration_t
struct to configure a screen layer
void nbgl_screen_reinit(void)
void nbgl_touchHandler(nbgl_touchStatePosition_t *touchEvent, uint32_t currentTimeMs)
Function to be called periodically to check touchscreen state and coordinates.
@ VERTICAL
from top to bottom
nbgl_obj_type_t
All types of graphical objects.
@ CONTAINER
Empty container.
@ RELEASED
the finger has been released from the screen
The low level Touchscreen event, coming from driver.
nbgl_touchState_t state
state of the touch event, e.g PRESSED or RELEASED