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_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_event_cb(mbox, Modal::mbox_event_cb); lv_obj_set_event_cb(mbox, Modal::mbox_event_cb);
mbox->user_data = this;
/* Fade the message box in with an animation */ /* Fade the message box in with an animation */
// lv_anim_t a; lv_anim_t a;
// lv_anim_init(&a); lv_anim_init(&a);
// lv_anim_set_time(&a, 500, 0); lv_anim_set_time(&a, 500, 0);
// lv_anim_set_values(&a, LV_OPA_TRANSP, LV_OPA_COVER); 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_set_exec_cb(&a, obj, (lv_anim_exec_xcb_t)lv_obj_set_opa_scale);
// lv_anim_create(&a); lv_anim_create(&a);
} }
void Modal::Hide() { 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) { void Modal::OnEvent(lv_obj_t *event_obj, lv_event_t evt) {
if(evt == LV_EVENT_DELETE && event_obj == mbox) { if(evt == LV_EVENT_DELETE && event_obj == mbox) {
/* Delete the parent modal background */ Hide();
lv_obj_del_async(lv_obj_get_parent(mbox));
mbox = NULL; /* happens before object is actually deleted! */
} else if(evt == LV_EVENT_VALUE_CHANGED) { } else if(evt == LV_EVENT_VALUE_CHANGED) {
/* A button was clicked */ /* 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); 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) { Tile::Tile(DisplayApp* app) : Screen(app) {
modal.reset(new Modal(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(); tile->StartClockApp();
break; break;
case 3: case 3:
// modal->Show(); modal->Show();
// break; break;
case 4: case 4:
case 5: case 5:
tile->StartTestApp(); tile->StartTestApp();