Add screen_widget_broadcast()

This commit is contained in:
Pim van Pelt
2017-12-02 14:18:54 +01:00
parent ef4451b81f
commit f7a62fce48
2 changed files with 17 additions and 0 deletions

View File

@ -27,6 +27,10 @@ struct widget_t *screen_widget_add_from_file(struct screen_t *s, char *fn);
bool screen_widget_destroy(struct screen_t *s, struct widget_t **w); bool screen_widget_destroy(struct screen_t *s, struct widget_t **w);
uint16_t screen_get_num_widgets(struct screen_t *s); uint16_t screen_get_num_widgets(struct screen_t *s);
struct widget_t *screen_widget_find_by_xy(struct screen_t *s, uint16_t x, uint16_t y); struct widget_t *screen_widget_find_by_xy(struct screen_t *s, uint16_t x, uint16_t y);
void screen_widget_broadcast(struct screen_t *s, int ev, void *ev_data);
#endif //__SCREEN_H #endif //__SCREEN_H

View File

@ -155,6 +155,19 @@ struct widget_t *screen_widget_find_by_xy(struct screen_t *s, uint16_t x, uint16
return NULL; return NULL;
} }
void screen_widget_broadcast(struct screen_t *s, int ev, void *ev_data) {
struct widget_list_t *wl;
if (!s)
return NULL;
SLIST_FOREACH(wl, &s->widget_entries, entries) {
if (wl->widget->handler)
wl->widget->handler(ev, wl->widget, ev_data);
}
return NULL;
}
void screen_widget_set_handler(struct screen_t *s, widget_event_fn handler) { void screen_widget_set_handler(struct screen_t *s, widget_event_fn handler) {
if (!s) if (!s)
return; return;