1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/lv_objx/lv_sw.h

146 lines
3.1 KiB
C
Raw Normal View History

2017-08-18 17:43:14 +02:00
/**
* @file lv_sw.h
2018-06-19 09:49:58 +02:00
*
2017-08-18 17:43:14 +02:00
*/
#ifndef LV_SW_H
#define LV_SW_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
2017-11-26 23:57:39 +01:00
#include "../../lv_conf.h"
#endif
2017-08-18 17:43:14 +02:00
#if USE_LV_SW != 0
2017-08-18 21:14:11 +02:00
/*Testing of dependencies*/
2018-01-30 14:48:21 +01:00
#if USE_LV_SLIDER == 0
2017-08-18 21:14:11 +02:00
#error "lv_sw: lv_slider is required. Enable it in lv_conf.h (USE_LV_SLIDER 1)"
#endif
2017-11-30 11:35:33 +01:00
#include "../lv_core/lv_obj.h"
2017-08-18 21:14:11 +02:00
#include "lv_slider.h"
2017-08-18 17:43:14 +02:00
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Data of switch*/
typedef struct
{
2017-11-09 17:13:04 +01:00
lv_slider_ext_t slider; /*Ext. of ancestor*/
2017-08-18 17:43:14 +02:00
/*New data for this type */
lv_style_t *style_knob_off; /*Style of the knob when the switch is OFF*/
lv_style_t *style_knob_on; /*Style of the knob when the switch is ON (NULL to use the same as OFF)*/
2017-11-09 17:13:04 +01:00
uint8_t changed :1; /*Indicates the switch explicitly changed by drag*/
2018-06-19 09:49:58 +02:00
} lv_sw_ext_t;
2017-08-18 17:43:14 +02:00
2018-09-18 13:59:40 +02:00
enum {
LV_SW_STYLE_BG,
LV_SW_STYLE_INDIC,
LV_SW_STYLE_KNOB_OFF,
LV_SW_STYLE_KNOB_ON,
2018-09-18 13:59:40 +02:00
};
typedef uint8_t lv_sw_style_t;
2017-08-18 17:43:14 +02:00
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a switch objects
* @param par pointer to an object, it will be the parent of the new switch
* @param copy pointer to a switch object, if not NULL then the new object will be copied from it
* @return pointer to the created switch
*/
lv_obj_t * lv_sw_create(lv_obj_t * par, const lv_obj_t * copy);
2017-08-18 17:43:14 +02:00
2017-11-10 15:01:40 +01:00
/*=====================
* Setter functions
*====================*/
2017-08-18 17:43:14 +02:00
/**
2017-11-09 17:13:04 +01:00
* Turn ON the switch
2017-08-18 17:43:14 +02:00
* @param sw pointer to a switch object
*/
2017-12-19 22:00:32 +01:00
void lv_sw_on(lv_obj_t *sw);
2017-11-09 17:13:04 +01:00
/**
* Turn OFF the switch
* @param sw pointer to a switch object
*/
2017-12-19 22:00:32 +01:00
void lv_sw_off(lv_obj_t *sw);
/**
* Set a function which will be called when the switch is toggled by the user
* @param sw pointer to switch object
* @param action a callback function
*/
static inline void lv_sw_set_action(lv_obj_t * sw, lv_action_t action)
{
lv_slider_set_action(sw, action);
}
2017-11-10 15:01:40 +01:00
/**
* Set a style of a switch
2017-11-10 15:01:40 +01:00
* @param sw pointer to a switch object
* @param type which style should be set
* @param style pointer to a style
2017-11-10 15:01:40 +01:00
*/
void lv_sw_set_style(lv_obj_t *sw, lv_sw_style_t type, lv_style_t *style);
2017-11-10 15:01:40 +01:00
/*=====================
* Getter functions
*====================*/
/**
* Get the state of a switch
* @param sw pointer to a switch object
* @return false: OFF; true: ON
*/
static inline bool lv_sw_get_state(const lv_obj_t *sw)
{
return lv_bar_get_value(sw) == 0 ? false : true;
}
/**
* Get the switch action function
* @param slider pointer to a switch object
* @return the callback function
*/
static inline lv_action_t lv_sw_get_action(const lv_obj_t * slider)
{
return lv_slider_get_action(slider);
}
/**
* Get a style of a switch
* @param sw pointer to a switch object
* @param type which style should be get
* @return style pointer to a style
*/
lv_style_t * lv_sw_get_style(const lv_obj_t *sw, lv_sw_style_t type);
2017-11-10 15:01:40 +01:00
2017-08-18 17:43:14 +02:00
/**********************
* MACROS
**********************/
#endif /*USE_LV_SW*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_SW_H*/