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

171 lines
5.2 KiB
C
Raw Normal View History

/**
* @file lv_ddlist.h
*
*/
#ifndef LV_DDLIST_H
#define LV_DDLIST_H
2017-07-09 15:32:49 +02:00
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
#if USE_LV_DDLIST != 0
2017-04-24 16:16:36 +02:00
/*Testing of dependencies*/
#if USE_LV_PAGE == 0
#error "lv_ddlist: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) "
#endif
#if USE_LV_LABEL == 0
#error "lv_ddlist: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) "
#endif
#include "../lv_obj/lv_obj.h"
#include "../lv_objx/lv_page.h"
#include "../lv_objx/lv_label.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Data of drop down list*/
typedef struct
{
lv_page_ext_t page; /*Ext. of ancestor*/
/*New data for this type */
2017-04-11 10:50:57 +02:00
lv_obj_t * opt_label; /*Label for the options*/
lv_style_t * style_sel; /*Style of the selected option*/
lv_action_t cb; /*Pointer to function to call when an option is selected*/
uint16_t num_opt; /*Number of options*/
2017-04-11 10:50:57 +02:00
uint16_t sel_opt; /*Index of the current option*/
uint16_t anim_time; /*Open/Close animation time [ms]*/
2017-04-11 10:50:57 +02:00
uint8_t opened :1; /*1: The list is opened*/
2017-10-05 11:29:21 +02:00
cord_t fix_height; /*Height if the ddlist is opened. (0: auto-size)*/
}lv_ddlist_ext_t;
/**********************
* 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
* @param copy pointer to a drop down list object, if not NULL then the new object will be copied from it
* @return pointer to the created drop down list
*/
lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy);
/**
* Signal function of the drop down list
* @param ddlist pointer to a drop down list object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
bool lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param);
/**
* Set the options in a drop down list
* @param ddlist pointer to drop down list object
* @param options an array of strings wit the text of the options.
* The lest element has to be "" (empty string)
* E.g. const char * opts[] = {"apple", "banana", "orange", ""};
*/
void lv_ddlist_set_options(lv_obj_t * ddlist, const char ** options);
2017-06-07 12:38:43 +02:00
void lv_ddlist_set_options_str(lv_obj_t * ddlist, const char * options);
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);
*/
void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt);
2017-04-24 14:12:32 +02:00
/**
* Set a function to call when a new option is chosen
2017-02-06 16:05:02 +01:00
* @param ddlist pointer to a drop down list
2017-04-24 14:12:32 +02:00
* @param cb pointer to a call back function
*/
2017-04-24 14:12:32 +02:00
void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_t cb);
2017-02-06 16:05:02 +01:00
/**
2017-10-05 11:29:21 +02:00
* Set the fix height value.
* 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
*/
2017-10-05 11:29:21 +02:00
void lv_ddlist_set_fix_height(lv_obj_t * ddlist, cord_t h);
2017-02-06 16:05:02 +01:00
2017-04-21 09:15:39 +02:00
/**
* Set the style of the rectangle on the selected option
* @param ddlist pointer to a drop down list object
* @param style pointer the new style of the select rectangle
*/
void lv_ddlist_set_style_select(lv_obj_t * ddlist, lv_style_t * style);
2017-10-05 11:29:21 +02:00
/**
* Open or Collapse the drop down list
* @param ddlist pointer to drop down list object
* @param state true: open; false: collapse
* @param anim true: use animations; false: not use animations
*/
void lv_ddlist_open(lv_obj_t * ddlist, bool state, bool anim);
/**
* 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")
*/
const char * lv_ddlist_get_options(lv_obj_t * ddlist);
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);
*/
uint16_t lv_ddlist_get_selected(lv_obj_t * ddlist);
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
*/
2017-06-07 12:38:43 +02:00
void lv_ddlist_get_selected_str(lv_obj_t * ddlist, char * buf);
2017-07-09 15:32:49 +02:00
2017-10-05 11:29:21 +02: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
*/
2017-10-05 11:29:21 +02:00
cord_t lv_ddlist_get_fix_height(lv_obj_t * ddlist);
2017-02-06 16:05:02 +01:00
2017-04-21 09:15:39 +02:00
/**
* Get the style of the rectangle on the selected option
* @param ddlist pointer to a drop down list object
* @return pointer the style of the select rectangle
*/
2017-04-28 16:12:35 +02:00
lv_style_t * lv_ddlist_get_style_select(lv_obj_t * ddlist);
/**********************
* MACROS
**********************/
2017-07-09 15:32:49 +02:00
#endif /*USE_LV_DDLIST*/
2017-07-09 15:32:49 +02:00
#ifdef __cplusplus
} /* extern "C" */
#endif
2017-07-09 15:32:49 +02:00
#endif /*LV_DDLIST_H*/