mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-10 12:47:51 +08:00
d76a346376
Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
69 lines
2.1 KiB
C
69 lines
2.1 KiB
C
#include "../lv_examples.h"
|
|
#if LV_BUILD_EXAMPLES && LV_USE_SWITCH
|
|
|
|
static void anim_x_cb(void * var, int32_t v)
|
|
{
|
|
lv_obj_set_x((lv_obj_t *) var, v);
|
|
}
|
|
|
|
static void timer_cb(lv_timer_t * timer)
|
|
{
|
|
|
|
lv_anim_t * anim = (lv_anim_t *) lv_timer_get_user_data(timer);
|
|
lv_anim_pause_for(anim, 1000);
|
|
lv_timer_delete(timer);
|
|
}
|
|
static void sw_event_cb(lv_event_t * e)
|
|
{
|
|
lv_obj_t * sw = lv_event_get_target_obj(e);
|
|
lv_obj_t * label = (lv_obj_t *) lv_event_get_user_data(e);
|
|
|
|
if(lv_obj_has_state(sw, LV_STATE_CHECKED)) {
|
|
lv_anim_t a;
|
|
lv_anim_init(&a);
|
|
lv_anim_set_var(&a, label);
|
|
lv_anim_set_values(&a, lv_obj_get_x(label), 100);
|
|
lv_anim_set_duration(&a, 500);
|
|
lv_anim_set_exec_cb(&a, anim_x_cb);
|
|
lv_anim_set_path_cb(&a, lv_anim_path_overshoot);
|
|
lv_timer_create(timer_cb, 200, lv_anim_start(&a));
|
|
}
|
|
else {
|
|
lv_anim_t a;
|
|
lv_anim_init(&a);
|
|
lv_anim_set_var(&a, label);
|
|
lv_anim_set_values(&a, lv_obj_get_x(label), -lv_obj_get_width(label));
|
|
lv_anim_set_duration(&a, 500);
|
|
lv_anim_set_exec_cb(&a, anim_x_cb);
|
|
lv_anim_set_path_cb(&a, lv_anim_path_ease_in);
|
|
lv_timer_create(timer_cb, 200, lv_anim_start(&a));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @title Pause a running animation
|
|
* @brief Pause a label slide for one second shortly after it starts.
|
|
*
|
|
* A label and a pre-checked switch are placed on the active screen. When
|
|
* the switch's `LV_EVENT_VALUE_CHANGED` fires, an `lv_anim_t` slides the
|
|
* label to x=100 with `lv_anim_path_overshoot` on check or to `-width`
|
|
* with `lv_anim_path_ease_in` on uncheck, each 500 ms long. After starting
|
|
* the animation a 200 ms `lv_timer_t` calls `lv_anim_pause_for` to hold
|
|
* it for 1000 ms before it resumes.
|
|
*/
|
|
void lv_example_anim_4(void)
|
|
{
|
|
lv_obj_t * label = lv_label_create(lv_screen_active());
|
|
lv_label_set_text(label, "Hello animations!");
|
|
lv_obj_set_pos(label, 100, 10);
|
|
|
|
lv_obj_t * sw = lv_switch_create(lv_screen_active());
|
|
lv_obj_center(sw);
|
|
lv_obj_add_state(sw, LV_STATE_CHECKED);
|
|
lv_obj_add_event_cb(sw, sw_event_cb, LV_EVENT_VALUE_CHANGED, label);
|
|
}
|
|
|
|
#endif
|