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

221 lines
5.7 KiB
C
Raw Normal View History

2017-04-11 10:51:31 +02:00
/**
* @file lv_slider.h
2018-06-19 09:49:58 +02:00
*
2017-04-11 10:51:31 +02:00
*/
#ifndef LV_SLIDER_H
#define LV_SLIDER_H
2017-07-09 15:32:49 +02:00
#ifdef __cplusplus
extern "C" {
#endif
2017-04-11 10:51:31 +02:00
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#if LV_USE_SLIDER != 0
2017-04-11 10:51:31 +02:00
/*Testing of dependencies*/
#if LV_USE_BAR == 0
#error "lv_slider: lv_bar is required. Enable it in lv_conf.h (LV_USE_BAR 1) "
#endif
2017-11-30 11:35:33 +01:00
#include "../lv_core/lv_obj.h"
2017-04-11 10:51:31 +02:00
#include "lv_bar.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
2019-12-02 07:37:33 -05:00
enum {
2020-02-26 19:48:27 +01:00
LV_SLIDER_TYPE_NORMAL,
2020-03-08 03:36:18 +01:00
LV_SLIDER_TYPE_SYMMETRICAL,
2020-02-26 19:48:27 +01:00
LV_SLIDER_TYPE_RANGE
2019-12-02 07:37:33 -05:00
};
typedef uint8_t lv_slider_type_t;
2020-03-08 03:36:18 +01:00
2017-04-11 10:51:31 +02:00
/*Data of slider*/
2020-02-26 19:48:27 +01:00
typedef struct {
2019-04-04 07:15:40 +02:00
lv_bar_ext_t bar; /*Ext. of ancestor*/
2017-04-11 10:51:31 +02:00
/*New data for this type */
lv_style_list_t style_knob; /*Style of the knob*/
2020-02-26 19:48:27 +01:00
lv_area_t left_knob_area;
lv_area_t right_knob_area;
int16_t * value_to_set; /* Which bar value to set */
uint8_t dragging : 1; /*1: the slider is being dragged*/
2018-06-19 09:49:58 +02:00
} lv_slider_ext_t;
2017-04-11 10:51:31 +02:00
2019-06-27 18:07:26 -04:00
/** Built-in styles of slider*/
2019-04-04 07:15:40 +02:00
enum {
2019-12-31 22:13:32 +01:00
LV_SLIDER_PART_BG, /** Slider background style. */
LV_SLIDER_PART_INDIC, /** Slider indicator (filled area) style. */
LV_SLIDER_PART_KNOB, /** Slider knob style. */
2018-09-18 13:59:40 +02:00
};
2017-04-11 10:51:31 +02:00
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a slider objects
* @param par pointer to an object, it will be the parent of the new slider
* @param copy pointer to a slider object, if not NULL then the new object will be copied from it
* @return pointer to the created slider
*/
lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy);
2017-04-11 10:51:31 +02:00
2017-11-10 15:01:40 +01:00
/*=====================
* Setter functions
*====================*/
/**
* Set a new value on the slider
* @param slider pointer to a slider object
* @param value new value
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-06-11 13:51:14 +02:00
static inline void lv_slider_set_value(lv_obj_t * slider, int16_t value, lv_anim_enable_t anim)
{
2019-03-01 23:50:30 +01:00
lv_bar_set_value(slider, value, anim);
}
2019-12-02 07:37:33 -05:00
/**
* Set a new value for the left knob of a slider
* @param slider pointer to a slider object
* @param left_value new value
* @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately
*/
2019-12-02 16:09:35 +01:00
static inline void lv_slider_set_left_value(lv_obj_t * slider, int16_t left_value, lv_anim_enable_t anim)
2019-12-02 07:37:33 -05:00
{
lv_bar_set_start_value(slider, left_value, anim);
}
/**
* Set minimum and the maximum values of a bar
* @param slider pointer to the slider object
* @param min minimum value
* @param max maximum value
*/
2019-04-04 07:15:40 +02:00
static inline void lv_slider_set_range(lv_obj_t * slider, int16_t min, int16_t max)
{
lv_bar_set_range(slider, min, max);
}
2019-06-17 16:05:30 +02:00
/**
2019-09-12 15:25:42 +02:00
* Make the slider symmetric to zero. The indicator will grow from zero instead of the minimum
* position.
* @param slider pointer to a slider object
* @param en true: enable disable symmetric behavior; false: disable
2019-06-17 16:05:30 +02:00
*/
2019-06-17 16:07:34 +02:00
static inline void lv_slider_set_anim_time(lv_obj_t * slider, uint16_t anim_time)
2019-06-17 16:05:30 +02:00
{
lv_bar_set_anim_time(slider, anim_time);
}
2017-11-10 15:01:40 +01:00
/**
2019-06-17 16:05:30 +02:00
* Set the animation time of the slider
* @param slider pointer to a bar object
* @param anim_time the animation time in milliseconds.
2017-11-10 15:01:40 +01:00
*/
2019-12-02 07:37:33 -05:00
static inline void lv_slider_set_type(lv_obj_t * slider, lv_slider_type_t type)
2019-06-17 16:05:30 +02:00
{
2020-02-26 19:48:27 +01:00
if(type == LV_SLIDER_TYPE_NORMAL)
lv_bar_set_type(slider, LV_BAR_TYPE_NORMAL);
2020-03-08 03:36:18 +01:00
else if(type == LV_SLIDER_TYPE_SYMMETRICAL)
2020-03-04 16:29:21 +01:00
lv_bar_set_type(slider, LV_BAR_TYPE_SYMMETRICAL);
2020-02-26 19:48:27 +01:00
else if(type == LV_SLIDER_TYPE_RANGE)
lv_bar_set_type(slider, LV_BAR_TYPE_CUSTOM);
2019-06-17 16:05:30 +02:00
}
2017-11-10 15:01:40 +01:00
/*=====================
* Getter functions
*====================*/
/**
2019-12-02 07:37:33 -05:00
* Get the value of the main knob of a slider
* @param slider pointer to a slider object
2019-12-02 07:37:33 -05:00
* @return the value of the main knob of the slider
*/
int16_t lv_slider_get_value(const lv_obj_t * slider);
2019-12-02 07:37:33 -05:00
/**
* Get the value of the left knob of a slider
* @param slider pointer to a slider object
* @return the value of the left knob of the slider
*/
static inline int16_t lv_slider_get_left_value(const lv_obj_t * slider)
{
return lv_bar_get_start_value(slider);
}
/**
* Get the minimum value of a slider
* @param slider pointer to a slider object
* @return the minimum value of the slider
*/
static inline int16_t lv_slider_get_min_value(const lv_obj_t * slider)
{
return lv_bar_get_min_value(slider);
}
/**
* Get the maximum value of a slider
* @param slider pointer to a slider object
* @return the maximum value of the slider
*/
static inline int16_t lv_slider_get_max_value(const lv_obj_t * slider)
{
return lv_bar_get_max_value(slider);
}
2017-11-10 15:01:40 +01:00
/**
2017-12-11 11:42:12 +01:00
* Give the slider is being dragged or not
2017-11-10 15:01:40 +01:00
* @param slider pointer to a slider object
2017-12-11 11:42:12 +01:00
* @return true: drag in progress false: not dragged
2017-11-10 15:01:40 +01:00
*/
bool lv_slider_is_dragged(const lv_obj_t * slider);
2017-11-10 15:01:40 +01:00
/**
2019-09-12 15:25:42 +02:00
* Get the animation time of the slider
* @param slider pointer to a slider object
* @return the animation time in milliseconds.
2017-11-10 15:01:40 +01:00
*/
2019-09-12 15:25:42 +02:00
static inline uint16_t lv_slider_get_anim_time(lv_obj_t * slider)
{
return lv_bar_get_anim_time(slider);
}
/**
* Get whether the slider is symmetric or not.
* @param slider pointer to a bar object
* @return true: symmetric is enabled; false: disable
*/
2019-12-02 07:37:33 -05:00
static inline lv_slider_type_t lv_slider_get_type(lv_obj_t * slider)
2019-09-12 15:25:42 +02:00
{
2020-02-26 19:48:27 +01:00
lv_bar_type_t type = lv_bar_get_type(slider);
2020-03-04 16:29:21 +01:00
if(type == LV_BAR_TYPE_SYMMETRICAL)
2020-03-08 03:36:18 +01:00
return LV_SLIDER_TYPE_SYMMETRICAL;
2020-02-26 19:48:27 +01:00
else if(type == LV_BAR_TYPE_CUSTOM)
return LV_SLIDER_TYPE_RANGE;
else
return LV_SLIDER_TYPE_NORMAL;
2019-09-12 15:25:42 +02:00
}
2017-04-11 10:51:31 +02:00
/**********************
* MACROS
**********************/
2019-04-04 07:15:40 +02:00
#endif /*LV_USE_SLIDER*/
2017-04-11 10:51:31 +02:00
2017-07-09 15:32:49 +02:00
#ifdef __cplusplus
} /* extern "C" */
2017-04-11 10:51:31 +02:00
#endif
2017-07-09 15:32:49 +02:00
2019-04-04 07:15:40 +02:00
#endif /*LV_SLIDER_H*/