feat(event) add lv_event_get_indev/clip_area/draw_part_dsc

This commit is contained in:
Gabor Kiss-Vamosi
2021-05-12 12:49:32 +02:00
parent 1b38632b6f
commit 75d1c05a23
11 changed files with 87 additions and 10 deletions

View File

@@ -8,7 +8,7 @@ static void set_value(void *bar, int32_t v)
static void event_cb(lv_event_t * e)
{
lv_obj_draw_dsc_t * dsc = lv_event_get_param(e);
lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e);
if(dsc->part != LV_PART_INDICATOR) return;
lv_obj_t * obj= lv_event_get_target(e);

View File

@@ -7,7 +7,7 @@ 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_DRAW_PART_BEGIN) {
lv_obj_draw_dsc_t * dsc = lv_event_get_param(e);
lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e);
/*Change the draw descriptor the 2nd button*/
if(dsc->id == 1) {
@@ -34,7 +34,7 @@ static void event_cb(lv_event_t * e)
}
}
if(code == LV_EVENT_DRAW_PART_END) {
lv_obj_draw_dsc_t * dsc = lv_event_get_param(e);
lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e);
/*Add custom content to the 4th button when the button itself was drawn*/
if(dsc->id == 3) {

View File

@@ -10,7 +10,7 @@ static void draw_event_cb(lv_event_t * e)
lv_obj_t * obj = lv_event_get_target(e);
/*Add the faded area before the lines are drawn*/
lv_obj_draw_dsc_t * dsc = lv_event_get_param(e);
lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e);
if(dsc->part == LV_PART_ITEMS) {
if(!dsc->p1 || !dsc->p2) return;

View File

@@ -3,7 +3,7 @@
static void draw_event_cb(lv_event_t * e)
{
lv_obj_draw_dsc_t * dsc = lv_event_get_param(e);
lv_obj_draw_part_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]);

View File

@@ -45,7 +45,7 @@ static void event_cb(lv_event_t * e)
a.y1 = chart->coords.y1 + p.y - 30;
a.y2 = chart->coords.y1 + p.y - 10;
const lv_area_t * clip_area = lv_event_get_param(e);
const lv_area_t * clip_area = lv_event_get_clip_area(e);
lv_draw_rect(&a, clip_area, &draw_rect_dsc);
ser = lv_chart_get_series_next(chart, ser);

View File

@@ -20,7 +20,7 @@ static void event_cb(lv_event_t * e)
}
}
else if(code == LV_EVENT_DRAW_PART_END) {
lv_obj_draw_dsc_t * dsc = lv_event_get_param(e);
lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e);
if(dsc->part == LV_PART_CURSOR && dsc->p1 && dsc->p2 && dsc->p1->y == dsc->p2->y && last_id >= 0) {
lv_coord_t * data_array = lv_chart_get_array(chart, ser);
lv_coord_t v = data_array[last_id];

View File

@@ -33,7 +33,7 @@ static void slider_event_cb(lv_event_t * e)
*size = LV_MAX(*size, 50);
}
else if(code == LV_EVENT_DRAW_PART_END) {
lv_obj_draw_dsc_t * dsc = lv_event_get_param(e);
lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e);
if(dsc->part == LV_PART_INDICATOR) {
char buf[16];
lv_snprintf(buf, sizeof(buf), "%d - %d", lv_slider_get_left_value(obj), lv_slider_get_value(obj));

View File

@@ -4,7 +4,7 @@
static void draw_part_event_cb(lv_event_t * e)
{
lv_obj_t * obj = lv_event_get_target(e);
lv_obj_draw_dsc_t * dsc = lv_event_get_param(e);
lv_obj_draw_part_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);

View File

@@ -6,7 +6,7 @@
static void draw_event_cb(lv_event_t * e)
{
lv_obj_t * obj = lv_event_get_target(e);
lv_obj_draw_dsc_t * dsc = lv_event_get_param(e);
lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(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);

View File

@@ -212,6 +212,61 @@ bool lv_obj_remove_event_dsc(lv_obj_t * obj, struct _lv_event_dsc_t * event_dsc)
return false;
}
lv_indev_t * lv_event_get_indev(lv_event_t * e)
{
if(e->code == LV_EVENT_PRESSED ||
e->code == LV_EVENT_PRESSING ||
e->code == LV_EVENT_PRESS_LOST ||
e->code == LV_EVENT_SHORT_CLICKED ||
e->code == LV_EVENT_LONG_PRESSED ||
e->code == LV_EVENT_LONG_PRESSED_REPEAT ||
e->code == LV_EVENT_CLICKED ||
e->code == LV_EVENT_RELEASED ||
e->code == LV_EVENT_SCROLL_BEGIN ||
e->code == LV_EVENT_SCROLL_END ||
e->code == LV_EVENT_SCROLL ||
e->code == LV_EVENT_GESTURE ||
e->code == LV_EVENT_KEY ||
e->code == LV_EVENT_FOCUSED ||
e->code == LV_EVENT_DEFOCUSED ||
e->code == LV_EVENT_LEAVE)
{
return lv_event_get_param(e);
} else {
LV_LOG_WARN("Not interpreted with this event code");
return NULL;
}
}
lv_obj_draw_part_dsc_t * lv_event_get_draw_part_dsc(lv_event_t * e)
{
if(e->code == LV_EVENT_DRAW_PART_BEGIN||
e->code == LV_EVENT_DRAW_PART_END)
{
return lv_event_get_param(e);
} else {
LV_LOG_WARN("Not interpreted with this event code");
return NULL;
}
}
const lv_area_t * lv_event_get_clip_area(lv_event_t * e)
{
if(e->code == LV_EVENT_DRAW_MAIN ||
e->code == LV_EVENT_DRAW_MAIN_BEGIN ||
e->code == LV_EVENT_DRAW_MAIN_END ||
e->code == LV_EVENT_DRAW_POST ||
e->code == LV_EVENT_DRAW_POST_BEGIN ||
e->code == LV_EVENT_DRAW_POST_END)
{
return lv_event_get_param(e);
} else {
LV_LOG_WARN("Not interpreted with this event code");
return NULL;
}
}
/**********************
* STATIC FUNCTIONS

View File

@@ -206,6 +206,28 @@ bool lv_obj_remove_event_cb(struct _lv_obj_t * obj, lv_event_cb_t event_cb);
*/
bool lv_obj_remove_event_dsc(struct _lv_obj_t * obj, struct _lv_event_dsc_t * event_dsc);
/**
* Get the input device passed as parameter to indev related events.
* @param e pointer to an event
* @return the indev that triggered the event or NULL if called on a not indev related event
*/
lv_indev_t * lv_event_get_indev(lv_event_t * e);
/**
* Get the part draw descriptor passed as parameter to `LV_EVENT_DRAW_PART_BEGIN/END`.
* @param e pointer to an event
* @return the part draw descriptor to hook the drawing or NULL if called on an unrelated event
*/
lv_obj_draw_part_dsc_t * lv_event_get_draw_part_dsc(lv_event_t * e);
/**
* Get the clip area passed as parameter to draw events events.
* Namely: `LV_EVENT_DRAW_MAIN/POST`, `LV_EVENT_DRAW_MAIN/POST_BEGIN`, `LV_EVENT_DRAW_MAIN/POST_END`
* @param e pointer to an event
* @return the clip area to use during drawing or NULL if called on an unrelated event
*/
const lv_area_t * lv_event_get_clip_area(lv_event_t * e);
/**********************
* MACROS
**********************/