From a676590e30e6f8b576097b0707f0ffdd0233a8b8 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 24 Feb 2018 11:55:39 +0100 Subject: [PATCH] add group focus callback and invalid area rounding callback option --- lv_core/lv_group.c | 42 ++++++++++++++++++++++++++++++++++++++---- lv_core/lv_group.h | 42 ++++++++++++++++++++++++++++++++++-------- lv_core/lv_refr.c | 25 +++++++++++++------------ lv_core/lv_refr.h | 7 +++++++ lv_objx/lv_img.c | 5 ++--- 5 files changed, 94 insertions(+), 27 deletions(-) diff --git a/lv_core/lv_group.c b/lv_core/lv_group.c index a7a424534..cfa40c2c7 100644 --- a/lv_core/lv_group.c +++ b/lv_core/lv_group.c @@ -158,6 +158,8 @@ void lv_group_focus_next(lv_group_t * group) if(group->obj_focus){ (*group->obj_focus)->signal_func(*group->obj_focus, LV_SIGNAL_FOCUS, NULL); lv_obj_invalidate(*group->obj_focus); + + if(group->focus_cb) group->focus_cb(group); } } @@ -184,6 +186,8 @@ void lv_group_focus_prev(lv_group_t * group) if(group->obj_focus != NULL){ (*group->obj_focus)->signal_func(*group->obj_focus, LV_SIGNAL_FOCUS, NULL); lv_obj_invalidate(*group->obj_focus); + + if(group->focus_cb) group->focus_cb(group); } } @@ -212,18 +216,28 @@ void lv_group_send_data(lv_group_t * group, uint32_t c) act->signal_func(act, LV_SIGNAL_CONTROLL, &c); } - /** * Set a function for a group which will modify the object's style if it is in focus * @param group pointer to a group - * @param style_cb the style modifier function pointer + * @param style_mod_func the style modifier function pointer */ -void lv_group_set_style_mod_cb(lv_group_t * group, void (*style_cb)(lv_style_t * style)) +void lv_group_set_style_mod_cb(lv_group_t * group,lv_group_style_mod_func_t style_mod_func) { - group->style_mod = style_cb; + group->style_mod = style_mod_func; if(group->obj_focus != NULL) lv_obj_invalidate(*group->obj_focus); } + +/** + * Set a function for a group which will be called when a new object is focused + * @param group pointer to a group + * @param focus_cb the call back function or NULL if unused + */ +void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb) +{ + group->focus_cb = focus_cb; +} + /** * Modify a style with the set 'style_mod' function. The input style remains unchanged. * @param group pointer to group @@ -253,6 +267,26 @@ lv_obj_t * lv_group_get_focused(lv_group_t * group) return *group->obj_focus; } +/** + * Get a the style modifier function of a group + * @param group pointer to a group + * @return pointer to the style modifier function + */ +lv_group_style_mod_func_t lv_group_get_style_mod_cb(lv_group_t * group) +{ + return group->style_mod ; +} + +/** + * Get the focus callback function of a group + * @param group pointer to a group + * @return the call back function or NULL if not set + */ +lv_group_focus_cb_t lv_group_get_focus_cb(lv_group_t * group) +{ + return group->focus_cb; +} + /********************** * STATIC FUNCTIONS **********************/ diff --git a/lv_core/lv_group.h b/lv_core/lv_group.h index d217d0517..8f8c29f2d 100644 --- a/lv_core/lv_group.h +++ b/lv_core/lv_group.h @@ -34,13 +34,19 @@ extern "C" { /********************** * TYPEDEFS **********************/ +struct _lv_group_t; + +typedef void (*lv_group_style_mod_func_t)(lv_style_t *); +typedef void (*lv_group_focus_cb_t)(struct _lv_group_t *); + typedef struct _lv_group_t { - lv_ll_t obj_ll; - lv_obj_t ** obj_focus; - void (*style_mod)(lv_style_t * style); - lv_style_t style_tmp; - uint8_t frozen:1; + lv_ll_t obj_ll; /*Linked list to store the objects in the group */ + lv_obj_t ** obj_focus; /*The object in focus*/ + lv_group_style_mod_func_t style_mod; /*A function which modifies the style of the focused object*/ + lv_group_focus_cb_t focus_cb; /*A function to call when a new object is focused (optional)*/ + lv_style_t style_tmp; /*Stores the modified style of the focused object */ + uint8_t frozen:1; /*1: can't focus to new object*/ }lv_group_t; /********************** @@ -98,13 +104,19 @@ void lv_group_focus_freeze(lv_group_t * group, bool en); */ void lv_group_send_data(lv_group_t * group, uint32_t c); - /** * Set a function for a group which will modify the object's style if it is in focus * @param group pointer to a group - * @param style_cb the style modifier function pointer + * @param style_mod_func the style modifier function pointer */ -void lv_group_set_style_mod_cb(lv_group_t * group, void (*style_cb)(lv_style_t * style)); +void lv_group_set_style_mod_cb(lv_group_t * group,lv_group_style_mod_func_t style_mod_func); + +/** + * Set a function for a group which will be called when a new object is focused + * @param group pointer to a group + * @param focus_cb the call back function or NULL if unused + */ +void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb); /** * Modify a style with the set 'style_mod' function. The input style remains unchanged. @@ -121,6 +133,20 @@ lv_style_t * lv_group_mod_style(lv_group_t * group, const lv_style_t * style); */ lv_obj_t * lv_group_get_focused(lv_group_t * group); +/** + * Get a the style modifier function of a group + * @param group pointer to a group + * @return pointer to the style modifier function + */ +lv_group_style_mod_func_t lv_group_get_style_mod_cb(lv_group_t * group); + +/** + * Get the focus callback function of a group + * @param group pointer to a group + * @return the call back function or NULL if not set + */ +lv_group_focus_cb_t lv_group_get_focus_cb(lv_group_t * group); + /********************** * MACROS **********************/ diff --git a/lv_core/lv_refr.c b/lv_core/lv_refr.c index 4e50d3b50..fe204e2e9 100644 --- a/lv_core/lv_refr.c +++ b/lv_core/lv_refr.c @@ -48,7 +48,8 @@ static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p); **********************/ static lv_join_t inv_buf[LV_INV_FIFO_SIZE]; static uint16_t inv_buf_p; -static void (*monitor_cb)(uint32_t, uint32_t); +static void (*monitor_cb)(uint32_t, uint32_t); /*Monitor the rendering time*/ +static void (*round_cb)(lv_area_t*); /*If set then called to modify invalidated areas for special display controllers*/ static uint32_t px_num; /********************** @@ -97,18 +98,8 @@ void lv_inv_area(const lv_area_t * area_p) /*The area is truncated to the screen*/ if(suc != false) { -#if LV_INV_FULL_ROW == 1 - /*Extend invalid area to be as wide as the screen*/ - com_area.x1 = 0; - com_area.x2 = LV_HOR_RES-1; -#endif + if(round_cb) round_cb(&com_area); -#if LV_INV_FULL_COL == 1 - /*Extend invalid area to be as tall as the screen*/ - com_area.y1 = 0; - com_area.y2 = LV_VER_RES-1; -#endif - /*Save only if this area is not in one of the saved areas*/ uint16_t i; for(i = 0; i < inv_buf_p; i++) { @@ -138,6 +129,16 @@ void lv_refr_set_monitor_cb(void (*cb)(uint32_t, uint32_t)) monitor_cb = cb; } +/** + * Called when an area is invalidated to modify the coordinates of the area. + * Special display controllers may require special coordinate rounding + * @param cb pointer to the a function which will modify the area + */ +void lv_refr_set_round_cd(void(*cb)(lv_area_t*)) +{ + round_cb = cb; +} + /********************** * STATIC FUNCTIONS **********************/ diff --git a/lv_core/lv_refr.h b/lv_core/lv_refr.h index 0132cebec..f0b5ab079 100644 --- a/lv_core/lv_refr.h +++ b/lv_core/lv_refr.h @@ -58,6 +58,13 @@ void lv_inv_area(const lv_area_t * area_p); */ void lv_refr_set_monitor_cb(void (*cb)(uint32_t, uint32_t)); +/** + * Called when an area is invalidated to modify the coordinates of the area. + * Special display controllers may require special coordinate rounding + * @param cb pointer to the a function which will modify the area + */ +void lv_refr_set_round_cd(void(*cb)(lv_area_t*)); + /********************** * STATIC FUNCTIONS **********************/ diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index bffa730f2..d6d38db4a 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -231,8 +231,9 @@ lv_img_src_t lv_img_get_src_type(const void * src) /*The first byte shows the type of the image source*/ if(u8_p[0] >= 'A' && u8_p[0] <= 'Z') return LV_IMG_SRC_FILE; /*It's a driver letter*/ - else if(u8_p[0] >= 127) return LV_IMG_SRC_SYMBOL; /*After ASCII letteres only symbols (even UTF-8) can be*/ else if(((u8_p[0] & 0xFC) >> 2) == LV_IMG_FORMAT_INTERNAL_RAW) return LV_IMG_SRC_VARIABLE; /*Mask the file format part og of lv_img_t header. IT should be 0 which means C array */ + else if(u8_p[0] >= ' ') return LV_IMG_SRC_SYMBOL; /*Other printable characters are considered symbols*/ + else return LV_IMG_SRC_UNKNOWN; } @@ -315,8 +316,6 @@ static bool lv_img_design(lv_obj_t * img, const lv_area_t * mask, lv_design_mode lv_draw_img(&img->coords, mask, style, NULL); } - - } return true;