2017-04-11 10:50:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file lv_bar.c
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2017-04-11 10:50:57 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2018-07-07 11:53:22 +02:00
|
|
|
#include "lv_bar.h"
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_BAR != 0
|
2017-04-11 10:50:57 +02:00
|
|
|
|
2019-09-24 16:30:38 +02:00
|
|
|
#include "../lv_core/lv_debug.h"
|
2017-04-11 10:50:57 +02:00
|
|
|
#include "../lv_draw/lv_draw.h"
|
2017-11-16 15:32:33 +01:00
|
|
|
#include "../lv_themes/lv_theme.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
#include "../lv_misc/lv_anim.h"
|
2019-09-16 10:58:28 +02:00
|
|
|
#include "../lv_misc/lv_math.h"
|
2017-04-11 10:50:57 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2019-09-26 10:51:54 +02:00
|
|
|
#define LV_OBJX_NAME "lv_bar"
|
2017-04-11 10:50:57 +02:00
|
|
|
|
2019-09-16 10:58:28 +02:00
|
|
|
#define LV_BAR_SIZE_MIN 4 /*hor. pad and ver. pad cannot make the indicator smaller then this [px]*/
|
2017-04-11 10:50:57 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2019-09-06 19:53:39 +02:00
|
|
|
static lv_design_res_t lv_bar_design(lv_obj_t * bar, const lv_area_t * clip_area, lv_design_mode_t mode);
|
2017-11-08 11:07:29 +01:00
|
|
|
static lv_res_t lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param);
|
2019-12-26 03:37:28 +01:00
|
|
|
|
2017-04-11 10:50:57 +02:00
|
|
|
|
2019-09-16 10:58:28 +02:00
|
|
|
static void draw_bg(lv_obj_t * bar, const lv_area_t * clip_area, lv_design_mode_t mode, lv_opa_t opa);
|
|
|
|
static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area, lv_design_mode_t mode, lv_opa_t opa);
|
|
|
|
|
2019-12-26 03:37:28 +01:00
|
|
|
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-12-26 03:37:28 +01:00
|
|
|
static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_t *value_ptr, lv_bar_anim_t *anim_info, lv_anim_enable_t en);
|
|
|
|
static void lv_bar_init_anim(lv_obj_t * bar, lv_bar_anim_t * bar_anim);
|
2019-12-02 07:37:33 -05:00
|
|
|
static void lv_bar_anim(lv_bar_anim_t * bar, lv_anim_value_t value);
|
2019-04-22 08:45:07 +02:00
|
|
|
static void lv_bar_anim_ready(lv_anim_t * a);
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2019-03-01 15:25:47 +01:00
|
|
|
|
2017-04-11 10:50:57 +02:00
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2019-02-26 09:25:46 +01:00
|
|
|
static lv_design_cb_t ancestor_design_f;
|
|
|
|
static lv_signal_cb_t ancestor_signal;
|
2017-04-11 10:50:57 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a bar objects
|
|
|
|
* @param par pointer to an object, it will be the parent of the new bar
|
|
|
|
* @param copy pointer to a bar object, if not NULL then the new object will be copied from it
|
|
|
|
* @return pointer to the created bar
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy)
|
2017-04-11 10:50:57 +02:00
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_TRACE("lv_bar create started");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2017-04-11 10:50:57 +02:00
|
|
|
/*Create the ancestor basic object*/
|
2017-04-13 15:57:02 +02:00
|
|
|
lv_obj_t * new_bar = lv_obj_create(par, copy);
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(new_bar);
|
2018-10-05 17:22:49 +02:00
|
|
|
if(new_bar == NULL) return NULL;
|
2017-04-11 10:50:57 +02:00
|
|
|
|
2019-04-10 06:40:49 +02:00
|
|
|
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_bar);
|
|
|
|
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_cb(new_bar);
|
2017-11-08 11:07:29 +01:00
|
|
|
|
2017-04-11 10:50:57 +02:00
|
|
|
/*Allocate the object type specific extended data*/
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_bar_ext_t * ext = lv_obj_allocate_ext_attr(new_bar, sizeof(lv_bar_ext_t));
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext);
|
2019-12-03 18:16:14 +01:00
|
|
|
if(ext == NULL) {
|
|
|
|
lv_obj_del(new_bar);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-25 13:33:53 +02:00
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->min_value = 0;
|
2019-12-02 07:37:33 -05:00
|
|
|
ext->start_value = 0;
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->max_value = 100;
|
|
|
|
ext->cur_value = 0;
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->anim_time = 200;
|
2019-12-02 07:37:33 -05:00
|
|
|
lv_bar_init_anim(new_bar, &ext->cur_value_anim);
|
|
|
|
lv_bar_init_anim(new_bar, &ext->start_value_anim);
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2019-12-02 07:37:33 -05:00
|
|
|
ext->type = LV_BAR_TYPE_NORMAL;
|
2017-11-16 10:20:30 +01:00
|
|
|
ext->style_indic = &lv_style_pretty_color;
|
2017-04-11 10:50:57 +02:00
|
|
|
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_obj_set_signal_cb(new_bar, lv_bar_signal);
|
|
|
|
lv_obj_set_design_cb(new_bar, lv_bar_design);
|
2017-04-11 10:50:57 +02:00
|
|
|
|
|
|
|
/*Init the new bar object*/
|
|
|
|
if(copy == NULL) {
|
|
|
|
lv_obj_set_click(new_bar, false);
|
2019-11-28 15:18:06 +01:00
|
|
|
lv_obj_set_size(new_bar, LV_DPI * 2, LV_DPI / 4);
|
2019-03-01 23:50:30 +01:00
|
|
|
lv_bar_set_value(new_bar, ext->cur_value, false);
|
2017-11-16 15:32:33 +01:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_theme_t * th = lv_theme_get_current();
|
|
|
|
if(th) {
|
2019-02-11 09:35:06 +01:00
|
|
|
lv_bar_set_style(new_bar, LV_BAR_STYLE_BG, th->style.bar.bg);
|
|
|
|
lv_bar_set_style(new_bar, LV_BAR_STYLE_INDIC, th->style.bar.indic);
|
2018-06-19 09:49:58 +02:00
|
|
|
} else {
|
2017-11-16 15:32:33 +01:00
|
|
|
lv_obj_set_style(new_bar, &lv_style_pretty);
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2017-04-11 10:50:57 +02:00
|
|
|
} else {
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_bar_ext_t * ext_copy = lv_obj_get_ext_attr(copy);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->min_value = ext_copy->min_value;
|
2019-12-02 07:37:33 -05:00
|
|
|
ext->start_value = ext_copy->start_value;
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->max_value = ext_copy->max_value;
|
|
|
|
ext->cur_value = ext_copy->cur_value;
|
|
|
|
ext->style_indic = ext_copy->style_indic;
|
2019-12-02 07:37:33 -05:00
|
|
|
ext->type = ext_copy->type;
|
2017-04-11 10:50:57 +02:00
|
|
|
/*Refresh the style with new signal function*/
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_refresh_style(new_bar);
|
2017-04-11 10:50:57 +02:00
|
|
|
|
2019-03-01 23:50:30 +01:00
|
|
|
lv_bar_set_value(new_bar, ext->cur_value, false);
|
2017-04-11 10:50:57 +02:00
|
|
|
}
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_INFO("bar created");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2017-04-11 10:50:57 +02:00
|
|
|
return new_bar;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a new value on the bar
|
|
|
|
* @param bar pointer to a bar 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 immediatelly
|
2017-04-11 10:50:57 +02:00
|
|
|
*/
|
2019-06-11 13:51:14 +02:00
|
|
|
void lv_bar_set_value(lv_obj_t * bar, int16_t value, lv_anim_enable_t anim)
|
2017-05-02 00:16:48 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(bar, LV_OBJX_NAME);
|
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
2018-06-19 09:49:58 +02:00
|
|
|
if(ext->cur_value == value) return;
|
2018-05-16 23:09:30 +02:00
|
|
|
|
2017-05-02 00:16:48 +02:00
|
|
|
int16_t new_value;
|
|
|
|
new_value = value > ext->max_value ? ext->max_value : value;
|
|
|
|
new_value = new_value < ext->min_value ? ext->min_value : new_value;
|
|
|
|
|
2019-03-01 15:25:47 +01:00
|
|
|
if(ext->cur_value == new_value) return;
|
2019-12-26 03:37:28 +01:00
|
|
|
#if LV_USE_ANIMATION == 0
|
|
|
|
ext->cur_value = new_value;
|
|
|
|
lv_obj_invalidate(bar);
|
|
|
|
#else
|
2019-12-02 07:37:33 -05:00
|
|
|
lv_bar_set_value_with_anim(bar, new_value, &ext->cur_value, &ext->cur_value_anim, anim);
|
2019-12-26 03:37:28 +01:00
|
|
|
#endif
|
2019-12-02 07:37:33 -05:00
|
|
|
}
|
2019-03-01 23:50:30 +01:00
|
|
|
|
2019-12-02 07:37:33 -05:00
|
|
|
/**
|
|
|
|
* Set a new start value on the bar
|
|
|
|
* @param bar pointer to a bar object
|
|
|
|
* @param value new start value
|
|
|
|
* @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediatelly
|
|
|
|
*/
|
|
|
|
void lv_bar_set_start_value(lv_obj_t * bar, int16_t start_value, lv_anim_enable_t anim)
|
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(bar, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
|
|
|
if(ext->start_value == start_value) return;
|
|
|
|
|
|
|
|
int16_t new_value;
|
|
|
|
new_value = start_value > ext->max_value ? ext->max_value : start_value;
|
|
|
|
new_value = new_value < ext->min_value ? ext->min_value : start_value;
|
|
|
|
|
|
|
|
if(ext->start_value == new_value) return;
|
2019-12-26 03:37:28 +01:00
|
|
|
#if LV_USE_ANIMATION == 0
|
|
|
|
ext->start_value = new_value;
|
|
|
|
#else
|
|
|
|
lv_bar_set_value_with_anim(bar, new_value, &ext->start_value, &ext->start_value_anim, anim);
|
|
|
|
#endif
|
2019-03-01 23:50:30 +01:00
|
|
|
}
|
2017-05-02 00:16:48 +02:00
|
|
|
|
2017-04-11 10:50:57 +02:00
|
|
|
/**
|
2017-04-21 09:15:39 +02:00
|
|
|
* Set minimum and the maximum values of a bar
|
2017-11-03 13:39:37 +01:00
|
|
|
* @param bar pointer to the bar object
|
2017-04-11 10:50:57 +02:00
|
|
|
* @param min minimum value
|
|
|
|
* @param max maximum value
|
|
|
|
*/
|
|
|
|
void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(bar, LV_OBJX_NAME);
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
|
|
|
if(ext->min_value == min && ext->max_value == max) return;
|
|
|
|
|
|
|
|
ext->max_value = max;
|
|
|
|
ext->min_value = min;
|
2019-12-02 07:37:33 -05:00
|
|
|
|
2019-12-19 16:36:29 -05:00
|
|
|
if(lv_bar_get_type(bar) != LV_BAR_TYPE_CUSTOM)
|
|
|
|
ext->start_value = min;
|
2019-12-02 07:37:33 -05:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
if(ext->cur_value > max) {
|
|
|
|
ext->cur_value = max;
|
2019-03-01 23:50:30 +01:00
|
|
|
lv_bar_set_value(bar, ext->cur_value, false);
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2017-11-05 00:48:57 +01:00
|
|
|
if(ext->cur_value < min) {
|
|
|
|
ext->cur_value = min;
|
2019-03-01 23:50:30 +01:00
|
|
|
lv_bar_set_value(bar, ext->cur_value, false);
|
2017-10-11 16:04:19 +02:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_invalidate(bar);
|
2017-04-11 10:50:57 +02:00
|
|
|
}
|
|
|
|
|
2019-01-01 14:14:17 +01:00
|
|
|
/**
|
2019-12-02 07:37:33 -05:00
|
|
|
* Set the type of bar.
|
|
|
|
* @param bar pointer to bar object
|
|
|
|
* @param type bar type
|
2019-01-01 14:14:17 +01:00
|
|
|
*/
|
2019-12-02 07:37:33 -05:00
|
|
|
void lv_bar_set_type(lv_obj_t * bar, lv_bar_type_t type)
|
2019-01-01 14:14:17 +01:00
|
|
|
{
|
2019-12-02 07:37:33 -05:00
|
|
|
LV_ASSERT_OBJ(bar, LV_OBJX_NAME);
|
2019-09-26 12:54:40 +02:00
|
|
|
|
2019-01-01 14:14:17 +01:00
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
2019-12-02 07:37:33 -05:00
|
|
|
ext->type = type;
|
|
|
|
if(ext->type != LV_BAR_TYPE_CUSTOM)
|
|
|
|
ext->start_value = ext->min_value;
|
|
|
|
|
|
|
|
lv_obj_invalidate(bar);
|
2019-01-01 14:14:17 +01:00
|
|
|
}
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2019-06-17 16:05:30 +02:00
|
|
|
/**
|
|
|
|
* Set the animation time of the bar
|
|
|
|
* @param bar pointer to a bar object
|
|
|
|
* @param anim_time the animation time in milliseconds.
|
|
|
|
*/
|
|
|
|
void lv_bar_set_anim_time(lv_obj_t * bar, uint16_t anim_time)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(bar, LV_OBJX_NAME);
|
|
|
|
|
2019-06-19 09:08:47 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-17 16:05:30 +02:00
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
2019-06-27 07:16:15 +02:00
|
|
|
ext->anim_time = anim_time;
|
2019-06-20 14:28:25 +02:00
|
|
|
#else
|
2019-06-27 07:16:15 +02:00
|
|
|
(void)bar; /*Unused*/
|
|
|
|
(void)anim_time; /*Unused*/
|
2019-06-19 09:08:47 -07:00
|
|
|
#endif
|
2019-06-17 16:05:30 +02:00
|
|
|
}
|
|
|
|
|
2017-04-13 10:20:35 +02:00
|
|
|
/**
|
2017-11-15 15:50:33 +01:00
|
|
|
* Set a style of a bar
|
2017-04-21 09:15:39 +02:00
|
|
|
* @param bar pointer to a bar object
|
2017-11-15 15:50:33 +01:00
|
|
|
* @param type which style should be set
|
|
|
|
* @param style pointer to a style
|
2017-04-13 10:20:35 +02:00
|
|
|
*/
|
2019-04-11 19:59:55 +08:00
|
|
|
void lv_bar_set_style(lv_obj_t * bar, lv_bar_style_t type, const lv_style_t * style)
|
2017-04-13 10:20:35 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(bar, LV_OBJX_NAME);
|
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
2017-04-13 10:20:35 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
switch(type) {
|
2019-04-04 07:15:40 +02:00
|
|
|
case LV_BAR_STYLE_BG: lv_obj_set_style(bar, style); break;
|
2017-11-15 15:50:33 +01:00
|
|
|
case LV_BAR_STYLE_INDIC:
|
2017-11-16 10:20:30 +01:00
|
|
|
ext->style_indic = style;
|
2019-04-11 06:26:41 +02:00
|
|
|
lv_obj_refresh_ext_draw_pad(bar);
|
2017-11-15 15:50:33 +01:00
|
|
|
break;
|
2017-11-03 13:39:37 +01:00
|
|
|
}
|
2017-04-13 10:20:35 +02:00
|
|
|
}
|
|
|
|
|
2017-04-11 10:50:57 +02:00
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value of a bar
|
|
|
|
* @param bar pointer to a bar object
|
|
|
|
* @return the value of the bar
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
int16_t lv_bar_get_value(const lv_obj_t * bar)
|
2017-04-11 10:50:57 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(bar, LV_OBJX_NAME);
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
2019-03-01 15:25:47 +01:00
|
|
|
/*If animated tell that it's already at the end value*/
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-12-02 07:37:33 -05:00
|
|
|
if(ext->cur_value_anim.is_animating) return ext->cur_value_anim.anim_end;
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2019-03-01 15:25:47 +01:00
|
|
|
/*No animation, simple return the current value*/
|
2019-05-20 09:22:09 -07:00
|
|
|
return ext->cur_value;
|
2017-04-11 10:50:57 +02:00
|
|
|
}
|
|
|
|
|
2019-12-02 07:37:33 -05:00
|
|
|
/**
|
|
|
|
* Get the start value of a bar
|
|
|
|
* @param bar pointer to a bar object
|
|
|
|
* @return the start value of the bar
|
|
|
|
*/
|
|
|
|
int16_t lv_bar_get_start_value(const lv_obj_t * bar)
|
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(bar, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
|
|
|
|
|
|
|
if(ext->type != LV_BAR_TYPE_CUSTOM) return ext->min_value;
|
|
|
|
|
|
|
|
/*If animated tell that it's already at the end value*/
|
|
|
|
#if LV_USE_ANIMATION
|
|
|
|
if(ext->start_value_anim.is_animating) return ext->start_value_anim.anim_end;
|
|
|
|
#endif
|
|
|
|
/*No animation, simple return the current value*/
|
|
|
|
return ext->start_value;
|
|
|
|
}
|
|
|
|
|
2017-04-21 09:15:39 +02:00
|
|
|
/**
|
|
|
|
* Get the minimum value of a bar
|
|
|
|
* @param bar pointer to a bar object
|
|
|
|
* @return the minimum value of the bar
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
int16_t lv_bar_get_min_value(const lv_obj_t * bar)
|
2017-04-21 09:15:39 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(bar, LV_OBJX_NAME);
|
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
2017-04-21 09:15:39 +02:00
|
|
|
return ext->min_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the maximum value of a bar
|
|
|
|
* @param bar pointer to a bar object
|
|
|
|
* @return the maximum value of the bar
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
int16_t lv_bar_get_max_value(const lv_obj_t * bar)
|
2017-04-21 09:15:39 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(bar, LV_OBJX_NAME);
|
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
2017-04-21 09:15:39 +02:00
|
|
|
return ext->max_value;
|
|
|
|
}
|
|
|
|
|
2019-01-01 14:14:17 +01:00
|
|
|
/**
|
2019-12-02 07:37:33 -05:00
|
|
|
* Get the type of bar.
|
|
|
|
* @param bar pointer to bar object
|
|
|
|
* @return bar type
|
2019-01-01 14:14:17 +01:00
|
|
|
*/
|
2019-12-02 07:37:33 -05:00
|
|
|
lv_bar_type_t lv_bar_get_type(lv_obj_t * bar) {
|
|
|
|
LV_ASSERT_OBJ(bar, LV_OBJX_NAME);
|
2019-09-26 12:54:40 +02:00
|
|
|
|
2019-01-01 14:14:17 +01:00
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
2019-12-02 07:37:33 -05:00
|
|
|
return ext->type;
|
2019-01-01 14:14:17 +01:00
|
|
|
}
|
|
|
|
|
2019-06-17 16:05:30 +02:00
|
|
|
/**
|
|
|
|
* Get the animation time of the bar
|
|
|
|
* @param bar pointer to a bar object
|
|
|
|
* @return the animation time in milliseconds.
|
|
|
|
*/
|
2019-11-29 15:10:10 +01:00
|
|
|
uint16_t lv_bar_get_anim_time(const lv_obj_t * bar)
|
2019-06-17 16:05:30 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(bar, LV_OBJX_NAME);
|
|
|
|
|
2019-06-17 16:05:30 +02:00
|
|
|
#if LV_USE_ANIMATION
|
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
|
|
|
return ext->anim_time;
|
|
|
|
#else
|
2019-06-27 07:16:15 +02:00
|
|
|
(void)bar; /*Unused*/
|
2019-06-17 16:05:30 +02:00
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/**
|
|
|
|
* Get a style of a bar
|
|
|
|
* @param bar pointer to a bar object
|
|
|
|
* @param type which style should be get
|
|
|
|
* @return style pointer to a style
|
|
|
|
*/
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * lv_bar_get_style(const lv_obj_t * bar, lv_bar_style_t type)
|
2017-11-15 15:50:33 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(bar, LV_OBJX_NAME);
|
|
|
|
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * style = NULL;
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
switch(type) {
|
2019-04-04 07:15:40 +02:00
|
|
|
case LV_BAR_STYLE_BG: style = lv_obj_get_style(bar); break;
|
|
|
|
case LV_BAR_STYLE_INDIC: style = ext->style_indic; break;
|
|
|
|
default: style = NULL; break;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
|
|
|
|
2018-11-05 22:21:20 -06:00
|
|
|
return style;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
|
|
|
|
2017-04-11 10:50:57 +02:00
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the drawing related tasks of the bars
|
|
|
|
* @param bar pointer to an object
|
2019-09-06 19:53:39 +02:00
|
|
|
* @param clip_area the object will be drawn only in this area
|
2017-04-11 10:50:57 +02:00
|
|
|
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
|
|
|
* (return 'true' if yes)
|
|
|
|
* LV_DESIGN_DRAW: draw the object (always return 'true')
|
|
|
|
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
2019-09-06 19:53:39 +02:00
|
|
|
* @param return an element of `lv_design_res_t`
|
2017-04-11 10:50:57 +02:00
|
|
|
*/
|
2019-09-06 19:53:39 +02:00
|
|
|
static lv_design_res_t lv_bar_design(lv_obj_t * bar, const lv_area_t * clip_area, lv_design_mode_t mode)
|
2017-04-11 10:50:57 +02:00
|
|
|
{
|
|
|
|
if(mode == LV_DESIGN_COVER_CHK) {
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Return false if the object is not covers the mask area*/
|
2019-09-06 19:53:39 +02:00
|
|
|
return ancestor_design_f(bar, clip_area, mode);
|
2017-04-11 10:50:57 +02:00
|
|
|
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
2018-09-23 23:27:28 +02:00
|
|
|
lv_opa_t opa_scale = lv_obj_get_opa_scale(bar);
|
2017-04-11 10:50:57 +02:00
|
|
|
|
2019-09-16 10:58:28 +02:00
|
|
|
draw_bg(bar, clip_area, mode, opa_scale);
|
|
|
|
draw_indic(bar, clip_area, mode, opa_scale);
|
|
|
|
|
|
|
|
#if LV_USE_GROUP
|
|
|
|
/*Draw the border*/
|
|
|
|
if(lv_obj_is_focused(bar)) {
|
|
|
|
const lv_style_t * style_bg = lv_bar_get_style(bar, LV_BAR_STYLE_BG);
|
|
|
|
lv_style_t style_tmp;
|
|
|
|
lv_style_copy(&style_tmp, style_bg);
|
|
|
|
style_tmp.body.opa = LV_OPA_TRANSP;
|
|
|
|
style_tmp.body.shadow.width = 0;
|
|
|
|
lv_draw_rect(&bar->coords, clip_area, &style_tmp, opa_scale);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} else if(mode == LV_DESIGN_DRAW_POST) {
|
|
|
|
|
|
|
|
}
|
|
|
|
return LV_DESIGN_RES_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_bg(lv_obj_t * bar, const lv_area_t * clip_area, lv_design_mode_t mode, lv_opa_t opa)
|
|
|
|
{
|
|
|
|
|
2019-11-16 11:22:23 +01:00
|
|
|
const lv_style_t * style_bg = lv_bar_get_style(bar, LV_BAR_STYLE_BG);
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP == 0
|
2019-09-16 10:58:28 +02:00
|
|
|
/*Simply draw the background*/
|
2019-11-16 11:22:23 +01:00
|
|
|
lv_draw_rect(&bar->coords, clip_area, style_bg, opa);
|
2018-09-23 23:27:28 +02:00
|
|
|
#else
|
|
|
|
/* Draw the borders later if the bar is focused.
|
2019-04-04 07:15:40 +02:00
|
|
|
* At value = 100% the indicator can cover to whole background and the focused style won't
|
|
|
|
* be visible*/
|
2018-09-23 23:27:28 +02:00
|
|
|
if(lv_obj_is_focused(bar)) {
|
|
|
|
lv_style_t style_tmp;
|
|
|
|
lv_style_copy(&style_tmp, style_bg);
|
|
|
|
style_tmp.body.border.width = 0;
|
2019-09-16 10:58:28 +02:00
|
|
|
lv_draw_rect(&bar->coords, clip_area, &style_tmp, opa);
|
2018-09-23 23:27:28 +02:00
|
|
|
} else {
|
2019-11-16 11:22:23 +01:00
|
|
|
lv_draw_rect(&bar->coords, clip_area, style_bg, opa);
|
2018-09-23 23:27:28 +02:00
|
|
|
}
|
|
|
|
#endif
|
2019-09-16 10:58:28 +02:00
|
|
|
}
|
2017-04-11 10:50:57 +02:00
|
|
|
|
2019-09-16 10:58:28 +02:00
|
|
|
static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area, lv_design_mode_t mode, lv_opa_t opa)
|
|
|
|
{
|
|
|
|
(void) mode; /*Unused*/
|
|
|
|
|
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
|
|
|
|
|
|
|
lv_coord_t objw = lv_obj_get_width(bar);
|
|
|
|
lv_coord_t objh = lv_obj_get_height(bar);
|
|
|
|
int32_t range = ext->max_value - ext->min_value;
|
|
|
|
bool hor = objw >= objh ? true : false;
|
|
|
|
bool sym = false;
|
2019-12-02 07:37:33 -05:00
|
|
|
if(ext->type == LV_BAR_TYPE_SYM && ext->min_value < 0 && ext->max_value > 0) sym = true;
|
2019-09-16 10:58:28 +02:00
|
|
|
|
2019-12-02 07:37:33 -05:00
|
|
|
bool cur_value_anim = false;
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-12-02 07:37:33 -05:00
|
|
|
if(ext->cur_value_anim.is_animating) cur_value_anim = true;
|
|
|
|
#endif
|
|
|
|
bool start_value_anim = false;
|
|
|
|
#if LV_USE_ANIMATION
|
|
|
|
if(ext->start_value_anim.is_animating) start_value_anim = true;
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2019-09-16 10:58:28 +02:00
|
|
|
|
|
|
|
/*Calculate the indicator area*/
|
|
|
|
lv_area_copy(&ext->indic_area, &bar->coords);
|
|
|
|
const lv_style_t * style_indic = lv_bar_get_style(bar, LV_BAR_STYLE_INDIC);
|
2019-11-16 12:29:37 +01:00
|
|
|
const lv_style_t * style_bg = lv_bar_get_style(bar, LV_BAR_STYLE_BG);
|
2019-09-16 10:58:28 +02:00
|
|
|
|
|
|
|
/*Respect padding and minimum width/height too*/
|
|
|
|
ext->indic_area.x1 += style_indic->body.padding.left;
|
|
|
|
ext->indic_area.x2 -= style_indic->body.padding.right;
|
|
|
|
ext->indic_area.y1 += style_indic->body.padding.top;
|
|
|
|
ext->indic_area.y2 -= style_indic->body.padding.bottom;
|
|
|
|
|
|
|
|
if(hor && lv_area_get_height(&ext->indic_area) < LV_BAR_SIZE_MIN) {
|
|
|
|
ext->indic_area.y1 = bar->coords.y1 + (objh / 2) - (LV_BAR_SIZE_MIN / 2);
|
|
|
|
ext->indic_area.y2 = ext->indic_area.y1 + LV_BAR_SIZE_MIN;
|
|
|
|
} else if(!hor && lv_area_get_width(&ext->indic_area) < LV_BAR_SIZE_MIN) {
|
|
|
|
ext->indic_area.x1 = bar->coords.x1 + (objw / 2) - (LV_BAR_SIZE_MIN / 2);
|
|
|
|
ext->indic_area.x2 = ext->indic_area.x1 + LV_BAR_SIZE_MIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
lv_coord_t indicw = lv_area_get_width(&ext->indic_area);
|
|
|
|
lv_coord_t indich = lv_area_get_height(&ext->indic_area);
|
|
|
|
|
|
|
|
/*Calculate the indicator length*/
|
|
|
|
lv_coord_t indic_length;
|
2019-12-02 07:37:33 -05:00
|
|
|
|
|
|
|
lv_coord_t anim_cur_value, anim_start_value;
|
|
|
|
if(cur_value_anim) {
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-12-02 07:37:33 -05:00
|
|
|
anim_cur_value = ext->cur_value_anim.anim_val;
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2019-12-02 07:37:33 -05:00
|
|
|
} else {
|
|
|
|
anim_cur_value = ext->cur_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(start_value_anim) {
|
|
|
|
#if LV_USE_ANIMATION
|
|
|
|
anim_start_value = ext->start_value_anim.anim_val;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
anim_start_value = ext->start_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
indic_length = (int32_t)((int32_t)(hor ? indicw : indich) * ((anim_cur_value - ext->min_value) - (anim_start_value - ext->min_value))) /
|
2019-09-16 10:58:28 +02:00
|
|
|
(ext->max_value - ext->min_value);
|
2018-10-05 17:22:49 +02:00
|
|
|
|
2019-09-16 10:58:28 +02:00
|
|
|
/*Horizontal bar*/
|
|
|
|
if(hor) {
|
|
|
|
ext->indic_area.x2 = ext->indic_area.x1 + indic_length - 1;
|
|
|
|
if(sym) {
|
|
|
|
lv_coord_t zero;
|
|
|
|
zero = ext->indic_area.x1 + (-ext->min_value * indicw) / range;
|
|
|
|
if(ext->indic_area.x2 > zero)
|
|
|
|
ext->indic_area.x1 = zero;
|
|
|
|
else {
|
|
|
|
ext->indic_area.x1 = ext->indic_area.x2;
|
|
|
|
ext->indic_area.x2 = zero;
|
|
|
|
}
|
2019-12-02 07:37:33 -05:00
|
|
|
} else {
|
2019-12-19 16:21:39 -05:00
|
|
|
lv_coord_t increment = ((anim_start_value-ext->min_value) * indicw) / range;
|
2019-12-02 07:37:33 -05:00
|
|
|
ext->indic_area.x1 += increment;
|
|
|
|
ext->indic_area.x2 += increment;
|
|
|
|
}
|
2019-09-16 10:58:28 +02:00
|
|
|
}
|
|
|
|
/*Vertical bar*/
|
|
|
|
else {
|
|
|
|
ext->indic_area.y1 = ext->indic_area.y2 - indic_length + 1;
|
|
|
|
if(sym) {
|
|
|
|
lv_coord_t zero;
|
|
|
|
zero = ext->indic_area.y2 - (-ext->min_value * objh) / range;
|
|
|
|
if(ext->indic_area.y1 < zero)
|
|
|
|
ext->indic_area.y2 = zero;
|
|
|
|
else {
|
|
|
|
ext->indic_area.y2 = ext->indic_area.y1;
|
|
|
|
ext->indic_area.y1 = zero;
|
|
|
|
}
|
2019-12-02 07:37:33 -05:00
|
|
|
} else {
|
2019-12-19 16:21:39 -05:00
|
|
|
lv_coord_t increment = ((anim_start_value-ext->min_value) * objh) / range;
|
2019-12-02 07:37:33 -05:00
|
|
|
ext->indic_area.y1 += increment;
|
|
|
|
ext->indic_area.y2 += increment;
|
|
|
|
}
|
2017-04-11 10:50:57 +02:00
|
|
|
}
|
2019-09-16 10:58:28 +02:00
|
|
|
|
|
|
|
/*Draw the indicator*/
|
|
|
|
|
|
|
|
/*Do not draw a zero length indicator*/
|
|
|
|
if(!sym && indic_length == 0) return;
|
|
|
|
|
2019-11-16 11:22:23 +01:00
|
|
|
lv_style_t style_indic_tmp;
|
|
|
|
lv_style_copy(&style_indic_tmp, style_indic);
|
2019-11-16 12:29:37 +01:00
|
|
|
uint16_t bg_radius = style_bg->body.radius;
|
|
|
|
lv_coord_t short_side = LV_MATH_MIN(objw, objh);
|
|
|
|
if(bg_radius > short_side >> 1) bg_radius = short_side >> 1;
|
2019-11-16 11:22:23 +01:00
|
|
|
/*Draw only the shadow*/
|
2019-11-16 12:29:37 +01:00
|
|
|
if((hor && lv_area_get_width(&ext->indic_area) > bg_radius * 2) ||
|
|
|
|
(!hor && lv_area_get_height(&ext->indic_area) > bg_radius * 2)) {
|
|
|
|
style_indic_tmp.body.opa = LV_OPA_TRANSP;
|
|
|
|
style_indic_tmp.body.border.width = 0;
|
|
|
|
lv_draw_rect(&ext->indic_area, clip_area, &style_indic_tmp, opa);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lv_draw_mask_radius_param_t mask_bg_param;
|
|
|
|
lv_draw_mask_radius_init(&mask_bg_param, &bar->coords, style_bg->body.radius, false);
|
|
|
|
int16_t mask_bg_id = lv_draw_mask_add(&mask_bg_param, NULL);
|
2019-11-16 11:22:23 +01:00
|
|
|
|
|
|
|
/*Draw_only the background*/
|
|
|
|
style_indic_tmp.body.shadow.width = 0;
|
|
|
|
style_indic_tmp.body.opa = style_indic->body.opa;
|
|
|
|
|
|
|
|
/*Get the max possible indicator area. The gradient should be applied on this*/
|
|
|
|
lv_area_t mask_indic_max_area;
|
|
|
|
lv_area_copy(&mask_indic_max_area, &bar->coords);
|
|
|
|
mask_indic_max_area.x1 += style_indic->body.padding.left;
|
|
|
|
mask_indic_max_area.y1 += style_indic->body.padding.top;
|
|
|
|
mask_indic_max_area.x2 -= style_indic->body.padding.right;
|
|
|
|
mask_indic_max_area.y2 -= style_indic->body.padding.bottom;
|
|
|
|
|
2019-11-16 12:29:37 +01:00
|
|
|
/*Create a mask to the current indicator area to see only this part from the whole gradient.*/
|
2019-11-16 11:22:23 +01:00
|
|
|
lv_draw_mask_radius_param_t mask_indic_param;
|
|
|
|
lv_draw_mask_radius_init(&mask_indic_param, &ext->indic_area, style_indic->body.radius, false);
|
|
|
|
int16_t mask_indic_id = lv_draw_mask_add(&mask_indic_param, NULL);
|
|
|
|
lv_draw_rect(&mask_indic_max_area, clip_area, &style_indic_tmp, opa);
|
2019-11-16 12:29:37 +01:00
|
|
|
|
|
|
|
/*Draw the border*/
|
|
|
|
style_indic_tmp.body.border.width = style_indic->body.border.width;
|
|
|
|
style_indic_tmp.body.opa = LV_OPA_TRANSP;
|
|
|
|
lv_draw_rect(&ext->indic_area, clip_area, &style_indic_tmp, opa);
|
|
|
|
|
2019-11-16 11:22:23 +01:00
|
|
|
lv_draw_mask_remove_id(mask_indic_id);
|
2019-11-16 12:29:37 +01:00
|
|
|
lv_draw_mask_remove_id(mask_bg_id);
|
|
|
|
|
2017-04-11 10:50:57 +02:00
|
|
|
}
|
|
|
|
|
2017-11-08 11:07:29 +01:00
|
|
|
/**
|
|
|
|
* Signal function of the bar
|
|
|
|
* @param bar pointer to a bar object
|
|
|
|
* @param sign a signal type from lv_signal_t enum
|
|
|
|
* @param param pointer to a signal specific variable
|
|
|
|
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
|
|
|
*/
|
|
|
|
static lv_res_t lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param)
|
|
|
|
{
|
|
|
|
lv_res_t res;
|
|
|
|
|
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = ancestor_signal(bar, sign, param);
|
|
|
|
if(res != LV_RES_OK) return res;
|
2019-09-26 12:54:40 +02:00
|
|
|
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
|
2017-11-08 11:07:29 +01:00
|
|
|
|
2019-04-11 06:26:41 +02:00
|
|
|
if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * style_indic = lv_bar_get_style(bar, LV_BAR_STYLE_INDIC);
|
2019-09-16 10:58:28 +02:00
|
|
|
const lv_style_t * style_bg = lv_bar_get_style(bar, LV_BAR_STYLE_BG);
|
|
|
|
|
|
|
|
lv_coord_t bg_size = style_bg->body.shadow.width + style_bg->body.shadow.spread;
|
|
|
|
bg_size += LV_MATH_MAX(LV_MATH_ABS(style_bg->body.shadow.offset.x), LV_MATH_ABS(style_bg->body.shadow.offset.y));
|
|
|
|
|
|
|
|
lv_coord_t indic_size = style_indic->body.shadow.width + style_indic->body.shadow.spread;
|
|
|
|
indic_size += LV_MATH_MAX(LV_MATH_ABS(style_indic->body.shadow.offset.x), LV_MATH_ABS(style_indic->body.shadow.offset.y));
|
|
|
|
|
|
|
|
bar->ext_draw_pad = LV_MATH_MAX(bar->ext_draw_pad, bg_size);
|
|
|
|
bar->ext_draw_pad = LV_MATH_MAX(bar->ext_draw_pad, indic_size);
|
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
if(style_indic->body.shadow.width > bar->ext_draw_pad) bar->ext_draw_pad = style_indic->body.shadow.width;
|
2018-02-28 15:37:41 +01:00
|
|
|
}
|
2017-11-08 11:07:29 +01:00
|
|
|
|
2019-12-02 07:37:33 -05:00
|
|
|
if(sign == LV_SIGNAL_CLEANUP) {
|
2019-12-26 03:37:28 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2019-12-02 07:37:33 -05:00
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
|
|
|
lv_anim_del(&ext->cur_value_anim, NULL);
|
|
|
|
lv_anim_del(&ext->start_value_anim, NULL);
|
2019-12-26 03:37:28 +01:00
|
|
|
#endif
|
2019-12-02 07:37:33 -05:00
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
return res;
|
2017-11-08 11:07:29 +01:00
|
|
|
}
|
|
|
|
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-12-02 07:37:33 -05:00
|
|
|
static void lv_bar_anim(lv_bar_anim_t * var, lv_anim_value_t value)
|
2019-03-01 15:25:47 +01:00
|
|
|
{
|
2019-12-02 07:37:33 -05:00
|
|
|
var->anim_val = value;
|
|
|
|
lv_obj_invalidate(var->bar);
|
2019-03-01 15:25:47 +01:00
|
|
|
}
|
|
|
|
|
2019-04-22 08:45:07 +02:00
|
|
|
static void lv_bar_anim_ready(lv_anim_t * a)
|
2019-03-01 15:25:47 +01:00
|
|
|
{
|
2019-12-02 07:37:33 -05:00
|
|
|
lv_bar_anim_t * var = a->var;
|
|
|
|
lv_bar_ext_t * ext = lv_obj_get_ext_attr(var->bar);
|
|
|
|
var->is_animating = false;
|
|
|
|
if(var == &ext->cur_value_anim)
|
|
|
|
ext->cur_value = var->anim_end;
|
|
|
|
else if(var == &ext->start_value_anim)
|
|
|
|
ext->start_value = var->anim_end;
|
|
|
|
lv_obj_invalidate(var->bar);
|
2019-03-01 15:25:47 +01:00
|
|
|
}
|
|
|
|
|
2019-12-02 07:37:33 -05:00
|
|
|
static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_t *value_ptr, lv_bar_anim_t *anim_info, lv_anim_enable_t en) {
|
|
|
|
if(en == LV_ANIM_OFF) {
|
|
|
|
*value_ptr = new_value;
|
|
|
|
lv_obj_invalidate(bar);
|
|
|
|
} else {
|
|
|
|
lv_bar_ext_t *ext = lv_obj_get_ext_attr(bar);
|
|
|
|
/*No animation in progress -> simply set the values*/
|
|
|
|
if(!anim_info->is_animating) {
|
|
|
|
anim_info->anim_start = *value_ptr;
|
|
|
|
anim_info->anim_end = new_value;
|
|
|
|
}
|
|
|
|
/*Animation in progress. Start from the animation end value*/
|
|
|
|
else {
|
|
|
|
anim_info->anim_start = anim_info->anim_end;
|
|
|
|
anim_info->anim_end = new_value;
|
|
|
|
}
|
|
|
|
/* Stop the previous animation if it exists */
|
|
|
|
lv_anim_del(anim_info, NULL);
|
|
|
|
|
|
|
|
lv_anim_t a;
|
|
|
|
a.var = anim_info;
|
|
|
|
a.start = anim_info->anim_start;
|
|
|
|
a.end = anim_info->anim_end;
|
|
|
|
a.exec_cb = (lv_anim_exec_xcb_t)lv_bar_anim;
|
|
|
|
a.path_cb = lv_anim_path_linear;
|
|
|
|
a.ready_cb = lv_bar_anim_ready;
|
|
|
|
a.act_time = 0;
|
|
|
|
a.time = ext->anim_time;
|
|
|
|
a.playback = 0;
|
|
|
|
a.playback_pause = 0;
|
|
|
|
a.repeat = 0;
|
|
|
|
a.repeat_pause = 0;
|
|
|
|
|
|
|
|
lv_anim_create(&a);
|
|
|
|
anim_info->is_animating = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lv_bar_init_anim(lv_obj_t * bar, lv_bar_anim_t * bar_anim)
|
|
|
|
{
|
|
|
|
bar_anim->bar = bar;
|
|
|
|
bar_anim->anim_start = 0;
|
|
|
|
bar_anim->anim_end = 0;
|
|
|
|
bar_anim->is_animating = false;
|
|
|
|
}
|
2019-12-26 03:37:28 +01:00
|
|
|
#endif
|
2019-12-02 07:37:33 -05:00
|
|
|
|
2017-04-11 10:50:57 +02:00
|
|
|
#endif
|