LVGL-tileview控件

控件特点

以page为基础扩展的控件,增加了释放后会有动画定格效果。

lv_tileview_set_tile_act(tileview, ext->act_id.x + x_move, ext->act_id.y + y_move, true);//切入时开启动画效果。

static void drag_end_handler(lv_obj_t * tileview)
{
    lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
    lv_indev_t * indev      = lv_indev_get_act();
    lv_point_t point_act;
    lv_indev_get_point(indev, &point_act);
    lv_obj_t * scrl = lv_page_get_scrollable(tileview);
    lv_point_t p;

    p.x = -(lv_obj_get_x(scrl) - lv_obj_get_width(tileview) / 2);
    p.y = -(lv_obj_get_y(scrl) - lv_obj_get_height(tileview) / 2);

    lv_drag_dir_t drag_dir = indev->proc.types.pointer.drag_dir;
    /*From the drag vector (drag throw) predict the end position*/
    if(drag_dir & LV_DRAG_DIR_HOR) {
        lv_point_t vect;
        lv_indev_get_vect(indev, &vect);
        lv_coord_t predict = 0;

        #if 0//saimen
        while(vect.x != 0) {
            predict += vect.x;  
            vect.x = vect.x * (100 - indev->driver.drag_throw) / 100;
        }
        #else
        if(vect.x>0)
        {
            predict = (LV_HOR_RES_MAX/2);
        }
        else if(vect.x<0)
        {
            predict = -(LV_HOR_RES_MAX/2);
        }
//        else
//        {
//            am_util_stdio_printf("vect.x:%d,%d\r\n",vect.x, lv_obj_get_x(scrl));
//        }
        #endif
        p.x -= predict;

    }
    else if(drag_dir & LV_DRAG_DIR_VER) {
        lv_point_t vect;
        lv_indev_get_vect(indev, &vect);
        lv_coord_t predict = 0;

        #if 0
        while(vect.y != 0) {
            predict += vect.y;
            vect.y = vect.y * (100 - indev->driver.drag_throw) / 100;
        }
        #else
        if(vect.y>0)
        {
            predict = (LV_VER_RES_MAX/2);
        }
        else if(vect.y<0)
        {
            predict = -(LV_VER_RES_MAX/2);
        }
//        else
//        {
//            am_util_stdio_printf("vect.x:%d,%d\r\n",vect.x, lv_obj_get_x(scrl));
//        }
        #endif

        p.y -= predict;
    }

    /*Get the index of the tile*/
    p.x = p.x / lv_obj_get_width(tileview);
    p.y = p.y / lv_obj_get_height(tileview);

    /*Max +- move*/
    lv_coord_t x_move = p.x - ext->act_id.x;
    lv_coord_t y_move = p.y - ext->act_id.y;
    if(x_move < -1) x_move = -1;
    if(x_move > 1) x_move = 1;
    if(y_move < -1) y_move = -1;
    if(y_move > 1) y_move = 1;

    /*Set the new tile*/
    lv_tileview_set_tile_act(tileview, ext->act_id.x + x_move, ext->act_id.y + y_move, true);
}

出错分析

容易出现1、2、3死循坏调用。原因目前未知

1、static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)

2、lv_obj_set_x(scrl, -ext->act_id.x * lv_obj_get_width(tileview) + left);

3、obj->signal_cb(obj, LV_SIGNAL_COORD_CHG, &ori);

优化

1、释放动画速度优化

2、趋势判断

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值