LVGL V8之Start animation on an event
On an Event start animation V8 LVGL
2023-09-14 09:11:17 时间
创建动画
- 动画回调处理函数
static void anim_x_cb(void* var, int32_t v)
{
lv_obj_set_x(var, v); // 设置对象x坐标
}
- slider事件处理回调函数
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); //获取事件用户数据
int end;
lv_anim_path_cb_t path_cb;
if (lv_obj_has_state(sw, LV_STATE_CHECKED)) { //检查事件类型是否为CHECKED
end = 100;
path_cb = lv_anim_path_overshoot; //overshoot动画方式
}
else {
end = -lv_obj_get_width(label);
path_cb = lv_anim_path_ease_in; //ease in动画方式
}
lv_anim_t a; // 定义动画变量
lv_anim_init(&a); // 初时化动画变量
lv_anim_set_var(&a, label); //设置动画变量
lv_anim_set_values(&a, lv_obj_get_x(label), end); //设置动画变量start,end初值
lv_anim_set_time(&a, 500); //设置动画持续时间
lv_anim_set_exec_cb(&a, anim_x_cb); //设置动画执行回调函数
lv_anim_set_path_cb(&a, path_cb);//设置动画path处理方式
lv_anim_start(&a); //开始一个动画播放
}
- 创建slider控制动画播放
static void lv_example_anim_1(void)
{
lv_obj_t* label = lv_label_create(lv_scr_act()); //当前活动界面创建label对象
lv_label_set_text(label, "Hello animations!");//设置显示内容
lv_obj_set_pos(label, 100, 10); //设置label位置
lv_obj_t* sw = lv_switch_create(lv_scr_act());//当前活动界面创建switch对象
lv_obj_center(sw); //居中显示
lv_obj_add_state(sw, LV_STATE_CHECKED); //设置checked状态
lv_obj_add_event_cb(sw, sw_event_cb, LV_EVENT_VALUE_CHANGED, label); //设置值发生改变后的事件
}
调用lv_example_anim_1运行效果
相关文章
- snapshots On Vmware
- install Mac OS on Vmware
- remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
- Hadoop Installation on Linux
- Android Studio解决unspecified on project app resolves to an APK archive which is not supported
- [Tools] Support VS Code Navigation and Autocomplete Based on Webpack Aliases with jsconfig.json
- [Tool] Open Multiple Terminal Tabs on npm Start with ttab and npm-run-all
- [Debug] Use Remote Sources to Debug a Web App on an Emulator, Simulator, or Physical Device
- [Webpack] Access Webpack Dev Server from Mobile Safari on an iPhone
- [AngularJS] Using an AngularJS directive to hide the keyboard on submit
- Don't know how to define struct flock on this system, set --enable-opcach=no
- FILESTREAM data cannot be placed on an empty filegroup 解决办法
- ON DUPLICATE KEY UPDATE
- [Debug] Use Remote Sources to Debug a Web App on an Emulator, Simulator, or Physical Device
- [AngularJS] Using an AngularJS directive to hide the keyboard on submit
- [Redux] Fetching Data on Route Change
- [Firebase + PWA] Keynote: Progressive Web Apps on Firebase
- [React] React Fundamentals: Add-on ClassSet() for ClassName
- LInux fork的写时复制(copy on write)
- Comments on task “Smart Service II: Wrap up and make it ready for Demo“
- SAP CRM WebClient UI ON_NEW_FOCUS的用途
- 论文解读(MGAE)《MGAE: Masked Autoencoders for Self-Supervised Learning on Graphs》
- 联机事务处理OLTP(on-line transaction processing)和联机分析处理OLAP(On-Line Analytical Processing)
- 【taro react hooks 错误解决】---- Warning: Can‘t perform a React state update on an unmounted component.
- 【python问题解决】---- sqlite3.OperationalError: AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY