From a1d79e7ecc64aa78299329a2431a76b5c951feca Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 1 Mar 2020 17:20:27 +0100 Subject: [PATCH] Fix Model that would crash when closing it. --- src/DisplayApp/Screens/Modal.cpp | 21 +++++++++++---------- src/DisplayApp/Screens/Tile.cpp | 6 +++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/DisplayApp/Screens/Modal.cpp b/src/DisplayApp/Screens/Modal.cpp index 553b31a0..13bd42fa 100644 --- a/src/DisplayApp/Screens/Modal.cpp +++ b/src/DisplayApp/Screens/Modal.cpp @@ -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(); } } diff --git a/src/DisplayApp/Screens/Tile.cpp b/src/DisplayApp/Screens/Tile.cpp index 8028d779..72fe35bc 100644 --- a/src/DisplayApp/Screens/Tile.cpp +++ b/src/DisplayApp/Screens/Tile.cpp @@ -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();