add LV_GROUP_KEY_ENETER_LONG to trigger long press evets of the objects
This commit is contained in:
@@ -25,11 +25,13 @@ extern "C" {
|
||||
#define LV_GROUP_KEY_DOWN 18 /*0x12*/
|
||||
#define LV_GROUP_KEY_RIGHT 19 /*0x13*/
|
||||
#define LV_GROUP_KEY_LEFT 20 /*0x14*/
|
||||
#define LV_GROUP_KEY_ESC 33 /*0x1B*/
|
||||
#define LV_GROUP_KEY_ESC 27 /*0x1B*/
|
||||
#define LV_GROUP_KEY_ENTER 10 /*0x0A, '\n'*/
|
||||
#define LV_GROUP_KEY_NEXT 9 /*0x09, '\t'*/
|
||||
#define LV_GROUP_KEY_PREV 11 /*0x0B, '*/
|
||||
|
||||
#define LV_GROUP_KEY_ENTER_LONG 14 /*0x0E, Sent by the library if ENTER is long pressed*/
|
||||
|
||||
#if USE_LV_GROUP != 0
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
|
||||
@@ -349,9 +349,32 @@ static void indev_pointer_proc(lv_indev_t * i, lv_indev_data_t * data)
|
||||
static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data)
|
||||
{
|
||||
#if USE_LV_GROUP
|
||||
if(i->group != NULL && data->key != 0 &&
|
||||
data->state == LV_INDEV_STATE_PR && i->proc.last_state == LV_INDEV_STATE_REL)
|
||||
if(i->group == NULL) return;
|
||||
|
||||
/*Key press happened*/
|
||||
if(data->state == LV_INDEV_STATE_PR &&
|
||||
i->proc.last_state == LV_INDEV_STATE_REL)
|
||||
{
|
||||
i->proc.pr_timestamp = lv_tick_get();
|
||||
}
|
||||
/*Pressing*/
|
||||
else if(data->state == LV_INDEV_STATE_PR && i->proc.last_state == LV_INDEV_STATE_PR) {
|
||||
if(data->key == LV_GROUP_KEY_ENTER &&
|
||||
i->proc.long_pr_sent == 0 &&
|
||||
lv_tick_elaps(i->proc.pr_timestamp) > LV_INDEV_LONG_PRESS_TIME)
|
||||
{
|
||||
|
||||
lv_group_send_data(i->group, LV_GROUP_KEY_ENTER_LONG);
|
||||
i->proc.long_pr_sent = 1;
|
||||
|
||||
}
|
||||
}
|
||||
/*Release happened*/
|
||||
else if(data->state == LV_INDEV_STATE_REL && i->proc.last_state == LV_INDEV_STATE_PR)
|
||||
{
|
||||
/*The user might clear the key it was released. Always release the pressed key*/
|
||||
data->key = i->proc.last_key;
|
||||
|
||||
if(data->key == LV_GROUP_KEY_NEXT) {
|
||||
lv_group_focus_next(i->group);
|
||||
}
|
||||
@@ -361,8 +384,13 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data)
|
||||
else {
|
||||
lv_group_send_data(i->group, data->key);
|
||||
}
|
||||
|
||||
i->proc.pr_timestamp = 0;
|
||||
i->proc.long_pr_sent = 0;
|
||||
}
|
||||
|
||||
i->proc.last_state = data->state;
|
||||
i->proc.last_key = data->key;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -61,12 +61,14 @@ lv_indev_t * lv_indev_drv_register(lv_indev_drv_t *driver)
|
||||
node = lv_mem_alloc(sizeof(lv_indev_t));
|
||||
if (!node) return NULL;
|
||||
|
||||
memset(node, 0, sizeof(lv_indev_t));
|
||||
memcpy(&node->driver, driver, sizeof(lv_indev_drv_t));
|
||||
|
||||
node->next = NULL;
|
||||
node->proc.reset_query = 1;
|
||||
node->cursor = NULL;
|
||||
node->group = NULL;
|
||||
node->btn_points = NULL;
|
||||
|
||||
if (indev_list == NULL) {
|
||||
indev_list = node;
|
||||
|
||||
@@ -81,6 +81,7 @@ typedef struct _lv_indev_proc_t {
|
||||
};
|
||||
struct { /*Keypad data*/
|
||||
lv_indev_state_t last_state;
|
||||
uint32_t last_key;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -368,7 +368,8 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
|
||||
res = ext->actions[LV_BTN_ACTION_CLICK](btn);
|
||||
}
|
||||
} else if(c == LV_GROUP_KEY_ENTER) {
|
||||
if(lv_btn_get_toggle(btn) != false) {
|
||||
if(!ext->long_pr_action_executed) {
|
||||
if(lv_btn_get_toggle(btn)) {
|
||||
if(state == LV_BTN_STATE_REL) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
|
||||
else if(state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_TGL_PR);
|
||||
else if(state == LV_BTN_STATE_TGL_REL) lv_btn_set_state(btn, LV_BTN_STATE_REL);
|
||||
@@ -378,6 +379,14 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
|
||||
res = ext->actions[LV_BTN_ACTION_CLICK](btn);
|
||||
}
|
||||
}
|
||||
ext->long_pr_action_executed = 0;
|
||||
}
|
||||
else if(c == LV_GROUP_KEY_ENTER_LONG) {
|
||||
if(ext->actions[LV_BTN_ACTION_LONG_PR] && state != LV_BTN_STATE_INA) {
|
||||
res = ext->actions[LV_BTN_ACTION_LONG_PR](btn);
|
||||
ext->long_pr_action_executed = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
@@ -516,6 +516,7 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par
|
||||
if(ext->sel_opt_id + 1 < ext->option_cnt) {
|
||||
ext->sel_opt_id ++;
|
||||
lv_ddlist_pos_current_option(ddlist);
|
||||
lv_obj_invalidate(ddlist);
|
||||
if(ext->action != NULL) {
|
||||
ext->action(ddlist);
|
||||
}
|
||||
@@ -524,6 +525,7 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par
|
||||
if(ext->sel_opt_id > 0) {
|
||||
ext->sel_opt_id --;
|
||||
lv_ddlist_pos_current_option(ddlist);
|
||||
lv_obj_invalidate(ddlist);
|
||||
if(ext->action != NULL) {
|
||||
ext->action(ddlist);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user