您当前的位置: 首页 > 

仙剑情缘

暂无认证

  • 0浏览

    0关注

    333博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

lvgl v8之Translate on scroll

仙剑情缘 发布时间:2021-10-31 18:40:11 ,浏览量:0

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 = 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             
关注
打赏
1658017818
查看更多评论
0.0680s