Call EV_WIDGET_CREATE upon first installing of set_handler()

This commit is contained in:
Pim van Pelt
2017-11-26 16:25:05 +01:00
parent 64af496314
commit 63f1088e7a
2 changed files with 5 additions and 0 deletions

View File

@ -26,6 +26,7 @@ struct widget_t {
// Private // Private
mgos_timer_id _timer_id; mgos_timer_id _timer_id;
uint8_t create_called;
}; };
struct widget_list_t { struct widget_list_t {

View File

@ -41,6 +41,7 @@ struct widget_t *widget_create(char *name, uint16_t x, uint16_t y, uint16_t w, u
widget->handler = NULL; widget->handler = NULL;
widget->timer_msec = 0; widget->timer_msec = 0;
widget->_timer_id = 0; widget->_timer_id = 0;
widget->create_called = false;
return widget; return widget;
} }
@ -82,6 +83,9 @@ void widget_set_handler(struct widget_t *w, widget_event_fn handler, void *user_
return; return;
w->handler = handler; w->handler = handler;
w->user_data = user_data; w->user_data = user_data;
if (!w->create_called && w->handler)
handler(EV_WIDGET_CREATE, w, NULL);
return; return;
} }