lv_group: add click_focus option

This commit is contained in:
Gabor Kiss-Vamosi
2018-07-12 23:38:27 +02:00
parent 9a28e559a4
commit d483d14c8e
8 changed files with 157 additions and 24 deletions

View File

@@ -50,6 +50,9 @@ lv_group_t * lv_group_create(void)
group->obj_focus = NULL;
group->frozen = 0;
group->focus_cb = NULL;
group->click_focus = 1;
group->edit_mode_en = 0;
group->editing = 0;
return group;
}
@@ -141,6 +144,7 @@ void lv_group_focus_obj(lv_obj_t * obj)
lv_obj_t ** i;
LL_READ(g->obj_ll, i) {
if(*i == obj) {
if(g->obj_focus == i) return; /*Don't focus the already focused object again*/
if(g->obj_focus != NULL) {
(*g->obj_focus)->signal_func(*g->obj_focus, LV_SIGNAL_DEFOCUS, NULL);
lv_obj_invalidate(*g->obj_focus);
@@ -150,6 +154,7 @@ void lv_group_focus_obj(lv_obj_t * obj)
if(g->obj_focus != NULL) {
(*g->obj_focus)->signal_func(*g->obj_focus, LV_SIGNAL_FOCUS, NULL);
if(g->focus_cb) g->focus_cb(g);
lv_obj_invalidate(*g->obj_focus);
}
break;
@@ -295,6 +300,16 @@ void lv_group_set_editing(lv_group_t * group, bool edit)
group->editing = edit ? 1 : 0;
}
/**
* Set the `click_focus` attribute. If enabled then the object will be focused then it is clicked.
* @param group pointer to group
* @param en: true: enable `click_focus`
*/
void lv_group_set_click_focus(lv_group_t * group, bool en)
{
group->click_focus = en ? 1 : 0;
}
/**
* Modify a style with the set 'style_mod' function. The input style remains unchanged.
* @param group pointer to group
@@ -322,7 +337,7 @@ 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)
{
if(group == NULL) return NULL;
if(!group) return NULL;
if(group->obj_focus == NULL) return NULL;
return *group->obj_focus;
@@ -335,6 +350,7 @@ lv_obj_t * lv_group_get_focused(lv_group_t * group)
*/
lv_group_style_mod_func_t lv_group_get_style_mod_cb(lv_group_t * group)
{
if(!group) return false;
return group->style_mod ;
}
@@ -345,6 +361,7 @@ lv_group_style_mod_func_t lv_group_get_style_mod_cb(lv_group_t * group)
*/
lv_group_style_mod_func_t lv_group_get_style_mod_edit_cb(lv_group_t * group)
{
if(!group) return false;
return group->style_mod_edit;
}
@@ -355,6 +372,7 @@ lv_group_style_mod_func_t lv_group_get_style_mod_edit_cb(lv_group_t * group)
*/
lv_group_focus_cb_t lv_group_get_focus_cb(lv_group_t * group)
{
if(!group) return false;
return group->focus_cb;
}
@@ -365,9 +383,21 @@ lv_group_focus_cb_t lv_group_get_focus_cb(lv_group_t * group)
*/
bool lv_group_get_editing(lv_group_t * group)
{
if(!group) return false;
return group->editing ? true : false;
}
/**
* Get the `click_focus` attribute.
* @param group pointer to group
* @return true: `click_focus` is enabled; false: disabled
*/
bool lv_group_get_click_focus(lv_group_t * group)
{
if(!group) return false;
return group->click_focus ? true : false;
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@@ -52,9 +52,10 @@ typedef struct _lv_group_t
lv_group_style_mod_func_t style_mod_edit;/*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*/
uint8_t edit_mode_en:1; /*1: By the long press of `LV_GROP_KEY_ENTER` the object can go to edit mode*/
uint8_t editing:1; /*1: Edit mode, 0: Navigate mode*/
uint8_t frozen :1; /*1: can't focus to new object*/
uint8_t edit_mode_en :1; /*1: By the long press of `LV_GROP_KEY_ENTER` the object can go to edit mode*/
uint8_t editing :1; /*1: Edit mode, 0: Navigate mode*/
uint8_t click_focus :1; /*1: If an object in a group is clicked by an indev then it will be focused */
} lv_group_t;
/**********************
@@ -152,12 +153,19 @@ void lv_group_set_edit_enable(lv_group_t * group, bool en);
/**
* Manually set the current mode (edit or navigate).
* Edit mode needs to be enabled with `lv_group_set_edit_enabel`.
* Edit mode needs to be enabled with `lv_group_set_edit_enable`.
* @param group pointer to group
* @param edit: true: edit mode; false: navigate mode
*/
void lv_group_set_editing(lv_group_t * group, bool edit);
/**
* Set the `click_focus` attribute. If enabled then the object will be focused then it is clicked.
* @param group pointer to group
* @param en: true: enable `click_focus`
*/
void lv_group_set_click_focus(lv_group_t * group, bool en);
/**
* Modify a style with the set 'style_mod' function. The input style remains unchanged.
* @param group pointer to group
@@ -200,6 +208,15 @@ lv_group_focus_cb_t lv_group_get_focus_cb(lv_group_t * group);
* @return true: edit mode; false: navigate mode
*/
bool lv_group_get_editing(lv_group_t * group);
/**
* Get the `click_focus` attribute.
* @param group pointer to group
* @return true: `click_focus` is enabled; false: disabled
*/
bool lv_group_get_click_focus(lv_group_t * group);
/**********************
* MACROS
**********************/

View File

@@ -542,6 +542,23 @@ static void indev_proc_release(lv_indev_proc_t * proc)
/*Forgot the act obj and send a released signal */
if(proc->act_obj != NULL) {
proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_RELEASED, indev_act);
/*Handle click focus*/
#if USE_LV_GROUP
lv_group_t * g = lv_obj_get_group(proc->act_obj);
lv_obj_t * parent = proc->act_obj;
while(g == NULL) {
parent = lv_obj_get_parent(parent);
if(parent == NULL) break;
g = lv_obj_get_group(parent);
}
if(g != NULL && parent != NULL)
if(lv_group_get_click_focus(g)) {
lv_group_focus_obj(parent);
}
#endif
if(proc->reset_query != 0) return;
proc->act_obj = NULL;
proc->pr_timestamp = 0;