Wrapped remaining animation and edge_flash references in #if LV_USE_ANIMATION to save memory/space

This commit is contained in:
Brian Pugh
2019-05-20 18:31:47 -07:00
parent cbb9c3f73b
commit cd1ad6eb3a
8 changed files with 120 additions and 43 deletions

View File

@@ -933,7 +933,6 @@ 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.
@@ -946,6 +945,7 @@ 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

View File

@@ -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);
/**********************
@@ -528,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)
{

View File

@@ -88,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;
@@ -95,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;
@@ -235,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
}
/**
@@ -260,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
}
}
@@ -320,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
}
/**
@@ -367,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;
}
@@ -661,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;
@@ -939,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
}
}
@@ -978,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
}
}

View File

@@ -77,6 +77,7 @@ 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
{
lv_anim_value_t state; /*Store the current size of the edge flash effect*/
@@ -91,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*/

View File

@@ -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

View File

@@ -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);

View File

@@ -375,9 +375,9 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en)
break;
}
if( anim_en == false ||
if( anim_en == false
#if LV_USE_ANIMATION
ext->anim_time == 0
|| ext->anim_time == 0
#endif
) {
lv_obj_set_x(ext->content, cont_x);
@@ -418,9 +418,9 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en)
break;
}
if( anim_en == false ||
if( anim_en == false
#if LV_USE_ANIMATION
ext->anim_time == 0
|| ext->anim_time == 0
#endif
) {
switch(ext->btns_pos) {

View File

@@ -370,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;
@@ -379,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);
@@ -387,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);
}
@@ -400,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);
@@ -413,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);
}
@@ -426,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);