diff --git a/lv_conf_template.h b/lv_conf_template.h index c9a8a62d0..59b6e02d4 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -394,7 +394,7 @@ typedef void * lv_obj_user_data_t; /*Page (dependencies: lv_cont)*/ #define LV_USE_PAGE 1 -/*Preload (dependencies: lv_arc)*/ +/*Preload (dependencies: lv_arc, lv_anim)*/ #define LV_USE_PRELOAD 1 #if LV_USE_PRELOAD != 0 # define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/ diff --git a/src/lv_conf_checker.h b/src/lv_conf_checker.h index 8be7b83d9..5977ca8d8 100644 --- a/src/lv_conf_checker.h +++ b/src/lv_conf_checker.h @@ -600,7 +600,7 @@ #define LV_USE_PAGE 1 #endif -/*Preload (dependencies: lv_arc)*/ +/*Preload (dependencies: lv_arc, lv_anim)*/ #ifndef LV_USE_PRELOAD #define LV_USE_PRELOAD 1 #endif diff --git a/src/lv_core/lv_style.c b/src/lv_core/lv_style.c index 9e3f8ad38..0b7c48a49 100644 --- a/src/lv_core/lv_style.c +++ b/src/lv_core/lv_style.c @@ -8,6 +8,7 @@ *********************/ #include "lv_obj.h" #include "../lv_misc/lv_mem.h" +#include "../lv_misc/lv_anim.h" /********************* * DEFINES @@ -31,7 +32,7 @@ * STATIC PROTOTYPES **********************/ #if LV_USE_ANIMATION -static void style_animator(lv_style_anim_dsc_t * dsc, int16_t val); +static void style_animator(lv_style_anim_dsc_t * dsc, lv_anim_value_t val); static void style_animation_common_end_cb(lv_anim_t * a); #endif @@ -318,7 +319,7 @@ void lv_style_anim_set_styles(lv_anim_t * a, lv_style_t * to_anim, const lv_styl * @param dsc the 'animated variable' set by lv_style_anim_create() * @param val the current state of the animation between 0 and LV_ANIM_RESOLUTION */ -static void style_animator(lv_style_anim_dsc_t * dsc, int16_t val) +static void style_animator(lv_style_anim_dsc_t * dsc, lv_anim_value_t val) { const lv_style_t * start = &dsc->style_start; const lv_style_t * end = &dsc->style_end; diff --git a/src/lv_objx/lv_bar.c b/src/lv_objx/lv_bar.c index 2ecdd142d..9f2ffc26d 100644 --- a/src/lv_objx/lv_bar.c +++ b/src/lv_objx/lv_bar.c @@ -30,8 +30,10 @@ static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode_t mode); static lv_res_t lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param); -static void lv_bar_anim(void * bar, int16_t value); +#if LV_USE_ANIMATION +static void lv_bar_anim(void * bar, lv_anim_value_t value); static void lv_bar_anim_ready(lv_anim_t * a); +#endif /********************** * STATIC VARIABLES @@ -73,10 +75,12 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy) ext->min_value = 0; ext->max_value = 100; ext->cur_value = 0; +#if LV_USE_ANIMATION ext->anim_time = 200; ext->anim_start = 0; ext->anim_end = 0; ext->anim_state = LV_BAR_ANIM_STATE_INV; +#endif ext->sym = 0; ext->style_indic = &lv_style_pretty_color; @@ -241,10 +245,11 @@ int16_t lv_bar_get_value(const lv_obj_t * bar) { lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); /*If animated tell that it's already at the end value*/ +#if LV_USE_ANIMATION if(ext->anim_state != LV_BAR_ANIM_STATE_INV) return ext->anim_end; +#endif /*No animation, simple return the current value*/ - else - return ext->cur_value; + return ext->cur_value; } /** @@ -340,8 +345,11 @@ static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode #endif lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); - if(ext->cur_value != ext->min_value || ext->sym || - ext->anim_start != LV_BAR_ANIM_STATE_INV) { + if(ext->cur_value != ext->min_value || ext->sym +#if LV_USE_ANIMATION + || ext->anim_start != LV_BAR_ANIM_STATE_INV +#endif + ) { const lv_style_t * style_indic = lv_bar_get_style(bar, LV_BAR_STYLE_INDIC); lv_area_t indic_area; lv_area_copy(&indic_area, &bar->coords); @@ -355,6 +363,7 @@ static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode if(w >= h) { /*Horizontal*/ +#if LV_USE_ANIMATION if(ext->anim_state != LV_BAR_ANIM_STATE_INV) { /*Calculate the coordinates of anim. start and end*/ lv_coord_t anim_start_x = @@ -369,7 +378,9 @@ static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode indic_area.x2 = anim_start_x + (((anim_end_x - anim_start_x) * ext->anim_state) >> LV_BAR_ANIM_STATE_NORM); - } else { + }else +#endif + { indic_area.x2 = (int32_t)((int32_t)w * (ext->cur_value - ext->min_value)) / (ext->max_value - ext->min_value); } @@ -388,6 +399,7 @@ static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode } } } else { +#if LV_USE_ANIMATION if(ext->anim_state != LV_BAR_ANIM_STATE_INV) { /*Calculate the coordinates of anim. start and end*/ lv_coord_t anim_start_y = @@ -402,7 +414,9 @@ static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode indic_area.y1 = anim_start_y + (((anim_end_y - anim_start_y) * ext->anim_state) >> LV_BAR_ANIM_STATE_NORM); - } else { + } else +#endif + { indic_area.y1 = (int32_t)((int32_t)h * (ext->cur_value - ext->min_value)) / (ext->max_value - ext->min_value); } @@ -475,7 +489,8 @@ static lv_res_t lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param) return res; } -static void lv_bar_anim(void * bar, int16_t value) +#if LV_USE_ANIMATION +static void lv_bar_anim(void * bar, lv_anim_value_t value) { lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); ext->anim_state = value; @@ -488,5 +503,6 @@ static void lv_bar_anim_ready(lv_anim_t * a) ext->anim_state = LV_BAR_ANIM_STATE_INV; lv_bar_set_value(a->var, ext->anim_end, false); } +#endif #endif diff --git a/src/lv_objx/lv_bar.h b/src/lv_objx/lv_bar.h index f2ba493a7..2d923563f 100644 --- a/src/lv_objx/lv_bar.h +++ b/src/lv_objx/lv_bar.h @@ -22,10 +22,12 @@ extern "C" { #if LV_USE_BAR != 0 #include "../lv_core/lv_obj.h" +#include "../lv_misc/lv_anim.h" #include "lv_cont.h" #include "lv_btn.h" #include "lv_label.h" + /********************* * DEFINES *********************/ @@ -46,10 +48,12 @@ typedef struct int16_t cur_value; /*Current value of the bar*/ int16_t min_value; /*Minimum value of the bar*/ int16_t max_value; /*Maximum value of the bar*/ - int16_t anim_start; - int16_t anim_end; - int16_t anim_state; - uint16_t anim_time; +#if LV_USE_ANIMATION + lv_anim_value_t anim_start; + lv_anim_value_t anim_end; + lv_anim_value_t anim_state; + lv_anim_value_t anim_time; +#endif uint8_t sym : 1; /*Symmetric: means the center is around zero value*/ const lv_style_t * style_indic; /*Style of the indicator*/ } lv_bar_ext_t; diff --git a/src/lv_objx/lv_btn.c b/src/lv_objx/lv_btn.c index 1d3700712..7dd163953 100644 --- a/src/lv_objx/lv_btn.c +++ b/src/lv_objx/lv_btn.c @@ -35,7 +35,7 @@ static bool lv_btn_design(lv_obj_t * btn, const lv_area_t * mask, lv_design_mode static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param); #if LV_USE_ANIMATION && LV_BTN_INK_EFFECT -static void lv_btn_ink_effect_anim(lv_obj_t * btn, int16_t val); +static void lv_btn_ink_effect_anim(lv_obj_t * btn, lv_anim_value_t val); static void lv_btn_ink_effect_anim_ready(lv_anim_t * a); #endif @@ -632,7 +632,7 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) * @param btn pointer to the animated button * @param val the new radius */ -static void lv_btn_ink_effect_anim(lv_obj_t * btn, int16_t val) +static void lv_btn_ink_effect_anim(lv_obj_t * btn, lv_anim_value_t val) { if(btn) { ink_act_value = val; diff --git a/src/lv_objx/lv_ddlist.c b/src/lv_objx/lv_ddlist.c index 0d2a92465..020b9686e 100644 --- a/src/lv_objx/lv_ddlist.c +++ b/src/lv_objx/lv_ddlist.c @@ -44,9 +44,11 @@ static lv_res_t release_handler(lv_obj_t * ddlist); static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en); static void lv_ddlist_pos_current_option(lv_obj_t * ddlist); static void lv_ddlist_refr_width(lv_obj_t* ddlist); +#if LV_USE_ANIMATION static void lv_ddlist_anim_ready_cb(lv_anim_t * a); static void lv_ddlist_anim_finish(lv_obj_t* ddlist); -static void lv_ddlist_adjust_height(lv_obj_t * ddlist, int16_t height); +static void lv_ddlist_adjust_height(lv_obj_t * ddlist, lv_anim_value_t height); +#endif /********************** * STATIC VARIABLES @@ -907,6 +909,7 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en) } } +#if LV_USE_ANIMATION /** * Position the list and remove the selection highlight if it's closed. * Called at end of list animation. @@ -937,11 +940,12 @@ static void lv_ddlist_anim_finish(lv_obj_t* ddlist) * @param ddlist Drop down list object * @param height New drop down list height */ -static void lv_ddlist_adjust_height(lv_obj_t * ddlist, int16_t height) +static void lv_ddlist_adjust_height(lv_obj_t * ddlist, lv_anim_value_t height) { lv_obj_set_height(ddlist, height); lv_ddlist_pos_current_option(ddlist); } +#endif /** * Set the position of list when it is closed to show the selected item diff --git a/src/lv_objx/lv_label.c b/src/lv_objx/lv_label.c index 4a8d3111b..1fefa043f 100644 --- a/src/lv_objx/lv_label.c +++ b/src/lv_objx/lv_label.c @@ -90,7 +90,9 @@ lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy) ext->align = LV_LABEL_ALIGN_LEFT; ext->dot_end = LV_LABEL_DOT_END_INV; ext->long_mode = LV_LABEL_LONG_EXPAND; +#if LV_USE_ANIMATION ext->anim_speed = LV_LABEL_DEF_SCROLL_SPEED; +#endif ext->offset.x = 0; ext->offset.y = 0; #if LV_LABEL_TEXT_SEL @@ -343,6 +345,7 @@ void lv_label_set_body_draw(lv_obj_t * label, bool en) */ void lv_label_set_anim_speed(lv_obj_t * label, uint16_t anim_speed) { +#if LV_USE_ANIMATION lv_label_ext_t * ext = lv_obj_get_ext_attr(label); if(ext->anim_speed == anim_speed) return; @@ -351,6 +354,7 @@ void lv_label_set_anim_speed(lv_obj_t * label, uint16_t anim_speed) if(ext->long_mode == LV_LABEL_LONG_ROLL || ext->long_mode == LV_LABEL_LONG_ROLL_CIRC) { lv_label_refr_text(label); } +#endif } void lv_label_set_text_sel_start( lv_obj_t * label, uint16_t index ) { @@ -437,8 +441,12 @@ bool lv_label_get_body_draw(const lv_obj_t * label) */ uint16_t lv_label_get_anim_speed(const lv_obj_t * label) { +#if LV_USE_ANIMATION lv_label_ext_t * ext = lv_obj_get_ext_attr(label); return ext->anim_speed; +#else + return 0; +#endif } /** diff --git a/src/lv_objx/lv_label.h b/src/lv_objx/lv_label.h index 51affba35..33f987695 100644 --- a/src/lv_objx/lv_label.h +++ b/src/lv_objx/lv_label.h @@ -68,9 +68,12 @@ typedef struct char tmp[ sizeof(char *) ]; /* Directly store the characters if <=4 characters */ } dot; uint16_t dot_end; /*The text end position in dot mode (Handled by the library)*/ - uint16_t anim_speed; /*Speed of scroll and roll animation in px/sec unit*/ lv_point_t offset; /*Text draw position offset*/ +#if LV_USE_ANIMATION + uint16_t anim_speed; /*Speed of scroll and roll animation in px/sec unit*/ +#endif + #if LV_LABEL_TEXT_SEL uint16_t txt_sel_start; /*Left-most selection character*/ uint16_t txt_sel_end; /*Right-most selection character*/ diff --git a/src/lv_objx/lv_list.c b/src/lv_objx/lv_list.c index 3e5c8de0c..46a948975 100644 --- a/src/lv_objx/lv_list.c +++ b/src/lv_objx/lv_list.c @@ -94,7 +94,9 @@ lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy) ext->styles_btn[LV_BTN_STATE_TGL_REL] = &lv_style_btn_tgl_rel; ext->styles_btn[LV_BTN_STATE_TGL_PR] = &lv_style_btn_tgl_pr; ext->styles_btn[LV_BTN_STATE_INA] = &lv_style_btn_ina; +#if LV_USE_ANIMATION ext->anim_time = LV_LIST_DEF_ANIM_TIME; +#endif ext->single_mode = false; ext->size = 0; @@ -249,11 +251,11 @@ lv_obj_t * lv_list_add(lv_obj_t * list, const void * img_src, const char * txt, * lv_list_ext_t.size * @return true: successfully deleted */ -bool lv_list_remove(const lv_obj_t * list, uint32_t index) +bool lv_list_remove(const lv_obj_t * list, uint16_t index) { lv_list_ext_t * ext = lv_obj_get_ext_attr(list); if(index >= ext->size) return false; - uint32_t count = 0; + uint16_t count = 0; lv_obj_t * e = lv_list_get_next_btn(list, NULL); while(e != NULL) { if(count == index) { @@ -318,7 +320,7 @@ void lv_list_set_btn_selected(lv_obj_t * list, lv_obj_t * btn) else if(s == LV_BTN_STATE_TGL_REL) lv_btn_set_state(ext->selected_btn, LV_BTN_STATE_TGL_PR); - lv_page_focus(list, ext->selected_btn, ext->anim_time); + lv_page_focus(list, ext->selected_btn, lv_list_get_anim_time(list) ); } } @@ -331,13 +333,13 @@ void lv_list_set_btn_selected(lv_obj_t * list, lv_obj_t * btn) */ void lv_list_set_anim_time(lv_obj_t * list, uint16_t anim_time) { +#if LV_USE_ANIMATION lv_list_ext_t * ext = lv_obj_get_ext_attr(list); -#if LV_USE_ANIMATION == 0 anim_time = 0; -#endif if(ext->anim_time == anim_time) return; ext->anim_time = anim_time; +#endif } /** @@ -542,7 +544,7 @@ int32_t lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn) * @param list pointer to a list object * @return the number of buttons in the list */ -uint32_t lv_list_get_size(const lv_obj_t * list) +uint16_t lv_list_get_size(const lv_obj_t * list) { lv_list_ext_t * ext = lv_obj_get_ext_attr(list); return ext->size; @@ -569,8 +571,12 @@ lv_obj_t * lv_list_get_btn_selected(const lv_obj_t * list) */ uint16_t lv_list_get_anim_time(const lv_obj_t * list) { +#if LV_USE_ANIMATION lv_list_ext_t * ext = lv_obj_get_ext_attr(list); return ext->anim_time; +#else + return 0; +#endif } /** @@ -622,8 +628,7 @@ void lv_list_up(const lv_obj_t * list) if(e_prev != NULL) { lv_coord_t new_y = lv_obj_get_height(list) - (lv_obj_get_y(e_prev) + lv_obj_get_height(e_prev)); - lv_list_ext_t * ext = lv_obj_get_ext_attr(list); - if(ext->anim_time == 0) { + if(lv_list_get_anim_time(list) == 0) { lv_obj_set_y(scrl, new_y); } else { #if LV_USE_ANIMATION @@ -631,9 +636,9 @@ void lv_list_up(const lv_obj_t * list) a.var = scrl; a.start = lv_obj_get_y(scrl); a.end = new_y; - a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_y; - a.path_cb = lv_anim_path_linear; - a.ready_cb = NULL; + a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_y; + a.path_cb = lv_anim_path_linear; + a.ready_cb = NULL; a.act_time = 0; a.time = LV_LIST_DEF_ANIM_TIME; a.playback = 0; @@ -665,8 +670,7 @@ void lv_list_down(const lv_obj_t * list) while(e != NULL) { if(e->coords.y1 < list->coords.y1) { lv_coord_t new_y = -lv_obj_get_y(e); - lv_list_ext_t * ext = lv_obj_get_ext_attr(list); - if(ext->anim_time == 0) { + if(lv_list_get_anim_time(list) == 0) { lv_obj_set_y(scrl, new_y); } else { #if LV_USE_ANIMATION @@ -674,9 +678,9 @@ void lv_list_down(const lv_obj_t * list) a.var = scrl; a.start = lv_obj_get_y(scrl); a.end = new_y; - a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_y; - a.path_cb = lv_anim_path_linear; - a.ready_cb = NULL; + a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_y; + a.path_cb = lv_anim_path_linear; + a.ready_cb = NULL; a.act_time = 0; a.time = LV_LIST_DEF_ANIM_TIME; a.playback = 0; @@ -684,7 +688,6 @@ void lv_list_down(const lv_obj_t * list) a.repeat = 0; a.repeat_pause = 0; lv_anim_create(&a); - #endif } break; diff --git a/src/lv_objx/lv_list.h b/src/lv_objx/lv_list.h index 5d6c2985f..31797ddc1 100644 --- a/src/lv_objx/lv_list.h +++ b/src/lv_objx/lv_list.h @@ -52,11 +52,15 @@ typedef struct { lv_page_ext_t page; /*Ext. of ancestor*/ /*New data for this type */ - uint16_t anim_time; /*Scroll animation time*/ const lv_style_t * styles_btn[LV_BTN_STATE_NUM]; /*Styles of the list element buttons*/ const lv_style_t * style_img; /*Style of the list element images on buttons*/ - uint32_t size; /*the number of items(buttons) in the list*/ - bool single_mode; /* whether single selected mode is enabled */ + uint16_t size; /*the number of items(buttons) in the list*/ +#if LV_USE_ANIMATION + uint16_t anim_time; /*Scroll animation time*/ +#endif + + uint8_t single_mode:1; /* whether single selected mode is enabled */ + #if LV_USE_GROUP lv_obj_t * last_sel; /* The last selected button. It will be reverted when the list is focused again */ lv_obj_t * selected_btn; /* The button is currently being selected*/ @@ -116,7 +120,7 @@ lv_obj_t * lv_list_add(lv_obj_t * list, const void * img_src, const char * txt, * lv_list_ext_t.size * @return true: successfully deleted */ -bool lv_list_remove(const lv_obj_t * list, uint32_t index); +bool lv_list_remove(const lv_obj_t * list, uint16_t index); /*===================== * Setter functions @@ -245,7 +249,7 @@ int32_t lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn); * @param list pointer to a list object * @return the number of buttons in the list */ -uint32_t lv_list_get_size(const lv_obj_t * list); +uint16_t lv_list_get_size(const lv_obj_t * list); #if LV_USE_GROUP /** diff --git a/src/lv_objx/lv_mbox.c b/src/lv_objx/lv_mbox.c index 2a5aa026e..f97f24a14 100644 --- a/src/lv_objx/lv_mbox.c +++ b/src/lv_objx/lv_mbox.c @@ -36,7 +36,9 @@ **********************/ static lv_res_t lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param); static void mbox_realign(lv_obj_t * mbox); +#if LV_USE_ANIMATION static void lv_mbox_close_ready_cb(lv_anim_t * a); +#endif static void lv_mbox_default_event_cb(lv_obj_t * mbox, lv_event_t event); /********************** @@ -77,7 +79,9 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, const lv_obj_t * copy) ext->text = NULL; ext->btnm = NULL; +#if LV_USE_ANIMATION ext->anim_time = LV_MBOX_CLOSE_ANIM_TIME; +#endif /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_cb(new_mbox, lv_mbox_signal); @@ -182,12 +186,14 @@ void lv_mbox_set_text(lv_obj_t * mbox, const char * txt) */ void lv_mbox_set_anim_time(lv_obj_t * mbox, uint16_t anim_time) { +#if LV_USE_ANIMATION lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); -#if LV_USE_ANIMATION == 0 anim_time = 0; -#endif - ext->anim_time = anim_time; +#else + (void) mbox; + (void) anim_time; +#endif } /** @@ -198,9 +204,7 @@ void lv_mbox_set_anim_time(lv_obj_t * mbox, uint16_t anim_time) void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t delay) { #if LV_USE_ANIMATION - lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); - - if(ext->anim_time != 0) { + if(lv_mbox_get_anim_time(mbox) != 0) { /*Add shrinking animations*/ lv_anim_t a; a.var = mbox; @@ -210,7 +214,7 @@ void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t delay) a.path_cb = lv_anim_path_linear; a.ready_cb = NULL; a.act_time = -delay; - a.time = ext->anim_time; + a.time = lv_mbox_get_anim_time(mbox); a.playback = 0; a.playback_pause = 0; a.repeat = 0; @@ -356,8 +360,13 @@ const char * lv_mbox_get_active_btn_text(lv_obj_t * mbox) */ uint16_t lv_mbox_get_anim_time(const lv_obj_t * mbox) { +#if LV_USE_ANIMATION lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); return ext->anim_time; +#else + (void) mbox; + return 0; +#endif } /** @@ -521,10 +530,12 @@ static void mbox_realign(lv_obj_t * mbox) } } +#if LV_USE_ANIMATION static void lv_mbox_close_ready_cb(lv_anim_t * a) { lv_obj_del(a->var); } +#endif static void lv_mbox_default_event_cb(lv_obj_t * mbox, lv_event_t event) { diff --git a/src/lv_objx/lv_mbox.h b/src/lv_objx/lv_mbox.h index b2c42e6e5..ed1a88964 100644 --- a/src/lv_objx/lv_mbox.h +++ b/src/lv_objx/lv_mbox.h @@ -54,7 +54,9 @@ typedef struct /*New data for this type */ lv_obj_t * text; /*Text of the message box*/ lv_obj_t * btnm; /*Button matrix for the buttons*/ +#if LV_USE_ANIMATION uint16_t anim_time; /*Duration of close animation [ms] (0: no animation)*/ +#endif } lv_mbox_ext_t; enum { diff --git a/src/lv_objx/lv_page.c b/src/lv_objx/lv_page.c index 641e20261..2470c87f3 100644 --- a/src/lv_objx/lv_page.c +++ b/src/lv_objx/lv_page.c @@ -40,9 +40,11 @@ static bool lv_page_design(lv_obj_t * page, const lv_area_t * mask, lv_design_mo static bool lv_scrl_design(lv_obj_t * scrl, const lv_area_t * mask, lv_design_mode_t mode); static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param); static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param); -static void edge_flash_anim(void * page, int16_t v); -static void edge_flash_anim_end(lv_anim_t * a); static void scrl_def_event_cb(lv_obj_t * scrl, lv_event_t event); +#if LV_USE_ANIMATION +static void edge_flash_anim(void * page, lv_anim_value_t v); +static void edge_flash_anim_end(lv_anim_t * a); +#endif /********************** * STATIC VARIABLES @@ -86,6 +88,7 @@ lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy) ext->sb.ver_draw = 0; ext->sb.style = &lv_style_pretty; ext->sb.mode = LV_SB_MODE_AUTO; +#if LV_USE_ANIMATION ext->edge_flash.enabled = 0; ext->edge_flash.bottom_ip = 0; ext->edge_flash.top_ip = 0; @@ -93,6 +96,7 @@ lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy) ext->edge_flash.right_ip = 0; ext->edge_flash.state = 0; ext->edge_flash.style = &lv_style_plain_color; +#endif ext->arrow_scroll = 0; ext->scroll_prop = 0; ext->scroll_prop_ip = 0; @@ -233,8 +237,13 @@ void lv_page_set_scroll_propagation(lv_obj_t * page, bool en) */ void lv_page_set_edge_flash(lv_obj_t * page, bool en) { +#if LV_USE_ANIMATION lv_page_ext_t * ext = lv_obj_get_ext_attr(page); ext->edge_flash.enabled = en ? 1 : 0; +#else + (void) page; + (void) en; +#endif } /** @@ -258,7 +267,9 @@ void lv_page_set_style(lv_obj_t * page, lv_page_style_t type, const lv_style_t * lv_obj_refresh_ext_draw_pad(page); lv_obj_invalidate(page); break; +#if LV_USE_ANIMATION case LV_PAGE_STYLE_EDGE_FLASH: ext->edge_flash.style = style; break; +#endif } } @@ -318,8 +329,13 @@ bool lv_page_get_scroll_propagation(lv_obj_t * page) */ bool lv_page_get_edge_flash(lv_obj_t * page) { +#if LV_USE_ANIMATION lv_page_ext_t * ext = lv_obj_get_ext_attr(page); return ext->edge_flash.enabled == 0 ? false : true; +#else + (void) page; + return false; +#endif } /** @@ -365,7 +381,9 @@ const lv_style_t * lv_page_get_style(const lv_obj_t * page, lv_page_style_t type case LV_PAGE_STYLE_BG: style = lv_obj_get_style(page); break; case LV_PAGE_STYLE_SCRL: style = lv_obj_get_style(ext->scrl); break; case LV_PAGE_STYLE_SB: style = ext->sb.style; break; +#if LV_USE_ANIMATION case LV_PAGE_STYLE_EDGE_FLASH: style = ext->edge_flash.style; break; +#endif default: style = NULL; break; } @@ -428,15 +446,15 @@ void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, uint16_t anim_time) { lv_page_ext_t * ext = lv_obj_get_ext_attr(page); -#if LV_USE_ANIMATION == 0 - anim_time = 0; -#else +#if LV_USE_ANIMATION /* Be sure there is no position changing animation in progress * because it can overide the current changes*/ lv_anim_del(page, (lv_anim_exec_cb_t)lv_obj_set_x); lv_anim_del(page, (lv_anim_exec_cb_t)lv_obj_set_y); lv_anim_del(ext->scrl, (lv_anim_exec_cb_t)lv_obj_set_x); lv_anim_del(ext->scrl, (lv_anim_exec_cb_t)lv_obj_set_y); +#else + anim_time = 0; #endif const lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_BG); @@ -528,9 +546,9 @@ void lv_page_scroll_hor(lv_obj_t * page, lv_coord_t dist) a.var = scrl; a.start = lv_obj_get_x(scrl); a.end = a.start + dist; - a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_x; - a.path_cb = lv_anim_path_linear; - a.ready_cb = NULL; + a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_x; + a.path_cb = lv_anim_path_linear; + a.ready_cb = NULL; a.act_time = 0; a.time = LV_PAGE_SCROLL_ANIM_TIME; a.playback = 0; @@ -557,9 +575,9 @@ void lv_page_scroll_ver(lv_obj_t * page, lv_coord_t dist) a.var = scrl; a.start = lv_obj_get_y(scrl); a.end = a.start + dist; - a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_y; - a.path_cb = lv_anim_path_linear; - a.ready_cb = NULL; + a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_y; + a.path_cb = lv_anim_path_linear; + a.ready_cb = NULL; a.act_time = 0; a.time = LV_PAGE_SCROLL_ANIM_TIME; a.playback = 0; @@ -659,41 +677,46 @@ static bool lv_page_design(lv_obj_t * page, const lv_area_t * mask, lv_design_mo lv_draw_rect(&sb_area, mask, ext->sb.style, lv_obj_get_opa_scale(page)); } - lv_coord_t page_w = lv_obj_get_width(page); - lv_coord_t page_h = lv_obj_get_height(page); - lv_area_t flash_area; +#if LV_USE_ANIMATION + { + lv_coord_t page_w = lv_obj_get_width(page); + lv_coord_t page_h = lv_obj_get_height(page); - if(ext->edge_flash.top_ip) { - flash_area.x1 = page->coords.x1 - page_w; - flash_area.x2 = page->coords.x2 + page_w; - flash_area.y1 = page->coords.y1 - 3 * page_w + ext->edge_flash.state; - flash_area.y2 = page->coords.y1 + ext->edge_flash.state; - } else if(ext->edge_flash.bottom_ip) { - flash_area.x1 = page->coords.x1 - page_w; - flash_area.x2 = page->coords.x2 + page_w; - flash_area.y1 = page->coords.y2 - ext->edge_flash.state; - flash_area.y2 = page->coords.y2 + 3 * page_w - ext->edge_flash.state; - } else if(ext->edge_flash.right_ip) { - flash_area.x1 = page->coords.x2 - ext->edge_flash.state; - flash_area.x2 = page->coords.x2 + 3 * page_h - ext->edge_flash.state; - flash_area.y1 = page->coords.y1 - page_h; - flash_area.y2 = page->coords.y2 + page_h; - } else if(ext->edge_flash.left_ip) { - flash_area.x1 = page->coords.x1 - 3 * page_h + ext->edge_flash.state; - flash_area.x2 = page->coords.x1 + ext->edge_flash.state; - flash_area.y1 = page->coords.y1 - page_h; - flash_area.y2 = page->coords.y2 + page_h; - } + lv_area_t flash_area; - if(ext->edge_flash.left_ip || ext->edge_flash.right_ip || ext->edge_flash.top_ip || - ext->edge_flash.bottom_ip) { - lv_style_t flash_style; - lv_style_copy(&flash_style, ext->edge_flash.style); - flash_style.body.radius = LV_RADIUS_CIRCLE; - uint32_t opa = (flash_style.body.opa * ext->edge_flash.state) / LV_PAGE_END_FLASH_SIZE; - flash_style.body.opa = opa; - lv_draw_rect(&flash_area, mask, &flash_style, lv_obj_get_opa_scale(page)); + if(ext->edge_flash.top_ip) { + flash_area.x1 = page->coords.x1 - page_w; + flash_area.x2 = page->coords.x2 + page_w; + flash_area.y1 = page->coords.y1 - 3 * page_w + ext->edge_flash.state; + flash_area.y2 = page->coords.y1 + ext->edge_flash.state; + } else if(ext->edge_flash.bottom_ip) { + flash_area.x1 = page->coords.x1 - page_w; + flash_area.x2 = page->coords.x2 + page_w; + flash_area.y1 = page->coords.y2 - ext->edge_flash.state; + flash_area.y2 = page->coords.y2 + 3 * page_w - ext->edge_flash.state; + } else if(ext->edge_flash.right_ip) { + flash_area.x1 = page->coords.x2 - ext->edge_flash.state; + flash_area.x2 = page->coords.x2 + 3 * page_h - ext->edge_flash.state; + flash_area.y1 = page->coords.y1 - page_h; + flash_area.y2 = page->coords.y2 + page_h; + } else if(ext->edge_flash.left_ip) { + flash_area.x1 = page->coords.x1 - 3 * page_h + ext->edge_flash.state; + flash_area.x2 = page->coords.x1 + ext->edge_flash.state; + flash_area.y1 = page->coords.y1 - page_h; + flash_area.y2 = page->coords.y2 + page_h; + } + + if(ext->edge_flash.left_ip || ext->edge_flash.right_ip || ext->edge_flash.top_ip || + ext->edge_flash.bottom_ip) { + lv_style_t flash_style; + lv_style_copy(&flash_style, ext->edge_flash.style); + flash_style.body.radius = LV_RADIUS_CIRCLE; + uint32_t opa = (flash_style.body.opa * ext->edge_flash.state) / LV_PAGE_END_FLASH_SIZE; + flash_style.body.opa = opa; + lv_draw_rect(&flash_area, mask, &flash_style, lv_obj_get_opa_scale(page)); + } } +#endif } return true; @@ -937,21 +960,25 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi new_x = lv_area_get_width(&page_coords) - lv_area_get_width(&scrl_coords) - page_style->body.padding.right; /* Right align */ refr_x = true; +#if LV_USE_ANIMATION if(page_ext->edge_flash.enabled && page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 && page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) { lv_page_start_edge_flash(page); page_ext->edge_flash.right_ip = 1; } +#endif } else if(scrl_coords.x1 > page_coords.x1 + page_style->body.padding.left) { new_x = page_style->body.padding.left; /*Left align*/ refr_x = true; +#if LV_USE_ANIMATION if(page_ext->edge_flash.enabled && page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 && page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) { lv_page_start_edge_flash(page); page_ext->edge_flash.left_ip = 1; } +#endif } } @@ -976,21 +1003,25 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi new_y = lv_area_get_height(&page_coords) - lv_area_get_height(&scrl_coords) - page_style->body.padding.bottom; /* Bottom align */ refr_y = true; +#if LV_USE_ANIMATION if(page_ext->edge_flash.enabled && page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 && page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) { lv_page_start_edge_flash(page); page_ext->edge_flash.bottom_ip = 1; } +#endif } else if(scrl_coords.y1 > page_coords.y1 + page_style->body.padding.top) { new_y = page_style->body.padding.top; /*Top align*/ refr_y = true; +#if LV_USE_ANIMATION if(page_ext->edge_flash.enabled && page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 && page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) { lv_page_start_edge_flash(page); page_ext->edge_flash.top_ip = 1; } +#endif } } @@ -1193,7 +1224,8 @@ static void lv_page_sb_refresh(lv_obj_t * page) } } -static void edge_flash_anim(void * page, int16_t v) +#if LV_USE_ANIMATION +static void edge_flash_anim(void * page, lv_anim_value_t v) { lv_page_ext_t * ext = lv_obj_get_ext_attr(page); ext->edge_flash.state = v; @@ -1209,5 +1241,6 @@ static void edge_flash_anim_end(lv_anim_t * a) ext->edge_flash.right_ip = 0; lv_obj_invalidate(a->var); } +#endif #endif diff --git a/src/lv_objx/lv_page.h b/src/lv_objx/lv_page.h index adda367bb..c81db1616 100644 --- a/src/lv_objx/lv_page.h +++ b/src/lv_objx/lv_page.h @@ -28,6 +28,7 @@ extern "C" { #include "lv_cont.h" #include "../lv_core/lv_indev.h" +#include "../lv_misc/lv_anim.h" /********************* * DEFINES @@ -76,9 +77,10 @@ typedef struct uint8_t ver_draw : 1; /*1: vertical scrollbar is visible now (Handled by the library)*/ lv_sb_mode_t mode : 3; /*Scrollbar visibility from 'lv_page_sb_mode_t'*/ } sb; +#if LV_USE_ANIMATION struct { - uint16_t state; /*Store the current size of the edge flash effect*/ + lv_anim_value_t state; /*Store the current size of the edge flash effect*/ const lv_style_t * style; /*Style of edge flash effect (usually homogeneous circle)*/ uint8_t enabled : 1; /*1: Show a flash animation on the edge*/ uint8_t top_ip : 1; /*Used internally to show that top most position is reached (flash is In @@ -90,6 +92,7 @@ typedef struct uint8_t left_ip : 1; /*Used internally to show that left most position is reached (flash is In Progress)*/ } edge_flash; +#endif uint8_t arrow_scroll : 1; /*1: Enable scrolling with LV_KEY_LEFT/RIGHT/UP/DOWN*/ uint8_t scroll_prop : 1; /*1: Propagate the scrolling the the parent if the edge is reached*/ diff --git a/src/lv_objx/lv_preload.c b/src/lv_objx/lv_preload.c index 5986c8c8f..d89c37aac 100644 --- a/src/lv_objx/lv_preload.c +++ b/src/lv_objx/lv_preload.c @@ -127,7 +127,7 @@ lv_obj_t * lv_preload_create(lv_obj_t * par, const lv_obj_t * copy) * @param preload pointer to a preload object * @param deg length of the arc */ -void lv_preload_set_arc_length(lv_obj_t * preload, int16_t deg) +void lv_preload_set_arc_length(lv_obj_t * preload, lv_anim_value_t deg) { lv_preload_ext_t * ext = lv_obj_get_ext_attr(preload); @@ -170,7 +170,6 @@ void lv_preload_set_style(lv_obj_t * preload, lv_preload_style_t type, const lv_ * */ void lv_preload_set_anim_type(lv_obj_t * preload, lv_preload_type_t type) { -#if LV_USE_ANIMATION lv_preload_ext_t * ext = lv_obj_get_ext_attr(preload); /*delete previous animation*/ @@ -250,8 +249,6 @@ void lv_preload_set_anim_type(lv_obj_t * preload, lv_preload_type_t type) break; } } - -#endif // LV_USE_ANIMATION } void lv_preload_set_anim_dir(lv_obj_t * preload, lv_preload_dir_t dir) { @@ -269,7 +266,7 @@ void lv_preload_set_anim_dir(lv_obj_t * preload, lv_preload_dir_t dir) { * Get the arc length [degree] of the a pre loader * @param preload pointer to a pre loader object */ -uint16_t lv_preload_get_arc_length(const lv_obj_t * preload) +lv_anim_value_t lv_preload_get_arc_length(const lv_obj_t * preload) { lv_preload_ext_t * ext = lv_obj_get_ext_attr(preload); return ext->arc_length; @@ -328,7 +325,7 @@ lv_preload_dir_t lv_preload_get_anim_dir(lv_obj_t * preload) { * @param ptr pointer to preloader * @param val the current desired value [0..360] */ -void lv_preload_spinner_anim(void * ptr, int16_t val) +void lv_preload_spinner_anim(void * ptr, lv_anim_value_t val) { lv_obj_t * preload = ptr; lv_preload_ext_t * ext = lv_obj_get_ext_attr(preload); diff --git a/src/lv_objx/lv_preload.h b/src/lv_objx/lv_preload.h index 25b1b37b9..7d73eb373 100644 --- a/src/lv_objx/lv_preload.h +++ b/src/lv_objx/lv_preload.h @@ -31,6 +31,7 @@ extern "C" { #endif #include "../lv_core/lv_obj.h" +#include "../lv_misc/lv_anim.h" #include "lv_arc.h" /********************* @@ -58,7 +59,7 @@ typedef struct { lv_arc_ext_t arc; /*Ext. of ancestor*/ /*New data for this type */ - uint16_t arc_length; /*Length of the spinning indicator in degree*/ + lv_anim_value_t arc_length; /*Length of the spinning indicator in degree*/ uint16_t time; /*Time of one round*/ lv_preload_type_t anim_type:1; /*Type of the arc animation*/ lv_preload_dir_t anim_dir:1; /*Animation Direction*/ @@ -92,7 +93,7 @@ lv_obj_t * lv_preload_create(lv_obj_t * par, const lv_obj_t * copy); * @param preload pointer to a preload object * @param deg length of the arc */ -void lv_preload_set_arc_length(lv_obj_t * preload, int16_t deg); +void lv_preload_set_arc_length(lv_obj_t * preload, lv_anim_value_t deg); /** * Set the spin time of the arc @@ -135,7 +136,7 @@ void lv_preload_set_anim_dir(lv_obj_t * preload, lv_preload_dir_t dir); * Get the arc length [degree] of the a pre loader * @param preload pointer to a pre loader object */ -uint16_t lv_preload_get_arc_length(const lv_obj_t * preload); +lv_anim_value_t lv_preload_get_arc_length(const lv_obj_t * preload); /** * Get the spin time of the arc @@ -175,7 +176,7 @@ lv_preload_dir_t lv_preload_get_anim_dir(lv_obj_t * preload); * @param type which style should be get * @return style pointer to the style * */ -void lv_preload_spinner_anim(void * ptr, int16_t val); +void lv_preload_spinner_anim(void * ptr, lv_anim_value_t val); /********************** * MACROS diff --git a/src/lv_objx/lv_roller.c b/src/lv_objx/lv_roller.c index 9d098463a..67c386cc3 100644 --- a/src/lv_objx/lv_roller.c +++ b/src/lv_objx/lv_roller.c @@ -38,7 +38,9 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par static void refr_position(lv_obj_t * roller, bool anim_en); static void refr_height(lv_obj_t * roller); static void inf_normalize(void * roller_scrl); +#if LV_USE_ANIMATION static void scroll_anim_ready_cb(lv_anim_t * a); +#endif static void draw_bg(lv_obj_t * roller, const lv_area_t * mask); /********************** @@ -407,7 +409,9 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par lv_obj_get_height(roller) != lv_area_get_height(param)) { refr_height(roller); +#if LV_USE_ANIMATION lv_anim_del(lv_page_get_scrl(roller), (lv_anim_exec_cb_t)lv_obj_set_y); +#endif lv_ddlist_set_selected(roller, ext->ddlist.sel_opt_id); refr_position(roller, false); } @@ -531,7 +535,9 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, } } else if(sign == LV_SIGNAL_PRESSED) { +#if LV_USE_ANIMATION lv_anim_del(roller_scrl, (lv_anim_exec_cb_t)lv_obj_set_y); +#endif } /*Position the scrollable according to the new selected option*/ @@ -614,7 +620,11 @@ static void refr_position(lv_obj_t * roller, bool anim_en) /* Normally the animtaion's `end_cb` sets correct position of the roller is infinite. * But without animations do it manually*/ - if(anim_en == false || ext->ddlist.anim_time == 0) { + if(anim_en == false +#if LV_USE_ANIMATION + || ext->ddlist.anim_time == 0 +#endif + ) { inf_normalize(roller_scrl); } @@ -623,7 +633,11 @@ static void refr_position(lv_obj_t * roller, bool anim_en) ext->ddlist.label->coords.y1 - roller_scrl->coords.y1; lv_coord_t new_y = -line_y1 + (h - font_h) / 2; - if(ext->ddlist.anim_time == 0 || anim_en == false) { + if( anim_en == false +#if LV_USE_ANIMATION + || ext->ddlist.anim_time == 0 +#endif + ) { lv_obj_set_y(roller_scrl, new_y); } else { #if LV_USE_ANIMATION @@ -664,7 +678,9 @@ static void refr_height(lv_obj_t * roller) lv_obj_set_height(lv_page_get_scrl(roller), lv_obj_get_height(ext->ddlist.label) + lv_obj_get_height(roller)); lv_obj_align(ext->ddlist.label, NULL, obj_align, 0, 0); +#if LV_USE_ANIMATION lv_anim_del(lv_page_get_scrl(roller), (lv_anim_exec_cb_t)lv_obj_set_y); +#endif lv_ddlist_set_selected(roller, ext->ddlist.sel_opt_id); } @@ -699,9 +715,11 @@ static void inf_normalize(void * scrl) } } +#if LV_USE_ANIMATION static void scroll_anim_ready_cb(lv_anim_t * a) { inf_normalize(a->var); } +#endif #endif diff --git a/src/lv_objx/lv_slider.c b/src/lv_objx/lv_slider.c index c41b49d5d..e2e7666cd 100644 --- a/src/lv_objx/lv_slider.c +++ b/src/lv_objx/lv_slider.c @@ -321,6 +321,7 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig if(slider_w >= slider_h) { lv_coord_t indic_w = lv_area_get_width(&area_indic); +#if LV_USE_ANIMATION if(ext->bar.anim_state != LV_BAR_ANIM_STATE_INV) { /*Calculate the coordinates of anim. start and end*/ lv_coord_t anim_start_x = @@ -334,7 +335,10 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig * `anim_end`)*/ area_indic.x2 = anim_start_x + (((anim_end_x - anim_start_x) * ext->bar.anim_state) >> 8); - } else { + } + else +#endif + { area_indic.x2 = (int32_t)((int32_t)indic_w * (cur_value - min_value)) / (max_value - min_value); } @@ -347,6 +351,7 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig } else { lv_coord_t indic_h = lv_area_get_height(&area_indic); +#if LV_USE_ANIMATION if(ext->bar.anim_state != LV_BAR_ANIM_STATE_INV) { /*Calculate the coordinates of anim. start and end*/ lv_coord_t anim_start_y = @@ -360,7 +365,10 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig * `anim_end`)*/ area_indic.y1 = anim_start_y + (((anim_end_y - anim_start_y) * ext->bar.anim_state) >> 8); - } else { + } + else +#endif + { area_indic.y1 = (int32_t)((int32_t)indic_h * (cur_value - min_value)) / (max_value - min_value); } @@ -395,6 +403,7 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig knob_area.x1 = area_indic.x2 - slider_h / 2; knob_area.x2 = knob_area.x1 + slider_h - 1; } else { +#if LV_USE_ANIMATION if(ext->bar.anim_state != LV_BAR_ANIM_STATE_INV) { lv_coord_t w = slider_w - slider_h - 1; lv_coord_t anim_start_x = @@ -408,7 +417,9 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig * `anim_end`)*/ knob_area.x1 = anim_start_x + (((anim_end_x - anim_start_x) * ext->bar.anim_state) >> 8); - } else { + } else +#endif + { knob_area.x1 = (int32_t)((int32_t)(slider_w - slider_h - 1) * (cur_value - min_value)) / (max_value - min_value); @@ -425,6 +436,7 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig knob_area.y1 = area_indic.y1 - slider_w / 2; knob_area.y2 = knob_area.y1 + slider_w - 1; } else { +#if LV_USE_ANIMATION if(ext->bar.anim_state != LV_BAR_ANIM_STATE_INV) { lv_coord_t h = slider_h - slider_w - 1; lv_coord_t anim_start_x = @@ -438,7 +450,9 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig * `anim_end`)*/ knob_area.y2 = anim_start_x + (((anim_end_x - anim_start_x) * ext->bar.anim_state) >> 8); - } else { + } else +#endif + { knob_area.y2 = (int32_t)((int32_t)(slider_h - slider_w - 1) * (cur_value - min_value)) / (max_value - min_value); diff --git a/src/lv_objx/lv_slider.h b/src/lv_objx/lv_slider.h index 7a4a1e178..e82525672 100644 --- a/src/lv_objx/lv_slider.h +++ b/src/lv_objx/lv_slider.h @@ -42,8 +42,7 @@ typedef struct lv_bar_ext_t bar; /*Ext. of ancestor*/ /*New data for this type */ const lv_style_t * style_knob; /*Style of the knob*/ - int16_t - drag_value; /*Store a temporal value during press until release (Handled by the library)*/ + int16_t drag_value; /*Store a temporal value during press until release (Handled by the library)*/ uint8_t knob_in : 1; /*1: Draw the knob inside the bar*/ } lv_slider_ext_t; diff --git a/src/lv_objx/lv_sw.c b/src/lv_objx/lv_sw.c index 3d44fabb1..5468dd9dd 100644 --- a/src/lv_objx/lv_sw.c +++ b/src/lv_objx/lv_sw.c @@ -202,6 +202,9 @@ void lv_sw_set_anim_time(lv_obj_t * sw, uint16_t anim_time) #if LV_USE_ANIMATION lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw); ext->anim_time = anim_time; +#else + (void) sw; + (void) anim_time; #endif } diff --git a/src/lv_objx/lv_sw.h b/src/lv_objx/lv_sw.h index 44801d3cb..1b4e73e25 100644 --- a/src/lv_objx/lv_sw.h +++ b/src/lv_objx/lv_sw.h @@ -107,7 +107,6 @@ bool lv_sw_toggle(lv_obj_t * sw, bool anim); */ void lv_sw_set_style(lv_obj_t * sw, lv_sw_style_t type, const lv_style_t * style); -#if LV_USE_ANIMATION /** * Set the animation time of the switch * @param sw pointer to a switch object @@ -115,7 +114,6 @@ void lv_sw_set_style(lv_obj_t * sw, lv_sw_style_t type, const lv_style_t * style * @return style pointer to a style */ void lv_sw_set_anim_time(lv_obj_t * sw, uint16_t anim_time); -#endif /*===================== * Getter functions diff --git a/src/lv_objx/lv_ta.c b/src/lv_objx/lv_ta.c index 16d7ee56e..dddf8b219 100644 --- a/src/lv_objx/lv_ta.c +++ b/src/lv_objx/lv_ta.c @@ -45,10 +45,10 @@ static bool lv_ta_scrollable_design(lv_obj_t * scrl, const lv_area_t * mask, lv_ static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param); static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param); #if LV_USE_ANIMATION -static void cursor_blink_anim(lv_obj_t * ta, uint8_t show); -static void pwd_char_hider_anim(lv_obj_t * ta, int32_t x); -#endif +static void cursor_blink_anim(lv_obj_t * ta, lv_anim_value_t show); +static void pwd_char_hider_anim(lv_obj_t * ta, lv_anim_value_t x); static void pwd_char_hider_anim_ready(lv_anim_t * a); +#endif static void pwd_char_hider(lv_obj_t * ta); static bool char_is_accepted(lv_obj_t * ta, uint32_t c); static void get_cursor_style(lv_obj_t * ta, lv_style_t * style_res); @@ -165,10 +165,10 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, const lv_obj_t * copy) /*Create a cursor blinker animation*/ lv_anim_t a; a.var = new_ta; - a.exec_cb = (lv_anim_exec_cb_t)cursor_blink_anim; + a.exec_cb = (lv_anim_exec_cb_t)cursor_blink_anim; a.time = LV_TA_CURSOR_BLINK_TIME; a.act_time = 0; - a.ready_cb = NULL; + a.ready_cb = NULL; a.start = 1; a.end = 0; a.repeat = 1; @@ -250,10 +250,10 @@ void lv_ta_add_char(lv_obj_t * ta, uint32_t c) /*Auto hide characters*/ lv_anim_t a; a.var = ta; - a.exec_cb = (lv_anim_exec_cb_t)pwd_char_hider_anim; + a.exec_cb = (lv_anim_exec_cb_t)pwd_char_hider_anim; a.time = LV_TA_PWD_SHOW_TIME; a.act_time = 0; - a.ready_cb = pwd_char_hider_anim_ready; + a.ready_cb = pwd_char_hider_anim_ready; a.start = 0; a.end = 1; a.repeat = 0; @@ -576,10 +576,10 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos) /*Reset cursor blink animation*/ lv_anim_t a; a.var = ta; - a.exec_cb = (lv_anim_exec_cb_t)cursor_blink_anim; + a.exec_cb = (lv_anim_exec_cb_t)cursor_blink_anim; a.time = LV_TA_CURSOR_BLINK_TIME; a.act_time = 0; - a.ready_cb = NULL; + a.ready_cb = NULL; a.start = 1; a.end = 0; a.repeat = 1; @@ -1386,7 +1386,7 @@ static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * @param ta pointer to a text area * @param hide 1: hide the cursor, 0: show it */ -static void cursor_blink_anim(lv_obj_t * ta, uint8_t show) +static void cursor_blink_anim(lv_obj_t * ta, lv_anim_value_t show) { lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); if(show != ext->cursor.state) { @@ -1411,15 +1411,12 @@ static void cursor_blink_anim(lv_obj_t * ta, uint8_t show) * @param ta unused * @param x unused */ -static void pwd_char_hider_anim(lv_obj_t * ta, int32_t x) +static void pwd_char_hider_anim(lv_obj_t * ta, lv_anim_value_t x) { (void)ta; (void)x; } -#endif - - /** * Call when an animation is ready to convert all characters to '*' * @param a pointer to the animation @@ -1429,6 +1426,7 @@ static void pwd_char_hider_anim_ready(lv_anim_t * a) lv_obj_t * ta = a->var; pwd_char_hider(ta); } +#endif /** * Hide all characters (convert them to '*') diff --git a/src/lv_objx/lv_tabview.c b/src/lv_objx/lv_tabview.c index fad7969ce..189970494 100644 --- a/src/lv_objx/lv_tabview.c +++ b/src/lv_objx/lv_tabview.c @@ -93,7 +93,9 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy) ext->indic = NULL; ext->btns = NULL; ext->btns_pos = LV_TABVIEW_BTNS_POS_TOP; +#if LV_USE_ANIMATION ext->anim_time = LV_TABVIEW_DEF_ANIM_TIME; +#endif ext->btns_hide = 0; /*The signal and design functions are not copied so set them here*/ @@ -158,7 +160,9 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy) ext->btns = lv_btnm_create(new_tabview, copy_ext->btns); ext->indic = lv_obj_create(ext->btns, copy_ext->indic); ext->content = lv_cont_create(new_tabview, copy_ext->content); +#if LV_USE_ANIMATION ext->anim_time = copy_ext->anim_time; +#endif ext->tab_name_ptr = lv_mem_alloc(sizeof(char *)); lv_mem_assert(ext->tab_name_ptr); @@ -371,7 +375,11 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en) break; } - if(ext->anim_time == 0 || anim_en == false) { + if( anim_en == false +#if LV_USE_ANIMATION + || ext->anim_time == 0 +#endif + ) { lv_obj_set_x(ext->content, cont_x); } else { #if LV_USE_ANIMATION @@ -379,9 +387,9 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en) a.var = ext->content; a.start = lv_obj_get_x(ext->content); a.end = cont_x; - a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_x; - a.path_cb = lv_anim_path_linear; - a.ready_cb = NULL; + a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_x; + a.path_cb = lv_anim_path_linear; + a.ready_cb = NULL; a.act_time = 0; a.time = ext->anim_time; a.playback = 0; @@ -410,7 +418,11 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en) break; } - if(ext->anim_time == 0 || anim_en == false) { + if( anim_en == false +#if LV_USE_ANIMATION + || ext->anim_time == 0 +#endif + ) { switch(ext->btns_pos) { case LV_TABVIEW_BTNS_POS_TOP: case LV_TABVIEW_BTNS_POS_BOTTOM: @@ -431,18 +443,18 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en) case LV_TABVIEW_BTNS_POS_BOTTOM: a.start = lv_obj_get_x(ext->indic); a.end = indic_pos; - a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_x; + a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_x; break; case LV_TABVIEW_BTNS_POS_LEFT: case LV_TABVIEW_BTNS_POS_RIGHT: a.start = lv_obj_get_y(ext->indic); a.end = indic_pos; - a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_y; + a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_y; break; } - a.path_cb = lv_anim_path_linear; - a.ready_cb = NULL; + a.path_cb = lv_anim_path_linear; + a.ready_cb = NULL; a.act_time = 0; a.time = ext->anim_time; a.playback = 0; @@ -474,11 +486,13 @@ void lv_tabview_set_sliding(lv_obj_t * tabview, bool en) */ void lv_tabview_set_anim_time(lv_obj_t * tabview, uint16_t anim_time) { +#if LV_USE_ANIMATION lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); -#if LV_USE_ANIMATION == 0 - anim_time = 0; -#endif ext->anim_time = anim_time; +#else + (void) tabview; + (void) anim_time; +#endif } /** @@ -621,8 +635,13 @@ bool lv_tabview_get_sliding(const lv_obj_t * tabview) */ uint16_t lv_tabview_get_anim_time(const lv_obj_t * tabview) { +#if LV_USE_ANIMATION lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); return ext->anim_time; +#else + (void) tabview; + return 0; +#endif } /** diff --git a/src/lv_objx/lv_tabview.h b/src/lv_objx/lv_tabview.h index 508bc4851..9482d7bff 100644 --- a/src/lv_objx/lv_tabview.h +++ b/src/lv_objx/lv_tabview.h @@ -62,7 +62,9 @@ typedef struct lv_point_t point_last; uint16_t tab_cur; uint16_t tab_cnt; +#if LV_USE_ANIMATION uint16_t anim_time; +#endif uint8_t slide_enable : 1; /*1: enable horizontal sliding by touch pad*/ uint8_t draging : 1; uint8_t drag_hor : 1; diff --git a/src/lv_objx/lv_tileview.c b/src/lv_objx/lv_tileview.c index 055d72acb..5e2103148 100644 --- a/src/lv_objx/lv_tileview.c +++ b/src/lv_objx/lv_tileview.c @@ -78,7 +78,9 @@ lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy) if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(new_tileview); /*Initialize the allocated 'ext' */ +#if LV_USE_ANIMATION ext->anim_time = LV_TILEVIEW_DEF_ANIM_TIME; +#endif ext->act_id.x = 0; ext->act_id.y = 0; ext->valid_pos = NULL; @@ -109,7 +111,9 @@ lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy) lv_tileview_ext_t * copy_ext = lv_obj_get_ext_attr(copy); ext->act_id.x = copy_ext->act_id.x; ext->act_id.y = copy_ext->act_id.y; +#if LV_USE_ANIMATION ext->anim_time = copy_ext->anim_time; +#endif /*Refresh the style with new signal function*/ lv_obj_refresh_style(new_tileview); @@ -211,9 +215,9 @@ void lv_tileview_set_tile_act(lv_obj_t * tileview, lv_coord_t x, lv_coord_t y, b lv_anim_t a; a.var = scrl; - a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_x; - a.path_cb = lv_anim_path_linear; - a.ready_cb = NULL; + a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_x; + a.path_cb = lv_anim_path_linear; + a.ready_cb = NULL; a.act_time = 0; a.time = ext->anim_time; a.playback = 0; @@ -228,9 +232,9 @@ void lv_tileview_set_tile_act(lv_obj_t * tileview, lv_coord_t x, lv_coord_t y, b } if(y_coord != y_act) { - a.start = y_act; - a.end = y_coord; - a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_y; + a.start = y_act; + a.end = y_coord; + a.exec_cb = (lv_anim_exec_cb_t)lv_obj_set_y; lv_anim_create(&a); } #endif @@ -366,6 +370,7 @@ static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void ext->drag_ver = 1; } +#if LV_USE_ANIMATION if(ext->drag_hor) { ext->page.edge_flash.top_ip = 0; ext->page.edge_flash.bottom_ip = 0; @@ -375,6 +380,7 @@ static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void ext->page.edge_flash.right_ip = 0; ext->page.edge_flash.left_ip = 0; } +#endif lv_coord_t x = lv_obj_get_x(scrl); lv_coord_t y = lv_obj_get_y(scrl); @@ -383,12 +389,14 @@ static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void if(ext->drag_top_en == 0) { if(y > -(ext->act_id.y * h) && indev->proc.types.pointer.vect.y > 0 && ext->drag_hor == 0) { +#if LV_USE_ANIMATION if(ext->page.edge_flash.enabled && ext->page.edge_flash.left_ip == 0 && ext->page.edge_flash.right_ip == 0 && ext->page.edge_flash.top_ip == 0 && ext->page.edge_flash.bottom_ip == 0) { ext->page.edge_flash.top_ip = 1; lv_page_start_edge_flash(tileview); } +#endif lv_obj_set_y(scrl, -ext->act_id.y * h + style_bg->body.padding.top); } @@ -396,12 +404,14 @@ static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void if(ext->drag_bottom_en == 0 && indev->proc.types.pointer.vect.y < 0 && ext->drag_hor == 0) { if(y < -(ext->act_id.y * h)) { +#if LV_USE_ANIMATION if(ext->page.edge_flash.enabled && ext->page.edge_flash.left_ip == 0 && ext->page.edge_flash.right_ip == 0 && ext->page.edge_flash.top_ip == 0 && ext->page.edge_flash.bottom_ip == 0) { ext->page.edge_flash.bottom_ip = 1; lv_page_start_edge_flash(tileview); } +#endif } lv_obj_set_y(scrl, -ext->act_id.y * h + style_bg->body.padding.top); @@ -409,12 +419,14 @@ static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void if(ext->drag_left_en == 0) { if(x > -(ext->act_id.x * w) && indev->proc.types.pointer.vect.x > 0 && ext->drag_ver == 0) { +#if LV_USE_ANIMATION if(ext->page.edge_flash.enabled && ext->page.edge_flash.left_ip == 0 && ext->page.edge_flash.right_ip == 0 && ext->page.edge_flash.top_ip == 0 && ext->page.edge_flash.bottom_ip == 0) { ext->page.edge_flash.left_ip = 1; lv_page_start_edge_flash(tileview); } +#endif lv_obj_set_x(scrl, -ext->act_id.x * w + style_bg->body.padding.left); } @@ -422,12 +434,14 @@ static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void if(ext->drag_right_en == 0 && indev->proc.types.pointer.vect.x < 0 && ext->drag_ver == 0) { if(x < -(ext->act_id.x * w)) { +#if LV_USE_ANIMATION if(ext->page.edge_flash.enabled && ext->page.edge_flash.left_ip == 0 && ext->page.edge_flash.right_ip == 0 && ext->page.edge_flash.top_ip == 0 && ext->page.edge_flash.bottom_ip == 0) { ext->page.edge_flash.right_ip = 1; lv_page_start_edge_flash(tileview); } +#endif } lv_obj_set_x(scrl, -ext->act_id.x * w + style_bg->body.padding.top); diff --git a/src/lv_objx/lv_tileview.h b/src/lv_objx/lv_tileview.h index 85ac9c086..53f6e9d92 100644 --- a/src/lv_objx/lv_tileview.h +++ b/src/lv_objx/lv_tileview.h @@ -37,7 +37,9 @@ typedef struct lv_page_ext_t page; /*New data for this type */ const lv_point_t * valid_pos; +#if LV_USE_ANIMATION uint16_t anim_time; +#endif lv_point_t act_id; uint8_t drag_top_en : 1; uint8_t drag_bottom_en : 1;