Skip to content

Commit

Permalink
feat(event) add LV_SCREEN_(UN)LOAD_START
Browse files Browse the repository at this point in the history
  • Loading branch information
kisvegabor committed Nov 10, 2021
1 parent 09e19bb commit 7bae9e3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 4 additions & 2 deletions docs/overview/event.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ The following event codes exist:
- `LV_EVENT_STYLE_CHANGED` Object's style has changed
- `LV_EVENT_BASE_DIR_CHANGED` The base dir has changed
- `LV_EVENT_GET_SELF_SIZE` Get the internal size of a widget
- `LV_EVENT_SCREEN_LOADED` A screen was loaded
- `LV_EVENT_SCREEN_UNLOADED` A screen was unloaded
- `LV_EVENT_SCREEN_UNLOAD_START` A screen unload started, fired immediately when lv_scr_load/lv_scr_load_anim is called
- `LV_EVENT_SCREEN_LOAD_START` A screen load started, fired when the screen change delay is expired
- `LV_EVENT_SCREEN_LOADED` A screen was loaded, called when all animations are finished
- `LV_EVENT_SCREEN_UNLOADED` A screen was unloaded, called when all animations are finished
### Special events
- `LV_EVENT_VALUE_CHANGED` The object's value has changed (i.e. slider moved)
Expand Down
20 changes: 17 additions & 3 deletions src/core/lv_disp.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ void lv_disp_load_scr(lv_obj_t * scr)
lv_disp_t * d = lv_obj_get_disp(scr);
if(!d) return; /*Shouldn't happen, just to be sure*/

if(d->act_scr) lv_event_send(d->act_scr, LV_EVENT_SCREEN_UNLOADED, NULL);
lv_obj_t * old_scr = d->act_scr;

if(d->act_scr) lv_event_send(old_scr, LV_EVENT_SCREEN_UNLOAD_START, NULL);
if(d->act_scr) lv_event_send(scr, LV_EVENT_SCREEN_LOAD_START, NULL);

d->act_scr = scr;

if(d->act_scr) lv_event_send(d->act_scr, LV_EVENT_SCREEN_LOADED, NULL);
if(d->act_scr) lv_event_send(scr, LV_EVENT_SCREEN_LOADED, NULL);
if(d->act_scr) lv_event_send(old_scr, LV_EVENT_SCREEN_UNLOADED, NULL);

lv_obj_invalidate(scr);
}
Expand Down Expand Up @@ -227,6 +231,8 @@ void lv_scr_load_anim(lv_obj_t * new_scr, lv_scr_load_anim_t anim_type, uint32_t
lv_disp_t * d = lv_obj_get_disp(new_scr);
lv_obj_t * act_scr = lv_scr_act();

/*If an other screen load animation is in progress
*make target screen loaded immediately. */
if(d->scr_to_load && act_scr != d->scr_to_load) {
lv_disp_load_scr(d->scr_to_load);
lv_anim_del(d->scr_to_load, NULL);
Expand Down Expand Up @@ -329,8 +335,11 @@ void lv_scr_load_anim(lv_obj_t * new_scr, lv_scr_load_anim_t anim_type, uint32_t
break;
}

lv_event_send(act_scr, LV_EVENT_SCREEN_UNLOAD_START, NULL);

lv_anim_start(&a_new);
lv_anim_start(&a_old);

}

/**
Expand Down Expand Up @@ -409,9 +418,11 @@ lv_timer_t * _lv_disp_get_refr_timer(lv_disp_t * disp)
static void scr_load_anim_start(lv_anim_t * a)
{
lv_disp_t * d = lv_obj_get_disp(a->var);

d->prev_scr = lv_scr_act();
d->act_scr = a->var;

lv_disp_load_scr(a->var);
lv_event_send(d->act_scr, LV_EVENT_SCREEN_LOAD_START, NULL);
}

static void opa_scale_anim(void * obj, int32_t v)
Expand All @@ -433,6 +444,9 @@ static void scr_anim_ready(lv_anim_t * a)
{
lv_disp_t * d = lv_obj_get_disp(a->var);

lv_event_send(d->act_scr, LV_EVENT_SCREEN_LOADED, NULL);
lv_event_send(d->prev_scr, LV_EVENT_SCREEN_UNLOADED, NULL);

if(d->prev_scr && d->del_prev) lv_obj_del(d->prev_scr);
d->prev_scr = NULL;
d->scr_to_load = NULL;
Expand Down
3 changes: 2 additions & 1 deletion src/core/lv_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ typedef enum {
LV_EVENT_CHILD_CHANGED, /**< Child was removed, added, or its size, position were changed */
LV_EVENT_CHILD_CREATED, /**< Child was created, always bubbles up to all parents*/
LV_EVENT_CHILD_DELETED, /**< Child was deleted, always bubbles up to all parents*/
LV_EVENT_SCREEN_UNLOAD_START, /**< A screen unload started, fired immediately when scr_load is called*/
LV_EVENT_SCREEN_LOAD_START, /**< A screen load started, fired when the screen change delay is expired*/
LV_EVENT_SCREEN_LOADED, /**< A screen was loaded*/
LV_EVENT_SCREEN_UNLOADED, /**< A screen was unloaded*/

LV_EVENT_SIZE_CHANGED, /**< Object coordinates/size have changed*/
LV_EVENT_STYLE_CHANGED, /**< Object's style has changed*/
LV_EVENT_LAYOUT_CHANGED, /**< The children position has changed due to a layout recalculation*/
Expand Down

0 comments on commit 7bae9e3

Please sign in to comment.