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