From bbfcb2454e28c679fc0863d925c6e600dcc0549c Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 19 Apr 2021 11:15:28 +0200 Subject: [PATCH] feat(event) add event filter to lv_event_send --- .../get_started/lv_example_get_started_1.c | 2 +- .../get_started/lv_example_get_started_3.c | 11 +-- examples/scroll/lv_example_scroll_2.c | 2 +- examples/scroll/lv_example_scroll_3.c | 2 +- examples/widgets/btn/lv_example_btn_1.c | 4 +- .../btnmatrix/lv_example_btnmatrix_1.c | 2 +- .../btnmatrix/lv_example_btnmatrix_2.c | 2 +- .../btnmatrix/lv_example_btnmatrix_3.c | 31 ++++---- .../widgets/calendar/lv_example_calendar_1.c | 2 +- examples/widgets/chart/lv_example_chart_2.c | 59 +++++++-------- examples/widgets/chart/lv_example_chart_3.c | 15 ++-- examples/widgets/chart/lv_example_chart_4.c | 2 +- examples/widgets/chart/lv_example_chart_5.c | 17 ++--- examples/widgets/chart/lv_example_chart_6.c | 2 +- .../widgets/checkbox/lv_example_checkbox_1.c | 8 +- .../widgets/dropdown/lv_example_dropdown_1.c | 2 +- .../widgets/dropdown/lv_example_dropdown_3.c | 11 +-- examples/widgets/img/lv_example_img_2.c | 16 ++-- .../widgets/keyboard/lv_example_keyboard_1.c | 4 +- examples/widgets/msgbox/lv_example_msgbox_1.c | 7 +- examples/widgets/roller/lv_example_roller_1.c | 2 +- examples/widgets/roller/lv_example_roller_2.c | 6 +- examples/widgets/slider/lv_example_slider_1.c | 13 ++-- .../widgets/spinbox/lv_example_spinbox_1.c | 4 +- examples/widgets/switch/lv_example_switch_1.c | 8 +- examples/widgets/table/lv_example_table_1.c | 45 ++++++----- examples/widgets/table/lv_example_table_2.c | 75 ++++++++++--------- .../widgets/textarea/lv_example_textarea_1.c | 15 ++-- .../widgets/textarea/lv_example_textarea_2.c | 2 +- .../widgets/textarea/lv_example_textarea_3.c | 19 ++--- src/core/lv_obj.c | 6 +- src/core/lv_obj.h | 5 +- src/extra/themes/default/lv_theme_default.c | 2 +- src/extra/widgets/calendar/lv_calendar.c | 67 ++++++++--------- .../calendar/lv_calendar_header_arrow.c | 8 +- .../calendar/lv_calendar_header_dropdown.c | 10 +-- src/extra/widgets/keyboard/lv_keyboard.c | 6 +- src/extra/widgets/list/lv_list.c | 2 +- src/extra/widgets/msgbox/lv_msgbox.c | 13 ++-- src/extra/widgets/tabview/lv_tabview.c | 38 ++++------ src/extra/widgets/tileview/lv_tileview.c | 2 +- src/extra/widgets/win/lv_win.c | 2 +- src/misc/lv_color.h | 4 +- 43 files changed, 249 insertions(+), 306 deletions(-) diff --git a/examples/get_started/lv_example_get_started_1.c b/examples/get_started/lv_example_get_started_1.c index 77c4c18e8..c63e94d06 100644 --- a/examples/get_started/lv_example_get_started_1.c +++ b/examples/get_started/lv_example_get_started_1.c @@ -23,7 +23,7 @@ void lv_example_get_started_1(void) lv_obj_t * btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/ lv_obj_set_pos(btn, 10, 10); /*Set its position*/ lv_obj_set_size(btn, 120, 50); /*Set its size*/ - lv_obj_add_event_cb(btn, btn_event_cb, NULL); /*Assign a callback to the button*/ + lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/ lv_obj_t * label = lv_label_create(btn); /*Add a label to the button*/ lv_label_set_text(label, "Button"); /*Set the labels text*/ diff --git a/examples/get_started/lv_example_get_started_3.c b/examples/get_started/lv_example_get_started_3.c index e49792c22..853b879c7 100644 --- a/examples/get_started/lv_example_get_started_3.c +++ b/examples/get_started/lv_example_get_started_3.c @@ -5,14 +5,11 @@ static lv_obj_t * label; static void slider_event_cb(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); lv_obj_t * slider = lv_event_get_target(e); - if(code == LV_EVENT_VALUE_CHANGED) { - /*Refresh the text*/ - lv_label_set_text_fmt(label, "%d", lv_slider_get_value(slider)); - lv_obj_align_to(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15); /*Align below the slider*/ - } + /*Refresh the text*/ + lv_label_set_text_fmt(label, "%d", lv_slider_get_value(slider)); + lv_obj_align_to(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15); /*Align below the slider*/ } /** @@ -24,7 +21,7 @@ void lv_example_get_started_3(void) lv_obj_t * slider = lv_slider_create(lv_scr_act()); lv_obj_set_width(slider, 200); /*Set the width*/ lv_obj_center(slider); /*Align to the center of the parent (screen)*/ - lv_obj_add_event_cb(slider, slider_event_cb, NULL); /*Assign an event function*/ + lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL); /*Assign an event function*/ /*Create a label below the slider*/ label = lv_label_create(lv_scr_act()); diff --git a/examples/scroll/lv_example_scroll_2.c b/examples/scroll/lv_example_scroll_2.c index ea5db7da5..c39c15c08 100644 --- a/examples/scroll/lv_example_scroll_2.c +++ b/examples/scroll/lv_example_scroll_2.c @@ -46,7 +46,7 @@ void lv_example_scroll_2(void) /*Switch between "One scroll" and "Normal scroll" mode*/ lv_obj_t * sw = lv_switch_create(lv_scr_act()); lv_obj_align(sw, LV_ALIGN_TOP_RIGHT, -20, 10); - lv_obj_add_event_cb(sw, sw_event_cb, panel); + lv_obj_add_event_cb(sw, sw_event_cb, LV_EVENT_ALL, panel); lv_obj_t * label = lv_label_create(lv_scr_act()); lv_label_set_text(label, "One scroll"); lv_obj_align_to(label, sw, LV_ALIGN_OUT_BOTTOM_MID, 0, 5); diff --git a/examples/scroll/lv_example_scroll_3.c b/examples/scroll/lv_example_scroll_3.c index c576883ff..89a0696f3 100644 --- a/examples/scroll/lv_example_scroll_3.c +++ b/examples/scroll/lv_example_scroll_3.c @@ -40,7 +40,7 @@ void lv_example_scroll_3(void) lv_obj_set_size(float_btn, 50, 50); lv_obj_add_flag(float_btn, LV_OBJ_FLAG_FLOATING); lv_obj_align(float_btn, LV_ALIGN_BOTTOM_RIGHT, 0, -lv_obj_get_style_pad_right(list, LV_PART_MAIN)); - lv_obj_add_event_cb(float_btn, float_btn_event_cb, list); + lv_obj_add_event_cb(float_btn, float_btn_event_cb, LV_EVENT_ALL, list); lv_obj_set_style_radius(float_btn, LV_RADIUS_CIRCLE, 0); lv_obj_set_style_bg_img_src(float_btn, LV_SYMBOL_PLUS, 0); lv_obj_set_style_text_font(float_btn, lv_theme_get_font_large(float_btn), 0); diff --git a/examples/widgets/btn/lv_example_btn_1.c b/examples/widgets/btn/lv_example_btn_1.c index 98966d0eb..1845e2094 100644 --- a/examples/widgets/btn/lv_example_btn_1.c +++ b/examples/widgets/btn/lv_example_btn_1.c @@ -18,7 +18,7 @@ void lv_example_btn_1(void) lv_obj_t * label; lv_obj_t * btn1 = lv_btn_create(lv_scr_act()); - lv_obj_add_event_cb(btn1, event_handler, NULL); + lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL); lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -40); label = lv_label_create(btn1); @@ -26,7 +26,7 @@ void lv_example_btn_1(void) lv_obj_center(label); lv_obj_t * btn2 = lv_btn_create(lv_scr_act()); - lv_obj_add_event_cb(btn2, event_handler, NULL); + lv_obj_add_event_cb(btn2, event_handler, LV_EVENT_ALL, NULL); lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 40); lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE); lv_obj_set_height(btn2, LV_SIZE_CONTENT); diff --git a/examples/widgets/btnmatrix/lv_example_btnmatrix_1.c b/examples/widgets/btnmatrix/lv_example_btnmatrix_1.c index a80445d07..3119ede17 100644 --- a/examples/widgets/btnmatrix/lv_example_btnmatrix_1.c +++ b/examples/widgets/btnmatrix/lv_example_btnmatrix_1.c @@ -26,7 +26,7 @@ void lv_example_btnmatrix_1(void) lv_btnmatrix_set_btn_ctrl(btnm1, 10, LV_BTNMATRIX_CTRL_CHECKABLE); lv_btnmatrix_set_btn_ctrl(btnm1, 11, LV_BTNMATRIX_CTRL_CHECKED); lv_obj_align(btnm1, LV_ALIGN_CENTER, 0, 0); - lv_obj_add_event_cb(btnm1, event_handler, NULL); + lv_obj_add_event_cb(btnm1, event_handler, LV_EVENT_ALL, NULL); } #endif diff --git a/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c b/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c index a72aab677..9be774ce3 100644 --- a/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c +++ b/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c @@ -65,7 +65,7 @@ static void event_cb(lv_event_t * e) void lv_example_btnmatrix_2(void) { lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act()); - lv_obj_add_event_cb(btnm, event_cb, NULL); + lv_obj_add_event_cb(btnm, event_cb, LV_EVENT_ALL, NULL); lv_obj_center(btnm); } diff --git a/examples/widgets/btnmatrix/lv_example_btnmatrix_3.c b/examples/widgets/btnmatrix/lv_example_btnmatrix_3.c index 46d3bddce..f35043d0e 100644 --- a/examples/widgets/btnmatrix/lv_example_btnmatrix_3.c +++ b/examples/widgets/btnmatrix/lv_example_btnmatrix_3.c @@ -3,24 +3,21 @@ static void event_cb(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_VALUE_CHANGED) { - uint32_t id = lv_btnmatrix_get_selected_btn(obj); - bool prev = id == 0 ? true : false; - bool next = id == 6 ? true : false; - if(prev || next) { - /*Find the checked button*/ - uint32_t i; - for(i = 1; i < 7; i++) { - if(lv_btnmatrix_has_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED)) break; - } - - if(prev && i > 1) i--; - else if(next && i < 5) i++; - - lv_btnmatrix_set_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED); + uint32_t id = lv_btnmatrix_get_selected_btn(obj); + bool prev = id == 0 ? true : false; + bool next = id == 6 ? true : false; + if(prev || next) { + /*Find the checked button*/ + uint32_t i; + for(i = 1; i < 7; i++) { + if(lv_btnmatrix_has_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED)) break; } + + if(prev && i > 1) i--; + else if(next && i < 5) i++; + + lv_btnmatrix_set_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED); } } @@ -53,7 +50,7 @@ void lv_example_btnmatrix_3(void) lv_btnmatrix_set_map(btnm, map); lv_obj_add_style(btnm, &style_bg, 0); lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS); - lv_obj_add_event_cb(btnm, event_cb, NULL); + lv_obj_add_event_cb(btnm, event_cb, LV_EVENT_VALUE_CHANGED, NULL); lv_obj_set_size(btnm, 225, 35); /*Allow selecting on one number at time*/ diff --git a/examples/widgets/calendar/lv_example_calendar_1.c b/examples/widgets/calendar/lv_example_calendar_1.c index bc9fc9a8e..6ccd7976c 100644 --- a/examples/widgets/calendar/lv_example_calendar_1.c +++ b/examples/widgets/calendar/lv_example_calendar_1.c @@ -19,7 +19,7 @@ void lv_example_calendar_1(void) lv_obj_t * calendar = lv_calendar_create(lv_scr_act()); lv_obj_set_size(calendar, 200, 200); lv_obj_align(calendar, LV_ALIGN_CENTER, 0, 20); - lv_obj_add_event_cb(calendar, event_handler, NULL); + lv_obj_add_event_cb(calendar, event_handler, LV_EVENT_ALL, NULL); lv_calendar_set_today_date(calendar, 2021, 02, 23); lv_calendar_set_showed_date(calendar, 2021, 02); diff --git a/examples/widgets/chart/lv_example_chart_2.c b/examples/widgets/chart/lv_example_chart_2.c index 32ed105b4..63a430432 100644 --- a/examples/widgets/chart/lv_example_chart_2.c +++ b/examples/widgets/chart/lv_example_chart_2.c @@ -5,45 +5,42 @@ static lv_obj_t * chart1; static lv_chart_series_t * ser1; static lv_chart_series_t * ser2; -static void event_cb(lv_event_t * e) +static void draw_event_cb(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); lv_obj_t * obj = lv_event_get_target(e); /*Add the faded area before the lines are drawn*/ - if(code == LV_EVENT_DRAW_PART_BEGIN) { - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); - if(dsc->part != LV_PART_ITEMS) return; - if(!dsc->p1 || !dsc->p2) return; + lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + if(dsc->part != LV_PART_ITEMS) return; + if(!dsc->p1 || !dsc->p2) return; - /*Add a line mask that keeps the area below the line*/ - lv_draw_mask_line_param_t line_mask_param; - lv_draw_mask_line_points_init(&line_mask_param, dsc->p1->x, dsc->p1->y, dsc->p2->x, dsc->p2->y, LV_DRAW_MASK_LINE_SIDE_BOTTOM); - int16_t line_mask_id = lv_draw_mask_add(&line_mask_param, NULL); + /*Add a line mask that keeps the area below the line*/ + lv_draw_mask_line_param_t line_mask_param; + lv_draw_mask_line_points_init(&line_mask_param, dsc->p1->x, dsc->p1->y, dsc->p2->x, dsc->p2->y, LV_DRAW_MASK_LINE_SIDE_BOTTOM); + int16_t line_mask_id = lv_draw_mask_add(&line_mask_param, NULL); - /*Add a fade effect: transparent bottom covering top*/ - lv_coord_t h = lv_obj_get_height(obj); - lv_draw_mask_fade_param_t fade_mask_param; - lv_draw_mask_fade_init(&fade_mask_param, &obj->coords, LV_OPA_COVER, obj->coords.y1 + h / 8, LV_OPA_TRANSP,obj->coords.y2); - int16_t fade_mask_id = lv_draw_mask_add(&fade_mask_param, NULL); + /*Add a fade effect: transparent bottom covering top*/ + lv_coord_t h = lv_obj_get_height(obj); + lv_draw_mask_fade_param_t fade_mask_param; + lv_draw_mask_fade_init(&fade_mask_param, &obj->coords, LV_OPA_COVER, obj->coords.y1 + h / 8, LV_OPA_TRANSP,obj->coords.y2); + int16_t fade_mask_id = lv_draw_mask_add(&fade_mask_param, NULL); - /*Draw a rectangle that will be affected by the mask*/ - lv_draw_rect_dsc_t draw_rect_dsc; - lv_draw_rect_dsc_init(&draw_rect_dsc); - draw_rect_dsc.bg_opa = LV_OPA_20; - draw_rect_dsc.bg_color = dsc->line_dsc->color; + /*Draw a rectangle that will be affected by the mask*/ + lv_draw_rect_dsc_t draw_rect_dsc; + lv_draw_rect_dsc_init(&draw_rect_dsc); + draw_rect_dsc.bg_opa = LV_OPA_20; + draw_rect_dsc.bg_color = dsc->line_dsc->color; - lv_area_t a; - a.x1 = dsc->p1->x; - a.x2 = dsc->p2->x - 1; - a.y1 = LV_MIN(dsc->p1->y, dsc->p2->y); - a.y2 = obj->coords.y2; - lv_draw_rect(&a, dsc->clip_area, &draw_rect_dsc); + lv_area_t a; + a.x1 = dsc->p1->x; + a.x2 = dsc->p2->x - 1; + a.y1 = LV_MIN(dsc->p1->y, dsc->p2->y); + a.y2 = obj->coords.y2; + lv_draw_rect(&a, dsc->clip_area, &draw_rect_dsc); - /*Remove the masks*/ - lv_draw_mask_remove_id(line_mask_id); - lv_draw_mask_remove_id(fade_mask_id); - } + /*Remove the masks*/ + lv_draw_mask_remove_id(line_mask_id); + lv_draw_mask_remove_id(fade_mask_id); } static void add_data(lv_timer_t * timer) @@ -68,7 +65,7 @@ void lv_example_chart_2(void) lv_obj_center(chart1); lv_chart_set_type(chart1, LV_CHART_TYPE_LINE); /*Show lines and points too*/ - lv_obj_add_event_cb(chart1, event_cb, NULL); + lv_obj_add_event_cb(chart1, draw_event_cb, LV_EVENT_DRAW_PART_BEGIN, NULL); lv_chart_set_update_mode(chart1, LV_CHART_UPDATE_MODE_CIRCULAR); /*Add two data series*/ diff --git a/examples/widgets/chart/lv_example_chart_3.c b/examples/widgets/chart/lv_example_chart_3.c index c06ab25e8..ab41e0703 100644 --- a/examples/widgets/chart/lv_example_chart_3.c +++ b/examples/widgets/chart/lv_example_chart_3.c @@ -1,15 +1,12 @@ #include "../../lv_examples.h" #if LV_USE_CHART && LV_BUILD_EXAMPLES -static void event_cb(lv_event_t * e) +static void draw_event_cb(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); - if(code == LV_EVENT_DRAW_PART_BEGIN) { - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); - if(dsc->part == LV_PART_TICKS && dsc->id == LV_CHART_AXIS_X) { - const char * month[] = {"Jan", "Febr", "March", "Apr", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov", "Dec"}; - lv_snprintf(dsc->text, sizeof(dsc->text), "%s", month[dsc->value]); - } + lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + if(dsc->part == LV_PART_TICKS && dsc->id == LV_CHART_AXIS_X) { + const char * month[] = {"Jan", "Febr", "March", "Apr", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov", "Dec"}; + lv_snprintf(dsc->text, sizeof(dsc->text), "%s", month[dsc->value]); } } @@ -27,7 +24,7 @@ void lv_example_chart_3(void) lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 0, 100); lv_chart_set_range(chart, LV_CHART_AXIS_SECONDARY_Y, 0, 400); lv_chart_set_point_count(chart, 12); - lv_obj_add_event_cb(chart, event_cb, NULL); + lv_obj_add_event_cb(chart, draw_event_cb, LV_EVENT_DRAW_PART_BEGIN, NULL); /*Add ticks and label to every axis*/ lv_chart_set_axis_tick(chart, LV_CHART_AXIS_X, 10, 5, 12, 3, true, 40); diff --git a/examples/widgets/chart/lv_example_chart_4.c b/examples/widgets/chart/lv_example_chart_4.c index eb085aa92..4d86c986e 100644 --- a/examples/widgets/chart/lv_example_chart_4.c +++ b/examples/widgets/chart/lv_example_chart_4.c @@ -64,7 +64,7 @@ void lv_example_chart_4(void) lv_obj_set_size(chart, 200, 150); lv_obj_center(chart); - lv_obj_add_event_cb(chart, event_cb, NULL); + lv_obj_add_event_cb(chart, event_cb, LV_EVENT_ALL, NULL); lv_obj_refresh_ext_draw_size(chart); /*Zoom in a little in X*/ diff --git a/examples/widgets/chart/lv_example_chart_5.c b/examples/widgets/chart/lv_example_chart_5.c index 50a5bcfdf..9089604c1 100644 --- a/examples/widgets/chart/lv_example_chart_5.c +++ b/examples/widgets/chart/lv_example_chart_5.c @@ -48,21 +48,16 @@ static const lv_coord_t ecg_sample[] = { static void slider_x_event_cb(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_VALUE_CHANGED) { - int32_t v = lv_slider_get_value(obj); - lv_chart_set_zoom_x(chart, v); - } + int32_t v = lv_slider_get_value(obj); + lv_chart_set_zoom_x(chart, v); } static void slider_y_event_cb(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_VALUE_CHANGED) { - lv_chart_set_zoom_y(chart, lv_slider_get_value(obj)); - } + int32_t v = lv_slider_get_value(obj); + lv_chart_set_zoom_y(chart, v); } /** @@ -90,13 +85,13 @@ void lv_example_chart_5(void) lv_obj_t * slider; slider = lv_slider_create(lv_scr_act()); lv_slider_set_range(slider, LV_IMG_ZOOM_NONE, LV_IMG_ZOOM_NONE * 10); - lv_obj_add_event_cb(slider, slider_x_event_cb, NULL); + lv_obj_add_event_cb(slider, slider_x_event_cb, LV_EVENT_VALUE_CHANGED, NULL); lv_obj_set_size(slider, lv_obj_get_width(chart), 10); lv_obj_align_to(slider, chart, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); slider = lv_slider_create(lv_scr_act()); lv_slider_set_range(slider, LV_IMG_ZOOM_NONE, LV_IMG_ZOOM_NONE * 10); - lv_obj_add_event_cb(slider, slider_y_event_cb, NULL); + lv_obj_add_event_cb(slider, slider_y_event_cb, LV_EVENT_VALUE_CHANGED, NULL); lv_obj_set_size(slider, 10, lv_obj_get_height(chart)); lv_obj_align_to(slider, chart, LV_ALIGN_OUT_RIGHT_MID, 20, 0); } diff --git a/examples/widgets/chart/lv_example_chart_6.c b/examples/widgets/chart/lv_example_chart_6.c index 61c222f23..4d5a84311 100644 --- a/examples/widgets/chart/lv_example_chart_6.c +++ b/examples/widgets/chart/lv_example_chart_6.c @@ -67,7 +67,7 @@ void lv_example_chart_6(void) lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_Y, 10, 5, 6, 5, true, 40); lv_chart_set_axis_tick(chart, LV_CHART_AXIS_X, 10, 5, 10, 1, true, 30); - lv_obj_add_event_cb(chart, event_cb, NULL); + lv_obj_add_event_cb(chart, event_cb, LV_EVENT_ALL, NULL); lv_obj_refresh_ext_draw_size(chart); cursor = lv_chart_add_cursor(chart, lv_color_blue(), LV_DIR_LEFT | LV_DIR_BOTTOM); diff --git a/examples/widgets/checkbox/lv_example_checkbox_1.c b/examples/widgets/checkbox/lv_example_checkbox_1.c index 1d0b4e76f..5a9fd8896 100644 --- a/examples/widgets/checkbox/lv_example_checkbox_1.c +++ b/examples/widgets/checkbox/lv_example_checkbox_1.c @@ -20,22 +20,22 @@ void lv_example_checkbox_1(void) lv_obj_t * cb; cb = lv_checkbox_create(lv_scr_act()); lv_checkbox_set_text(cb, "Apple"); - lv_obj_add_event_cb(cb, event_handler, NULL); + lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL); cb = lv_checkbox_create(lv_scr_act()); lv_checkbox_set_text(cb, "Banana"); lv_obj_add_state(cb, LV_STATE_CHECKED); - lv_obj_add_event_cb(cb, event_handler, NULL); + lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL); cb = lv_checkbox_create(lv_scr_act()); lv_checkbox_set_text(cb, "Lemon"); lv_obj_add_state(cb, LV_STATE_DISABLED); - lv_obj_add_event_cb(cb, event_handler, NULL); + lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL); cb = lv_checkbox_create(lv_scr_act()); lv_obj_add_state(cb, LV_STATE_CHECKED | LV_STATE_DISABLED); lv_checkbox_set_text(cb, "Melon"); - lv_obj_add_event_cb(cb, event_handler, NULL); + lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL); } #endif diff --git a/examples/widgets/dropdown/lv_example_dropdown_1.c b/examples/widgets/dropdown/lv_example_dropdown_1.c index 0f4a83f43..f35b337d3 100644 --- a/examples/widgets/dropdown/lv_example_dropdown_1.c +++ b/examples/widgets/dropdown/lv_example_dropdown_1.c @@ -29,7 +29,7 @@ void lv_example_dropdown_1(void) "Nuts"); lv_obj_align(dd, LV_ALIGN_TOP_MID, 0, 20); - lv_obj_add_event_cb(dd, event_handler, NULL); + lv_obj_add_event_cb(dd, event_handler, LV_EVENT_ALL, NULL); } #endif diff --git a/examples/widgets/dropdown/lv_example_dropdown_3.c b/examples/widgets/dropdown/lv_example_dropdown_3.c index eda649b0a..5010f1fd1 100644 --- a/examples/widgets/dropdown/lv_example_dropdown_3.c +++ b/examples/widgets/dropdown/lv_example_dropdown_3.c @@ -3,13 +3,10 @@ static void event_cb(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); lv_obj_t * dropdown = lv_event_get_target(e); - if(code == LV_EVENT_VALUE_CHANGED) { - char buf[64]; - lv_dropdown_get_selected_str(dropdown, buf, sizeof(buf)); - LV_LOG_USER("'%s' is selected", buf); - } + char buf[64]; + lv_dropdown_get_selected_str(dropdown, buf, sizeof(buf)); + LV_LOG_USER("'%s' is selected", buf); } /** @@ -38,7 +35,7 @@ void lv_example_dropdown_3(void) /*In a menu we don't need to show the last clicked item*/ lv_dropdown_set_selected_highlight(dropdown, false); - lv_obj_add_event_cb(dropdown, event_cb, NULL); + lv_obj_add_event_cb(dropdown, event_cb, LV_EVENT_VALUE_CHANGED, NULL); } #endif diff --git a/examples/widgets/img/lv_example_img_2.c b/examples/widgets/img/lv_example_img_2.c index f2cd80520..2d62da7fc 100644 --- a/examples/widgets/img/lv_example_img_2.c +++ b/examples/widgets/img/lv_example_img_2.c @@ -40,15 +40,13 @@ void lv_example_img_2(void) static void slider_event_cb(lv_event_t * e) { + LV_UNUSED(e); - lv_event_code_t code = lv_event_get_code(e); - if(code == LV_EVENT_VALUE_CHANGED) { - /*Recolor the image based on the sliders' values*/ - lv_color_t color = lv_color_make(lv_slider_get_value(red_slider), lv_slider_get_value(green_slider), lv_slider_get_value(blue_slider)); - lv_opa_t intense = lv_slider_get_value(intense_slider); - lv_obj_set_style_img_recolor_opa(img1, intense, 0); - lv_obj_set_style_img_recolor(img1, color, 0); - } + /*Recolor the image based on the sliders' values*/ + lv_color_t color = lv_color_make(lv_slider_get_value(red_slider), lv_slider_get_value(green_slider), lv_slider_get_value(blue_slider)); + lv_opa_t intense = lv_slider_get_value(intense_slider); + lv_obj_set_style_img_recolor_opa(img1, intense, 0); + lv_obj_set_style_img_recolor(img1, color, 0); } static lv_obj_t * create_slider(lv_color_t color) @@ -58,7 +56,7 @@ static lv_obj_t * create_slider(lv_color_t color) lv_obj_set_size(slider, 10, 200); lv_obj_set_style_bg_color(slider, color, LV_PART_KNOB); lv_obj_set_style_bg_color(slider, lv_color_darken(color, LV_OPA_40), LV_PART_INDICATOR); - lv_obj_add_event_cb(slider, slider_event_cb, NULL); + lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL); return slider; } diff --git a/examples/widgets/keyboard/lv_example_keyboard_1.c b/examples/widgets/keyboard/lv_example_keyboard_1.c index f7918d1c3..dbcdecea5 100644 --- a/examples/widgets/keyboard/lv_example_keyboard_1.c +++ b/examples/widgets/keyboard/lv_example_keyboard_1.c @@ -26,12 +26,12 @@ void lv_example_keyboard_1(void) lv_obj_t * ta; ta = lv_textarea_create(lv_scr_act()); lv_obj_align(ta, LV_ALIGN_TOP_LEFT, 10, 10); - lv_obj_add_event_cb(ta, ta_event_cb, kb); + lv_obj_add_event_cb(ta, ta_event_cb, LV_EVENT_ALL, kb); lv_textarea_set_placeholder_text(ta, "Hello"); ta = lv_textarea_create(lv_scr_act()); lv_obj_align(ta, LV_ALIGN_TOP_RIGHT, -10, 10); - lv_obj_add_event_cb(ta, ta_event_cb, kb); + lv_obj_add_event_cb(ta, ta_event_cb, LV_EVENT_ALL, kb); lv_keyboard_set_textarea(kb, ta); } diff --git a/examples/widgets/msgbox/lv_example_msgbox_1.c b/examples/widgets/msgbox/lv_example_msgbox_1.c index b9eb42c5a..d6a84246e 100644 --- a/examples/widgets/msgbox/lv_example_msgbox_1.c +++ b/examples/widgets/msgbox/lv_example_msgbox_1.c @@ -3,11 +3,8 @@ static void event_cb(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_VALUE_CHANGED) { - LV_LOG_USER("Button %s clicked", lv_msgbox_get_active_btn_text(obj)); - } + LV_LOG_USER("Button %s clicked", lv_msgbox_get_active_btn_text(obj)); } void lv_example_msgbox_1(void) @@ -15,7 +12,7 @@ void lv_example_msgbox_1(void) static const char * btns[] ={"Apply", "Close", ""}; lv_obj_t * mbox1 = lv_msgbox_create("Hello", "This is a message box with two buttons.", btns, true); - lv_obj_add_event_cb(mbox1, event_cb, NULL); + lv_obj_add_event_cb(mbox1, event_cb, LV_EVENT_VALUE_CHANGED, NULL); lv_obj_center(mbox1); } diff --git a/examples/widgets/roller/lv_example_roller_1.c b/examples/widgets/roller/lv_example_roller_1.c index e9781eb77..2aa3523a8 100644 --- a/examples/widgets/roller/lv_example_roller_1.c +++ b/examples/widgets/roller/lv_example_roller_1.c @@ -35,7 +35,7 @@ void lv_example_roller_1(void) lv_roller_set_visible_row_count(roller1, 4); lv_obj_center(roller1); - lv_obj_add_event_cb(roller1, event_handler, NULL); + lv_obj_add_event_cb(roller1, event_handler, LV_EVENT_ALL, NULL); } #endif diff --git a/examples/widgets/roller/lv_example_roller_2.c b/examples/widgets/roller/lv_example_roller_2.c index daef45305..55712b754 100644 --- a/examples/widgets/roller/lv_example_roller_2.c +++ b/examples/widgets/roller/lv_example_roller_2.c @@ -33,7 +33,7 @@ void lv_example_roller_2(void) lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED); lv_obj_set_style_text_align(roller, LV_TEXT_ALIGN_LEFT, 0); lv_obj_align(roller, LV_ALIGN_LEFT_MID, 10, 0); - lv_obj_add_event_cb(roller, event_handler, NULL); + lv_obj_add_event_cb(roller, event_handler, LV_EVENT_ALL, NULL); lv_roller_set_selected(roller, 2, LV_ANIM_OFF); /*A roller on the middle with center aligned text, and auto (default) width*/ @@ -42,7 +42,7 @@ void lv_example_roller_2(void) lv_roller_set_visible_row_count(roller, 3); lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED); lv_obj_align(roller, LV_ALIGN_CENTER, 0, 0); - lv_obj_add_event_cb(roller, event_handler, NULL); + lv_obj_add_event_cb(roller, event_handler, LV_EVENT_ALL, NULL); lv_roller_set_selected(roller, 5, LV_ANIM_OFF); /*A roller on the right with right aligned text, and custom width*/ @@ -53,7 +53,7 @@ void lv_example_roller_2(void) lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED); lv_obj_set_style_text_align(roller, LV_TEXT_ALIGN_RIGHT, 0); lv_obj_align(roller, LV_ALIGN_RIGHT_MID, -10, 0); - lv_obj_add_event_cb(roller, event_handler, NULL); + lv_obj_add_event_cb(roller, event_handler, LV_EVENT_ALL, NULL); lv_roller_set_selected(roller, 8, LV_ANIM_OFF); } diff --git a/examples/widgets/slider/lv_example_slider_1.c b/examples/widgets/slider/lv_example_slider_1.c index 69363c64d..b8f661bbf 100644 --- a/examples/widgets/slider/lv_example_slider_1.c +++ b/examples/widgets/slider/lv_example_slider_1.c @@ -12,7 +12,7 @@ void lv_example_slider_1(void) /*Create a slider in the center of the display*/ lv_obj_t * slider = lv_slider_create(lv_scr_act()); lv_obj_center(slider); - lv_obj_add_event_cb(slider, slider_event_cb, NULL); + lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL); /*Create a label below the slider*/ slider_label = lv_label_create(lv_scr_act()); @@ -23,14 +23,11 @@ void lv_example_slider_1(void) static void slider_event_cb(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); lv_obj_t * slider = lv_event_get_target(e); - if(code == LV_EVENT_VALUE_CHANGED) { - char buf[8]; - lv_snprintf(buf, sizeof(buf), "%d%%", lv_slider_get_value(slider)); - lv_label_set_text(slider_label, buf); - lv_obj_align_to(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); - } + char buf[8]; + lv_snprintf(buf, sizeof(buf), "%d%%", lv_slider_get_value(slider)); + lv_label_set_text(slider_label, buf); + lv_obj_align_to(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); } #endif diff --git a/examples/widgets/spinbox/lv_example_spinbox_1.c b/examples/widgets/spinbox/lv_example_spinbox_1.c index 494c6f636..2395aa4e0 100644 --- a/examples/widgets/spinbox/lv_example_spinbox_1.c +++ b/examples/widgets/spinbox/lv_example_spinbox_1.c @@ -36,13 +36,13 @@ void lv_example_spinbox_1(void) lv_obj_set_size(btn, h, h); lv_obj_align_to(btn, spinbox, LV_ALIGN_OUT_RIGHT_MID, 5, 0); lv_obj_set_style_bg_img_src(btn, LV_SYMBOL_PLUS, 0); - lv_obj_add_event_cb(btn, lv_spinbox_increment_event_cb, NULL); + lv_obj_add_event_cb(btn, lv_spinbox_increment_event_cb, LV_EVENT_ALL, NULL); btn = lv_btn_create(lv_scr_act()); lv_obj_set_size(btn, h, h); lv_obj_align_to(btn, spinbox, LV_ALIGN_OUT_LEFT_MID, -5, 0); lv_obj_set_style_bg_img_src(btn, LV_SYMBOL_MINUS, 0); - lv_obj_add_event_cb(btn, lv_spinbox_decrement_event_cb, NULL); + lv_obj_add_event_cb(btn, lv_spinbox_decrement_event_cb, LV_EVENT_ALL, NULL); } #endif diff --git a/examples/widgets/switch/lv_example_switch_1.c b/examples/widgets/switch/lv_example_switch_1.c index ff4c848aa..39fd8a7c7 100644 --- a/examples/widgets/switch/lv_example_switch_1.c +++ b/examples/widgets/switch/lv_example_switch_1.c @@ -18,19 +18,19 @@ void lv_example_switch_1(void) lv_obj_t * sw; sw = lv_switch_create(lv_scr_act()); - lv_obj_add_event_cb(sw, event_handler, NULL); + lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL); sw = lv_switch_create(lv_scr_act()); lv_obj_add_state(sw, LV_STATE_CHECKED); - lv_obj_add_event_cb(sw, event_handler, NULL); + lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL); sw = lv_switch_create(lv_scr_act()); lv_obj_add_state(sw, LV_STATE_DISABLED); - lv_obj_add_event_cb(sw, event_handler, NULL); + lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL); sw = lv_switch_create(lv_scr_act()); lv_obj_add_state(sw, LV_STATE_CHECKED | LV_STATE_DISABLED); - lv_obj_add_event_cb(sw, event_handler, NULL); + lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL); } #endif diff --git a/examples/widgets/table/lv_example_table_1.c b/examples/widgets/table/lv_example_table_1.c index 6c9af6fbe..cd2b80a39 100644 --- a/examples/widgets/table/lv_example_table_1.c +++ b/examples/widgets/table/lv_example_table_1.c @@ -1,33 +1,30 @@ #include "../../lv_examples.h" #if LV_USE_TABLE && LV_BUILD_EXAMPLES -static void event_cb(lv_event_t * e) +static void draw_part_event_cb(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_DRAW_PART_BEGIN) { - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); - /*If the cells are drawn...*/ - if(dsc->part == LV_PART_ITEMS) { - uint32_t row = dsc->id / lv_table_get_col_cnt(obj); - uint32_t col = dsc->id - row * lv_table_get_col_cnt(obj); + lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + /*If the cells are drawn...*/ + if(dsc->part == LV_PART_ITEMS) { + uint32_t row = dsc->id / lv_table_get_col_cnt(obj); + uint32_t col = dsc->id - row * lv_table_get_col_cnt(obj); - /*Make the texts in the first cell center aligned*/ - if(row == 0) { - dsc->label_dsc->align = LV_TEXT_ALIGN_CENTER; - dsc->rect_dsc->bg_color = lv_color_mix(lv_color_blue(), dsc->rect_dsc->bg_color, LV_OPA_20); - dsc->rect_dsc->bg_opa = LV_OPA_COVER; - } - /*In the first column align the texts to the right*/ - else if(col == 0) { - dsc->label_dsc->flag = LV_TEXT_ALIGN_RIGHT; - } + /*Make the texts in the first cell center aligned*/ + if(row == 0) { + dsc->label_dsc->align = LV_TEXT_ALIGN_CENTER; + dsc->rect_dsc->bg_color = lv_color_mix(lv_color_blue(), dsc->rect_dsc->bg_color, LV_OPA_20); + dsc->rect_dsc->bg_opa = LV_OPA_COVER; + } + /*In the first column align the texts to the right*/ + else if(col == 0) { + dsc->label_dsc->flag = LV_TEXT_ALIGN_RIGHT; + } - /*MAke every 2nd row grayish*/ - if((row != 0 && row % 2) == 0) { - dsc->rect_dsc->bg_color = lv_color_mix(lv_color_grey(), dsc->rect_dsc->bg_color, LV_OPA_10); - dsc->rect_dsc->bg_opa = LV_OPA_COVER; - } + /*MAke every 2nd row grayish*/ + if((row != 0 && row % 2) == 0) { + dsc->rect_dsc->bg_color = lv_color_mix(lv_color_grey(), dsc->rect_dsc->bg_color, LV_OPA_10); + dsc->rect_dsc->bg_opa = LV_OPA_COVER; } } } @@ -62,7 +59,7 @@ void lv_example_table_1(void) lv_obj_center(table); /*Add an event callback to to apply some custom drawing*/ - lv_obj_add_event_cb(table, event_cb, NULL); + lv_obj_add_event_cb(table, draw_part_event_cb, LV_EVENT_DRAW_PART_BEGIN, NULL); } #endif diff --git a/examples/widgets/table/lv_example_table_2.c b/examples/widgets/table/lv_example_table_2.c index eda42e4bd..86193b314 100644 --- a/examples/widgets/table/lv_example_table_2.c +++ b/examples/widgets/table/lv_example_table_2.c @@ -3,49 +3,49 @@ #define ITEM_CNT 200 -static void event_cb(lv_event_t * e) +static void draw_event_cb(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_DRAW_PART_END) { - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); - /*If the cells are drawn...*/ - if(dsc->part == LV_PART_ITEMS) { - bool chk = lv_table_has_cell_ctrl(obj, dsc->id, 0, LV_TABLE_CELL_CTRL_CUSTOM_1); + lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + /*If the cells are drawn...*/ + if(dsc->part == LV_PART_ITEMS) { + bool chk = lv_table_has_cell_ctrl(obj, dsc->id, 0, LV_TABLE_CELL_CTRL_CUSTOM_1); - lv_draw_rect_dsc_t rect_dsc; - lv_draw_rect_dsc_init(&rect_dsc); - rect_dsc.bg_color = chk ? lv_theme_get_color_primary(obj) : lv_color_grey_lighten_2(); - rect_dsc.radius = LV_RADIUS_CIRCLE; + lv_draw_rect_dsc_t rect_dsc; + lv_draw_rect_dsc_init(&rect_dsc); + rect_dsc.bg_color = chk ? lv_theme_get_color_primary(obj) : lv_color_grey_lighten_2(); + rect_dsc.radius = LV_RADIUS_CIRCLE; - lv_area_t sw_area; - sw_area.x1 = dsc->draw_area->x2 - 50; - sw_area.x2 = sw_area.x1 + 40; - sw_area.y1 = dsc->draw_area->y1 + lv_area_get_height(dsc->draw_area) / 2 - 10; - sw_area.y2 = sw_area.y1 + 20; - lv_draw_rect(&sw_area, dsc->clip_area, &rect_dsc); + lv_area_t sw_area; + sw_area.x1 = dsc->draw_area->x2 - 50; + sw_area.x2 = sw_area.x1 + 40; + sw_area.y1 = dsc->draw_area->y1 + lv_area_get_height(dsc->draw_area) / 2 - 10; + sw_area.y2 = sw_area.y1 + 20; + lv_draw_rect(&sw_area, dsc->clip_area, &rect_dsc); - rect_dsc.bg_color = lv_color_white(); - if(chk) { - sw_area.x2 -= 2; - sw_area.x1 = sw_area.x2 - 16; - } else { - sw_area.x1 += 2; - sw_area.x2 = sw_area.x1 + 16; - } - sw_area.y1 += 2; - sw_area.y2 -= 2; - lv_draw_rect(&sw_area, dsc->clip_area, &rect_dsc); + rect_dsc.bg_color = lv_color_white(); + if(chk) { + sw_area.x2 -= 2; + sw_area.x1 = sw_area.x2 - 16; + } else { + sw_area.x1 += 2; + sw_area.x2 = sw_area.x1 + 16; } + sw_area.y1 += 2; + sw_area.y2 -= 2; + lv_draw_rect(&sw_area, dsc->clip_area, &rect_dsc); } - else if(code == LV_EVENT_VALUE_CHANGED) { - uint16_t col; - uint16_t row; - lv_table_get_selected_cell(obj, &row, &col); - bool chk = lv_table_has_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1); - if(chk) lv_table_clear_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1); - else lv_table_add_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1); - } +} + +static void change_event_cb(lv_event_t * e) +{ + lv_obj_t * obj = lv_event_get_target(e); + uint16_t col; + uint16_t row; + lv_table_get_selected_cell(obj, &row, &col); + bool chk = lv_table_has_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1); + if(chk) lv_table_clear_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1); + else lv_table_add_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1); } @@ -80,7 +80,8 @@ void lv_example_table_2(void) lv_obj_align(table, LV_ALIGN_CENTER, 0, -20); /*Add an event callback to to apply some custom drawing*/ - lv_obj_add_event_cb(table, event_cb, NULL); + lv_obj_add_event_cb(table, draw_event_cb, LV_EVENT_DRAW_PART_BEGIN, NULL); + lv_obj_add_event_cb(table, change_event_cb, LV_EVENT_VALUE_CHANGED, NULL); lv_mem_monitor_t mon2; lv_mem_monitor(&mon2); diff --git a/examples/widgets/textarea/lv_example_textarea_1.c b/examples/widgets/textarea/lv_example_textarea_1.c index 232fbb134..f5939790a 100644 --- a/examples/widgets/textarea/lv_example_textarea_1.c +++ b/examples/widgets/textarea/lv_example_textarea_1.c @@ -4,17 +4,14 @@ static void btnm_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_VALUE_CHANGED) { - lv_obj_t * ta = lv_event_get_user_data(e); - const char * txt = lv_btnmatrix_get_btn_text(obj, lv_btnmatrix_get_selected_btn(obj)); + lv_obj_t * ta = lv_event_get_user_data(e); + const char * txt = lv_btnmatrix_get_btn_text(obj, lv_btnmatrix_get_selected_btn(obj)); - if(strcmp(txt, LV_SYMBOL_BACKSPACE) == 0) lv_textarea_del_char(ta); - else if(strcmp(txt, LV_SYMBOL_NEW_LINE) == 0) lv_textarea_add_char(ta, '\n'); - else lv_textarea_add_text(ta, txt); + if(strcmp(txt, LV_SYMBOL_BACKSPACE) == 0) lv_textarea_del_char(ta); + else if(strcmp(txt, LV_SYMBOL_NEW_LINE) == 0) lv_textarea_add_char(ta, '\n'); + else lv_textarea_add_text(ta, txt); - } } void lv_example_textarea_1(void) @@ -32,7 +29,7 @@ void lv_example_textarea_1(void) lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act()); lv_obj_set_size(btnm, 200, 150); lv_obj_align(btnm, LV_ALIGN_BOTTOM_MID, 0, -10); - lv_obj_add_event_cb(btnm, btnm_event_handler, ta); + lv_obj_add_event_cb(btnm, btnm_event_handler, LV_EVENT_VALUE_CHANGED, ta); lv_obj_clear_flag(btnm, LV_OBJ_FLAG_CLICK_FOCUSABLE); /*To keep the text area focused on button clicks*/ lv_btnmatrix_set_map(btnm, btnm_map); } diff --git a/examples/widgets/textarea/lv_example_textarea_2.c b/examples/widgets/textarea/lv_example_textarea_2.c index 40bdcc713..44749fa41 100644 --- a/examples/widgets/textarea/lv_example_textarea_2.c +++ b/examples/widgets/textarea/lv_example_textarea_2.c @@ -14,7 +14,7 @@ void lv_example_textarea_2(void) lv_textarea_set_one_line(pwd_ta, true); lv_obj_set_width(pwd_ta, LV_HOR_RES / 2 - 20); lv_obj_set_pos(pwd_ta, 5, 20); - lv_obj_add_event_cb(pwd_ta, ta_event_cb, NULL); + lv_obj_add_event_cb(pwd_ta, ta_event_cb, LV_EVENT_ALL, NULL); /*Create a label and position it above the text box*/ lv_obj_t * pwd_label = lv_label_create(lv_scr_act()); diff --git a/examples/widgets/textarea/lv_example_textarea_3.c b/examples/widgets/textarea/lv_example_textarea_3.c index 5bfc0b838..21cb31bb1 100644 --- a/examples/widgets/textarea/lv_example_textarea_3.c +++ b/examples/widgets/textarea/lv_example_textarea_3.c @@ -13,7 +13,7 @@ void lv_example_textarea_3(void) { /*Create the text area*/ lv_obj_t * ta = lv_textarea_create(lv_scr_act()); - lv_obj_add_event_cb(ta, ta_event_cb, NULL); + lv_obj_add_event_cb(ta, ta_event_cb, LV_EVENT_VALUE_CHANGED, NULL); lv_textarea_set_accepted_chars(ta, "0123456789:"); lv_textarea_set_max_length(ta, 5); lv_textarea_set_one_line(ta, true); @@ -28,17 +28,14 @@ void lv_example_textarea_3(void) static void ta_event_cb(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); lv_obj_t * ta = lv_event_get_target(e); - if(code == LV_EVENT_VALUE_CHANGED) { - const char * txt = lv_textarea_get_text(ta); - if(txt[0] >= '0' && txt[0] <= '9' && - txt[1] >= '0' && txt[1] <= '9' && - txt[2] != ':') - { - lv_textarea_set_cursor_pos(ta, 2); - lv_textarea_add_char(ta, ':'); - } + const char * txt = lv_textarea_get_text(ta); + if(txt[0] >= '0' && txt[0] <= '9' && + txt[1] >= '0' && txt[1] <= '9' && + txt[2] != ':') + { + lv_textarea_set_cursor_pos(ta, 2); + lv_textarea_add_char(ta, ':'); } } diff --git a/src/core/lv_obj.c b/src/core/lv_obj.c index c28348e6f..96d73f875 100644 --- a/src/core/lv_obj.c +++ b/src/core/lv_obj.c @@ -51,6 +51,7 @@ typedef struct _lv_event_temp_data { typedef struct _lv_event_dsc_t{ lv_event_cb_t cb; void * user_data; + lv_event_code_t filter :8; }lv_event_dsc_t; /********************** @@ -361,7 +362,7 @@ void lv_obj_clear_state(lv_obj_t * obj, lv_state_t state) } } -struct _lv_event_dsc_t * lv_obj_add_event_cb(lv_obj_t * obj, lv_event_cb_t event_cb, void * user_data) +struct _lv_event_dsc_t * lv_obj_add_event_cb(lv_obj_t * obj, lv_event_cb_t event_cb, lv_event_code_t filter, void * user_data) { LV_ASSERT_OBJ(obj, MY_CLASS); lv_obj_allocate_spec_attr(obj); @@ -371,6 +372,7 @@ struct _lv_event_dsc_t * lv_obj_add_event_cb(lv_obj_t * obj, lv_event_cb_t event LV_ASSERT_MALLOC(obj->spec_attr->event_dsc); obj->spec_attr->event_dsc[obj->spec_attr->event_dsc_cnt - 1].cb = event_cb; + obj->spec_attr->event_dsc[obj->spec_attr->event_dsc_cnt - 1].filter = filter; obj->spec_attr->event_dsc[obj->spec_attr->event_dsc_cnt - 1].user_data = user_data; return &obj->spec_attr->event_dsc[obj->spec_attr->event_dsc_cnt - 1]; @@ -1100,7 +1102,7 @@ static lv_res_t event_send_core(lv_obj_t * obj, lv_event_code_t event_code, void uint32_t i = 0; while(event_dsc && res == LV_RES_OK) { - if(event_dsc->cb) { + if(event_dsc->cb && (event_dsc->filter == LV_EVENT_ALL || event_dsc->filter == event_code)) { void * event_act_user_data_cb_save = event_act_user_data_cb; event_act_user_data_cb = event_dsc->user_data; diff --git a/src/core/lv_obj.h b/src/core/lv_obj.h index 94dc59bca..4a3e22eb7 100644 --- a/src/core/lv_obj.h +++ b/src/core/lv_obj.h @@ -44,6 +44,8 @@ struct _lv_event_dsc_t; * Type of event being sent to the object. */ typedef enum { + LV_EVENT_ALL = 0, + /** Input device events*/ LV_EVENT_PRESSED, /**< The object has been pressed*/ LV_EVENT_PRESSING, /**< The object is being pressed (called continuously while pressing)*/ @@ -388,11 +390,12 @@ void lv_obj_clear_state(lv_obj_t * obj, lv_state_t state); * Used by the user to react on event which happens with the object. * An object can have multiple event handler. They will be called in the same order as they were added. * @param obj pointer to an object + * @param filter and event code (e.g. `LV_EVENT_CLICKED`) on which the event should be called. `LV_EVENT_ALL` can be sued the receive all the events. * @param event_cb the new event function * @param user_data custom data data will be available in `event_cb` * @return a pointer the event descriptor. Can be used in ::lv_obj_remove_event_dsc */ -struct _lv_event_dsc_t * lv_obj_add_event_cb(lv_obj_t * obj, lv_event_cb_t event_cb, void * user_data); +struct _lv_event_dsc_t * lv_obj_add_event_cb(lv_obj_t * obj, lv_event_cb_t event_cb, lv_event_code_t filter, void * user_data); /** * Remove an event handler function for an object. diff --git a/src/extra/themes/default/lv_theme_default.c b/src/extra/themes/default/lv_theme_default.c index 4e77f460c..6b38d4169 100644 --- a/src/extra/themes/default/lv_theme_default.c +++ b/src/extra/themes/default/lv_theme_default.c @@ -32,7 +32,7 @@ static lv_color_t color_secondary_muted; #define TRANSITION_TIME LV_THEME_DEFAULT_TRANSITON_TIME #define BORDER_WIDTH LV_DPX(2) -#define OUTLINE_WIDTH LV_DPX(4) +#define OUTLINE_WIDTH LV_DPX(3) #define PAD_DEF (disp_size == DISP_LARGE ? LV_DPX(24) : disp_size == DISP_MEDIUM ? LV_DPX(20) : LV_DPX(20)) #define PAD_SMALL (disp_size == DISP_LARGE ? LV_DPX(14) : disp_size == DISP_MEDIUM ? LV_DPX(12) : LV_DPX(12)) diff --git a/src/extra/widgets/calendar/lv_calendar.c b/src/extra/widgets/calendar/lv_calendar.c index 58d0ff2d4..5b4095d67 100644 --- a/src/extra/widgets/calendar/lv_calendar.c +++ b/src/extra/widgets/calendar/lv_calendar.c @@ -23,8 +23,8 @@ /********************** * STATIC PROTOTYPES **********************/ -static void my_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj); -static void draw_event_cb(lv_event_t * e); +static void lv_calendar_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj); +static void draw_part_begin_event_cb(lv_event_t * e); static uint8_t get_day_of_week(uint32_t year, uint32_t month, uint32_t day); static uint8_t get_month_length(int32_t year, int32_t month); @@ -35,7 +35,7 @@ static void highlight_update(lv_obj_t * calendar); * STATIC VARIABLES **********************/ const lv_obj_class_t lv_calendar_class = { - .constructor_cb = my_constructor, + .constructor_cb = lv_calendar_constructor, .width_def = (LV_DPI_DEF * 3) / 2, .height_def =(LV_DPI_DEF * 3) / 2, .instance_size = sizeof(lv_calendar_t), @@ -206,7 +206,7 @@ bool lv_calendar_get_pressed_date(const lv_obj_t * obj, lv_calendar_date_t * dat * STATIC FUNCTIONS **********************/ -static void my_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) +static void lv_calendar_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) { LV_UNUSED(class_p); lv_calendar_t * calendar = (lv_calendar_t *)obj; @@ -247,44 +247,41 @@ static void my_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) lv_calendar_set_showed_date(obj, calendar->showed_date.year, calendar->showed_date.month); lv_calendar_set_today_date(obj, calendar->today.year, calendar->today.month, calendar->today.day); - lv_obj_add_event_cb(obj, draw_event_cb, NULL); + lv_obj_add_event_cb(obj, draw_part_begin_event_cb, LV_EVENT_DRAW_PART_BEGIN, NULL); } -static void draw_event_cb(lv_event_t * e) +static void draw_part_begin_event_cb(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_DRAW_PART_BEGIN) { - lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); - if(dsc->part == LV_PART_ITEMS) { - /*Day name styles*/ - if(dsc->id < 7) { - dsc->rect_dsc->bg_opa = LV_OPA_TRANSP; - dsc->rect_dsc->border_opa = LV_OPA_TRANSP; - } - else if(lv_btnmatrix_has_btn_ctrl(obj, dsc->id, LV_BTNMATRIX_CTRL_DISABLED)) { - dsc->rect_dsc->bg_opa = LV_OPA_TRANSP; - dsc->rect_dsc->border_opa = LV_OPA_TRANSP; - dsc->label_dsc->color = lv_color_grey(); - } - - if(lv_btnmatrix_has_btn_ctrl(obj, dsc->id, LV_CALENDAR_CTRL_HIGHLIGHT)) { - dsc->rect_dsc->bg_opa = LV_OPA_40; - dsc->rect_dsc->bg_color = lv_theme_get_color_primary(obj); - if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) { - dsc->rect_dsc->bg_opa = LV_OPA_70; - } - } - - if(lv_btnmatrix_has_btn_ctrl(obj, dsc->id, LV_CALENDAR_CTRL_TODAY)) { - dsc->rect_dsc->border_opa = LV_OPA_COVER; - dsc->rect_dsc->border_color = lv_theme_get_color_primary(obj); - dsc->rect_dsc->border_width += 1; - } - + lv_obj_draw_dsc_t * dsc = lv_event_get_param(e); + if(dsc->part == LV_PART_ITEMS) { + /*Day name styles*/ + if(dsc->id < 7) { + dsc->rect_dsc->bg_opa = LV_OPA_TRANSP; + dsc->rect_dsc->border_opa = LV_OPA_TRANSP; } + else if(lv_btnmatrix_has_btn_ctrl(obj, dsc->id, LV_BTNMATRIX_CTRL_DISABLED)) { + dsc->rect_dsc->bg_opa = LV_OPA_TRANSP; + dsc->rect_dsc->border_opa = LV_OPA_TRANSP; + dsc->label_dsc->color = lv_color_grey(); + } + + if(lv_btnmatrix_has_btn_ctrl(obj, dsc->id, LV_CALENDAR_CTRL_HIGHLIGHT)) { + dsc->rect_dsc->bg_opa = LV_OPA_40; + dsc->rect_dsc->bg_color = lv_theme_get_color_primary(obj); + if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) { + dsc->rect_dsc->bg_opa = LV_OPA_70; + } + } + + if(lv_btnmatrix_has_btn_ctrl(obj, dsc->id, LV_CALENDAR_CTRL_TODAY)) { + dsc->rect_dsc->border_opa = LV_OPA_COVER; + dsc->rect_dsc->border_color = lv_theme_get_color_primary(obj); + dsc->rect_dsc->border_width += 1; + } + } } diff --git a/src/extra/widgets/calendar/lv_calendar_header_arrow.c b/src/extra/widgets/calendar/lv_calendar_header_arrow.c index 20e13b7ea..6a7a64471 100644 --- a/src/extra/widgets/calendar/lv_calendar_header_arrow.c +++ b/src/extra/widgets/calendar/lv_calendar_header_arrow.c @@ -62,7 +62,7 @@ lv_obj_t * lv_calendar_header_arrow_create(lv_obj_t * parent, lv_obj_t * calenda lv_obj_t * mo_prev = lv_btn_create(header); lv_obj_set_style_bg_img_src(mo_prev, LV_SYMBOL_LEFT, 0); lv_obj_set_size(mo_prev, btn_size, btn_size); - lv_obj_add_event_cb(mo_prev, month_event_cb, calendar); + lv_obj_add_event_cb(mo_prev, month_event_cb, LV_EVENT_CLICKED, calendar); lv_obj_clear_flag(mo_prev, LV_OBJ_FLAG_CLICK_FOCUSABLE); lv_obj_t * label = lv_label_create(header); @@ -74,7 +74,7 @@ lv_obj_t * lv_calendar_header_arrow_create(lv_obj_t * parent, lv_obj_t * calenda lv_obj_t * mo_next = lv_btn_create(header); lv_obj_set_style_bg_img_src(mo_next, LV_SYMBOL_RIGHT, 0); lv_obj_set_size(mo_next, btn_size, btn_size); - lv_obj_add_event_cb(mo_next, month_event_cb, calendar); + lv_obj_add_event_cb(mo_next, month_event_cb, LV_EVENT_CLICKED, calendar); lv_obj_clear_flag(mo_next, LV_OBJ_FLAG_CLICK_FOCUSABLE); lv_obj_align_to(header, calendar, LV_ALIGN_OUT_TOP_MID, 0, 0); @@ -88,12 +88,8 @@ lv_obj_t * lv_calendar_header_arrow_create(lv_obj_t * parent, lv_obj_t * calenda static void month_event_cb(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); lv_obj_t * btn = lv_event_get_target(e); - if(code != LV_EVENT_CLICKED) return; - - lv_obj_t * header = lv_obj_get_parent(btn); lv_obj_t * calendar = lv_event_get_user_data(e); diff --git a/src/extra/widgets/calendar/lv_calendar_header_dropdown.c b/src/extra/widgets/calendar/lv_calendar_header_dropdown.c index c70371ff2..90b04b7b7 100644 --- a/src/extra/widgets/calendar/lv_calendar_header_dropdown.c +++ b/src/extra/widgets/calendar/lv_calendar_header_dropdown.c @@ -71,13 +71,13 @@ lv_obj_t * lv_calendar_header_dropdown_create(lv_obj_t * parent, lv_obj_t * cale lv_obj_t * year_dd = lv_dropdown_create(header); lv_dropdown_set_options(year_dd, year_list); lv_dropdown_set_selected(year_dd, 2023 - cur_date->year); - lv_obj_add_event_cb(year_dd, year_event_cb, calendar); + lv_obj_add_event_cb(year_dd, year_event_cb, LV_EVENT_VALUE_CHANGED, calendar); lv_obj_set_flex_grow(year_dd, 1); lv_obj_t * month_dd = lv_dropdown_create(header); lv_dropdown_set_options(month_dd, month_list); lv_dropdown_set_selected(month_dd, cur_date->month - 1); - lv_obj_add_event_cb(month_dd, month_event_cb, calendar); + lv_obj_add_event_cb(month_dd, month_event_cb, LV_EVENT_VALUE_CHANGED, calendar); lv_obj_set_flex_grow(month_dd, 1); lv_obj_align_to(header, calendar, LV_ALIGN_OUT_TOP_MID, 0, 0); @@ -91,9 +91,6 @@ lv_obj_t * lv_calendar_header_dropdown_create(lv_obj_t * parent, lv_obj_t * cale static void month_event_cb(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); - if(code != LV_EVENT_VALUE_CHANGED) return; - lv_obj_t * dropdown = lv_event_get_target(e); lv_obj_t * calendar = lv_event_get_user_data(e); @@ -108,9 +105,6 @@ static void month_event_cb(lv_event_t * e) } static void year_event_cb(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); - if(code != LV_EVENT_VALUE_CHANGED) return; - lv_obj_t * dropdown = lv_event_get_target(e); lv_obj_t * calendar = lv_event_get_user_data(e); diff --git a/src/extra/widgets/keyboard/lv_keyboard.c b/src/extra/widgets/keyboard/lv_keyboard.c index 1f8433079..f0877def3 100644 --- a/src/extra/widgets/keyboard/lv_keyboard.c +++ b/src/extra/widgets/keyboard/lv_keyboard.c @@ -222,15 +222,11 @@ lv_keyboard_mode_t lv_keyboard_get_mode(const lv_obj_t * obj) */ void lv_keyboard_def_event_cb(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_VALUE_CHANGED) return; lv_keyboard_t * keyboard = (lv_keyboard_t *)obj; uint16_t btn_id = lv_btnmatrix_get_selected_btn(obj); if(btn_id == LV_BTNMATRIX_BTN_NONE) return; - if(lv_btnmatrix_has_btn_ctrl(obj, btn_id, LV_BTNMATRIX_CTRL_HIDDEN | LV_BTNMATRIX_CTRL_DISABLED)) return; - if(lv_btnmatrix_has_btn_ctrl(obj, btn_id, LV_BTNMATRIX_CTRL_NO_REPEAT) && code == LV_EVENT_LONG_PRESSED_REPEAT) return; const char * txt = lv_btnmatrix_get_btn_text(obj, lv_btnmatrix_get_selected_btn(obj)); if(txt == NULL) return; @@ -332,7 +328,7 @@ static void lv_keyboard_constructor(const lv_obj_class_t * class_p, lv_obj_t * o keyboard->mode = LV_KEYBOARD_MODE_TEXT_LOWER; lv_obj_align(obj, LV_ALIGN_BOTTOM_MID, 0, 0); - lv_obj_add_event_cb(obj, lv_keyboard_def_event_cb, NULL); + lv_obj_add_event_cb(obj, lv_keyboard_def_event_cb, LV_EVENT_VALUE_CHANGED, NULL); lv_obj_set_base_dir(obj, LV_BIDI_DIR_LTR); lv_btnmatrix_set_map(obj, kb_map[keyboard->mode]); diff --git a/src/extra/widgets/list/lv_list.c b/src/extra/widgets/list/lv_list.c index cbba06563..b34315420 100644 --- a/src/extra/widgets/list/lv_list.c +++ b/src/extra/widgets/list/lv_list.c @@ -74,7 +74,7 @@ lv_obj_t * lv_list_add_btn(lv_obj_t * list, const char * icon, const char * txt, { lv_obj_t * btn = lv_obj_create_from_class(&lv_list_btn_class, list); lv_obj_set_size(btn, LV_PCT(100), LV_SIZE_CONTENT); - lv_obj_add_event_cb(btn, event_cb, NULL); + lv_obj_add_event_cb(btn, event_cb, LV_EVENT_ALL, NULL); if(icon) { lv_obj_t * img = lv_img_create(btn); diff --git a/src/extra/widgets/msgbox/lv_msgbox.c b/src/extra/widgets/msgbox/lv_msgbox.c index 8237fad90..f452b9779 100644 --- a/src/extra/widgets/msgbox/lv_msgbox.c +++ b/src/extra/widgets/msgbox/lv_msgbox.c @@ -21,7 +21,7 @@ /********************** * STATIC PROTOTYPES **********************/ -static void msgbox_close_event_cb(lv_event_t * e); +static void msgbox_close_click_event_cb(lv_event_t * e); /********************** * STATIC VARIABLES @@ -70,7 +70,7 @@ lv_obj_t * lv_msgbox_create(const char * title, const char * txt, const char * b if(add_close_btn) { lv_obj_t * close_btn = lv_btn_create(mbox); lv_obj_set_ext_click_area(close_btn, LV_DPX(10)); - lv_obj_add_event_cb(close_btn, msgbox_close_event_cb, NULL); + lv_obj_add_event_cb(close_btn, msgbox_close_click_event_cb, LV_EVENT_CLICKED, NULL); label = lv_label_create(close_btn); lv_label_set_text(label, LV_SYMBOL_CLOSE); lv_coord_t close_btn_size = LV_MAX(lv_obj_get_width(label), lv_obj_get_height(label)) + LV_DPX(10); @@ -138,14 +138,11 @@ void lv_msgbox_close(lv_obj_t * mbox) * STATIC FUNCTIONS **********************/ -static void msgbox_close_event_cb(lv_event_t * e) +static void msgbox_close_click_event_cb(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); lv_obj_t * btn = lv_event_get_target(e); - if(code == LV_EVENT_CLICKED) { - lv_obj_t * mbox = lv_obj_get_parent(btn); - lv_msgbox_close(mbox); - } + lv_obj_t * mbox = lv_obj_get_parent(btn); + lv_msgbox_close(mbox); } #endif /*LV_USE_MSGBOX*/ diff --git a/src/extra/widgets/tabview/lv_tabview.c b/src/extra/widgets/tabview/lv_tabview.c index 7c617441c..8acc34329 100644 --- a/src/extra/widgets/tabview/lv_tabview.c +++ b/src/extra/widgets/tabview/lv_tabview.c @@ -22,8 +22,8 @@ **********************/ static void lv_tabview_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj); static void lv_tabview_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj); -static void btns_event_cb(lv_event_t * e); -static void cont_event_cb(lv_event_t * e); +static void btns_value_changed_event_cb(lv_event_t * e); +static void cont_scroll_end_event_cb(lv_event_t * e); /********************** * STATIC VARIABLES @@ -180,10 +180,10 @@ static void lv_tabview_constructor(const lv_obj_class_t * class_p, lv_obj_t * ob tabview->map = lv_mem_alloc(sizeof(const char *)); tabview->map[0] = ""; lv_btnmatrix_set_map(btnm, (const char **)tabview->map); - lv_obj_add_event_cb(btnm, btns_event_cb, NULL); + lv_obj_add_event_cb(btnm, btns_value_changed_event_cb, LV_EVENT_VALUE_CHANGED, NULL); lv_obj_add_flag(btnm, LV_OBJ_FLAG_EVENT_BUBBLE); - lv_obj_add_event_cb(cont, cont_event_cb, NULL); + lv_obj_add_event_cb(cont, cont_scroll_end_event_cb, LV_EVENT_SCROLL_END, NULL); lv_obj_set_scrollbar_mode(cont, LV_SCROLLBAR_MODE_OFF); switch(tabview->tab_pos) { @@ -228,32 +228,26 @@ static void lv_tabview_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj tabview->map = NULL; } -static void btns_event_cb(lv_event_t * e) +static void btns_value_changed_event_cb(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); lv_obj_t * btns = lv_event_get_target(e); - if(code == LV_EVENT_VALUE_CHANGED) { - lv_obj_t * tv = lv_obj_get_parent(btns); - uint32_t id = lv_btnmatrix_get_selected_btn(btns); - lv_tabview_set_act(tv, id, LV_ANIM_ON); - } + lv_obj_t * tv = lv_obj_get_parent(btns); + uint32_t id = lv_btnmatrix_get_selected_btn(btns); + lv_tabview_set_act(tv, id, LV_ANIM_ON); } -static void cont_event_cb(lv_event_t * e) +static void cont_scroll_end_event_cb(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); lv_obj_t * cont = lv_event_get_target(e); - if(code == LV_EVENT_SCROLL_END) { - lv_obj_t * tv = lv_obj_get_parent(cont); + lv_obj_t * tv = lv_obj_get_parent(cont); - lv_point_t p; - lv_obj_get_scroll_end(cont, &p); + lv_point_t p; + lv_obj_get_scroll_end(cont, &p); - lv_coord_t w = lv_obj_get_width_fit(cont); - lv_coord_t t = (p.x + w/ 2) / w; - if(t < 0) t = 0; - lv_tabview_set_act(tv, t, LV_ANIM_ON); - } + lv_coord_t w = lv_obj_get_width_fit(cont); + lv_coord_t t = (p.x + w/ 2) / w; + if(t < 0) t = 0; + lv_tabview_set_act(tv, t, LV_ANIM_ON); } #endif /*LV_USE_TABVIEW*/ diff --git a/src/extra/widgets/tileview/lv_tileview.c b/src/extra/widgets/tileview/lv_tileview.c index c7b36ea7e..ba45b5e2c 100644 --- a/src/extra/widgets/tileview/lv_tileview.c +++ b/src/extra/widgets/tileview/lv_tileview.c @@ -105,7 +105,7 @@ static void lv_tileview_constructor(const lv_obj_class_t * class_p, lv_obj_t * o { LV_UNUSED(class_p); lv_obj_set_size(obj, LV_PCT(100), LV_PCT(100)); - lv_obj_add_event_cb(obj, tileview_event_cb, NULL); + lv_obj_add_event_cb(obj, tileview_event_cb, LV_EVENT_ALL, NULL); lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ONE); lv_obj_set_scroll_snap_x(obj, LV_SCROLL_SNAP_CENTER); lv_obj_set_scroll_snap_y(obj, LV_SCROLL_SNAP_CENTER); diff --git a/src/extra/widgets/win/lv_win.c b/src/extra/widgets/win/lv_win.c index 9c8a37294..d44cddb8a 100644 --- a/src/extra/widgets/win/lv_win.c +++ b/src/extra/widgets/win/lv_win.c @@ -63,7 +63,7 @@ lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * icon, lv_coord_t btn_w, l lv_obj_t * header = lv_win_get_header(win); lv_obj_t * btn = lv_btn_create(header); lv_obj_set_size(btn, btn_w, LV_PCT(100)); - lv_obj_add_event_cb(btn, event_cb, NULL); + lv_obj_add_event_cb(btn, event_cb, LV_EVENT_ALL, NULL); lv_obj_t * img = lv_img_create(btn); lv_img_set_src(img, icon); diff --git a/src/misc/lv_color.h b/src/misc/lv_color.h index 1a3f788cf..7114b3aa9 100644 --- a/src/misc/lv_color.h +++ b/src/misc/lv_color.h @@ -276,7 +276,6 @@ typedef struct _lv_color_filter_dsc_t { typedef enum { - LV_COLOR_PALETTE_NONE, LV_COLOR_PALETTE_RED, LV_COLOR_PALETTE_PINK, LV_COLOR_PALETTE_PURPLE, @@ -296,7 +295,8 @@ typedef enum { LV_COLOR_PALETTE_BROWN, LV_COLOR_PALETTE_BLUE_GREY, LV_COLOR_PALETTE_GREY, - _LV_COLOR_PALETTE_LAST + _LV_COLOR_PALETTE_LAST, + LV_COLOR_PALETTE_NONE = 0xff, }lv_color_palette_t; /**********************