1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/src/lv_widgets/lv_checkbox.h

152 lines
3.7 KiB
C
Raw Normal View History

2016-07-19 14:05:27 +02:00
/**
* @file lv_cb.h
2018-06-19 09:49:58 +02:00
*
2016-07-19 14:05:27 +02:00
*/
#ifndef LV_CHECKBOX_H
#define LV_CHECKBOX_H
2016-07-19 14:05:27 +02:00
2017-07-09 15:32:49 +02:00
#ifdef __cplusplus
extern "C" {
#endif
2016-07-19 14:05:27 +02:00
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#if LV_USE_CHECKBOX != 0
2017-04-24 16:16:36 +02:00
2017-01-02 10:48:21 +01:00
/*Testing of dependencies*/
#if LV_USE_BTN == 0
#error "lv_cb: lv_btn is required. Enable it in lv_conf.h (LV_USE_BTN 1) "
2017-01-02 10:48:21 +01:00
#endif
#if LV_USE_LABEL == 0
#error "lv_cb: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1) "
2017-01-02 10:48:21 +01:00
#endif
2016-07-19 14:05:27 +02:00
2017-11-30 11:35:33 +01:00
#include "../lv_core/lv_obj.h"
2016-07-19 14:05:27 +02:00
#include "lv_btn.h"
#include "lv_label.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Data of check box*/
2020-02-26 19:48:27 +01:00
typedef struct {
lv_btn_ext_t bg_btn; /*Ext. of ancestor*/
/*New data for this type */
2019-04-04 07:15:40 +02:00
lv_obj_t * bullet; /*Pointer to button*/
lv_obj_t * label; /*Pointer to label*/
} lv_checkbox_ext_t;
2019-06-27 18:07:26 -04:00
/** Checkbox styles. */
2018-09-18 13:59:40 +02:00
enum {
LV_CHECKBOX_PART_BG = LV_BTN_PART_MAIN, /**< Style of object background. */
2020-03-06 13:14:25 +01:00
_LV_CHECKBOX_PART_VIRTUAL_LAST,
LV_CHECKBOX_PART_BULLET = _LV_BTN_PART_REAL_LAST, /**< Style of box (released). */
2020-03-06 13:14:25 +01:00
_LV_CHECKBOX_PART_REAL_LAST
2018-09-18 13:59:40 +02:00
};
typedef uint8_t lv_checkbox_style_t;
2016-07-19 14:05:27 +02:00
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a check box objects
* @param par pointer to an object, it will be the parent of the new check box
* @param copy pointer to a check box object, if not NULL then the new object will be copied from it
* @return pointer to the created check box
*/
lv_obj_t * lv_checkbox_create(lv_obj_t * par, const lv_obj_t * copy);
2017-11-10 15:01:40 +01:00
/*=====================
* Setter functions
*====================*/
/**
2019-03-01 15:25:29 +08:00
* Set the text of a check box. `txt` will be copied and may be deallocated
* after this function returns.
* @param cb pointer to a check box
2019-03-01 15:25:29 +08:00
* @param txt the text of the check box. NULL to refresh with the current text.
*/
void lv_checkbox_set_text(lv_obj_t * cb, const char * txt);
2019-03-01 15:25:29 +08:00
/**
* Set the text of a check box. `txt` must not be deallocated during the life
* of this checkbox.
* @param cb pointer to a check box
* @param txt the text of the check box. NULL to refresh with the current text.
*/
void lv_checkbox_set_text_static(lv_obj_t * cb, const char * txt);
2019-03-01 15:25:29 +08:00
/**
* Set the state of the check box
* @param cb pointer to a check box object
* @param checked true: make the check box checked; false: make it unchecked
*/
static inline void lv_checkbox_set_checked(lv_obj_t * cb, bool checked)
{
2020-02-26 19:48:27 +01:00
lv_btn_set_state(cb, checked ? LV_BTN_STATE_CHECKED_RELEASED : LV_BTN_STATE_RELEASED);
}
/**
* Make the check box inactive (disabled)
* @param cb pointer to a check box object
*/
2020-03-06 13:14:25 +01:00
static inline void lv_checkbox_set_disabled(lv_obj_t * cb)
{
2020-02-13 13:56:08 +01:00
lv_btn_set_state(cb, LV_BTN_STATE_DISABLED);
}
2017-11-10 15:01:40 +01:00
/*=====================
* Getter functions
*====================*/
/**
* Get the text of a check box
* @param cb pointer to check box object
* @return pointer to the text of the check box
*/
const char * lv_checkbox_get_text(const lv_obj_t * cb);
2017-11-10 15:01:40 +01:00
/**
* Get the current state of the check box
* @param cb pointer to a check box object
* @return true: checked; false: not checked
*/
static inline bool lv_checkbox_is_checked(const lv_obj_t * cb)
{
2020-02-13 13:56:08 +01:00
return lv_btn_get_state(cb) == LV_BTN_STATE_RELEASED ? false : true;
}
2019-06-17 16:05:30 +02:00
/**
* Get whether the check box is inactive or not.
* @param cb pointer to a check box object
* @return true: inactive; false: not inactive
*/
static inline bool lv_checkbox_is_inactive(const lv_obj_t * cb)
2019-06-17 16:05:30 +02:00
{
2020-02-26 19:48:27 +01:00
return lv_btn_get_state(cb) == LV_BTN_STATE_DISABLED ? true : false;
2019-06-17 16:05:30 +02:00
}
2017-04-28 16:12:35 +02:00
2016-07-19 14:05:27 +02:00
/**********************
* MACROS
**********************/
#endif /*LV_USE_CHECKBOX*/
2016-07-19 14:05:27 +02:00
2017-07-09 15:32:49 +02:00
#ifdef __cplusplus
} /* extern "C" */
2016-07-19 14:05:27 +02:00
#endif
2017-07-09 15:32:49 +02:00
#endif /*LV_CHECKBOX_H*/