From a6f0afde4ccb77eaa0cf2729cff2fcdc9b0e7882 Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Mon, 20 May 2019 09:22:09 -0700 Subject: [PATCH] change some int16_t types to lv_anim_value_t for animation functions. use LV_USE_ANIMATION macros to remove unused variables when animation capabilities is disabled --- lv_conf_template.h | 2 +- src/lv_conf_checker.h | 2 +- src/lv_objx/lv_bar.c | 30 ++++++++++++++++++++------- src/lv_objx/lv_bar.h | 12 +++++++---- src/lv_objx/lv_btn.c | 4 ++-- src/lv_objx/lv_ddlist.c | 8 ++++++-- src/lv_objx/lv_label.c | 8 ++++++++ src/lv_objx/lv_label.h | 5 ++++- src/lv_objx/lv_list.c | 37 +++++++++++++++++---------------- src/lv_objx/lv_list.h | 14 ++++++++----- src/lv_objx/lv_mbox.c | 21 ++++++++++++------- src/lv_objx/lv_mbox.h | 2 ++ src/lv_objx/lv_page.c | 28 ++++++++++++++----------- src/lv_objx/lv_page.h | 3 ++- src/lv_objx/lv_preload.c | 9 +++----- src/lv_objx/lv_preload.h | 9 ++++---- src/lv_objx/lv_slider.h | 3 +-- src/lv_objx/lv_sw.c | 3 +++ src/lv_objx/lv_sw.h | 2 -- src/lv_objx/lv_ta.c | 24 ++++++++++------------ src/lv_objx/lv_tabview.c | 43 ++++++++++++++++++++++++++++----------- src/lv_objx/lv_tabview.h | 2 ++ src/lv_objx/lv_tileview.c | 16 +++++++++------ src/lv_objx/lv_tileview.h | 2 ++ 24 files changed, 184 insertions(+), 105 deletions(-) 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_objx/lv_bar.c b/src/lv_objx/lv_bar.c index 2ecdd142d..a63921985 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; } /** @@ -341,7 +346,10 @@ static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode 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 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..f3d244718 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. @@ -930,6 +933,7 @@ static void lv_ddlist_anim_finish(lv_obj_t* ddlist) ext->force_sel = 0; /*Turn off drawing of selection*/ if(ext->opened) lv_page_set_sb_mode(ddlist, LV_SB_MODE_UNHIDE); } +#endif /** * Adjusts the ddlist's height and then positions the option within it's new height. @@ -937,7 +941,7 @@ 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); 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..c6f1c432d 100644 --- a/src/lv_objx/lv_mbox.c +++ b/src/lv_objx/lv_mbox.c @@ -77,7 +77,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 +184,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 +202,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 +212,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 +358,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 } /** 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..0e33a6df9 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 @@ -428,15 +430,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 +530,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 +559,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; @@ -1193,7 +1195,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 +1212,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..60b8536b1 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 @@ -78,7 +79,7 @@ typedef struct } sb; 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 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_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..169c08338 100644 --- a/src/lv_objx/lv_ta.c +++ b/src/lv_objx/lv_ta.c @@ -46,9 +46,9 @@ 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 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..f40be85f3 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..bac4a475d 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 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;