Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_objx/lv_ddlist.h
1476 views
1
/*
2
* Copyright (c) 2019 CTCaer
3
*
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms and conditions of the GNU General Public License,
6
* version 2, as published by the Free Software Foundation.
7
*
8
* This program is distributed in the hope it will be useful, but WITHOUT
9
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11
* more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
*/
16
17
/**
18
* @file lv_ddlist.h
19
*
20
*/
21
22
#ifndef LV_DDLIST_H
23
#define LV_DDLIST_H
24
25
#ifdef __cplusplus
26
extern "C" {
27
#endif
28
29
/*********************
30
* INCLUDES
31
*********************/
32
#ifdef LV_CONF_INCLUDE_SIMPLE
33
#include "lv_conf.h"
34
#else
35
#include "../../lv_conf.h"
36
#endif
37
38
#if USE_LV_DDLIST != 0
39
40
/*Testing of dependencies*/
41
#if USE_LV_PAGE == 0
42
#error "lv_ddlist: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) "
43
#endif
44
45
#if USE_LV_LABEL == 0
46
#error "lv_ddlist: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) "
47
#endif
48
49
#include "../lv_core/lv_obj.h"
50
#include "../lv_objx/lv_page.h"
51
#include "../lv_objx/lv_label.h"
52
53
/*********************
54
* DEFINES
55
*********************/
56
57
/**********************
58
* TYPEDEFS
59
**********************/
60
/*Data of drop down list*/
61
typedef struct
62
{
63
lv_page_ext_t page; /*Ext. of ancestor*/
64
/*New data for this type */
65
lv_obj_t *label; /*Label for the options*/
66
lv_style_t * sel_style; /*Style of the selected option*/
67
lv_action_t action; /*Pointer to function to call when an option is selected*/
68
uint16_t option_cnt; /*Number of options*/
69
uint16_t sel_opt_id; /*Index of the current option*/
70
uint16_t sel_opt_id_ori; /*Store the original index on focus*/
71
uint16_t anim_time; /*Open/Close animation time [ms]*/
72
uint8_t opened :1; /*1: The list is opened (handled by the library)*/
73
uint8_t draw_arrow :1; /*1: Draw arrow*/
74
uint8_t direction_up : 1; /*1: Open direction*/
75
76
lv_coord_t fix_height; /*Height of the ddlist when opened. (0: auto-size)*/
77
} lv_ddlist_ext_t;
78
79
enum {
80
LV_DDLIST_STYLE_BG,
81
LV_DDLIST_STYLE_BGO,
82
LV_DDLIST_STYLE_PR,
83
LV_DDLIST_STYLE_SEL,
84
LV_DDLIST_STYLE_SB,
85
};
86
typedef uint8_t lv_ddlist_style_t;
87
88
/**********************
89
* GLOBAL PROTOTYPES
90
**********************/
91
/**
92
* Create a drop down list objects
93
* @param par pointer to an object, it will be the parent of the new drop down list
94
* @param copy pointer to a drop down list object, if not NULL then the new object will be copied from it
95
* @return pointer to the created drop down list
96
*/
97
lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy);
98
99
/*=====================
100
* Setter functions
101
*====================*/
102
103
/**
104
* Set arrow draw in a drop down list
105
* @param ddlist pointer to drop down list object
106
* @param en enable/disable a arrow draw. E.g. "true" for draw.
107
*/
108
void lv_ddlist_set_draw_arrow(lv_obj_t * ddlist, bool en);
109
110
/**
111
* Set the options in a drop down list from a string
112
* @param ddlist pointer to drop down list object
113
* @param options a string with '\n' separated options. E.g. "One\nTwo\nThree"
114
*/
115
void lv_ddlist_set_options(lv_obj_t * ddlist, const char * options);
116
117
/**
118
* Set the selected option
119
* @param ddlist pointer to drop down list object
120
* @param sel_opt id of the selected option (0 ... number of option - 1);
121
*/
122
void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt);
123
124
/**
125
* Set a function to call when a new option is chosen
126
* @param ddlist pointer to a drop down list
127
* @param action pointer to a call back function
128
*/
129
void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_t action);
130
131
/**
132
* Set the fix height for the drop down list
133
* If 0 then the opened ddlist will be auto. sized else the set height will be applied.
134
* @param ddlist pointer to a drop down list
135
* @param h the height when the list is opened (0: auto size)
136
*/
137
void lv_ddlist_set_fix_height(lv_obj_t * ddlist, lv_coord_t h);
138
139
/**
140
* Enable or disable the horizontal fit to the content
141
* @param ddlist pointer to a drop down list
142
* @param en true: enable auto fit; false: disable auto fit
143
*/
144
void lv_ddlist_set_hor_fit(lv_obj_t * ddlist, bool en);
145
146
/**
147
* Set the scroll bar mode of a drop down list
148
* @param ddlist pointer to a drop down list object
149
* @param sb_mode the new mode from 'lv_page_sb_mode_t' enum
150
*/
151
static inline void lv_ddlist_set_sb_mode(lv_obj_t * ddlist, lv_sb_mode_t mode)
152
{
153
lv_page_set_sb_mode(ddlist, mode);
154
}
155
156
/**
157
* Set the open/close animation time.
158
* @param ddlist pointer to a drop down list
159
* @param anim_time: open/close animation time [ms]
160
*/
161
void lv_ddlist_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time);
162
163
164
/**
165
* Set a style of a drop down list
166
* @param ddlist pointer to a drop down list object
167
* @param type which style should be set
168
* @param style pointer to a style
169
* */
170
void lv_ddlist_set_style(lv_obj_t *ddlist, lv_ddlist_style_t type, lv_style_t *style);
171
172
/**
173
* Set the alignment of the labels in a drop down list
174
* @param ddlist pointer to a drop down list object
175
* @param align alignment of labels
176
*/
177
void lv_ddlist_set_align(lv_obj_t *ddlist, lv_label_align_t align);
178
179
void lv_ddlist_set_direction_up(lv_obj_t *ddlist, bool enable);
180
181
/*=====================
182
* Getter functions
183
*====================*/
184
185
/**
186
* Get arrow draw in a drop down list
187
* @param ddlist pointer to drop down list object
188
*/
189
bool lv_ddlist_get_draw_arrow(lv_obj_t * ddlist);
190
191
/**
192
* Get the options of a drop down list
193
* @param ddlist pointer to drop down list object
194
* @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3")
195
*/
196
const char * lv_ddlist_get_options(const lv_obj_t * ddlist);
197
198
/**
199
* Get the selected option
200
* @param ddlist pointer to drop down list object
201
* @return id of the selected option (0 ... number of option - 1);
202
*/
203
uint16_t lv_ddlist_get_selected(const lv_obj_t * ddlist);
204
205
/**
206
* Get the current selected option as a string
207
* @param ddlist pointer to ddlist object
208
* @param buf pointer to an array to store the string
209
*/
210
void lv_ddlist_get_selected_str(const lv_obj_t * ddlist, char * buf);
211
212
/**
213
* Get the "option selected" callback function
214
* @param ddlist pointer to a drop down list
215
* @return pointer to the call back function
216
*/
217
lv_action_t lv_ddlist_get_action(const lv_obj_t * ddlist);
218
219
/**
220
* Get the fix height value.
221
* @param ddlist pointer to a drop down list object
222
* @return the height if the ddlist is opened (0: auto size)
223
*/
224
lv_coord_t lv_ddlist_get_fix_height(const lv_obj_t * ddlist);
225
226
/**
227
* Get the scroll bar mode of a drop down list
228
* @param ddlist pointer to a drop down list object
229
* @return scrollbar mode from 'lv_page_sb_mode_t' enum
230
*/
231
static inline lv_sb_mode_t lv_ddlist_get_sb_mode(const lv_obj_t * ddlist)
232
{
233
return lv_page_get_sb_mode(ddlist);
234
}
235
236
/**
237
* Get the open/close animation time.
238
* @param ddlist pointer to a drop down list
239
* @return open/close animation time [ms]
240
*/
241
uint16_t lv_ddlist_get_anim_time(const lv_obj_t * ddlist);
242
243
/**
244
* Get a style of a drop down list
245
* @param ddlist pointer to a drop down list object
246
* @param type which style should be get
247
* @return style pointer to a style
248
*/
249
lv_style_t * lv_ddlist_get_style(const lv_obj_t *ddlist, lv_ddlist_style_t type);
250
251
/**
252
* Get the alignment of the labels in a drop down list
253
* @param ddlist pointer to a drop down list object
254
* @return alignment of labels
255
*/
256
lv_label_align_t lv_ddlist_get_align(const lv_obj_t *ddlist);
257
258
/*=====================
259
* Other functions
260
*====================*/
261
262
/**
263
* Open the drop down list with or without animation
264
* @param ddlist pointer to drop down list object
265
* @param anim_en true: use animation; false: not use animations
266
*/
267
void lv_ddlist_open(lv_obj_t * ddlist, bool anim_en);
268
269
/**
270
* Close (Collapse) the drop down list
271
* @param ddlist pointer to drop down list object
272
* @param anim_en true: use animation; false: not use animations
273
*/
274
void lv_ddlist_close(lv_obj_t * ddlist, bool anim_en);
275
276
/**********************
277
* MACROS
278
**********************/
279
280
#endif /*USE_LV_DDLIST*/
281
282
#ifdef __cplusplus
283
} /* extern "C" */
284
#endif
285
286
#endif /*LV_DDLIST_H*/
287
288