From 7bae9e3ddde9d6bdc06ae437f20a789cd330a556 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 10 Nov 2021 10:13:43 +0100 Subject: [PATCH] feat(event) add LV_SCREEN_(UN)LOAD_START --- docs/overview/event.md | 6 ++++-- src/core/lv_disp.c | 22 ++++++++++++++++++---- src/core/lv_event.h | 3 ++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/docs/overview/event.md b/docs/overview/event.md index a31be161e..9aceeff25 100644 --- a/docs/overview/event.md +++ b/docs/overview/event.md @@ -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) diff --git a/src/core/lv_disp.c b/src/core/lv_disp.c index 91206c619..2806c4e7b 100644 --- a/src/core/lv_disp.c +++ b/src/core/lv_disp.c @@ -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); } @@ -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); @@ -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); + } /** @@ -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(); - lv_disp_load_scr(a->var); + d->prev_scr = lv_scr_act(); + d->act_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) @@ -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; diff --git a/src/core/lv_event.h b/src/core/lv_event.h index 6035a9a50..dd425543b 100644 --- a/src/core/lv_event.h +++ b/src/core/lv_event.h @@ -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*/