2017-02-06 10:06:18 +01:00
|
|
|
/**
|
|
|
|
* @file lv_ddlist.h
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2017-02-06 10:06:18 +01:00
|
|
|
*/
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
#ifndef LV_DROPDOWN_H
|
|
|
|
#define LV_DROPDOWN_H
|
2017-02-06 10:06:18 +01:00
|
|
|
|
2017-07-09 15:32:49 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2019-12-26 02:49:30 +01:00
|
|
|
#include "../lv_conf_internal.h"
|
2018-07-07 11:53:22 +02:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
#if LV_USE_DROPDOWN != 0
|
2017-04-24 16:16:36 +02:00
|
|
|
|
|
|
|
/*Testing of dependencies*/
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_PAGE == 0
|
|
|
|
#error "lv_ddlist: lv_page is required. Enable it in lv_conf.h (LV_USE_PAGE 1) "
|
2017-04-24 16:16:36 +02:00
|
|
|
#endif
|
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_LABEL == 0
|
|
|
|
#error "lv_ddlist: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1) "
|
2017-04-24 16:16:36 +02:00
|
|
|
#endif
|
|
|
|
|
2020-02-14 22:04:00 +01:00
|
|
|
#include "../lv_widgets/lv_btn.h"
|
|
|
|
#include "../lv_widgets/lv_page.h"
|
|
|
|
#include "../lv_widgets/lv_label.h"
|
2017-02-06 10:06:18 +01:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2020-03-02 08:12:42 -08:00
|
|
|
#define LV_DROPDOWN_POS_LAST 0xFFFF
|
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
2020-01-23 17:16:11 +01:00
|
|
|
|
|
|
|
enum {
|
2020-02-14 12:36:44 +01:00
|
|
|
LV_DROPDOWN_DIR_DOWN,
|
|
|
|
LV_DROPDOWN_DIR_UP,
|
|
|
|
LV_DROPDOWN_DIR_LEFT,
|
|
|
|
LV_DROPDOWN_DIR_RIGHT,
|
2020-01-23 17:16:11 +01:00
|
|
|
};
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
typedef uint8_t lv_dropdown_dir_t;
|
2020-01-23 17:16:11 +01:00
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
/*Data of drop down list*/
|
2020-02-26 19:48:27 +01:00
|
|
|
typedef struct {
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_btn_ext_t btn; /*Ext. of ancestor*/
|
2017-02-06 10:06:18 +01:00
|
|
|
/*New data for this type */
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_obj_t * page; /*The dropped down list*/
|
|
|
|
const char * text; /*Text to display on the ddlist's button*/
|
|
|
|
const char * symbol; /*Arrow or other icon when the drop-down list is closed*/
|
2020-03-02 08:12:42 -08:00
|
|
|
char * options;
|
2020-01-23 17:16:11 +01:00
|
|
|
lv_style_list_t style_selected; /*Style of the selected option*/
|
|
|
|
lv_style_list_t style_page; /*Style of the dropped down list*/
|
|
|
|
lv_style_list_t style_scrlbar; /*Style of the scroll bar*/
|
|
|
|
lv_coord_t max_height; /*Height of the ddlist when opened. (0: auto-size)*/
|
2019-06-06 06:05:40 +02:00
|
|
|
uint16_t option_cnt; /*Number of options*/
|
2020-01-24 14:55:56 +01:00
|
|
|
uint16_t sel_opt_id; /*Index of the currently selected option*/
|
|
|
|
uint16_t sel_opt_id_orig; /*Store the original index on focus*/
|
|
|
|
uint16_t pr_opt_id; /*Index of the currently pressed option*/
|
|
|
|
uint16_t anim_time;
|
2020-02-26 19:48:27 +01:00
|
|
|
lv_dropdown_dir_t dir : 2;
|
|
|
|
uint8_t show_selected : 1;
|
2020-03-02 08:12:42 -08:00
|
|
|
uint8_t static_txt : 1;
|
2020-02-14 12:36:44 +01:00
|
|
|
} lv_dropdown_ext_t;
|
2017-02-06 10:06:18 +01:00
|
|
|
|
2018-09-18 13:59:40 +02:00
|
|
|
enum {
|
2020-02-14 12:36:44 +01:00
|
|
|
LV_DROPDOWN_PART_BTN = LV_BTN_PART_MAIN,
|
|
|
|
LV_DROPDOWN_PART_LIST = _LV_BTN_PART_REAL_LAST,
|
|
|
|
LV_DROPDOWN_PART_SCRLBAR,
|
|
|
|
LV_DROPDOWN_PART_SELECTED,
|
2018-09-18 13:59:40 +02:00
|
|
|
};
|
2020-02-14 12:36:44 +01:00
|
|
|
typedef uint8_t lv_dropdown_part_t;
|
2017-02-06 10:06:18 +01:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL PROTOTYPES
|
|
|
|
**********************/
|
|
|
|
/**
|
|
|
|
* Create a drop down list objects
|
|
|
|
* @param par pointer to an object, it will be the parent of the new drop down list
|
2019-04-04 07:15:40 +02:00
|
|
|
* @param copy pointer to a drop down list object, if not NULL then the new object will be copied
|
|
|
|
* from it
|
2017-02-06 10:06:18 +01:00
|
|
|
* @return pointer to the created drop down list
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_t * lv_dropdown_create(lv_obj_t * par, const lv_obj_t * copy);
|
2017-02-06 10:06:18 +01:00
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
|
|
|
|
2020-02-12 08:54:03 +01:00
|
|
|
/**
|
|
|
|
* Set text of the ddlist (Displayed on the button if `show_selected = false`)
|
|
|
|
* @param ddlist pointer to a drop down list object
|
|
|
|
* @param txt the text as a string (Only it's pointer is saved)
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_set_text(lv_obj_t * ddlist, const char * txt);
|
2020-02-12 08:54:03 +01:00
|
|
|
|
2017-10-26 21:20:10 +02:00
|
|
|
/**
|
|
|
|
* Set the options in a drop down list from a string
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
* @param options a string with '\n' separated options. E.g. "One\nTwo\nThree"
|
2020-03-02 08:12:42 -08:00
|
|
|
* The options string can be destroyed after calling this function
|
2017-10-26 21:20:10 +02:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_set_options(lv_obj_t * ddlist, const char * options);
|
2017-10-26 21:20:10 +02:00
|
|
|
|
2020-03-02 08:12:42 -08:00
|
|
|
/**
|
|
|
|
* Set the options in a drop down list from a string
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
* @param options a static string with '\n' separated options. E.g. "One\nTwo\nThree"
|
|
|
|
*/
|
|
|
|
void lv_dropdown_set_static_options(lv_obj_t * ddlist, const char * options);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an options to a drop down list from a string. Only works for dynamic options.
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
* @param options a string without '\n'. E.g. "Four"
|
|
|
|
* @param position the insert position, indexed from 0, LV_DROPDOWN_POS_LAST = end of string
|
|
|
|
*/
|
|
|
|
void lv_dropdown_add_option(lv_obj_t * ddlist, const char * option, int pos);
|
|
|
|
|
2017-02-06 16:05:02 +01:00
|
|
|
/**
|
|
|
|
* Set the selected option
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
* @param sel_opt id of the selected option (0 ... number of option - 1);
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_set_selected(lv_obj_t * ddlist, uint16_t sel_opt);
|
2017-02-06 16:05:02 +01:00
|
|
|
|
|
|
|
/**
|
2020-01-23 17:16:11 +01:00
|
|
|
* Set a maximum height for the drop down list
|
2017-10-05 11:29:21 +02:00
|
|
|
* If 0 then the opened ddlist will be auto. sized else the set height will be applied.
|
2017-02-06 16:05:02 +01:00
|
|
|
* @param ddlist pointer to a drop down list
|
2017-10-05 11:29:21 +02:00
|
|
|
* @param h the height when the list is opened (0: auto size)
|
2017-02-06 16:05:02 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_set_max_height(lv_obj_t * ddlist, lv_coord_t h);
|
2019-11-20 16:18:56 +01:00
|
|
|
|
2019-02-26 16:07:40 +01:00
|
|
|
/**
|
2019-11-20 16:18:56 +01:00
|
|
|
* Set an arrow or other symbol to display when the drop-down list is closed.
|
2019-02-26 16:07:40 +01:00
|
|
|
* @param ddlist pointer to drop down list object
|
2019-11-20 16:18:56 +01:00
|
|
|
* @param symbol a text like `LV_SYMBOL_DOWN` or NULL to not draw icon
|
2019-02-26 16:07:40 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_set_symbol(lv_obj_t * ddlist, const char * symbol);
|
2017-11-17 15:43:08 +01:00
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/**
|
|
|
|
* Set the scroll bar mode of a drop down list
|
|
|
|
* @param ddlist pointer to a drop down list object
|
|
|
|
* @param sb_mode the new mode from 'lv_page_sb_mode_t' enum
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static inline void lv_dropdown_set_sb_mode(lv_obj_t * ddlist, lv_sb_mode_t mode)
|
2017-11-10 15:01:40 +01:00
|
|
|
{
|
|
|
|
lv_page_set_sb_mode(ddlist, mode);
|
|
|
|
}
|
2019-06-19 00:35:35 +02:00
|
|
|
/**
|
|
|
|
* Set the open/close animation time.
|
|
|
|
* @param ddlist pointer to a drop down list
|
|
|
|
* @param anim_time: open/close animation time [ms]
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static inline void lv_dropdown_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time)
|
2019-06-19 00:35:35 +02:00
|
|
|
{
|
|
|
|
lv_page_set_anim_time(ddlist, anim_time);
|
|
|
|
}
|
2017-11-10 15:01:40 +01:00
|
|
|
|
2018-12-09 20:51:32 -05:00
|
|
|
/**
|
2020-01-23 17:16:11 +01:00
|
|
|
* Set the direction of the a drop down list
|
2018-12-09 20:51:32 -05:00
|
|
|
* @param ddlist pointer to a drop down list object
|
2020-02-14 12:36:44 +01:00
|
|
|
* @param dir LV_DROPDOWN_DIR_LEF/RIGHT/TOP/BOTTOM
|
2018-12-09 20:51:32 -05:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_set_dir(lv_obj_t * ddlist, lv_dropdown_dir_t dir);
|
2018-12-09 20:51:32 -05:00
|
|
|
|
2020-02-12 08:54:03 +01:00
|
|
|
/**
|
|
|
|
* Set whether the ddlist highlight the last selected option and display its text or not
|
|
|
|
* @param ddlist pointer to a drop down list object
|
|
|
|
* @param show true/false
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_set_show_selected(lv_obj_t * ddlist, bool show);
|
2020-02-12 08:54:03 +01:00
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2020-02-12 08:54:03 +01:00
|
|
|
/**
|
|
|
|
* Get text of the ddlist (Displayed on the button if `show_selected = false`)
|
|
|
|
* @param ddlist pointer to a drop down list object
|
|
|
|
* @return the text string
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
const char * lv_dropdown_get_text(lv_obj_t * ddlist);
|
2020-02-12 08:54:03 +01:00
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
/**
|
|
|
|
* Get the options of a drop down list
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
* @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3")
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
const char * lv_dropdown_get_options(const lv_obj_t * ddlist);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2017-02-06 16:05:02 +01:00
|
|
|
/**
|
|
|
|
* Get the selected option
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
* @return id of the selected option (0 ... number of option - 1);
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
uint16_t lv_dropdown_get_selected(const lv_obj_t * ddlist);
|
2017-02-06 16:05:02 +01:00
|
|
|
|
2019-12-19 16:34:10 -05:00
|
|
|
/**
|
|
|
|
* Get the total number of options
|
|
|
|
* @param ddlist pointer to drop down list object
|
|
|
|
* @return the total number of options in the list
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
uint16_t lv_dropdown_get_option_cnt(const lv_obj_t * ddlist);
|
2019-12-19 16:34:10 -05:00
|
|
|
|
2017-07-09 15:32:49 +02:00
|
|
|
/**
|
|
|
|
* Get the current selected option as a string
|
|
|
|
* @param ddlist pointer to ddlist object
|
|
|
|
* @param buf pointer to an array to store the string
|
2019-03-29 16:10:18 +01:00
|
|
|
* @param buf_size size of `buf` in bytes. 0: to ignore it.
|
2017-07-09 15:32:49 +02:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_get_selected_str(const lv_obj_t * ddlist, char * buf, uint16_t buf_size);
|
2017-11-05 22:37:03 +01:00
|
|
|
|
2017-02-06 16:05:02 +01:00
|
|
|
/**
|
2017-10-05 11:29:21 +02:00
|
|
|
* Get the fix height value.
|
2017-04-21 09:15:39 +02:00
|
|
|
* @param ddlist pointer to a drop down list object
|
2017-10-05 11:29:21 +02:00
|
|
|
* @return the height if the ddlist is opened (0: auto size)
|
2017-02-06 16:05:02 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_coord_t lv_dropdown_get_max_height(const lv_obj_t * ddlist);
|
2017-02-06 16:05:02 +01:00
|
|
|
|
2019-02-26 16:07:40 +01:00
|
|
|
/**
|
2019-11-20 16:18:56 +01:00
|
|
|
* Get the symbol to draw when the drop-down list is closed
|
2019-02-26 16:07:40 +01:00
|
|
|
* @param ddlist pointer to drop down list object
|
2019-11-20 16:18:56 +01:00
|
|
|
* @return the symbol or NULL if not enabled
|
2019-02-26 16:07:40 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
const char * lv_dropdown_get_symbol(lv_obj_t * ddlist);
|
2019-02-26 16:07:40 +01:00
|
|
|
|
|
|
|
/**
|
2020-01-23 17:16:11 +01:00
|
|
|
* Get the symbol to draw when the drop-down list is closed
|
2019-02-26 16:07:40 +01:00
|
|
|
* @param ddlist pointer to drop down list object
|
2020-01-23 17:16:11 +01:00
|
|
|
* @return the symbol or NULL if not enabled
|
2019-02-26 16:07:40 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_dropdown_dir_t lv_dropdown_get_dir(const lv_obj_t * ddlist);
|
2019-02-26 16:07:40 +01:00
|
|
|
|
2020-02-12 08:54:03 +01:00
|
|
|
/**
|
|
|
|
* Get whether the ddlist highlight the last selected option and display its text or not
|
|
|
|
* @param ddlist pointer to a drop down list object
|
|
|
|
* @return true/false
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
bool lv_dropdown_get_show_selected(lv_obj_t * ddlist);
|
2020-02-12 08:54:03 +01:00
|
|
|
|
2017-11-05 14:12:50 +01:00
|
|
|
/**
|
|
|
|
* Get the scroll bar mode of a drop down list
|
|
|
|
* @param ddlist pointer to a drop down list object
|
|
|
|
* @return scrollbar mode from 'lv_page_sb_mode_t' enum
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static inline lv_sb_mode_t lv_dropdown_get_sb_mode(const lv_obj_t * ddlist)
|
2017-11-05 14:12:50 +01:00
|
|
|
{
|
2017-11-07 14:31:35 +01:00
|
|
|
return lv_page_get_sb_mode(ddlist);
|
2017-11-05 14:12:50 +01:00
|
|
|
}
|
|
|
|
|
2019-06-19 00:35:35 +02:00
|
|
|
/**
|
|
|
|
* Get the open/close animation time.
|
|
|
|
* @param ddlist pointer to a drop down list
|
|
|
|
* @return open/close animation time [ms]
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static inline uint16_t lv_dropdown_get_anim_time(const lv_obj_t * ddlist)
|
2019-06-19 00:35:35 +02:00
|
|
|
{
|
|
|
|
return lv_page_get_anim_time(ddlist);
|
|
|
|
}
|
|
|
|
|
2018-12-09 20:51:32 -05:00
|
|
|
/**
|
|
|
|
* Get the alignment of the labels in a drop down list
|
|
|
|
* @param ddlist pointer to a drop down list object
|
|
|
|
* @return alignment of labels
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_label_align_t lv_dropdown_get_align(const lv_obj_t * ddlist);
|
2018-12-09 20:51:32 -05:00
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/*=====================
|
|
|
|
* Other functions
|
|
|
|
*====================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open the drop down list with or without animation
|
|
|
|
* @param ddlist pointer to drop down list object
|
2019-06-11 13:51:14 +02:00
|
|
|
* @param anim_en LV_ANIM_ON: use animation; LV_ANOM_OFF: not use animations
|
2017-11-10 15:01:40 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_open(lv_obj_t * ddlist, lv_anim_enable_t anim);
|
2018-03-01 12:21:49 +01:00
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/**
|
|
|
|
* Close (Collapse) the drop down list
|
|
|
|
* @param ddlist pointer to drop down list object
|
2019-06-11 13:51:14 +02:00
|
|
|
* @param anim_en LV_ANIM_ON: use animation; LV_ANOM_OFF: not use animations
|
2017-11-10 15:01:40 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_dropdown_close(lv_obj_t * ddlist, lv_anim_enable_t anim);
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2017-02-06 10:06:18 +01:00
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
#endif /*LV_USE_DROPDOWN*/
|
2017-02-06 10:06:18 +01:00
|
|
|
|
2017-07-09 15:32:49 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
2017-02-06 10:06:18 +01:00
|
|
|
#endif
|
2017-07-09 15:32:49 +02:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
#endif /*LV_DROPDOWN_H*/
|