animation: add more control over object animations (e.g. ddlist open/close anim time set by func. instead of define)
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <lvgl/lv_objx/lv_bar.h>
|
||||
#include "../lv_draw/lv_draw.h"
|
||||
#include "misc/gfx/anim.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/*********************
|
||||
@@ -135,6 +136,39 @@ void lv_bar_set_value(lv_obj_t * bar, int16_t value)
|
||||
lv_obj_inv(bar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new value with animation on the bar
|
||||
* @param bar pointer to a bar object
|
||||
* @param value new value
|
||||
* @param anim_time animation time in milliseconds
|
||||
*/
|
||||
void lv_bar_set_value_anim(lv_obj_t * bar, int16_t value, uint16_t anim_time)
|
||||
{
|
||||
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext(bar);
|
||||
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;
|
||||
|
||||
anim_t a;
|
||||
a.var = bar;
|
||||
a.start = ext->act_value;
|
||||
a.end = new_value;
|
||||
a.fp = (anim_fp_t)lv_bar_set_value;
|
||||
a.path = anim_get_path(ANIM_PATH_LIN);
|
||||
a.end_cb = NULL;
|
||||
a.act_time = 0;
|
||||
a.time = anim_time;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 0;
|
||||
a.repeat_pause = 0;
|
||||
|
||||
anim_create(&a);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set minimum and the maximum values of a bar
|
||||
* @param bar pointer to he bar object
|
||||
|
||||
@@ -63,6 +63,14 @@ bool lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param);
|
||||
*/
|
||||
void lv_bar_set_value(lv_obj_t * bar, int16_t value);
|
||||
|
||||
/**
|
||||
* Set a new value with animation on the bar
|
||||
* @param bar pointer to a bar object
|
||||
* @param value new value
|
||||
* @param anim_time animation time in milliseconds
|
||||
*/
|
||||
void lv_bar_set_value_anim(lv_obj_t * bar, int16_t value, uint16_t anim_time);
|
||||
|
||||
/**
|
||||
* Set minimum and the maximum values of a bar
|
||||
* @param bar pointer to he bar object
|
||||
|
||||
@@ -17,9 +17,8 @@
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#ifndef LV_DDLIST_ANIM_TIME
|
||||
#define LV_DDLIST_ANIM_TIME 100 /*ms*/
|
||||
#endif
|
||||
#define LV_DDLIST_DEF_ANIM_TIME 200 /*ms*/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
@@ -29,7 +28,7 @@
|
||||
**********************/
|
||||
static bool lv_ddlist_design(lv_obj_t * ddlist, const area_t * mask, lv_design_mode_t mode);
|
||||
static lv_action_res_t lv_ddlist_rel_action(lv_obj_t * ddlist, lv_dispi_t * dispi);
|
||||
static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en);
|
||||
static void lv_ddlist_refr_size(lv_obj_t * ddlist, uint16_t anim_time);
|
||||
static void lv_ddlist_pos_act_option(lv_obj_t * ddlist);
|
||||
|
||||
/**********************
|
||||
@@ -71,6 +70,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
ext->opened = 0;
|
||||
ext->auto_size = 0;
|
||||
ext->sel_opt = 0;
|
||||
ext->anim_time = LV_DDLIST_DEF_ANIM_TIME;
|
||||
ext->style_sel = lv_style_get(LV_STYLE_PLAIN_COLOR, NULL);
|
||||
|
||||
/*The signal and design functions are not copied so set them here*/
|
||||
@@ -128,7 +128,7 @@ bool lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param)
|
||||
if(sign == LV_SIGNAL_STYLE_CHG) {
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
|
||||
lv_obj_set_style(ext->opt_label, lv_obj_get_style(ddlist));
|
||||
lv_ddlist_refr_size(ddlist, false);
|
||||
lv_ddlist_refr_size(ddlist, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ void lv_ddlist_set_options(lv_obj_t * ddlist, const char ** options)
|
||||
i++;
|
||||
}
|
||||
|
||||
lv_ddlist_refr_size(ddlist, false);
|
||||
lv_ddlist_refr_size(ddlist, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,6 +201,16 @@ void lv_ddlist_set_auto_size(lv_obj_t * ddlist, bool auto_size)
|
||||
ext->auto_size = auto_size == false ? 0 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the open/close animation time.
|
||||
* @param ddlist pointer to a drop down list
|
||||
* @param anim_time: open/close animation time [ms]
|
||||
*/
|
||||
void lv_ddlist_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time)
|
||||
{
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
|
||||
ext->anim_time = anim_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the style of the rectangle on the selected option
|
||||
@@ -262,14 +272,22 @@ lv_style_t * lv_ddlist_get_style_select(lv_obj_t * ddlist)
|
||||
if(ext->style_sel == NULL) return lv_obj_get_style(ddlist);
|
||||
|
||||
return ext->style_sel;
|
||||
|
||||
}
|
||||
/**
|
||||
* Get the open/close animation time.
|
||||
* @param ddlist pointer to a drop down list
|
||||
* @return open/close animation time [ms]
|
||||
*/
|
||||
uint16_t lv_ddlist_get_anim_time(lv_obj_t * ddlist)
|
||||
{
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
|
||||
return ext->anim_time;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the drop down lists
|
||||
* @param ddlist pointer to an object
|
||||
@@ -355,11 +373,7 @@ static lv_action_res_t lv_ddlist_rel_action(lv_obj_t * ddlist, lv_dispi_t * disp
|
||||
ext->cb(ddlist, dispi);
|
||||
}
|
||||
}
|
||||
#if LV_DDLIST_ANIM_TIME == 0
|
||||
lv_ddlist_refr_size(ddlist, false);
|
||||
#else
|
||||
lv_ddlist_refr_size(ddlist, true);
|
||||
#endif
|
||||
lv_ddlist_refr_size(ddlist, ext->anim_time);
|
||||
|
||||
return LV_ACTION_RES_OK;
|
||||
|
||||
@@ -367,10 +381,10 @@ static lv_action_res_t lv_ddlist_rel_action(lv_obj_t * ddlist, lv_dispi_t * disp
|
||||
|
||||
/**
|
||||
* Refresh the size of drop down list according its start (open or closed)
|
||||
* @param ddlist poinr to a drop down list object
|
||||
* @param anim_en true: refresh the size with an animation, false: do not use animations
|
||||
* @param ddlist pointer to a drop down list object
|
||||
* @param anim_time animations time for open/close [ms]
|
||||
*/
|
||||
static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en)
|
||||
static void lv_ddlist_refr_size(lv_obj_t * ddlist, uint16_t anim_time)
|
||||
{
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
|
||||
lv_style_t * style = lv_obj_get_style(ddlist);
|
||||
@@ -388,7 +402,7 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en)
|
||||
cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS;
|
||||
new_height = font_h + 2 * label_style->line_space;
|
||||
}
|
||||
if(anim_en == false) {
|
||||
if(anim_time == 0) {
|
||||
lv_obj_set_height(ddlist, new_height);
|
||||
lv_ddlist_pos_act_option(ddlist);
|
||||
} else {
|
||||
@@ -400,7 +414,7 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en)
|
||||
a.path = anim_get_path(ANIM_PATH_LIN);
|
||||
a.end_cb = (anim_cb_t)lv_ddlist_pos_act_option;
|
||||
a.act_time = 0;
|
||||
a.time = LV_DDLIST_ANIM_TIME;
|
||||
a.time = ext->anim_time;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 0;
|
||||
|
||||
@@ -41,6 +41,7 @@ typedef struct
|
||||
lv_style_t * style_sel; /*Style of the selected option*/
|
||||
lv_action_t cb; /*Pointer to function to call when an option is slected*/
|
||||
uint16_t sel_opt; /*Index of the current option*/
|
||||
uint16_t anim_time; /*Open/Close animation time [ms]*/
|
||||
uint8_t opened :1; /*1: The list is opened*/
|
||||
uint8_t auto_size :1; /*1: Set height to show all options. 0: Set height maximum to the parent bottom*/
|
||||
}lv_ddlist_ext_t;
|
||||
|
||||
@@ -17,10 +17,6 @@
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
/*Test configurations*/
|
||||
#ifndef LV_MBOX_ANIM_TIME
|
||||
#define LV_MBOX_ANIM_TIME 250 /*How fast animate out the message box in auto close. 0: no animation [ms]*/
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
@@ -256,20 +252,20 @@ void lv_mbox_set_styles_btn(lv_obj_t * mbox, lv_style_t * rel, lv_style_t * pr)
|
||||
* Automatically delete the message box after a given time
|
||||
* @param mbox pointer to a message box object
|
||||
* @param tout a time (in milliseconds) to wait before delete the message box
|
||||
* @param anim_time time of close animation in milliseconds (0: no animation)
|
||||
*/
|
||||
void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t tout)
|
||||
void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t tout, uint16_t anim_time)
|
||||
{
|
||||
#if LV_MBOX_ANIM_TIME != 0
|
||||
/*Add shrinking animations*/
|
||||
lv_obj_anim(mbox, LV_ANIM_GROW_H| ANIM_OUT, LV_MBOX_ANIM_TIME, tout, NULL);
|
||||
lv_obj_anim(mbox, LV_ANIM_GROW_V| ANIM_OUT, LV_MBOX_ANIM_TIME, tout, lv_obj_del);
|
||||
if(anim_time != 0) {
|
||||
/*Add shrinking animations*/
|
||||
lv_obj_anim(mbox, LV_ANIM_GROW_H| ANIM_OUT, anim_time, tout, NULL);
|
||||
lv_obj_anim(mbox, LV_ANIM_GROW_V| ANIM_OUT, anim_time, tout, lv_obj_del);
|
||||
|
||||
/*When the animations start disable fit to let shrinking work*/
|
||||
lv_obj_anim(mbox, LV_ANIM_NONE, 1, tout, lv_mbox_disable_fit);
|
||||
|
||||
#else
|
||||
lv_obj_anim(mbox, LV_ANIM_NONE, LV_MBOX_ANIM_TIME, tout, lv_obj_del);
|
||||
#endif
|
||||
/*When the animations start disable fit to let shrinking work*/
|
||||
lv_obj_anim(mbox, LV_ANIM_NONE, 1, tout, lv_mbox_disable_fit);
|
||||
} else {
|
||||
lv_obj_anim(mbox, LV_ANIM_NONE, anim_time, tout, lv_obj_del);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -111,7 +111,7 @@ void lv_mbox_set_styles_btn(lv_obj_t * mbox, lv_style_t * rel, lv_style_t * pr);
|
||||
* @param mbox pointer to a message box object
|
||||
* @param tout a time (in milliseconds) to wait before delete the message box
|
||||
*/
|
||||
void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t tout);
|
||||
void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t tout, uint16_t anim_time);
|
||||
|
||||
/**
|
||||
* Stop the auto. closing of message box
|
||||
|
||||
@@ -19,10 +19,6 @@
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
/*Test configurations*/
|
||||
#ifndef LV_PAGE_ANIM_FOCUS_TIME
|
||||
#define LV_PAGE_ANIM_FOCUS_TIME 300 /*List focus animation time [ms] (0: turn off the animation)*/
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
@@ -418,9 +414,9 @@ void lv_page_glue_obj(lv_obj_t * obj, bool glue)
|
||||
* Focus on an object. It ensures that the object will be visible on the page.
|
||||
* @param page pointer to a page object
|
||||
* @param obj pointer to an object to focus (must be on the page)
|
||||
* @param anim_en true: scroll with animation
|
||||
* @param anim_time true: scroll animation time in milliseconds (0: no animation)
|
||||
*/
|
||||
void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en)
|
||||
void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, uint16_t anim_time)
|
||||
{
|
||||
lv_page_ext_t * ext = lv_obj_get_ext(page);
|
||||
lv_style_t * style = lv_obj_get_style(page);
|
||||
@@ -456,29 +452,23 @@ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en)
|
||||
refr = true;
|
||||
}
|
||||
|
||||
if(refr != false) {
|
||||
#if LV_PAGE_ANIM_FOCUS_TIME == 0
|
||||
if(anim_time == 0) {
|
||||
lv_obj_set_y(ext->scrl, scrlable_y);
|
||||
#else
|
||||
if(anim_en == false) {
|
||||
lv_obj_set_y(ext->scrl, scrlable_y);
|
||||
} else {
|
||||
anim_t a;
|
||||
a.act_time = 0;
|
||||
a.start = lv_obj_get_y(ext->scrl);
|
||||
a.end = scrlable_y;
|
||||
a.time = LV_PAGE_ANIM_FOCUS_TIME;//anim_speed_to_time(LV_PAGE_ANIM_SPEED, a.start, a.end);
|
||||
a.end_cb = NULL;
|
||||
a.playback = 0;
|
||||
a.repeat = 0;
|
||||
a.var = ext->scrl;
|
||||
a.path = anim_get_path(ANIM_PATH_LIN);
|
||||
|
||||
a.fp = (anim_fp_t) lv_obj_set_y;
|
||||
anim_create(&a);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
anim_t a;
|
||||
a.act_time = 0;
|
||||
a.start = lv_obj_get_y(ext->scrl);
|
||||
a.end = scrlable_y;
|
||||
a.time = LV_PAGE_ANIM_FOCUS_TIME;//anim_speed_to_time(LV_PAGE_ANIM_SPEED, a.start, a.end);
|
||||
a.end_cb = NULL;
|
||||
a.playback = 0;
|
||||
a.repeat = 0;
|
||||
a.var = ext->scrl;
|
||||
a.path = anim_get_path(ANIM_PATH_LIN);
|
||||
a.fp = (anim_fp_t) lv_obj_set_y;
|
||||
anim_create(&a);
|
||||
}
|
||||
}
|
||||
|
||||
/*=====================
|
||||
|
||||
@@ -124,7 +124,7 @@ void lv_page_glue_obj(lv_obj_t * obj, bool glue);
|
||||
* @param obj pointer to an object to focus (must be on the page)
|
||||
* @param anim_en true: scroll with animation
|
||||
*/
|
||||
void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en);
|
||||
void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, uint16_t anim_time);
|
||||
|
||||
/**
|
||||
* Get the scrollable object of a page-
|
||||
|
||||
Reference in New Issue
Block a user