feat(list, win) remove event_cb paramter from *_add_btn() functions

It was difficult to handle in the Micropython binding and the user can add events to the returned button in a more flexible way
This commit is contained in:
Gabor Kiss-Vamosi
2021-05-13 00:42:52 +02:00
parent 3091e44d65
commit 4f8e3a38b3
8 changed files with 53 additions and 36 deletions

View File

@@ -4,20 +4,24 @@
static void event_handler(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
if(code == LV_EVENT_CLICKED) {
LV_LOG_USER("Button %d clicked", lv_obj_get_child_id(obj));
}
LV_LOG_USER("Button %d clicked", lv_obj_get_child_id(obj));
}
void lv_example_win_1(void)
{
lv_obj_t * win = lv_win_create(lv_scr_act(), 60);
lv_win_add_btn(win, LV_SYMBOL_LEFT, 40, event_handler);
lv_obj_t * btn;
btn = lv_win_add_btn(win, LV_SYMBOL_LEFT, 40);
lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
lv_win_add_title(win, "A title");
lv_win_add_btn(win, LV_SYMBOL_RIGHT, 40, event_handler);
lv_win_add_btn(win, LV_SYMBOL_CLOSE, 60, event_handler);
btn = lv_win_add_btn(win, LV_SYMBOL_RIGHT, 40);
lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
btn = lv_win_add_btn(win, LV_SYMBOL_CLOSE, 60);
lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
lv_obj_t * cont = lv_win_get_content(win); /*Content can be aded here*/
lv_obj_t * label = lv_label_create(cont);