mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-28 13:36:27 +08:00
lv_btnm (and lv_kb): add up/down navigation with LV_GROUP_KEY_UP/DOWN
This commit is contained in:
+44
-3
@@ -576,16 +576,57 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
|
||||
}
|
||||
else if(sign == LV_SIGNAL_CONTROLL) {
|
||||
char c = *((char*)param);
|
||||
if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) {
|
||||
if(c == LV_GROUP_KEY_RIGHT) {
|
||||
if(ext->btn_id_pr == LV_BTNM_PR_NONE) ext->btn_id_pr = 0;
|
||||
else ext->btn_id_pr++;
|
||||
if(ext->btn_id_pr >= ext->btn_cnt - 1) ext->btn_id_pr = ext->btn_cnt - 1;
|
||||
lv_obj_invalidate(btnm);
|
||||
} else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) {
|
||||
} else if(c == LV_GROUP_KEY_LEFT) {
|
||||
if(ext->btn_id_pr == LV_BTNM_PR_NONE) ext->btn_id_pr = 0;
|
||||
if(ext->btn_id_pr > 0) ext->btn_id_pr--;
|
||||
lv_obj_invalidate(btnm);
|
||||
} else if(c == LV_GROUP_KEY_ENTER || c == LV_GROUP_KEY_ENTER_LONG) {
|
||||
} else if(c == LV_GROUP_KEY_DOWN) {
|
||||
lv_style_t * style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BG);
|
||||
/*Find the area below the the current*/
|
||||
if(ext->btn_id_pr == LV_BTNM_PR_NONE) {
|
||||
ext->btn_id_pr = 0;
|
||||
} else {
|
||||
uint16_t area_below;
|
||||
lv_coord_t pr_center = ext->button_areas[ext->btn_id_pr].x1 + (lv_area_get_width(&ext->button_areas[ext->btn_id_pr]) >> 1);
|
||||
|
||||
for(area_below = ext->btn_id_pr; area_below < ext->btn_cnt; area_below ++) {
|
||||
if(ext->button_areas[area_below].y1 > ext->button_areas[ext->btn_id_pr].y1 &&
|
||||
pr_center >= ext->button_areas[area_below].x1 &&
|
||||
pr_center <= ext->button_areas[area_below].x2 + style->body.padding.hor)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
ext->btn_id_pr = area_below;
|
||||
}
|
||||
lv_obj_invalidate(btnm);
|
||||
} else if(c == LV_GROUP_KEY_UP) {
|
||||
lv_style_t * style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BG);
|
||||
/*Find the area below the the current*/
|
||||
if(ext->btn_id_pr == LV_BTNM_PR_NONE) {
|
||||
ext->btn_id_pr = 0;
|
||||
} else {
|
||||
uint16_t area_above;
|
||||
lv_coord_t pr_center = ext->button_areas[ext->btn_id_pr].x1 + (lv_area_get_width(&ext->button_areas[ext->btn_id_pr]) >> 1);
|
||||
|
||||
for(area_above = ext->btn_id_pr; area_above > 0; area_above --) {
|
||||
if(ext->button_areas[area_above].y1 < ext->button_areas[ext->btn_id_pr].y1 &&
|
||||
pr_center >= ext->button_areas[area_above].x1 - style->body.padding.hor &&
|
||||
pr_center <= ext->button_areas[area_above].x2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
ext->btn_id_pr = area_above;
|
||||
|
||||
}
|
||||
lv_obj_invalidate(btnm);
|
||||
}else if(c == LV_GROUP_KEY_ENTER || c == LV_GROUP_KEY_ENTER_LONG) {
|
||||
if(ext->action != NULL) {
|
||||
uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr);
|
||||
if(txt_i != LV_BTNM_PR_NONE) {
|
||||
|
||||
+7
-7
@@ -47,14 +47,14 @@ typedef struct
|
||||
{
|
||||
/*No inherited ext.*/ /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
const char ** map_p; /*Pointer to the current map*/
|
||||
lv_area_t *button_areas; /*Array of areas of buttons*/
|
||||
lv_btnm_action_t action; /*A function to call when a button is releases*/
|
||||
const char ** map_p; /*Pointer to the current map*/
|
||||
lv_area_t *button_areas; /*Array of areas of buttons*/
|
||||
lv_btnm_action_t action; /*A function to call when a button is releases*/
|
||||
lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of buttons in each state*/
|
||||
uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/
|
||||
uint16_t btn_id_pr; /*Index of the currently pressed button or LV_BTNM_PR_NONE*/
|
||||
uint16_t btn_id_tgl; /*Index of the currently toggled button or LV_BTNM_PR_NONE */
|
||||
uint8_t toggle :1; /*Enable toggling*/
|
||||
uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/
|
||||
uint16_t btn_id_pr; /*Index of the currently pressed button (in `button_areas`) or LV_BTNM_PR_NONE*/
|
||||
uint16_t btn_id_tgl; /*Index of the currently toggled button (in `button_areas`) or LV_BTNM_PR_NONE */
|
||||
uint8_t toggle :1; /*Enable toggling*/
|
||||
}lv_btnm_ext_t;
|
||||
|
||||
typedef enum {
|
||||
|
||||
Reference in New Issue
Block a user