2016-06-22 17:24:02 +02:00
|
|
|
/**
|
|
|
|
* @file lv_list.c
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2016-06-22 17:24:02 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2018-07-07 11:53:22 +02:00
|
|
|
#include "lv_list.h"
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_LIST != 0
|
2016-06-22 17:24:02 +02:00
|
|
|
|
2017-11-30 11:35:33 +01:00
|
|
|
#include "../lv_core/lv_group.h"
|
2017-11-16 15:32:33 +01:00
|
|
|
#include "../lv_themes/lv_theme.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
#include "../lv_misc/lv_anim.h"
|
|
|
|
#include "../lv_misc/lv_math.h"
|
2016-06-22 17:24:02 +02:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2019-04-04 07:15:40 +02:00
|
|
|
#define LV_LIST_LAYOUT_DEF LV_LAYOUT_COL_M
|
2017-11-27 17:48:54 +01:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2019-04-04 16:44:16 +02:00
|
|
|
/*Animation time of focusing to the a list element [ms] (0: no animation) */
|
|
|
|
#ifndef LV_LIST_DEF_ANIM_TIME
|
|
|
|
#define LV_LIST_DEF_ANIM_TIME 100
|
2019-04-04 07:15:40 +02:00
|
|
|
#endif
|
2017-11-27 17:48:54 +01:00
|
|
|
#else
|
2019-04-04 16:44:16 +02:00
|
|
|
/*No animations*/
|
2019-04-04 07:15:40 +02:00
|
|
|
#undef LV_LIST_DEF_ANIM_TIME
|
2019-04-04 16:44:16 +02:00
|
|
|
#define LV_LIST_DEF_ANIM_TIME 0
|
2017-07-20 12:26:34 +02:00
|
|
|
#endif
|
2016-06-22 17:24:02 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2018-06-19 09:49:58 +02:00
|
|
|
static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param);
|
2018-07-13 00:01:10 +02:00
|
|
|
static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param);
|
2019-04-04 07:15:40 +02:00
|
|
|
static void lv_list_btn_single_selected(lv_obj_t * btn);
|
2019-04-10 19:52:11 -04:00
|
|
|
static bool lv_list_is_list_btn(lv_obj_t * list_btn);
|
|
|
|
static bool lv_list_is_list_img(lv_obj_t * list_btn);
|
|
|
|
static bool lv_list_is_list_label(lv_obj_t * list_btn);
|
2017-07-20 13:29:22 +02:00
|
|
|
|
2016-06-22 17:24:02 +02:00
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_IMG
|
2019-02-26 09:25:46 +01:00
|
|
|
static lv_signal_cb_t img_signal;
|
2018-01-16 11:54:35 +01:00
|
|
|
#endif
|
2019-02-26 09:25:46 +01:00
|
|
|
static lv_signal_cb_t label_signal;
|
|
|
|
static lv_signal_cb_t ancestor_page_signal;
|
|
|
|
static lv_signal_cb_t ancestor_btn_signal;
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP
|
2019-04-04 07:15:40 +02:00
|
|
|
/*Used to make the last clicked button pressed (selected) when the list become focused and
|
|
|
|
* `click_focus == 1`*/
|
2018-07-13 00:37:28 +02:00
|
|
|
static lv_obj_t * last_clicked_btn;
|
|
|
|
#endif
|
2016-06-22 17:24:02 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a list objects
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param par pointer to an object, it will be the parent of the new list
|
|
|
|
* @param copy pointer to a list object, if not NULL then the new object will be copied from it
|
2016-06-22 17:24:02 +02:00
|
|
|
* @return pointer to the created list
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy)
|
2016-06-22 17:24:02 +02:00
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_TRACE("list create started");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2016-06-22 17:24:02 +02:00
|
|
|
/*Create the ancestor basic object*/
|
2016-10-07 11:15:46 +02:00
|
|
|
lv_obj_t * new_list = lv_page_create(par, copy);
|
2017-11-26 11:38:28 +01:00
|
|
|
lv_mem_assert(new_list);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(new_list == NULL) return NULL;
|
|
|
|
|
2019-04-10 06:40:49 +02:00
|
|
|
if(ancestor_page_signal == NULL) ancestor_page_signal = lv_obj_get_signal_cb(new_list);
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_list_ext_t * ext = lv_obj_allocate_ext_attr(new_list, sizeof(lv_list_ext_t));
|
2017-11-26 11:38:28 +01:00
|
|
|
lv_mem_assert(ext);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(ext == NULL) return NULL;
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->style_img = NULL;
|
|
|
|
ext->styles_btn[LV_BTN_STATE_REL] = &lv_style_btn_rel;
|
|
|
|
ext->styles_btn[LV_BTN_STATE_PR] = &lv_style_btn_pr;
|
2017-11-20 14:26:18 +01:00
|
|
|
ext->styles_btn[LV_BTN_STATE_TGL_REL] = &lv_style_btn_tgl_rel;
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->styles_btn[LV_BTN_STATE_TGL_PR] = &lv_style_btn_tgl_pr;
|
|
|
|
ext->styles_btn[LV_BTN_STATE_INA] = &lv_style_btn_ina;
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->anim_time = LV_LIST_DEF_ANIM_TIME;
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->single_mode = false;
|
|
|
|
ext->size = 0;
|
2019-03-12 19:20:23 +01:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->last_sel = NULL;
|
2018-07-30 07:42:36 +02:00
|
|
|
ext->selected_btn = NULL;
|
2018-10-09 15:03:46 +02:00
|
|
|
#endif
|
2017-04-13 10:20:35 +02:00
|
|
|
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_obj_set_signal_cb(new_list, lv_list_signal);
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2016-06-22 17:24:02 +02:00
|
|
|
/*Init the new list object*/
|
2016-10-07 11:15:46 +02:00
|
|
|
if(copy == NULL) {
|
2019-02-24 06:24:36 +01:00
|
|
|
lv_page_set_scrl_fit2(new_list, LV_FIT_FLOOD, LV_FIT_TIGHT);
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_set_size(new_list, 2 * LV_DPI, 3 * LV_DPI);
|
|
|
|
lv_page_set_scrl_layout(new_list, LV_LIST_LAYOUT_DEF);
|
|
|
|
lv_list_set_sb_mode(new_list, LV_SB_MODE_DRAG);
|
2017-11-16 15:32:33 +01:00
|
|
|
|
|
|
|
/*Set the default styles*/
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_theme_t * th = lv_theme_get_current();
|
2017-11-16 15:32:33 +01:00
|
|
|
if(th) {
|
2019-02-11 09:35:06 +01:00
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_BG, th->style.list.bg);
|
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_SCRL, th->style.list.scrl);
|
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_SB, th->style.list.sb);
|
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_REL, th->style.list.btn.rel);
|
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_PR, th->style.list.btn.pr);
|
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_REL, th->style.list.btn.tgl_rel);
|
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_PR, th->style.list.btn.tgl_pr);
|
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_INA, th->style.list.btn.ina);
|
2017-11-16 15:32:33 +01:00
|
|
|
} else {
|
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_BG, &lv_style_transp_fit);
|
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_SCRL, &lv_style_pretty);
|
|
|
|
}
|
2016-10-04 09:45:39 +02:00
|
|
|
} else {
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_list_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
2017-04-21 09:15:39 +02:00
|
|
|
|
2018-08-27 19:55:17 +02:00
|
|
|
lv_obj_t * copy_btn = lv_list_get_next_btn(copy, NULL);
|
2017-11-07 14:31:35 +01:00
|
|
|
while(copy_btn) {
|
2018-10-05 17:22:49 +02:00
|
|
|
const void * img_src = NULL;
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_IMG
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_t * copy_img = lv_list_get_btn_img(copy_btn);
|
2018-08-04 01:46:00 +02:00
|
|
|
if(copy_img) img_src = lv_img_get_src(copy_img);
|
2018-01-16 11:54:35 +01:00
|
|
|
#endif
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_list_add(new_list, img_src, lv_list_get_btn_text(copy_btn), copy_btn->event_cb);
|
2018-10-05 17:22:49 +02:00
|
|
|
copy_btn = lv_list_get_next_btn(copy, copy_btn);
|
2017-11-07 14:31:35 +01:00
|
|
|
}
|
2017-04-21 09:15:39 +02:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_REL, copy_ext->styles_btn[LV_BTN_STATE_REL]);
|
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_PR, copy_ext->styles_btn[LV_BTN_STATE_PR]);
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_REL, copy_ext->styles_btn[LV_BTN_STATE_TGL_REL]);
|
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_TGL_PR, copy_ext->styles_btn[LV_BTN_STATE_TGL_REL]);
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_list_set_style(new_list, LV_LIST_STYLE_BTN_INA, copy_ext->styles_btn[LV_BTN_STATE_INA]);
|
|
|
|
|
2017-01-08 13:06:41 +01:00
|
|
|
/*Refresh the style with new signal function*/
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_refresh_style(new_list);
|
2016-07-12 01:16:27 +02:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_INFO("list created");
|
2018-07-25 20:39:24 +02:00
|
|
|
|
2016-10-07 11:15:46 +02:00
|
|
|
return new_list;
|
2016-06-22 17:24:02 +02:00
|
|
|
}
|
|
|
|
|
2018-03-16 11:53:27 -04:00
|
|
|
/**
|
|
|
|
* Delete all children of the scrl object, without deleting scrl child.
|
|
|
|
* @param obj pointer to an object
|
|
|
|
*/
|
2018-09-07 17:09:09 +02:00
|
|
|
void lv_list_clean(lv_obj_t * obj)
|
2018-03-16 11:53:27 -04:00
|
|
|
{
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(obj);
|
2018-03-16 11:53:27 -04:00
|
|
|
lv_obj_clean(scrl);
|
2018-10-30 18:08:38 +08:00
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(obj);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->size = 0;
|
2018-03-16 11:53:27 -04:00
|
|
|
}
|
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/*======================
|
|
|
|
* Add/remove functions
|
|
|
|
*=====================*/
|
|
|
|
|
2016-07-12 01:16:27 +02:00
|
|
|
/**
|
|
|
|
* Add a list element to the list
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param list pointer to list object
|
2016-07-12 01:16:27 +02:00
|
|
|
* @param img_fn file name of an image before the text (NULL if unused)
|
|
|
|
* @param txt text of the list element (NULL if unused)
|
2019-02-26 09:25:46 +01:00
|
|
|
* @param event_cb specify the an event handler function. NULL if unused
|
2016-07-12 01:16:27 +02:00
|
|
|
* @return pointer to the new list element which can be customized (a button)
|
|
|
|
*/
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_obj_t * lv_list_add(lv_obj_t * list, const void * img_src, const char * txt, lv_event_cb_t event_cb)
|
2016-06-22 17:24:02 +02:00
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->size++;
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Create a list element with the image an the text*/
|
|
|
|
lv_obj_t * liste;
|
|
|
|
liste = lv_btn_create(list, NULL);
|
2017-12-31 11:11:46 +01:00
|
|
|
|
2018-07-13 00:01:10 +02:00
|
|
|
/*Save the original signal function because it will be required in `lv_list_btn_signal`*/
|
2019-04-10 06:40:49 +02:00
|
|
|
if(ancestor_btn_signal == NULL) ancestor_btn_signal = lv_obj_get_signal_cb(liste);
|
2018-07-13 00:01:10 +02:00
|
|
|
|
2017-12-31 11:11:46 +01:00
|
|
|
/*Set the default styles*/
|
|
|
|
lv_btn_set_style(liste, LV_BTN_STYLE_REL, ext->styles_btn[LV_BTN_STATE_REL]);
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_btn_set_style(liste, LV_BTN_STYLE_PR, ext->styles_btn[LV_BTN_STATE_PR]);
|
|
|
|
lv_btn_set_style(liste, LV_BTN_STYLE_TGL_REL, ext->styles_btn[LV_BTN_STATE_TGL_REL]);
|
|
|
|
lv_btn_set_style(liste, LV_BTN_STYLE_TGL_PR, ext->styles_btn[LV_BTN_STATE_TGL_PR]);
|
|
|
|
lv_btn_set_style(liste, LV_BTN_STYLE_INA, ext->styles_btn[LV_BTN_STATE_INA]);
|
2017-04-13 10:20:35 +02:00
|
|
|
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_obj_set_event_cb(liste, event_cb);
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_page_glue_obj(liste, true);
|
|
|
|
lv_btn_set_layout(liste, LV_LAYOUT_ROW_M);
|
2019-02-24 06:24:36 +01:00
|
|
|
lv_btn_set_fit2(liste, LV_FIT_FLOOD, LV_FIT_TIGHT);
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_set_protect(liste, LV_PROTECT_PRESS_LOST);
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_obj_set_signal_cb(liste, lv_list_btn_signal);
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_IMG != 0
|
2017-12-03 00:35:39 +01:00
|
|
|
lv_obj_t * img = NULL;
|
2018-06-19 09:49:58 +02:00
|
|
|
if(img_src) {
|
|
|
|
img = lv_img_create(liste, NULL);
|
|
|
|
lv_img_set_src(img, img_src);
|
|
|
|
lv_obj_set_style(img, ext->style_img);
|
|
|
|
lv_obj_set_click(img, false);
|
2019-04-10 06:40:49 +02:00
|
|
|
if(img_signal == NULL) img_signal = lv_obj_get_signal_cb(img);
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2017-08-21 14:55:06 +02:00
|
|
|
#endif
|
2018-06-19 09:49:58 +02:00
|
|
|
if(txt != NULL) {
|
2019-03-13 23:58:33 +01:00
|
|
|
lv_coord_t btn_hor_pad = ext->styles_btn[LV_BTN_STYLE_REL]->body.padding.left -
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->styles_btn[LV_BTN_STYLE_REL]->body.padding.right;
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_t * label = lv_label_create(liste, NULL);
|
|
|
|
lv_label_set_text(label, txt);
|
|
|
|
lv_obj_set_click(label, false);
|
2019-04-02 06:44:50 +02:00
|
|
|
lv_label_set_long_mode(label, LV_LABEL_LONG_ROLL_CIRC);
|
2018-12-18 07:25:34 +01:00
|
|
|
lv_obj_set_width(label, liste->coords.x2 - label->coords.x1 - btn_hor_pad);
|
2019-04-10 06:40:49 +02:00
|
|
|
if(label_signal == NULL) label_signal = lv_obj_get_signal_cb(label);
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP
|
2019-01-03 15:30:30 -08:00
|
|
|
/* If this is the first item to be added to the list and the list is
|
2019-03-13 23:58:33 +01:00
|
|
|
* focused, select it */
|
2019-01-03 15:30:30 -08:00
|
|
|
{
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_group_t * g = lv_obj_get_group(list);
|
2019-01-03 15:30:30 -08:00
|
|
|
if(ext->size == 1 && lv_group_get_focused(g) == list) {
|
|
|
|
lv_list_set_btn_selected(list, liste);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
return liste;
|
2016-06-22 17:24:02 +02:00
|
|
|
}
|
|
|
|
|
2018-10-30 16:38:39 +08:00
|
|
|
/**
|
|
|
|
* Remove the index of the button in the list
|
|
|
|
* @param list pointer to a list object
|
2019-04-04 07:15:40 +02:00
|
|
|
* @param index pointer to a the button's index in the list, index must be 0 <= index <
|
|
|
|
* lv_list_ext_t.size
|
2018-10-30 16:38:39 +08:00
|
|
|
* @return true: successfully deleted
|
|
|
|
*/
|
2019-05-20 09:22:09 -07:00
|
|
|
bool lv_list_remove(const lv_obj_t * list, uint16_t index)
|
2018-10-30 16:38:39 +08:00
|
|
|
{
|
2019-01-12 14:28:20 -08:00
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
|
|
|
if(index >= ext->size) return false;
|
2019-05-20 09:22:09 -07:00
|
|
|
uint16_t count = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_t * e = lv_list_get_next_btn(list, NULL);
|
2019-01-12 14:28:20 -08:00
|
|
|
while(e != NULL) {
|
|
|
|
if(count == index) {
|
|
|
|
lv_obj_del(e);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->size--;
|
2019-01-12 14:28:20 -08:00
|
|
|
return true;
|
|
|
|
}
|
2018-10-30 16:38:39 +08:00
|
|
|
e = lv_list_get_next_btn(list, e);
|
2019-04-04 07:15:40 +02:00
|
|
|
count++;
|
2019-01-12 14:28:20 -08:00
|
|
|
}
|
|
|
|
return false;
|
2018-10-30 16:38:39 +08:00
|
|
|
}
|
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/*=====================
|
2018-06-19 09:49:58 +02:00
|
|
|
* Setter functions
|
2017-11-10 15:01:40 +01:00
|
|
|
*====================*/
|
2016-07-12 01:16:27 +02:00
|
|
|
|
2018-12-03 19:44:58 +08:00
|
|
|
/**
|
2018-12-07 15:22:07 +08:00
|
|
|
* 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.
|
2018-12-03 19:44:58 +08:00
|
|
|
*/
|
2019-04-04 07:15:40 +02:00
|
|
|
void lv_list_set_single_mode(lv_obj_t * list, bool mode)
|
2018-12-03 19:44:58 +08:00
|
|
|
{
|
2019-01-12 14:28:20 -08:00
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2018-12-03 19:44:58 +08:00
|
|
|
|
2019-01-12 14:28:20 -08:00
|
|
|
ext->single_mode = mode;
|
2018-12-03 19:44:58 +08:00
|
|
|
}
|
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP
|
2018-07-30 07:42:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make a button selected
|
|
|
|
* @param list pointer to a list object
|
2019-05-17 16:59:12 +02:00
|
|
|
* @param btn pointer to a button to select
|
|
|
|
* NULL to not select any buttons
|
2018-07-30 07:42:36 +02:00
|
|
|
*/
|
|
|
|
void lv_list_set_btn_selected(lv_obj_t * list, lv_obj_t * btn)
|
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2018-07-30 07:42:36 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
if(ext->selected_btn) {
|
|
|
|
lv_btn_state_t s = lv_btn_get_state(ext->selected_btn);
|
2019-04-04 07:15:40 +02:00
|
|
|
if(s == LV_BTN_STATE_PR)
|
|
|
|
lv_btn_set_state(ext->selected_btn, LV_BTN_STATE_REL);
|
|
|
|
else if(s == LV_BTN_STATE_TGL_PR)
|
|
|
|
lv_btn_set_state(ext->selected_btn, LV_BTN_STATE_TGL_REL);
|
2018-10-05 17:22:49 +02:00
|
|
|
}
|
2018-07-30 07:42:36 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
ext->selected_btn = btn;
|
2019-05-17 16:59:12 +02:00
|
|
|
|
|
|
|
/*Don't forgat whci hbutton was selected.
|
|
|
|
* It will be restored when the list is focused.*/
|
2019-04-04 07:15:40 +02:00
|
|
|
if(btn != NULL) {
|
2019-02-21 21:40:00 -08:00
|
|
|
ext->last_sel = btn;
|
|
|
|
}
|
2018-07-30 07:42:36 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
if(ext->selected_btn) {
|
|
|
|
lv_btn_state_t s = lv_btn_get_state(ext->selected_btn);
|
2019-04-04 07:15:40 +02:00
|
|
|
if(s == LV_BTN_STATE_REL)
|
|
|
|
lv_btn_set_state(ext->selected_btn, LV_BTN_STATE_PR);
|
|
|
|
else if(s == LV_BTN_STATE_TGL_REL)
|
|
|
|
lv_btn_set_state(ext->selected_btn, LV_BTN_STATE_TGL_PR);
|
2018-07-30 07:42:36 +02:00
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_page_focus(list, ext->selected_btn, lv_list_get_anim_time(list));
|
2018-10-05 17:22:49 +02:00
|
|
|
}
|
2018-07-30 07:42:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-07-12 01:16:27 +02:00
|
|
|
/**
|
2017-11-10 15:01:40 +01:00
|
|
|
* Set scroll animation duration on 'list_up()' 'list_down()' 'list_focus()'
|
2016-10-07 11:15:46 +02:00
|
|
|
* @param list pointer to a list object
|
2017-11-10 15:01:40 +01:00
|
|
|
* @param anim_time duration of animation [ms]
|
2016-07-12 01:16:27 +02:00
|
|
|
*/
|
2018-06-19 09:49:58 +02:00
|
|
|
void lv_list_set_anim_time(lv_obj_t * list, uint16_t anim_time)
|
2017-11-07 14:31:35 +01:00
|
|
|
{
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2017-11-10 15:01:40 +01:00
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2019-06-06 06:05:40 +02:00
|
|
|
anim_time = 0;
|
2018-05-16 23:09:30 +02:00
|
|
|
|
|
|
|
if(ext->anim_time == anim_time) return;
|
2017-11-10 15:01:40 +01:00
|
|
|
ext->anim_time = anim_time;
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2017-11-07 14:31:35 +01:00
|
|
|
}
|
|
|
|
|
2017-04-13 10:20:35 +02:00
|
|
|
/**
|
2017-11-15 15:50:33 +01:00
|
|
|
* Set a style of a list
|
|
|
|
* @param list pointer to a list object
|
|
|
|
* @param type which style should be set
|
|
|
|
* @param style pointer to a style
|
2017-04-13 10:20:35 +02:00
|
|
|
*/
|
2019-04-11 19:59:55 +08:00
|
|
|
void lv_list_set_style(lv_obj_t * list, lv_list_style_t type, const lv_style_t * style)
|
2017-04-13 10:20:35 +02:00
|
|
|
{
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2017-11-16 10:20:30 +01:00
|
|
|
lv_btn_style_t btn_style_refr = LV_BTN_STYLE_REL;
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_t * btn;
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
switch(type) {
|
2019-04-04 07:15:40 +02:00
|
|
|
case LV_LIST_STYLE_BG:
|
|
|
|
lv_page_set_style(list, LV_PAGE_STYLE_BG, style);
|
|
|
|
/*style change signal will call 'refr_btn_width' */
|
|
|
|
break;
|
|
|
|
case LV_LIST_STYLE_SCRL: lv_page_set_style(list, LV_PAGE_STYLE_SCRL, style); break;
|
|
|
|
case LV_LIST_STYLE_SB: lv_page_set_style(list, LV_PAGE_STYLE_SB, style); break;
|
2019-06-06 06:05:40 +02:00
|
|
|
case LV_LIST_STYLE_EDGE_FLASH: lv_page_set_style(list, LV_PAGE_STYLE_EDGE_FLASH, style); break;
|
2019-04-04 07:15:40 +02:00
|
|
|
case LV_LIST_STYLE_BTN_REL:
|
|
|
|
ext->styles_btn[LV_BTN_STATE_REL] = style;
|
|
|
|
btn_style_refr = LV_BTN_STYLE_REL;
|
|
|
|
break;
|
|
|
|
case LV_LIST_STYLE_BTN_PR:
|
|
|
|
ext->styles_btn[LV_BTN_STATE_PR] = style;
|
|
|
|
btn_style_refr = LV_BTN_STYLE_PR;
|
|
|
|
break;
|
|
|
|
case LV_LIST_STYLE_BTN_TGL_REL:
|
|
|
|
ext->styles_btn[LV_BTN_STATE_TGL_REL] = style;
|
|
|
|
btn_style_refr = LV_BTN_STYLE_TGL_REL;
|
|
|
|
break;
|
|
|
|
case LV_LIST_STYLE_BTN_TGL_PR:
|
|
|
|
ext->styles_btn[LV_BTN_STATE_TGL_PR] = style;
|
|
|
|
btn_style_refr = LV_BTN_STYLE_TGL_PR;
|
|
|
|
break;
|
|
|
|
case LV_LIST_STYLE_BTN_INA:
|
|
|
|
ext->styles_btn[LV_BTN_STATE_INA] = style;
|
|
|
|
btn_style_refr = LV_BTN_STYLE_INA;
|
|
|
|
break;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
2017-04-13 10:20:35 +02:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/*Refresh existing buttons' style*/
|
2019-06-06 06:05:40 +02:00
|
|
|
if(type == LV_LIST_STYLE_BTN_PR || type == LV_LIST_STYLE_BTN_REL || type == LV_LIST_STYLE_BTN_TGL_REL ||
|
|
|
|
type == LV_LIST_STYLE_BTN_TGL_PR || type == LV_LIST_STYLE_BTN_INA) {
|
2018-08-27 19:55:17 +02:00
|
|
|
btn = lv_list_get_prev_btn(list, NULL);
|
2017-11-16 10:20:30 +01:00
|
|
|
while(btn != NULL) {
|
|
|
|
lv_btn_set_style(btn, btn_style_refr, ext->styles_btn[btn_style_refr]);
|
2018-08-27 19:55:17 +02:00
|
|
|
btn = lv_list_get_prev_btn(list, btn);
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
2017-04-21 09:15:39 +02:00
|
|
|
}
|
2017-04-13 10:20:35 +02:00
|
|
|
}
|
2016-06-22 17:24:02 +02:00
|
|
|
|
|
|
|
/*=====================
|
2018-06-19 09:49:58 +02:00
|
|
|
* Getter functions
|
2016-06-22 17:24:02 +02:00
|
|
|
*====================*/
|
|
|
|
|
2018-12-07 15:22:07 +08:00
|
|
|
/**
|
|
|
|
* Get single button selected mode.
|
|
|
|
* @param list pointer to the currently pressed list object.
|
|
|
|
*/
|
2019-04-04 07:15:40 +02:00
|
|
|
bool lv_list_get_single_mode(lv_obj_t * list)
|
2018-12-07 15:22:07 +08:00
|
|
|
{
|
2019-01-12 14:28:20 -08:00
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2018-12-07 15:22:07 +08:00
|
|
|
|
2019-01-12 14:28:20 -08:00
|
|
|
return (ext->single_mode);
|
2018-12-07 15:22:07 +08:00
|
|
|
}
|
|
|
|
|
2016-12-29 23:48:01 +01:00
|
|
|
/**
|
|
|
|
* Get the text of a list element
|
2017-11-10 15:01:40 +01:00
|
|
|
* @param btn pointer to list element
|
2016-12-29 23:48:01 +01:00
|
|
|
* @return pointer to the text
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
const char * lv_list_get_btn_text(const lv_obj_t * btn)
|
2016-12-29 23:48:01 +01:00
|
|
|
{
|
2017-11-10 15:01:40 +01:00
|
|
|
lv_obj_t * label = lv_list_get_btn_label(btn);
|
2017-07-20 13:29:22 +02:00
|
|
|
if(label == NULL) return "";
|
2016-12-29 23:48:01 +01:00
|
|
|
return lv_label_get_text(label);
|
|
|
|
}
|
2016-10-04 09:45:39 +02:00
|
|
|
|
2017-07-20 13:29:22 +02:00
|
|
|
/**
|
|
|
|
* Get the label object from a list element
|
2017-11-10 15:01:40 +01:00
|
|
|
* @param btn pointer to a list element (button)
|
2017-07-20 13:29:22 +02:00
|
|
|
* @return pointer to the label from the list element or NULL if not found
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_list_get_btn_label(const lv_obj_t * btn)
|
2017-07-20 13:29:22 +02:00
|
|
|
{
|
2017-11-10 15:01:40 +01:00
|
|
|
lv_obj_t * label = lv_obj_get_child(btn, NULL);
|
2017-07-20 13:29:22 +02:00
|
|
|
if(label == NULL) return NULL;
|
|
|
|
|
2019-04-11 06:57:19 +02:00
|
|
|
while(lv_list_is_list_label(label) == false) {
|
2017-11-10 15:01:40 +01:00
|
|
|
label = lv_obj_get_child(btn, label);
|
2017-07-20 13:29:22 +02:00
|
|
|
if(label == NULL) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the image object from a list element
|
2017-11-10 15:01:40 +01:00
|
|
|
* @param btn pointer to a list element (button)
|
2017-07-20 13:29:22 +02:00
|
|
|
* @return pointer to the image from the list element or NULL if not found
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_list_get_btn_img(const lv_obj_t * btn)
|
2017-07-20 13:29:22 +02:00
|
|
|
{
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_IMG != 0
|
2017-11-10 15:01:40 +01:00
|
|
|
lv_obj_t * img = lv_obj_get_child(btn, NULL);
|
2017-07-20 13:29:22 +02:00
|
|
|
if(img == NULL) return NULL;
|
|
|
|
|
2019-04-11 06:57:19 +02:00
|
|
|
while(lv_list_is_list_img(img) == false) {
|
2017-11-10 15:01:40 +01:00
|
|
|
img = lv_obj_get_child(btn, img);
|
2017-07-20 13:29:22 +02:00
|
|
|
if(img == NULL) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return img;
|
2017-08-21 14:55:06 +02:00
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
2017-07-20 13:29:22 +02:00
|
|
|
}
|
|
|
|
|
2018-08-27 19:55:17 +02:00
|
|
|
/**
|
2018-12-11 10:21:22 +01:00
|
|
|
* Get the previous button from list. (Starts from the top button)
|
2018-08-27 19:55:17 +02:00
|
|
|
* @param list pointer to a list object
|
2018-12-11 10:21:22 +01:00
|
|
|
* @param prev_btn pointer to button. Search the previous before it.
|
|
|
|
* @return pointer to the previous button or NULL when no more buttons
|
2018-08-27 19:55:17 +02:00
|
|
|
*/
|
|
|
|
lv_obj_t * lv_list_get_prev_btn(const lv_obj_t * list, lv_obj_t * prev_btn)
|
|
|
|
{
|
|
|
|
/* Not a good practice but user can add/create objects to the lists manually.
|
|
|
|
* When getting the next button try to be sure that it is at least a button */
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_t * btn;
|
2018-08-27 19:55:17 +02:00
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(list);
|
|
|
|
|
|
|
|
btn = lv_obj_get_child(scrl, prev_btn);
|
|
|
|
if(btn == NULL) return NULL;
|
|
|
|
|
2019-04-11 06:57:19 +02:00
|
|
|
while(lv_list_is_list_btn(btn) == false) {
|
2018-10-17 11:27:08 +02:00
|
|
|
btn = lv_obj_get_child(scrl, btn);
|
2018-08-27 19:55:17 +02:00
|
|
|
if(btn == NULL) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return btn;
|
|
|
|
}
|
|
|
|
|
2019-03-12 19:20:23 +01:00
|
|
|
/**
|
2018-12-11 10:21:22 +01:00
|
|
|
* Get the next button from list. (Starts from the bottom button)
|
2018-08-27 19:55:17 +02:00
|
|
|
* @param list pointer to a list object
|
2018-12-11 10:21:22 +01:00
|
|
|
* @param prev_btn pointer to button. Search the next after it.
|
|
|
|
* @return pointer to the next button or NULL when no more buttons
|
2018-08-27 19:55:17 +02:00
|
|
|
*/
|
|
|
|
lv_obj_t * lv_list_get_next_btn(const lv_obj_t * list, lv_obj_t * prev_btn)
|
|
|
|
{
|
|
|
|
/* Not a good practice but user can add/create objects to the lists manually.
|
|
|
|
* When getting the next button try to be sure that it is at least a button */
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_t * btn;
|
2018-08-27 19:55:17 +02:00
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(list);
|
|
|
|
|
|
|
|
btn = lv_obj_get_child_back(scrl, prev_btn);
|
|
|
|
if(btn == NULL) return NULL;
|
|
|
|
|
2019-04-11 06:57:19 +02:00
|
|
|
while(lv_list_is_list_btn(btn) == false) {
|
2018-10-17 11:27:08 +02:00
|
|
|
btn = lv_obj_get_child_back(scrl, btn);
|
2018-08-27 19:55:17 +02:00
|
|
|
if(btn == NULL) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return btn;
|
|
|
|
}
|
|
|
|
|
2018-10-30 16:38:39 +08:00
|
|
|
/**
|
|
|
|
* Get the index of the button in the list
|
2019-01-12 12:08:41 -08:00
|
|
|
* @param list pointer to a list object. If NULL, assumes btn is part of a list.
|
2018-10-30 16:38:39 +08:00
|
|
|
* @param btn pointer to a list element (button)
|
|
|
|
* @return the index of the button in the list, or -1 of the button not in this list
|
|
|
|
*/
|
2018-10-30 17:05:27 +08:00
|
|
|
int32_t lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn)
|
2018-10-30 16:38:39 +08:00
|
|
|
{
|
2019-01-12 14:28:20 -08:00
|
|
|
int index = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
if(list == NULL) {
|
2019-01-12 12:08:41 -08:00
|
|
|
/* no list provided, assuming btn is part of a list */
|
|
|
|
list = lv_obj_get_parent(lv_obj_get_parent(btn));
|
|
|
|
}
|
2019-01-12 14:28:20 -08:00
|
|
|
lv_obj_t * e = lv_list_get_next_btn(list, NULL);
|
|
|
|
while(e != NULL) {
|
|
|
|
if(e == btn) {
|
|
|
|
return index;
|
|
|
|
}
|
2019-04-04 07:15:40 +02:00
|
|
|
index++;
|
2018-10-30 16:38:39 +08:00
|
|
|
e = lv_list_get_next_btn(list, e);
|
2019-01-12 14:28:20 -08:00
|
|
|
}
|
|
|
|
return -1;
|
2018-10-30 16:38:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of buttons in the list
|
|
|
|
* @param list pointer to a list object
|
|
|
|
* @return the number of buttons in the list
|
|
|
|
*/
|
2019-05-20 09:22:09 -07:00
|
|
|
uint16_t lv_list_get_size(const lv_obj_t * list)
|
2018-10-30 16:38:39 +08:00
|
|
|
{
|
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
|
|
|
return ext->size;
|
|
|
|
}
|
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP
|
2018-07-30 07:42:36 +02:00
|
|
|
/**
|
|
|
|
* Get the currently selected button
|
|
|
|
* @param list pointer to a list object
|
|
|
|
* @return pointer to the selected button
|
|
|
|
*/
|
|
|
|
lv_obj_t * lv_list_get_btn_selected(const lv_obj_t * list)
|
|
|
|
{
|
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2018-10-05 17:22:49 +02:00
|
|
|
return ext->selected_btn;
|
2018-07-30 07:42:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/**
|
|
|
|
* Get scroll animation duration
|
|
|
|
* @param list pointer to a list object
|
|
|
|
* @return duration of animation [ms]
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
uint16_t lv_list_get_anim_time(const lv_obj_t * list)
|
2017-11-10 15:01:40 +01:00
|
|
|
{
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2017-11-10 15:01:40 +01:00
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
|
|
|
return ext->anim_time;
|
2019-05-20 09:22:09 -07:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2017-11-10 15:01:40 +01:00
|
|
|
}
|
|
|
|
|
2016-10-04 09:45:39 +02:00
|
|
|
/**
|
2017-11-15 15:50:33 +01:00
|
|
|
* Get a style of a list
|
2017-04-21 09:15:39 +02:00
|
|
|
* @param list pointer to a list object
|
2017-11-15 15:50:33 +01:00
|
|
|
* @param type which style should be get
|
|
|
|
* @return style pointer to a style
|
|
|
|
* */
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * lv_list_get_style(const lv_obj_t * list, lv_list_style_t type)
|
2016-10-04 09:45:39 +02:00
|
|
|
{
|
2019-06-06 06:05:40 +02:00
|
|
|
const lv_style_t * style = NULL;
|
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
|
|
|
switch(type) {
|
2019-04-04 07:15:40 +02:00
|
|
|
case LV_LIST_STYLE_BG: style = lv_page_get_style(list, LV_PAGE_STYLE_BG); break;
|
2019-05-16 19:42:50 -04:00
|
|
|
case LV_LIST_STYLE_SCRL: style = lv_page_get_style(list, LV_PAGE_STYLE_SCRL); break;
|
|
|
|
case LV_LIST_STYLE_SB: style = lv_page_get_style(list, LV_PAGE_STYLE_SB); break;
|
2019-06-06 06:05:40 +02:00
|
|
|
case LV_LIST_STYLE_EDGE_FLASH: style = lv_page_get_style(list, LV_PAGE_STYLE_EDGE_FLASH); break;
|
2019-04-04 07:15:40 +02:00
|
|
|
case LV_LIST_STYLE_BTN_REL: style = ext->styles_btn[LV_BTN_STATE_REL]; break;
|
|
|
|
case LV_LIST_STYLE_BTN_PR: style = ext->styles_btn[LV_BTN_STATE_PR]; break;
|
|
|
|
case LV_LIST_STYLE_BTN_TGL_REL: style = ext->styles_btn[LV_BTN_STATE_TGL_REL]; break;
|
|
|
|
case LV_LIST_STYLE_BTN_TGL_PR: style = ext->styles_btn[LV_BTN_STATE_TGL_PR]; break;
|
|
|
|
case LV_LIST_STYLE_BTN_INA: style = ext->styles_btn[LV_BTN_STATE_INA]; break;
|
|
|
|
default: style = NULL; break;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
2016-10-04 15:19:07 +02:00
|
|
|
|
2018-11-05 22:21:20 -06:00
|
|
|
return style;
|
2016-10-04 09:45:39 +02:00
|
|
|
}
|
2017-11-10 15:01:40 +01:00
|
|
|
/*=====================
|
|
|
|
* Other functions
|
|
|
|
*====================*/
|
|
|
|
|
2017-11-07 14:31:35 +01:00
|
|
|
/**
|
2017-11-10 15:01:40 +01:00
|
|
|
* Move the list elements up by one
|
|
|
|
* @param list pointer a to list object
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
void lv_list_up(const lv_obj_t * list)
|
2017-11-10 15:01:40 +01:00
|
|
|
{
|
|
|
|
/*Search the first list element which 'y' coordinate is below the parent
|
|
|
|
* and position the list to show this element on the bottom*/
|
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(list);
|
|
|
|
lv_obj_t * e;
|
|
|
|
lv_obj_t * e_prev = NULL;
|
2019-04-04 07:15:40 +02:00
|
|
|
e = lv_list_get_prev_btn(list, NULL);
|
2017-11-10 15:01:40 +01:00
|
|
|
while(e != NULL) {
|
|
|
|
if(e->coords.y2 <= list->coords.y2) {
|
|
|
|
if(e_prev != NULL) {
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_coord_t new_y = lv_obj_get_height(list) - (lv_obj_get_y(e_prev) + lv_obj_get_height(e_prev));
|
2019-05-20 09:22:09 -07:00
|
|
|
if(lv_list_get_anim_time(list) == 0) {
|
2017-11-10 15:01:40 +01:00
|
|
|
lv_obj_set_y(scrl, new_y);
|
|
|
|
} else {
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_anim_t a;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.var = scrl;
|
|
|
|
a.start = lv_obj_get_y(scrl);
|
|
|
|
a.end = new_y;
|
2019-05-20 09:22:09 -07:00
|
|
|
a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_y;
|
|
|
|
a.path_cb = lv_anim_path_linear;
|
|
|
|
a.ready_cb = NULL;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.act_time = 0;
|
|
|
|
a.time = LV_LIST_DEF_ANIM_TIME;
|
|
|
|
a.playback = 0;
|
2017-11-10 15:01:40 +01:00
|
|
|
a.playback_pause = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.repeat = 0;
|
|
|
|
a.repeat_pause = 0;
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_anim_create(&a);
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2017-11-10 15:01:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
e_prev = e;
|
2019-04-04 07:15:40 +02:00
|
|
|
e = lv_list_get_prev_btn(list, e);
|
2017-11-10 15:01:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the list elements down by one
|
2017-11-07 14:31:35 +01:00
|
|
|
* @param list pointer to a list object
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
void lv_list_down(const lv_obj_t * list)
|
2017-11-07 14:31:35 +01:00
|
|
|
{
|
2017-11-10 15:01:40 +01:00
|
|
|
/*Search the first list element which 'y' coordinate is above the parent
|
|
|
|
* and position the list to show this element on the top*/
|
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(list);
|
|
|
|
lv_obj_t * e;
|
2018-08-27 19:55:17 +02:00
|
|
|
e = lv_list_get_prev_btn(list, NULL);
|
2017-11-10 15:01:40 +01:00
|
|
|
while(e != NULL) {
|
|
|
|
if(e->coords.y1 < list->coords.y1) {
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_coord_t new_y = -lv_obj_get_y(e);
|
2019-05-20 09:22:09 -07:00
|
|
|
if(lv_list_get_anim_time(list) == 0) {
|
2017-11-10 15:01:40 +01:00
|
|
|
lv_obj_set_y(scrl, new_y);
|
|
|
|
} else {
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_anim_t a;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.var = scrl;
|
|
|
|
a.start = lv_obj_get_y(scrl);
|
|
|
|
a.end = new_y;
|
2019-05-20 09:22:09 -07:00
|
|
|
a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_y;
|
|
|
|
a.path_cb = lv_anim_path_linear;
|
|
|
|
a.ready_cb = NULL;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.act_time = 0;
|
|
|
|
a.time = LV_LIST_DEF_ANIM_TIME;
|
|
|
|
a.playback = 0;
|
2017-11-10 15:01:40 +01:00
|
|
|
a.playback_pause = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
a.repeat = 0;
|
|
|
|
a.repeat_pause = 0;
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_anim_create(&a);
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2017-11-10 15:01:40 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-08-27 19:55:17 +02:00
|
|
|
e = lv_list_get_prev_btn(list, e);
|
2017-11-10 15:01:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Focus on a list button. It ensures that the button will be visible on the list.
|
|
|
|
* @param btn pointer to a list button to focus
|
2019-06-11 13:51:14 +02:00
|
|
|
* @param anim_en LV_ANIM_ON: scroll with animation, LV_ANOM_OFF: without animation
|
2017-11-10 15:01:40 +01:00
|
|
|
*/
|
2019-06-11 13:51:14 +02:00
|
|
|
void lv_list_focus(const lv_obj_t * btn, lv_anim_enable_t anim)
|
2017-11-10 15:01:40 +01:00
|
|
|
{
|
2018-03-01 12:21:49 +01:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION == 0
|
2018-03-01 12:21:49 +01:00
|
|
|
anim_en = false;
|
|
|
|
#endif
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn));
|
2017-11-10 15:01:40 +01:00
|
|
|
|
2019-06-11 13:51:14 +02:00
|
|
|
lv_page_focus(list, btn, anim == LV_ANIM_OFF ? 0 : lv_list_get_anim_time(list));
|
2017-11-07 14:31:35 +01:00
|
|
|
}
|
|
|
|
|
2016-06-22 17:24:02 +02:00
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
2017-11-07 14:31:35 +01:00
|
|
|
/**
|
|
|
|
* Signal function of the list
|
|
|
|
* @param list pointer to a list object
|
|
|
|
* @param sign a signal type from lv_signal_t enum
|
|
|
|
* @param param pointer to a signal specific variable
|
|
|
|
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
|
|
|
*/
|
|
|
|
static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
|
|
|
|
{
|
|
|
|
lv_res_t res;
|
|
|
|
|
|
|
|
/* Include the ancient signal function */
|
2018-07-13 00:01:10 +02:00
|
|
|
res = ancestor_page_signal(list, sign, param);
|
2017-11-07 17:00:55 +01:00
|
|
|
if(res != LV_RES_OK) return res;
|
2017-11-07 14:31:35 +01:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_PRESSING ||
|
|
|
|
sign == LV_SIGNAL_LONG_PRESS || sign == LV_SIGNAL_LONG_PRESS_REP) {
|
2019-03-12 19:20:23 +01:00
|
|
|
/*If pressed/released etc by a KEYPAD or ENCODER delegate signal to the button*/
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_indev_t * indev = lv_indev_get_act();
|
2019-03-29 16:10:18 +01:00
|
|
|
lv_indev_type_t indev_type = lv_indev_get_type(indev);
|
2019-03-12 19:20:23 +01:00
|
|
|
if(indev_type == LV_INDEV_TYPE_KEYPAD ||
|
2019-04-04 07:15:40 +02:00
|
|
|
(indev_type == LV_INDEV_TYPE_ENCODER && lv_group_get_editing(lv_obj_get_group(list)))) {
|
2019-03-12 19:20:23 +01:00
|
|
|
/*Get the 'pressed' button*/
|
|
|
|
lv_obj_t * btn = NULL;
|
2019-04-04 07:15:40 +02:00
|
|
|
btn = lv_list_get_prev_btn(list, btn);
|
2019-03-12 19:20:23 +01:00
|
|
|
while(btn != NULL) {
|
|
|
|
if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
|
|
|
|
btn = lv_list_get_prev_btn(list, btn);
|
|
|
|
}
|
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
|
|
|
|
2019-04-04 16:44:16 +02:00
|
|
|
/*The page receives the key presses so the events should be propagated to the selected
|
|
|
|
* button*/
|
2019-03-12 19:20:23 +01:00
|
|
|
if(btn) {
|
|
|
|
if(sign == LV_SIGNAL_PRESSED) {
|
2019-04-12 07:22:37 +02:00
|
|
|
res = lv_event_send(btn, LV_EVENT_PRESSED, NULL);
|
2019-04-04 07:15:40 +02:00
|
|
|
} else if(sign == LV_SIGNAL_PRESSING) {
|
2019-04-12 07:22:37 +02:00
|
|
|
res = lv_event_send(btn, LV_EVENT_PRESSING, NULL);
|
2019-04-04 16:44:16 +02:00
|
|
|
} else if(sign == LV_SIGNAL_LONG_PRESS) {
|
2019-04-12 07:22:37 +02:00
|
|
|
res = lv_event_send(btn, LV_EVENT_LONG_PRESSED, NULL);
|
2019-04-04 16:44:16 +02:00
|
|
|
} else if(sign == LV_SIGNAL_LONG_PRESS_REP) {
|
2019-04-12 07:22:37 +02:00
|
|
|
res = lv_event_send(btn, LV_EVENT_LONG_PRESSED_REPEAT, NULL);
|
2019-04-04 16:44:16 +02:00
|
|
|
} else if(sign == LV_SIGNAL_RELEASED) {
|
2019-03-12 19:20:23 +01:00
|
|
|
ext->last_sel = btn;
|
2019-04-12 07:22:37 +02:00
|
|
|
if(indev->proc.long_pr_sent == 0) {
|
|
|
|
res = lv_event_send(btn, LV_EVENT_SHORT_CLICKED, NULL);
|
|
|
|
}
|
|
|
|
if(lv_indev_is_dragging(indev) == false && res == LV_RES_OK) {
|
|
|
|
res = lv_event_send(btn, LV_EVENT_CLICKED, NULL);
|
|
|
|
}
|
|
|
|
if(res == LV_RES_OK) {
|
|
|
|
res = lv_event_send(btn, LV_EVENT_RELEASED, NULL);
|
|
|
|
}
|
2019-03-12 19:20:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-04 07:15:40 +02:00
|
|
|
} else if(sign == LV_SIGNAL_FOCUS) {
|
2018-10-09 15:03:46 +02:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP
|
2019-03-29 16:10:18 +01:00
|
|
|
lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
|
2018-09-26 14:21:39 +02:00
|
|
|
/*With ENCODER select the first button only in edit mode*/
|
|
|
|
if(indev_type == LV_INDEV_TYPE_ENCODER) {
|
|
|
|
lv_group_t * g = lv_obj_get_group(list);
|
|
|
|
if(lv_group_get_editing(g)) {
|
2018-11-07 17:58:19 +01:00
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2019-02-12 22:48:39 +01:00
|
|
|
if(ext->last_sel) {
|
2018-11-07 20:41:52 +01:00
|
|
|
/* Select the last used button */
|
2018-11-07 17:58:19 +01:00
|
|
|
lv_list_set_btn_selected(list, ext->last_sel);
|
2019-04-04 07:15:40 +02:00
|
|
|
} else {
|
2018-11-07 17:58:19 +01:00
|
|
|
/*Get the first button and mark it as selected*/
|
|
|
|
lv_list_set_btn_selected(list, lv_list_get_next_btn(list, NULL));
|
|
|
|
}
|
2018-09-26 14:21:39 +02:00
|
|
|
} else {
|
|
|
|
lv_list_set_btn_selected(list, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*Else select the clicked button*/
|
|
|
|
else {
|
|
|
|
/*Mark the last clicked button (if any) as selected because it triggered the focus*/
|
|
|
|
if(last_clicked_btn) {
|
|
|
|
lv_list_set_btn_selected(list, last_clicked_btn);
|
|
|
|
} else {
|
2018-11-05 08:46:17 -08:00
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2019-02-12 22:48:39 +01:00
|
|
|
if(ext->last_sel) {
|
2018-11-05 08:46:17 -08:00
|
|
|
/* Select the last used button */
|
|
|
|
lv_list_set_btn_selected(list, ext->last_sel);
|
2019-04-04 07:15:40 +02:00
|
|
|
} else {
|
2018-11-05 08:46:17 -08:00
|
|
|
/*Get the first button and mark it as selected*/
|
|
|
|
lv_list_set_btn_selected(list, lv_list_get_next_btn(list, NULL));
|
|
|
|
}
|
2018-09-26 14:21:39 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-09 15:03:46 +02:00
|
|
|
#endif
|
2018-06-19 09:49:58 +02:00
|
|
|
} else if(sign == LV_SIGNAL_DEFOCUS) {
|
2018-10-09 15:03:46 +02:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP
|
2018-07-30 07:42:36 +02:00
|
|
|
/*De-select the selected btn*/
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_list_set_btn_selected(list, NULL);
|
2019-04-04 07:15:40 +02:00
|
|
|
last_clicked_btn = NULL; /*button click will be set if click happens before focus*/
|
2018-10-09 15:03:46 +02:00
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->selected_btn = NULL;
|
2018-10-09 15:03:46 +02:00
|
|
|
#endif
|
2018-07-25 21:52:50 +02:00
|
|
|
} else if(sign == LV_SIGNAL_GET_EDITABLE) {
|
2018-10-05 17:22:49 +02:00
|
|
|
bool * editable = (bool *)param;
|
2019-04-04 07:15:40 +02:00
|
|
|
*editable = true;
|
2019-03-19 07:15:00 +01:00
|
|
|
} else if(sign == LV_SIGNAL_CONTROL) {
|
2018-10-09 15:03:46 +02:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP
|
2018-06-19 09:49:58 +02:00
|
|
|
char c = *((char *)param);
|
2019-04-08 14:36:20 +02:00
|
|
|
if(c == LV_KEY_RIGHT || c == LV_KEY_DOWN) {
|
2018-10-09 15:03:46 +02:00
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2018-10-05 17:22:49 +02:00
|
|
|
/*If there is a valid selected button the make the previous selected*/
|
|
|
|
if(ext->selected_btn) {
|
|
|
|
lv_obj_t * btn_prev = lv_list_get_next_btn(list, ext->selected_btn);
|
|
|
|
if(btn_prev) lv_list_set_btn_selected(list, btn_prev);
|
|
|
|
}
|
|
|
|
/*If there is no selected button the make the first selected*/
|
2018-07-30 07:42:36 +02:00
|
|
|
else {
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_obj_t * btn = lv_list_get_next_btn(list, NULL);
|
2019-04-04 07:15:40 +02:00
|
|
|
if(btn)
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_list_set_btn_selected(list,
|
|
|
|
btn); /*If there are no buttons on the list then there is no first button*/
|
2017-11-07 14:31:35 +01:00
|
|
|
}
|
2019-04-08 14:36:20 +02:00
|
|
|
} else if(c == LV_KEY_LEFT || c == LV_KEY_UP) {
|
2018-10-09 15:03:46 +02:00
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2018-07-30 07:42:36 +02:00
|
|
|
/*If there is a valid selected button the make the next selected*/
|
|
|
|
if(ext->selected_btn != NULL) {
|
2018-08-27 19:55:17 +02:00
|
|
|
lv_obj_t * btn_next = lv_list_get_prev_btn(list, ext->selected_btn);
|
2018-07-30 07:42:36 +02:00
|
|
|
if(btn_next) lv_list_set_btn_selected(list, btn_next);
|
2017-11-07 14:31:35 +01:00
|
|
|
}
|
2018-07-30 07:42:36 +02:00
|
|
|
/*If there is no selected button the make the first selected*/
|
2018-07-12 23:38:27 +02:00
|
|
|
else {
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_obj_t * btn = lv_list_get_next_btn(list, NULL);
|
|
|
|
if(btn) lv_list_set_btn_selected(list, btn);
|
2018-07-12 23:38:27 +02:00
|
|
|
}
|
2018-02-28 15:37:41 +01:00
|
|
|
}
|
2018-10-09 15:03:46 +02:00
|
|
|
#endif
|
|
|
|
} else if(sign == LV_SIGNAL_GET_TYPE) {
|
|
|
|
lv_obj_type_t * buf = param;
|
|
|
|
uint8_t i;
|
2019-04-04 07:15:40 +02:00
|
|
|
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
|
2018-10-09 15:03:46 +02:00
|
|
|
if(buf->type[i] == NULL) break;
|
|
|
|
}
|
|
|
|
buf->type[i] = "lv_list";
|
2017-11-07 14:31:35 +01:00
|
|
|
}
|
2017-11-15 15:50:33 +01:00
|
|
|
return res;
|
2017-11-07 14:31:35 +01:00
|
|
|
}
|
|
|
|
|
2018-07-13 00:01:10 +02:00
|
|
|
/**
|
|
|
|
* Signal function of the list buttons
|
|
|
|
* @param btn pointer to a button on the list
|
|
|
|
* @param sign a signal type from lv_signal_t enum
|
|
|
|
* @param param pointer to a signal specific variable
|
|
|
|
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
|
|
|
*/
|
|
|
|
static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
|
|
|
|
{
|
|
|
|
lv_res_t res;
|
|
|
|
|
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = ancestor_btn_signal(btn, sign, param);
|
|
|
|
if(res != LV_RES_OK) return res;
|
|
|
|
|
|
|
|
if(sign == LV_SIGNAL_RELEASED) {
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn));
|
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2018-11-25 19:40:19 +01:00
|
|
|
ext->page.scroll_prop_ip = 0;
|
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_group_t * g = lv_obj_get_group(list);
|
|
|
|
if(lv_group_get_focused(g) == list && lv_indev_is_dragging(lv_indev_get_act()) == false) {
|
|
|
|
/* Is the list is focused then be sure only the button being released
|
|
|
|
* has a pressed state to indicate the selected state on the list*/
|
|
|
|
lv_obj_t * btn_i = lv_list_get_prev_btn(list, NULL);
|
|
|
|
while(btn_i) {
|
|
|
|
lv_btn_state_t s = lv_btn_get_state(btn_i);
|
2019-04-04 07:15:40 +02:00
|
|
|
if(s == LV_BTN_STATE_PR)
|
|
|
|
lv_btn_set_state(btn_i, LV_BTN_STATE_REL);
|
|
|
|
else if(s == LV_BTN_STATE_TGL_PR)
|
|
|
|
lv_btn_set_state(btn_i, LV_BTN_STATE_TGL_REL);
|
2018-10-05 17:22:49 +02:00
|
|
|
btn_i = lv_list_get_prev_btn(list, btn_i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Make the released button "selected"*/
|
|
|
|
lv_list_set_btn_selected(list, btn);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If `click_focus == 1` then LV_SIGNAL_FOCUS need to know which button triggered the focus
|
|
|
|
* to mark it as selected (pressed state)*/
|
|
|
|
last_clicked_btn = btn;
|
2018-11-25 19:40:19 +01:00
|
|
|
#endif
|
2019-04-04 07:15:40 +02:00
|
|
|
if(lv_indev_is_dragging(lv_indev_get_act()) == false && ext->single_mode) {
|
2019-01-12 14:28:20 -08:00
|
|
|
lv_list_btn_single_selected(btn);
|
2018-12-07 15:22:07 +08:00
|
|
|
}
|
2019-04-04 07:15:40 +02:00
|
|
|
} else if(sign == LV_SIGNAL_PRESS_LOST) {
|
|
|
|
lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn));
|
|
|
|
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
2018-11-25 19:40:19 +01:00
|
|
|
ext->page.scroll_prop_ip = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
} else if(sign == LV_SIGNAL_CLEANUP) {
|
2018-07-13 00:01:10 +02:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP
|
2018-10-15 19:00:03 +02:00
|
|
|
lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn));
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_t * sel = lv_list_get_btn_selected(list);
|
2018-10-15 19:00:03 +02:00
|
|
|
if(sel == btn) lv_list_set_btn_selected(list, lv_list_get_next_btn(list, btn));
|
2018-11-25 19:40:19 +01:00
|
|
|
#endif
|
2018-10-15 19:00:03 +02:00
|
|
|
}
|
|
|
|
|
2018-07-13 00:01:10 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2018-12-07 15:22:07 +08:00
|
|
|
/**
|
2019-04-04 07:15:40 +02:00
|
|
|
* Make a single button selected in the list, deselect others, should be called in list btns call
|
|
|
|
* back.
|
2018-12-07 15:22:07 +08:00
|
|
|
* @param btn pointer to the currently pressed list btn object
|
|
|
|
*/
|
2019-04-04 07:15:40 +02:00
|
|
|
static void lv_list_btn_single_selected(lv_obj_t * btn)
|
2018-12-07 15:22:07 +08:00
|
|
|
{
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn));
|
2019-01-12 14:28:20 -08:00
|
|
|
|
|
|
|
lv_obj_t * e = lv_list_get_next_btn(list, NULL);
|
2019-04-04 07:15:40 +02:00
|
|
|
do {
|
|
|
|
if(e == btn) {
|
2019-01-12 14:28:20 -08:00
|
|
|
lv_btn_set_state(e, LV_BTN_STATE_TGL_REL);
|
2019-04-04 07:15:40 +02:00
|
|
|
} else {
|
2019-01-12 14:28:20 -08:00
|
|
|
lv_btn_set_state(e, LV_BTN_STATE_REL);
|
|
|
|
}
|
|
|
|
e = lv_list_get_next_btn(list, e);
|
2019-04-04 07:15:40 +02:00
|
|
|
} while(e != NULL);
|
2018-12-07 15:22:07 +08:00
|
|
|
}
|
2017-11-07 14:31:35 +01:00
|
|
|
|
2019-04-10 19:52:11 -04:00
|
|
|
/**
|
|
|
|
* Check if this is really a list button or another object.
|
|
|
|
* @param list_btn List button
|
|
|
|
*/
|
|
|
|
static bool lv_list_is_list_btn(lv_obj_t * list_btn)
|
|
|
|
{
|
|
|
|
lv_obj_type_t type;
|
|
|
|
|
|
|
|
lv_obj_get_type(list_btn, &type);
|
|
|
|
uint8_t cnt;
|
|
|
|
for(cnt = 0; cnt < LV_MAX_ANCESTOR_NUM; cnt++) {
|
|
|
|
if(type.type[cnt] == NULL) break;
|
2019-06-06 06:05:40 +02:00
|
|
|
if(!strcmp(type.type[cnt], "lv_btn")) return true;
|
2019-04-10 19:52:11 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if this is really a list label or another object.
|
|
|
|
* @param list_label List label
|
|
|
|
*/
|
|
|
|
static bool lv_list_is_list_label(lv_obj_t * list_label)
|
|
|
|
{
|
|
|
|
lv_obj_type_t type;
|
|
|
|
|
|
|
|
lv_obj_get_type(list_label, &type);
|
|
|
|
uint8_t cnt;
|
|
|
|
for(cnt = 0; cnt < LV_MAX_ANCESTOR_NUM; cnt++) {
|
|
|
|
if(type.type[cnt] == NULL) break;
|
2019-06-06 06:05:40 +02:00
|
|
|
if(!strcmp(type.type[cnt], "lv_label")) return true;
|
2019-04-10 19:52:11 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if this is really a list image or another object.
|
|
|
|
* @param list_image List image
|
|
|
|
*/
|
|
|
|
static bool lv_list_is_list_img(lv_obj_t * list_img)
|
|
|
|
{
|
|
|
|
lv_obj_type_t type;
|
|
|
|
|
|
|
|
lv_obj_get_type(list_img, &type);
|
|
|
|
uint8_t cnt;
|
|
|
|
for(cnt = 0; cnt < LV_MAX_ANCESTOR_NUM; cnt++) {
|
|
|
|
if(type.type[cnt] == NULL) break;
|
2019-06-06 06:05:40 +02:00
|
|
|
if(!strcmp(type.type[cnt], "lv_img")) return true;
|
2019-04-10 19:52:11 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-22 17:24:02 +02:00
|
|
|
#endif
|