1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/src/lv_widgets/lv_list.h

312 lines
8.5 KiB
C
Raw Normal View History

2016-06-22 17:24:02 +02:00
/**
* @file lv_list.h
2018-06-19 09:49:58 +02:00
*
2016-06-22 17:24:02 +02:00
*/
#ifndef LV_LIST_H
#define LV_LIST_H
2017-07-09 15:32:49 +02:00
#ifdef __cplusplus
extern "C" {
#endif
2016-06-22 17:24:02 +02:00
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#if LV_USE_LIST != 0
2016-06-22 17:24:02 +02:00
2017-01-02 10:48:21 +01:00
/*Testing of dependencies*/
#if LV_USE_PAGE == 0
#error "lv_list: lv_page is required. Enable it in lv_conf.h (LV_USE_PAGE 1) "
2017-05-15 09:14:48 +02:00
#endif
#if LV_USE_BTN == 0
#error "lv_list: lv_btn is required. Enable it in lv_conf.h (LV_USE_BTN 1) "
2017-01-02 10:48:21 +01:00
#endif
#if LV_USE_LABEL == 0
#error "lv_list: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1) "
2017-01-02 10:48:21 +01:00
#endif
2017-11-30 11:35:33 +01:00
#include "../lv_core/lv_obj.h"
2016-06-22 17:24:02 +02:00
#include "lv_page.h"
#include "lv_btn.h"
2016-07-12 01:16:27 +02:00
#include "lv_label.h"
#include "lv_img.h"
2016-06-22 17:24:02 +02:00
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Data of list*/
2020-02-26 19:48:27 +01:00
typedef struct {
2017-04-11 10:50:57 +02:00
lv_page_ext_t page; /*Ext. of ancestor*/
/*New data for this type */
#if LV_USE_GROUP
2020-02-02 10:39:46 +01:00
lv_obj_t * last_sel_btn; /* The last selected button. It will be reverted when the list is focused again */
#endif
2020-02-15 02:19:44 +01:00
lv_obj_t * act_sel_btn; /* The button is currently being selected*/
2018-06-19 09:49:58 +02:00
} lv_list_ext_t;
2016-06-22 17:24:02 +02:00
2019-06-27 18:07:26 -04:00
/** List styles. */
2018-09-18 13:59:40 +02:00
enum {
LV_LIST_PART_BG = LV_PAGE_PART_BG, /**< List background style */
2020-05-06 19:39:10 +02:00
LV_LIST_PART_SCROLLBAR = LV_PAGE_PART_SCROLLBAR, /**< List scrollbar style. */
LV_LIST_PART_EDGE_FLASH = LV_PAGE_PART_EDGE_FLASH, /**< List edge flash style. */
_LV_LIST_PART_VIRTUAL_LAST = _LV_PAGE_PART_VIRTUAL_LAST,
2020-05-06 19:39:10 +02:00
LV_LIST_PART_SCROLLABLE = LV_PAGE_PART_SCROLLABLE, /**< List scrollable area style. */
_LV_LIST_PART_REAL_LAST = _LV_PAGE_PART_REAL_LAST,
2018-09-18 13:59:40 +02:00
};
typedef uint8_t lv_list_style_t;
2016-06-22 17:24:02 +02:00
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a list objects
* @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
* @return pointer to the created list
*/
lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy);
2017-11-10 15:01:40 +01:00
/**
* Delete all children of the scrl object, without deleting scrl child.
* @param list pointer to an object
*/
void lv_list_clean(lv_obj_t * list);
2017-11-10 15:01:40 +01:00
/*======================
* Add/remove functions
*=====================*/
/**
* Add a list element to the list
* @param list pointer to list object
* @param img_fn file name of an image before the text (NULL if unused)
* @param txt text of the list element (NULL if unused)
* @return pointer to the new list element which can be customized (a button)
*/
lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * img_src, const char * txt);
2017-11-10 15:01:40 +01:00
2018-10-30 16:38:00 +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:00 +08:00
* @return true: successfully deleted
*/
bool lv_list_remove(const lv_obj_t * list, uint16_t index);
2018-10-30 16:38:00 +08:00
2017-11-10 15:01:40 +01:00
/*=====================
* Setter functions
*====================*/
2019-04-04 07:15:40 +02:00
/**
2019-05-18 11:21:20 +02:00
* Make a button selected
* @param list pointer to a list object
* @param btn pointer to a button to select
2019-05-18 11:21:20 +02:00
* NULL to not select any buttons
*/
2020-02-02 10:39:46 +01:00
void lv_list_focus_btn(lv_obj_t * list, lv_obj_t * btn);
2016-10-07 11:15:46 +02:00
/**
2017-11-10 15:01:40 +01:00
* Set the scroll bar mode of a list
* @param list pointer to a list object
2017-11-10 15:01:40 +01:00
* @param sb_mode the new mode from 'lv_page_sb_mode_t' enum
*/
static inline void lv_list_set_scrollbar_mode(lv_obj_t * list, lv_scrollbar_mode_t mode)
2017-11-10 15:01:40 +01:00
{
lv_page_set_scrollbar_mode(list, mode);
2017-11-10 15:01:40 +01:00
}
/**
2019-04-04 07:15:40 +02:00
* Enable the scroll propagation feature. If enabled then the List will move its parent if there is
* no more space to scroll.
* @param list pointer to a List
* @param en true or false to enable/disable scroll propagation
*/
static inline void lv_list_set_scroll_propagation(lv_obj_t * list, bool en)
{
lv_page_set_scroll_propagation(list, en);
}
2018-11-24 20:31:06 +01:00
/**
* Enable the edge flash effect. (Show an arc when the an edge is reached)
* @param list pointer to a List
* @param en true or false to enable/disable end flash
*/
static inline void lv_list_set_edge_flash(lv_obj_t * list, bool en)
{
lv_page_set_edge_flash(list, en);
}
2019-06-19 00:35:35 +02:00
/**
* Set scroll animation duration on 'list_up()' 'list_down()' 'list_focus()'
* @param list pointer to a list object
* @param anim_time duration of animation [ms]
*/
static inline void lv_list_set_anim_time(lv_obj_t * list, uint16_t anim_time)
{
lv_page_set_anim_time(list, anim_time);
}
2019-07-07 12:17:06 -05:00
/**
* Set layout of a list
* @param list pointer to a list object
* @param layout which layout should be used
*/
void lv_list_set_layout(lv_obj_t * list, lv_layout_t layout);
2019-07-07 12:17:06 -05:00
2017-11-10 15:01:40 +01:00
/*=====================
* Getter functions
*====================*/
2017-11-07 14:31:35 +01:00
/**
* Get the text of a list element
2017-11-10 15:01:40 +01:00
* @param btn pointer to list element
* @return pointer to the text
*/
const char * lv_list_get_btn_text(const lv_obj_t * btn);
/**
* Get the label object from a list element
2017-11-10 15:01:40 +01:00
* @param btn pointer to a list element (button)
* @return pointer to the label from the list element or NULL if not found
*/
lv_obj_t * lv_list_get_btn_label(const lv_obj_t * btn);
/**
* Get the image object from a list element
2017-11-10 15:01:40 +01:00
* @param btn pointer to a list element (button)
* @return pointer to the image from the list element or NULL if not found
*/
lv_obj_t * lv_list_get_btn_img(const lv_obj_t * btn);
2017-11-07 14:31:35 +01:00
/**
* Get the next button from list. (Starts from the bottom button)
* @param list pointer to a list object
* @param prev_btn pointer to button. Search the next after it.
* @return pointer to the next button or NULL when no more buttons
*/
lv_obj_t * lv_list_get_prev_btn(const lv_obj_t * list, lv_obj_t * prev_btn);
/**
* Get the previous button from list. (Starts from the top button)
* @param list pointer to a list object
* @param prev_btn pointer to button. Search the previous before it.
* @return pointer to the previous button or NULL when no more buttons
*/
lv_obj_t * lv_list_get_next_btn(const lv_obj_t * list, lv_obj_t * prev_btn);
2018-10-30 16:38:00 +08:00
/**
* Get the index of the button in the list
* @param list pointer to a list object. If NULL, assumes btn is part of a list.
2018-10-30 16:38:00 +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:04:11 +08:00
int32_t lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn);
2018-10-30 16:38:00 +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
*/
uint16_t lv_list_get_size(const lv_obj_t * list);
2018-10-30 16:38:00 +08:00
#if LV_USE_GROUP
/**
2018-11-02 12:45:09 +01:00
* Get the currently selected button. Can be used while navigating in the list with a keypad.
* @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);
#endif
2019-07-07 12:17:06 -05:00
/**
* Get layout of a list
* @param list pointer to a list object
* @return layout of the list object
2019-07-07 12:17:06 -05:00
*/
lv_layout_t lv_list_get_layout(lv_obj_t * list);
2019-07-07 12:17:06 -05:00
2017-11-07 14:31:35 +01:00
/**
* Get the scroll bar mode of a list
* @param list pointer to a list object
* @return scrollbar mode from 'lv_scrollbar_mode_t' enum
2017-11-07 14:31:35 +01:00
*/
static inline lv_scrollbar_mode_t lv_list_get_scrollbar_mode(const lv_obj_t * list)
2017-11-07 14:31:35 +01:00
{
return lv_page_get_scrollbar_mode(list);
2017-11-07 14:31:35 +01:00
}
/**
* Get the scroll propagation property
* @param list pointer to a List
* @return true or false
*/
static inline bool lv_list_get_scroll_propagation(lv_obj_t * list)
{
return lv_page_get_scroll_propagation(list);
}
2018-11-24 20:31:06 +01:00
/**
* Get the scroll propagation property
* @param list pointer to a List
* @return true or false
*/
static inline bool lv_list_get_edge_flash(lv_obj_t * list)
{
return lv_page_get_edge_flash(list);
}
2019-06-19 00:35:35 +02:00
/**
* Get scroll animation duration
* @param list pointer to a list object
* @return duration of animation [ms]
*/
static inline uint16_t lv_list_get_anim_time(const lv_obj_t * list)
{
return lv_page_get_anim_time(list);
}
2017-11-10 15:01:40 +01:00
/*=====================
* Other functions
*====================*/
/**
* Move the list elements up by one
* @param list pointer a to list object
*/
void lv_list_up(const lv_obj_t * list);
2017-11-10 15:01:40 +01:00
/**
* Move the list elements down by one
* @param list pointer to a list object
*/
void lv_list_down(const lv_obj_t * list);
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 LV_ANOM_ON: scroll with animation, LV_ANIM_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
2016-06-22 17:24:02 +02:00
/**********************
* MACROS
**********************/
2019-04-04 07:15:40 +02:00
#endif /*LV_USE_LIST*/
2016-06-22 17:24:02 +02:00
2017-07-09 15:32:49 +02:00
#ifdef __cplusplus
} /* extern "C" */
2016-06-22 17:24:02 +02:00
#endif
2017-07-09 15:32:49 +02:00
2019-04-04 07:15:40 +02:00
#endif /*LV_LIST_H*/