feat(event) add event filter to lv_event_send
This commit is contained in:
@@ -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*/
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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, ':');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user