lvgl v8之Translate on scroll
On V8 LVGL scroll translate
2023-09-14 09:06:41 时间
Translate on scroll事件处理
static void scroll_event_cb(lv_event_t* e)
{
lv_obj_t* cont = lv_event_get_target(e); //获取产生事件的对象
lv_area_t cont_a;
lv_obj_get_coords(cont, &cont_a); // 获取坐标信息
lv_coord_t cont_y_center = cont_a.y1 + lv_area_get_height(&cont_a) / 2; //计算中点
lv_coord_t r = lv_obj_get_height(cont) * 7 / 10; // 计算半径
uint32_t i;
uint32_t child_cnt = lv_obj_get_child_cnt(cont); // 获取子对象数量
for (i = 0; i < child_cnt; i++) {
lv_obj_t* child = lv_obj_get_child(cont, i); // 根据序号获取子对象
lv_area_t child_a;
lv_obj_get_coords(child, &child_a); //获取子对象的坐标信息
lv_coord_t child_y_center = child_a.y1 + lv_area_get_height(&child_a) / 2; // 计算子对象的中点
lv_coord_t diff_y = child_y_center - cont_y_center; //计算子对象child_a的中点与父对象cont的中点之差
diff_y = LV_ABS(diff_y); // 取中点差绝对值
/*Get the x of diff_y on a circle.*/
lv_coord_t x;
/*If diff_y is out of the circle use the last point of the circle (the␣
,→radius)*/
if (diff_y >= r) { //中点差值大于等于半径
x = r;
}
else { //中点差值小于半径
/*Use Pythagoras theorem to get x from radius and y*/
lv_coord_t x_sqr = r * r - diff_y * diff_y; //计算方差值
lv_sqrt_res_t res;
lv_sqrt(x_sqr, &res, 0x8000); /*Use lvgl's built in sqrt root function*/
x = r - res.i;
}
/*Translate the item by the calculated X coordinate*/
lv_obj_set_style_translate_x(child, x, 0);
/*Use some opacity with larger translations*/
lv_opa_t opa = lv_map(x, 0, r, LV_OPA_TRANSP, LV_OPA_COVER);
lv_obj_set_style_opa(child, LV_OPA_COVER - opa, 0);
}
}
Translate the object as they scroll
/**
* Translate the object as they scroll
*/
static void lv_example_scroll_6(void)
{
lv_obj_t* cont = lv_obj_create(lv_scr_act()); //创建obj对象
lv_obj_set_size(cont, 200, 200); // 设置大小
lv_obj_center(cont); // 居中显示
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN); //设置LV_FLEX_FLOW_COLUMN布局
lv_obj_add_event_cb(cont, scroll_event_cb, LV_EVENT_SCROLL, NULL);//设置滚动事件
lv_obj_set_style_radius(cont, LV_RADIUS_CIRCLE, 0); /设置圆形风格
lv_obj_set_style_clip_corner(cont, true, 0); // 设置clip cornner
lv_obj_set_scroll_dir(cont, LV_DIR_VER); //设置滚动方向LV_DIR_VER
lv_obj_set_scroll_snap_y(cont, LV_SCROLL_SNAP_CENTER); //设置y轴snap
lv_obj_set_scrollbar_mode(cont, LV_SCROLLBAR_MODE_OFF);//关闭滚动条显示
uint32_t i;
for (i = 0; i < 20; i++) { //创建20个按键对象
lv_obj_t* btn = lv_btn_create(cont);
lv_obj_set_width(btn, lv_pct(100));
lv_obj_t* label = lv_label_create(btn);
lv_label_set_text_fmt(label, "Button %d", i);
}
/*Update the buttons position manually for first*/
lv_event_send(cont, LV_EVENT_SCROLL, NULL);
/*Be sure the fist button is in the middle*/
lv_obj_scroll_to_view(lv_obj_get_child(cont, 0), LV_ANIM_OFF); //第一个按键滚动到中间显示
}
显示效果图
相关文章
- Flink on Zeppelin 作业管理系统实践
- Hive on Tez 的安装配置
- ORA-02048: attempt to begin distributed transaction without logging on ORACLE 报错 故障修复 远程处理
- ORA-22307: operation must be on a user-defined type ORACLE 报错 故障修复 远程处理
- ORA-22872: OID INDEX clause not allowed on tables with primary key based object identifiers ORACLE 报错 故障修复 远程处理
- ORA-39809: Data saves are not allowed on tables with domain indexes. ORACLE 报错 故障修复 远程处理
- ORA-47062: error creating Identity map for Identity string.string, Factor Link string, string already defined for operation string on string ORACLE 报错 故障修复 远程处理
- ORA-47954: Oracle Data Pump authorization for Oracle Database Vault to string on object string.string already exists ORACLE 报错 故障修复 远程处理
- ORA-54036: cannot define referential constraint with ON DELETE SET NULL clause on virtual column ORACLE 报错 故障修复 远程处理
- MySQL Error number: 3961; Symbol: ER_WARN_DEPRECATED_JSON_TABLE_ON_ERROR_ON_EMPTY; SQLSTATE: HY000 报错 故障修复 远程处理
- MySQL Error number: MY-011648; Symbol: ER_GRP_RPL_TIMEOUT_RECEIVING_VIEW_CHANGE_ON_SHUTDOWN; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-07480: snchmod: cannot change permissions on ?/dbs/sgalm.dbf. ORACLE 报错 故障修复 远程处理
- ORA-14063: Unusable index exists on unique/primary constraint key ORACLE 报错 故障修复 远程处理
- ORA-16263: Dynamic parameters can only be set on SQL apply instance ORACLE 报错 故障修复 远程处理
- ORA-16831: operation disallowed on this standby database type ORACLE 报错 故障修复 远程处理
- MySQL Error number: MY-013785; Symbol: ER_GRP_RPL_FAILOVER_CONF_PARSE_ON_MEMBER_JOIN; SQLSTATE: HY000 报错 故障修复 远程处理
- inflationInflation Putting Pressure on Oom Linux Private Sectors(oomlinux)
- delete cascadeMySQL:探索ON DELETE CASCADE功能(mysql支持on)