demo工程暂存 优化菜单界面UI和功能
This commit is contained in:
19
Demo/lvgl/examples/anim/index.rst
Normal file
19
Demo/lvgl/examples/anim/index.rst
Normal file
@ -0,0 +1,19 @@
|
||||
C
|
||||
^
|
||||
|
||||
Start animation on an event
|
||||
""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: anim/lv_example_anim_1
|
||||
:language: c
|
||||
|
||||
Playback animation
|
||||
"""""""""""""""""""
|
||||
.. lv_example:: anim/lv_example_anim_2
|
||||
:language: c
|
||||
|
||||
|
||||
MicroPython
|
||||
^^^^^^^^^^^
|
||||
|
||||
No examples yet.
|
39
Demo/lvgl/examples/anim/lv_example_anim.h
Normal file
39
Demo/lvgl/examples/anim/lv_example_anim.h
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @file lv_example_anim.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EXAMPLE_ANIM_H
|
||||
#define LV_EXAMPLE_ANIM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_anim_1(void);
|
||||
void lv_example_anim_2(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_ANIM_H*/
|
52
Demo/lvgl/examples/anim/lv_example_anim_1.c
Normal file
52
Demo/lvgl/examples/anim/lv_example_anim_1.c
Normal file
@ -0,0 +1,52 @@
|
||||
#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(var, v);
|
||||
}
|
||||
|
||||
static void sw_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * sw = lv_event_get_target(e);
|
||||
lv_obj_t * label = 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_time(&a, 500);
|
||||
lv_anim_set_exec_cb(&a, anim_x_cb);
|
||||
lv_anim_set_path_cb(&a, lv_anim_path_overshoot);
|
||||
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_time(&a, 500);
|
||||
lv_anim_set_exec_cb(&a, anim_x_cb);
|
||||
lv_anim_set_path_cb(&a, lv_anim_path_ease_in);
|
||||
lv_anim_start(&a);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Start animation on an event
|
||||
*/
|
||||
void lv_example_anim_1(void)
|
||||
{
|
||||
lv_obj_t * label = lv_label_create(lv_scr_act());
|
||||
lv_label_set_text(label, "Hello animations!");
|
||||
lv_obj_set_pos(label, 100, 10);
|
||||
|
||||
|
||||
lv_obj_t * sw = lv_switch_create(lv_scr_act());
|
||||
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
|
45
Demo/lvgl/examples/anim/lv_example_anim_2.c
Normal file
45
Demo/lvgl/examples/anim/lv_example_anim_2.c
Normal file
@ -0,0 +1,45 @@
|
||||
#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(var, v);
|
||||
}
|
||||
|
||||
static void anim_size_cb(void * var, int32_t v)
|
||||
{
|
||||
lv_obj_set_size(var, v, v);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a playback animation
|
||||
*/
|
||||
void lv_example_anim_2(void)
|
||||
{
|
||||
|
||||
lv_obj_t * obj = lv_obj_create(lv_scr_act());
|
||||
lv_obj_set_style_bg_color(obj, lv_palette_main(LV_PALETTE_RED), 0);
|
||||
lv_obj_set_style_radius(obj, LV_RADIUS_CIRCLE, 0);
|
||||
|
||||
lv_obj_align(obj, LV_ALIGN_LEFT_MID, 10, 0);
|
||||
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, obj);
|
||||
lv_anim_set_values(&a, 10, 50);
|
||||
lv_anim_set_time(&a, 1000);
|
||||
lv_anim_set_playback_delay(&a, 100);
|
||||
lv_anim_set_playback_time(&a, 300);
|
||||
lv_anim_set_repeat_delay(&a, 500);
|
||||
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
|
||||
lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out);
|
||||
|
||||
lv_anim_set_exec_cb(&a, anim_size_cb);
|
||||
lv_anim_start(&a);
|
||||
lv_anim_set_exec_cb(&a, anim_x_cb);
|
||||
lv_anim_set_values(&a, 10, 240);
|
||||
lv_anim_start(&a);
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user