1 /**
2 * @file lv_cb.h
3 *
4 */
5
6 #ifndef LV_CB_H
7 #define LV_CB_H
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 /*********************
14 * INCLUDES
15 *********************/
16 #ifdef LV_CONF_INCLUDE_SIMPLE
17 #include "lv_conf.h"
18 #else
19 #include "../../lv_conf.h"
20 #endif
21
22 #if LV_USE_CB != 0
23
24 /*Testing of dependencies*/
25 #if LV_USE_BTN == 0
26 #error "lv_cb: lv_btn is required. Enable it in lv_conf.h (LV_USE_BTN 1) "
27 #endif
28
29 #if LV_USE_LABEL == 0
30 #error "lv_cb: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1) "
31 #endif
32
33 #include "../lv_core/lv_obj.h"
34 #include "lv_btn.h"
35 #include "lv_label.h"
36
37 /*********************
38 * DEFINES
39 *********************/
40
41 /**********************
42 * TYPEDEFS
43 **********************/
44
45 /*Data of check box*/
46 typedef struct
47 {
48 lv_btn_ext_t bg_btn; /*Ext. of ancestor*/
49 /*New data for this type */
50 lv_obj_t * bullet; /*Pointer to button*/
51 lv_obj_t * label; /*Pointer to label*/
52 } lv_cb_ext_t;
53
54 /** Checkbox styles. */
55 enum {
56 LV_CB_STYLE_BG, /**< Style of object background. */
57 LV_CB_STYLE_BOX_REL, /**< Style of box (released). */
58 LV_CB_STYLE_BOX_PR, /**< Style of box (pressed). */
59 LV_CB_STYLE_BOX_TGL_REL, /**< Style of box (released but checked). */
60 LV_CB_STYLE_BOX_TGL_PR, /**< Style of box (pressed and checked). */
61 LV_CB_STYLE_BOX_INA, /**< Style of disabled box */
62 };
63 typedef uint8_t lv_cb_style_t;
64
65 /**********************
66 * GLOBAL PROTOTYPES
67 **********************/
68
69 /**
70 * Create a check box objects
71 * @param par pointer to an object, it will be the parent of the new check box
72 * @param copy pointer to a check box object, if not NULL then the new object will be copied from it
73 * @return pointer to the created check box
74 */
75 lv_obj_t * lv_cb_create(lv_obj_t * par, const lv_obj_t * copy);
76
77 /*=====================
78 * Setter functions
79 *====================*/
80
81 /**
82 * Set the text of a check box. `txt` will be copied and may be deallocated
83 * after this function returns.
84 * @param cb pointer to a check box
85 * @param txt the text of the check box. NULL to refresh with the current text.
86 */
87 void lv_cb_set_text(lv_obj_t * cb, const char * txt);
88
89 /**
90 * Set the text of a check box. `txt` must not be deallocated during the life
91 * of this checkbox.
92 * @param cb pointer to a check box
93 * @param txt the text of the check box. NULL to refresh with the current text.
94 */
95 void lv_cb_set_static_text(lv_obj_t * cb, const char * txt);
96
97 /**
98 * Set the state of the check box
99 * @param cb pointer to a check box object
100 * @param checked true: make the check box checked; false: make it unchecked
101 */
lv_cb_set_checked(lv_obj_t * cb,bool checked)102 static inline void lv_cb_set_checked(lv_obj_t * cb, bool checked)
103 {
104 lv_btn_set_state(cb, checked ? LV_BTN_STATE_TGL_REL : LV_BTN_STATE_REL);
105 }
106
107 /**
108 * Make the check box inactive (disabled)
109 * @param cb pointer to a check box object
110 */
lv_cb_set_inactive(lv_obj_t * cb)111 static inline void lv_cb_set_inactive(lv_obj_t * cb)
112 {
113 lv_btn_set_state(cb, LV_BTN_STATE_INA);
114 }
115
116 /**
117 * Set a style of a check box
118 * @param cb pointer to check box object
119 * @param type which style should be set
120 * @param style pointer to a style
121 * */
122 void lv_cb_set_style(lv_obj_t * cb, lv_cb_style_t type, const lv_style_t * style);
123
124 /*=====================
125 * Getter functions
126 *====================*/
127
128 /**
129 * Get the text of a check box
130 * @param cb pointer to check box object
131 * @return pointer to the text of the check box
132 */
133 const char * lv_cb_get_text(const lv_obj_t * cb);
134
135 /**
136 * Get the current state of the check box
137 * @param cb pointer to a check box object
138 * @return true: checked; false: not checked
139 */
lv_cb_is_checked(const lv_obj_t * cb)140 static inline bool lv_cb_is_checked(const lv_obj_t * cb)
141 {
142 return lv_btn_get_state(cb) == LV_BTN_STATE_REL ? false : true;
143 }
144
145 /**
146 * Get whether the check box is inactive or not.
147 * @param cb pointer to a check box object
148 * @return true: inactive; false: not inactive
149 */
lv_cb_is_inactive(const lv_obj_t * cb)150 static inline bool lv_cb_is_inactive(const lv_obj_t * cb)
151 {
152 return lv_btn_get_state(cb) == LV_BTN_STATE_INA ? false : true;
153 }
154
155 /**
156 * Get a style of a button
157 * @param cb pointer to check box object
158 * @param type which style should be get
159 * @return style pointer to the style
160 * */
161 const lv_style_t * lv_cb_get_style(const lv_obj_t * cb, lv_cb_style_t type);
162
163 /**********************
164 * MACROS
165 **********************/
166
167 #endif /*LV_USE_CB*/
168
169 #ifdef __cplusplus
170 } /* extern "C" */
171 #endif
172
173 #endif /*LV_CB_H*/
174