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

169 lines
4.3 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
*********************/
#include "../lv_conf_internal.h"
#if LV_USE_SW != 0
2017-08-18 17:43:14 +02:00
2017-08-18 21:14:11 +02:00
/*Testing of dependencies*/
#if LV_USE_SLIDER == 0
#error "lv_sw: lv_slider is required. Enable it in lv_conf.h (LV_USE_SLIDER 1)"
2017-08-18 21:14:11 +02:00
#endif
2017-11-30 11:35:33 +01:00
#include "../lv_core/lv_obj.h"
2019-12-31 22:13:32 +01:00
#include "lv_slider.h"
2017-08-18 17:43:14 +02:00
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Data of switch*/
typedef struct
{
2019-12-31 22:13:32 +01:00
lv_slider_ext_t slider; /*Ext. of ancestor*/
2017-08-18 17:43:14 +02:00
/*New data for this type */
2019-09-16 10:58:28 +02:00
uint8_t state :1; /*The current state*/
2018-06-19 09:49:58 +02:00
} lv_sw_ext_t;
2017-08-18 17:43:14 +02:00
2019-06-27 18:07:26 -04:00
/**
2019-12-31 22:13:32 +01:00
* Switch parts.
2019-06-27 18:07:26 -04:00
*/
2018-09-18 13:59:40 +02:00
enum {
2019-12-31 22:13:32 +01:00
LV_SW_PART_BG, /**< Switch background. */
LV_SW_PART_INDIC, /**< Switch fill area. */
LV_SW_PART_KNOB, /**< Switch knob (when off). */
2018-09-18 13:59:40 +02:00
};
2019-12-31 22:13:32 +01:00
typedef uint8_t lv_sw_part_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
2019-06-11 13:51:14 +02:00
* @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately
2017-08-18 17:43:14 +02:00
*/
2019-06-11 13:51:14 +02:00
void lv_sw_on(lv_obj_t * sw, lv_anim_enable_t anim);
2017-11-09 17:13:04 +01:00
/**
* Turn OFF the switch
* @param sw pointer to a switch object
2019-06-11 13:51:14 +02:00
* @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately
2017-11-09 17:13:04 +01:00
*/
2019-06-11 13:51:14 +02:00
void lv_sw_off(lv_obj_t * sw, lv_anim_enable_t anim);
2019-01-25 17:09:59 -08:00
/**
* Toggle the position of the switch
* @param sw pointer to a switch object
2019-06-11 13:51:14 +02:00
* @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately
2019-01-25 17:09:59 -08:00
* @return resulting state of the switch.
*/
2019-06-11 13:51:14 +02:00
bool lv_sw_toggle(lv_obj_t * sw, lv_anim_enable_t anim);
2017-11-10 15:01:40 +01:00
/**
2019-12-31 22:13:32 +01:00
* Set an image to display on the knob of the switch.
2017-11-10 15:01:40 +01:00
* @param sw pointer to a switch object
2019-11-30 11:41:18 +01:00
* @param img_src pointer to an `lv_img_dsc_t` variable or a path to an image
* (not an `lv_img` object)
2017-11-10 15:01:40 +01:00
*/
2019-12-31 22:13:32 +01:00
void lv_sw_set_knob_img(lv_obj_t * sw, const void * img_src);
/**
* Set an image to display on the knob of the switch when it's in ON state
* @param sw pointer to a switch object
2019-11-30 11:41:18 +01:00
* @param img_src pointer to an `lv_img_dsc_t` variable or a path to an image
* (not an `lv_img` object)
*/
void lv_sw_set_knob_on_img(lv_obj_t * sw, const void * img_src);
2017-11-10 15:01:40 +01:00
/**
* Set the animation time of the switch
* @param sw pointer to a switch object
* @param anim_time animation time
* @return style pointer to a style
*/
static inline void lv_sw_set_anim_time(lv_obj_t * sw, uint16_t anim_time)
{
lv_bar_set_anim_time(sw, anim_time);
}
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
*/
2019-04-04 07:15:40 +02:00
static inline bool lv_sw_get_state(const lv_obj_t * sw)
{
2019-12-03 14:56:17 +01:00
lv_sw_ext_t * ext = (lv_sw_ext_t *)lv_obj_get_ext_attr(sw);
2019-09-16 10:58:28 +02:00
return ext->state ? true : false;
}
/**
* Get an image to display on the knob of the switch when it's in OFF state
* @param sw pointer to a switch object
2019-11-30 11:41:18 +01:00
* @return the image source: pointer to an `lv_img_dsc_t` variable or a path to an image
* (not an `lv_img` object)
*/
const void * lv_slider_get_knob_off_img(lv_obj_t * sw, const void * img_src);
/**
* Get an image to display on the knob of the switch when it's in ON state
* @param sw pointer to a switch object
2019-11-30 11:41:18 +01:00
* @return the image source: pointer to an `lv_img_dsc_t` variable or a path to an image
* (not an `lv_img` object)
*/
const void * lv_slider_get_knob_on_img(lv_obj_t * sw, const void * img_src);
/**
* Get the animation time of the switch
* @param sw pointer to a switch object
* @return style pointer to a style
*/
static inline uint16_t lv_sw_get_anim_time(const lv_obj_t * sw)
{
return lv_bar_get_anim_time(sw);
}
2017-11-10 15:01:40 +01:00
2017-08-18 17:43:14 +02:00
/**********************
* MACROS
**********************/
2019-04-04 07:15:40 +02:00
#endif /*LV_USE_SW*/
2017-08-18 17:43:14 +02:00
#ifdef __cplusplus
} /* extern "C" */
#endif
2019-04-04 07:15:40 +02:00
#endif /*LV_SW_H*/