/*1* Copyright (c) 2019 CTCaer2*3* This program is free software; you can redistribute it and/or modify it4* under the terms and conditions of the GNU General Public License,5* version 2, as published by the Free Software Foundation.6*7* This program is distributed in the hope it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for10* more details.11*12* You should have received a copy of the GNU General Public License13* along with this program. If not, see <http://www.gnu.org/licenses/>.14*/1516/**17* @file lv_ddlist.h18*19*/2021#ifndef LV_DDLIST_H22#define LV_DDLIST_H2324#ifdef __cplusplus25extern "C" {26#endif2728/*********************29* INCLUDES30*********************/31#ifdef LV_CONF_INCLUDE_SIMPLE32#include "lv_conf.h"33#else34#include "../../lv_conf.h"35#endif3637#if USE_LV_DDLIST != 03839/*Testing of dependencies*/40#if USE_LV_PAGE == 041#error "lv_ddlist: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) "42#endif4344#if USE_LV_LABEL == 045#error "lv_ddlist: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) "46#endif4748#include "../lv_core/lv_obj.h"49#include "../lv_objx/lv_page.h"50#include "../lv_objx/lv_label.h"5152/*********************53* DEFINES54*********************/5556/**********************57* TYPEDEFS58**********************/59/*Data of drop down list*/60typedef struct61{62lv_page_ext_t page; /*Ext. of ancestor*/63/*New data for this type */64lv_obj_t *label; /*Label for the options*/65lv_style_t * sel_style; /*Style of the selected option*/66lv_action_t action; /*Pointer to function to call when an option is selected*/67uint16_t option_cnt; /*Number of options*/68uint16_t sel_opt_id; /*Index of the current option*/69uint16_t sel_opt_id_ori; /*Store the original index on focus*/70uint16_t anim_time; /*Open/Close animation time [ms]*/71uint8_t opened :1; /*1: The list is opened (handled by the library)*/72uint8_t draw_arrow :1; /*1: Draw arrow*/73uint8_t direction_up : 1; /*1: Open direction*/7475lv_coord_t fix_height; /*Height of the ddlist when opened. (0: auto-size)*/76} lv_ddlist_ext_t;7778enum {79LV_DDLIST_STYLE_BG,80LV_DDLIST_STYLE_BGO,81LV_DDLIST_STYLE_PR,82LV_DDLIST_STYLE_SEL,83LV_DDLIST_STYLE_SB,84};85typedef uint8_t lv_ddlist_style_t;8687/**********************88* GLOBAL PROTOTYPES89**********************/90/**91* Create a drop down list objects92* @param par pointer to an object, it will be the parent of the new drop down list93* @param copy pointer to a drop down list object, if not NULL then the new object will be copied from it94* @return pointer to the created drop down list95*/96lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy);9798/*=====================99* Setter functions100*====================*/101102/**103* Set arrow draw in a drop down list104* @param ddlist pointer to drop down list object105* @param en enable/disable a arrow draw. E.g. "true" for draw.106*/107void lv_ddlist_set_draw_arrow(lv_obj_t * ddlist, bool en);108109/**110* Set the options in a drop down list from a string111* @param ddlist pointer to drop down list object112* @param options a string with '\n' separated options. E.g. "One\nTwo\nThree"113*/114void lv_ddlist_set_options(lv_obj_t * ddlist, const char * options);115116/**117* Set the selected option118* @param ddlist pointer to drop down list object119* @param sel_opt id of the selected option (0 ... number of option - 1);120*/121void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt);122123/**124* Set a function to call when a new option is chosen125* @param ddlist pointer to a drop down list126* @param action pointer to a call back function127*/128void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_t action);129130/**131* Set the fix height for the drop down list132* If 0 then the opened ddlist will be auto. sized else the set height will be applied.133* @param ddlist pointer to a drop down list134* @param h the height when the list is opened (0: auto size)135*/136void lv_ddlist_set_fix_height(lv_obj_t * ddlist, lv_coord_t h);137138/**139* Enable or disable the horizontal fit to the content140* @param ddlist pointer to a drop down list141* @param en true: enable auto fit; false: disable auto fit142*/143void lv_ddlist_set_hor_fit(lv_obj_t * ddlist, bool en);144145/**146* Set the scroll bar mode of a drop down list147* @param ddlist pointer to a drop down list object148* @param sb_mode the new mode from 'lv_page_sb_mode_t' enum149*/150static inline void lv_ddlist_set_sb_mode(lv_obj_t * ddlist, lv_sb_mode_t mode)151{152lv_page_set_sb_mode(ddlist, mode);153}154155/**156* Set the open/close animation time.157* @param ddlist pointer to a drop down list158* @param anim_time: open/close animation time [ms]159*/160void lv_ddlist_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time);161162163/**164* Set a style of a drop down list165* @param ddlist pointer to a drop down list object166* @param type which style should be set167* @param style pointer to a style168* */169void lv_ddlist_set_style(lv_obj_t *ddlist, lv_ddlist_style_t type, lv_style_t *style);170171/**172* Set the alignment of the labels in a drop down list173* @param ddlist pointer to a drop down list object174* @param align alignment of labels175*/176void lv_ddlist_set_align(lv_obj_t *ddlist, lv_label_align_t align);177178void lv_ddlist_set_direction_up(lv_obj_t *ddlist, bool enable);179180/*=====================181* Getter functions182*====================*/183184/**185* Get arrow draw in a drop down list186* @param ddlist pointer to drop down list object187*/188bool lv_ddlist_get_draw_arrow(lv_obj_t * ddlist);189190/**191* Get the options of a drop down list192* @param ddlist pointer to drop down list object193* @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3")194*/195const char * lv_ddlist_get_options(const lv_obj_t * ddlist);196197/**198* Get the selected option199* @param ddlist pointer to drop down list object200* @return id of the selected option (0 ... number of option - 1);201*/202uint16_t lv_ddlist_get_selected(const lv_obj_t * ddlist);203204/**205* Get the current selected option as a string206* @param ddlist pointer to ddlist object207* @param buf pointer to an array to store the string208*/209void lv_ddlist_get_selected_str(const lv_obj_t * ddlist, char * buf);210211/**212* Get the "option selected" callback function213* @param ddlist pointer to a drop down list214* @return pointer to the call back function215*/216lv_action_t lv_ddlist_get_action(const lv_obj_t * ddlist);217218/**219* Get the fix height value.220* @param ddlist pointer to a drop down list object221* @return the height if the ddlist is opened (0: auto size)222*/223lv_coord_t lv_ddlist_get_fix_height(const lv_obj_t * ddlist);224225/**226* Get the scroll bar mode of a drop down list227* @param ddlist pointer to a drop down list object228* @return scrollbar mode from 'lv_page_sb_mode_t' enum229*/230static inline lv_sb_mode_t lv_ddlist_get_sb_mode(const lv_obj_t * ddlist)231{232return lv_page_get_sb_mode(ddlist);233}234235/**236* Get the open/close animation time.237* @param ddlist pointer to a drop down list238* @return open/close animation time [ms]239*/240uint16_t lv_ddlist_get_anim_time(const lv_obj_t * ddlist);241242/**243* Get a style of a drop down list244* @param ddlist pointer to a drop down list object245* @param type which style should be get246* @return style pointer to a style247*/248lv_style_t * lv_ddlist_get_style(const lv_obj_t *ddlist, lv_ddlist_style_t type);249250/**251* Get the alignment of the labels in a drop down list252* @param ddlist pointer to a drop down list object253* @return alignment of labels254*/255lv_label_align_t lv_ddlist_get_align(const lv_obj_t *ddlist);256257/*=====================258* Other functions259*====================*/260261/**262* Open the drop down list with or without animation263* @param ddlist pointer to drop down list object264* @param anim_en true: use animation; false: not use animations265*/266void lv_ddlist_open(lv_obj_t * ddlist, bool anim_en);267268/**269* Close (Collapse) the drop down list270* @param ddlist pointer to drop down list object271* @param anim_en true: use animation; false: not use animations272*/273void lv_ddlist_close(lv_obj_t * ddlist, bool anim_en);274275/**********************276* MACROS277**********************/278279#endif /*USE_LV_DDLIST*/280281#ifdef __cplusplus282} /* extern "C" */283#endif284285#endif /*LV_DDLIST_H*/286287288