1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

Merge pull request #604 from turoksama/dev-5.3

Add ability to have only one button selected on a list at a time
This commit is contained in:
embeddedt 2018-12-09 20:32:42 -05:00 committed by GitHub
commit 3fc3c9d0cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 1 deletions

View File

@ -38,6 +38,7 @@
static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param);
static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param);
static void refr_btn_width(lv_obj_t * list);
static void lv_list_btn_single_selected(lv_obj_t *btn);
/**********************
* STATIC VARIABLES
@ -89,6 +90,8 @@ lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy)
ext->styles_btn[LV_BTN_STATE_TGL_PR] = &lv_style_btn_tgl_pr;
ext->styles_btn[LV_BTN_STATE_INA] = &lv_style_btn_ina;
ext->anim_time = LV_LIST_FOCUS_TIME;
ext->single_mode = false;
#if USE_LV_GROUP
ext->last_sel = NULL;
ext->selected_btn = NULL;
@ -256,6 +259,18 @@ bool lv_list_remove(const lv_obj_t * list, uint32_t index)
* Setter functions
*====================*/
/**
* Set single button selected mode, only one button will be selected if enabled.
* @param list pointer to the currently pressed list object
* @param mode, enable(true)/disable(false) single selected mode.
*/
void lv_list_set_single_mode(lv_obj_t *list, bool mode)
{
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
ext->single_mode = mode;
}
#if USE_LV_GROUP
/**
@ -368,6 +383,17 @@ void lv_list_set_style(lv_obj_t * list, lv_list_style_t type, lv_style_t * style
* Getter functions
*====================*/
/**
* Get single button selected mode.
* @param list pointer to the currently pressed list object.
*/
bool lv_list_get_single_mode(lv_obj_t *list)
{
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
return (ext->single_mode);
}
/**
* Get the text of a list element
* @param btn pointer to list element
@ -859,7 +885,10 @@ static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * para
* to mark it as selected (pressed state)*/
last_clicked_btn = btn;
#endif
if(lv_indev_is_dragging(lv_indev_get_act()) == false && ext->single_mode)
{
lv_list_btn_single_selected(btn);
}
}
else if(sign == LV_SIGNAL_PRESS_LOST) {
lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn));
@ -900,5 +929,27 @@ static void refr_btn_width(lv_obj_t * list)
}
}
/**
* Make a single button selected in the list, deselect others, should be called in list btns call back.
* @param btn pointer to the currently pressed list btn object
*/
static void lv_list_btn_single_selected(lv_obj_t *btn)
{
lv_obj_t *list = lv_obj_get_parent(lv_obj_get_parent(btn));
lv_obj_t * e = lv_list_get_next_btn(list, NULL);
do
{
if(e == btn)
{
lv_btn_set_state(e, LV_BTN_STATE_TGL_REL);
}
else
{
lv_btn_set_state(e, LV_BTN_STATE_REL);
}
e = lv_list_get_next_btn(list, e);
} while (e != NULL);
}
#endif

View File

@ -57,6 +57,7 @@ typedef struct
lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of the list element buttons*/
lv_style_t *style_img; /*Style of the list element images on buttons*/
uint32_t size; /*the number of items(buttons) in the list*/
bool single_mode; /* whether single selected mode is enabled */
#if USE_LV_GROUP
lv_obj_t * last_sel; /* Last btn selected */
lv_obj_t * selected_btn;
@ -120,6 +121,14 @@ bool lv_list_remove(const lv_obj_t * list, uint32_t index);
/*=====================
* Setter functions
*====================*/
/**
* Set single button selected mode, only one button will be selected if enabled.
* @param list pointer to the currently pressed list object
* @param mode, enable(true)/disable(false) single selected mode.
*/
void lv_list_set_single_mode(lv_obj_t *list, bool mode);
#if USE_LV_GROUP
/**
@ -179,6 +188,12 @@ void lv_list_set_style(lv_obj_t *list, lv_list_style_t type, lv_style_t *style);
* Getter functions
*====================*/
/**
* Get single button selected mode.
* @param list pointer to the currently pressed list object.
*/
bool lv_list_get_single_mode(lv_obj_t *list);
/**
* Get the text of a list element
* @param btn pointer to list element