Fix Model that would crash when closing it.

This commit is contained in:
JF 2020-03-01 17:20:27 +01:00
parent 63c5725882
commit a1d79e7ecc
2 changed files with 14 additions and 13 deletions

View File

@ -45,13 +45,15 @@ void Modal::Show() {
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_event_cb(mbox, Modal::mbox_event_cb);
mbox->user_data = this;
/* Fade the message box in with an animation */
// lv_anim_t a;
// lv_anim_init(&a);
// lv_anim_set_time(&a, 500, 0);
// lv_anim_set_values(&a, LV_OPA_TRANSP, LV_OPA_COVER);
// lv_anim_set_exec_cb(&a, obj, (lv_anim_exec_xcb_t)lv_obj_set_opa_scale);
// lv_anim_create(&a);
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_time(&a, 500, 0);
lv_anim_set_values(&a, LV_OPA_TRANSP, LV_OPA_COVER);
lv_anim_set_exec_cb(&a, obj, (lv_anim_exec_xcb_t)lv_obj_set_opa_scale);
lv_anim_create(&a);
}
void Modal::Hide() {
@ -67,11 +69,10 @@ void Modal::mbox_event_cb(lv_obj_t *obj, lv_event_t evt) {
void Modal::OnEvent(lv_obj_t *event_obj, lv_event_t evt) {
if(evt == LV_EVENT_DELETE && event_obj == mbox) {
/* Delete the parent modal background */
lv_obj_del_async(lv_obj_get_parent(mbox));
mbox = NULL; /* happens before object is actually deleted! */
Hide();
} else if(evt == LV_EVENT_VALUE_CHANGED) {
/* A button was clicked */
lv_mbox_start_auto_close(mbox, 100);
lv_mbox_start_auto_close(mbox, 0);
// Hide();
}
}

View File

@ -16,7 +16,7 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) {
screen->OnObjectEvent(obj, event, eventData);
}
static const char * btnm_map1[] = {"Meter", "Gauge", "Clock", "\n", "App1", "App2", "App3", ""};
static const char * btnm_map1[] = {"Meter", "Gauge", "Clock", "\n", "MsgBox", "App2", "App3", ""};
Tile::Tile(DisplayApp* app) : Screen(app) {
modal.reset(new Modal(app));
@ -123,8 +123,8 @@ void Tile::OnObjectEvent(lv_obj_t *obj, lv_event_t event, uint32_t buttonId) {
tile->StartClockApp();
break;
case 3:
// modal->Show();
// break;
modal->Show();
break;
case 4:
case 5:
tile->StartTestApp();