Animation of opacity does not work, but animation of position works

Hello. I use ESP32 + TFT_eSPI + LVGL (last version) and Arduino IDE.
I try to dynamically create object with label inside, so I wrote the code:

int32_t _ui_anim_callback_get_y(lv_anim_t * a)
{
return lv_obj_get_y_aligned((lv_obj_t *)a->user_data);
}
void _ui_anim_callback_set_y(lv_anim_t * a, int32_t v)
{
lv_obj_set_y((lv_obj_t *)a->user_data, v);
}
void show_my_message(char mess[]){
// creating new object
lv_obj_t * my_message = lv_obj_create(ui_Screen1_Panel2);
lv_obj_set_width(my_message, 200);
lv_obj_set_height(my_message, LV_SIZE_CONTENT);
lv_obj_set_x(my_message, 0);
lv_obj_set_y(my_message, msg_y+0);
lv_obj_set_align(my_message, LV_ALIGN_TOP_RIGHT);
lv_obj_clear_flag(my_message, LV_OBJ_FLAG_SCROLLABLE); /// Flags
lv_obj_set_style_radius(my_message, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_bg_color(my_message, lv_color_hex(0xAFC5FF), LV_PART_MAIN | LV_STATE_DEFAULT);
//lv_obj_set_style_bg_opa(my_message, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_width(my_message, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_pad_left(my_message, 8, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_pad_right(my_message, 8, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_pad_top(my_message, 8, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_pad_bottom(my_message, 8, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_t * my_message_text = lv_label_create(my_message);
lv_obj_set_width(my_message_text, lv_pct(100)); /// 1
lv_obj_set_height(my_message_text, LV_SIZE_CONTENT); /// 1
lv_label_set_text(my_message_text, mess);
lv_obj_scroll_to_view(my_message, LV_ANIM_ON);
lv_obj_set_style_opa(my_message, 0, 0);

// animation of the object
lv_anim_t messagemove;
lv_anim_init(&messagemove);
lv_anim_set_time(&messagemove, 500);
lv_anim_set_user_data(&messagemove, my_message);
lv_anim_set_custom_exec_cb(&messagemove, _ui_anim_callback_set_y);
lv_anim_set_values(&messagemove, 0, -20);
lv_anim_set_path_cb(&messagemove, lv_anim_path_linear);
lv_anim_set_delay(&messagemove, 100);
lv_anim_set_playback_time(&messagemove, 0);
lv_anim_set_playback_delay(&messagemove, 0);
lv_anim_set_repeat_count(&messagemove, 0);
lv_anim_set_repeat_delay(&messagemove, 0);
lv_anim_set_early_apply(&messagemove, true);
lv_anim_set_get_value_cb(&messagemove, &_ui_anim_callback_get_y);
lv_anim_start(&messagemove);
msg_y = msg_y + lv_obj_get_height(my_message) + 8; // y position stored for the next object

}

And it works great. When I call
show_my_message(“any text”);
I can see on the screen the new message which moves up a little bit and then stops.

But when I correct the functions as
int32_t _ui_anim_callback_get_opacity(lv_anim_t * a)
{
return lv_obj_get_style_opa((lv_obj_t *)a->user_data, 0);
}
void _ui_anim_callback_set_opacity(lv_anim_t * a, int32_t v)
{
lv_obj_set_style_opa((lv_obj_t *)a->user_data, v, 0);
}
void show_my_message(char mess[]){
lv_obj_t * my_message = lv_obj_create(ui_Screen1_Panel2);
lv_obj_set_width(my_message, 200);
lv_obj_set_height(my_message, LV_SIZE_CONTENT);
lv_obj_set_x(my_message, 0);
lv_obj_set_y(my_message, msg_y+0);
lv_obj_set_align(my_message, LV_ALIGN_TOP_RIGHT);
lv_obj_clear_flag(my_message, LV_OBJ_FLAG_SCROLLABLE); /// Flags
lv_obj_set_style_radius(my_message, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_bg_color(my_message, lv_color_hex(0xAFC5FF), LV_PART_MAIN | LV_STATE_DEFAULT);
//lv_obj_set_style_bg_opa(my_message, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_width(my_message, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_pad_left(my_message, 8, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_pad_right(my_message, 8, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_pad_top(my_message, 8, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_pad_bottom(my_message, 8, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_t * my_message_text = lv_label_create(my_message);
lv_obj_set_width(my_message_text, lv_pct(100)); /// 1
lv_obj_set_height(my_message_text, LV_SIZE_CONTENT); /// 1
lv_label_set_text(my_message_text, mess);
lv_obj_scroll_to_view(my_message, LV_ANIM_ON);
lv_obj_set_style_opa(my_message, 0, 0);
lv_anim_t messageopacity;
lv_anim_init(&messageopacity);
lv_anim_set_time(&messageopacity, 2000);
lv_anim_set_user_data(&messageopacity, my_message);
lv_anim_set_custom_exec_cb(&messageopacity, _ui_anim_callback_set_opacity);
lv_anim_set_values(&messageopacity, 0, 100);
lv_anim_set_path_cb(&messageopacity, lv_anim_path_linear);
lv_anim_set_delay(&messageopacity, 0);
lv_anim_set_playback_time(&messageopacity, 0);
lv_anim_set_playback_delay(&messageopacity, 0);
lv_anim_set_repeat_count(&messageopacity, 0);
lv_anim_set_repeat_delay(&messageopacity, 0);
lv_anim_set_early_apply(&messageopacity, true);
lv_anim_set_get_value_cb(&messageopacity, &_ui_anim_callback_get_opacity);
lv_anim_start(&messageopacity);
msg_y = msg_y + lv_obj_get_height(my_message) + 8;
}

The new object created, but without animation.
What’s wrong? Maybe, there is a problem with _ui_anim_callback_get_opacity and _ui_anim_callback_set_opacity ???

sorry for formatting

Later I will try to compile with
#define LV_COLOR_SCREEN_TRANSP 1
But I don’t think it will help.

The problem has been solved when I defined
#define LV_COLOR_SCREEN_TRANSP 1

1 Like