侧边栏壁纸
博主头像
潦草地博主等级

行动起来,活在当下

  • 累计撰写 8 篇文章
  • 累计创建 2 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

LVGL 滑动

Storen
2025-02-28 / 0 评论 / 0 点赞 / 13 阅读 / 2237 字

static lv_obj_t* snapshot_obj = NULL;
static lv_obj_t* btn1 = NULL;

static void scroll_event_cb(lv_event_t* e) {
    lv_obj_t* tv = lv_event_get_target_obj(e);

    lv_event_code_t ec = lv_event_get_code(e);
    if (ec == LV_EVENT_RELEASED) {
        lv_obj_delete(snapshot_obj);
        snapshot_obj = NULL;
        return;
    }

    int32_t st = lv_obj_get_scroll_top(tv);

    if (st == 0) {
        lv_obj_delete(snapshot_obj);
        snapshot_obj = NULL;
    } else {
        if (snapshot_obj == NULL) {
            /*Create an image object to show snapshot*/
            snapshot_obj = lv_image_create(tv);
            // lv_obj_set_style_bg_color(snapshot_obj, lv_palette_main(LV_PALETTE_PURPLE), 0);
            lv_obj_set_style_bg_opa(snapshot_obj, LV_OPA_10, 0);
            lv_image_set_scale(snapshot_obj, 300);
            lv_image_set_rotation(snapshot_obj, st);
            // snapshot
            lv_obj_t * img = btn1;
            lv_draw_buf_t * snapshot = (lv_draw_buf_t *)lv_image_get_src(snapshot_obj);
            if(snapshot) {
                lv_draw_buf_destroy(snapshot);
            }

            /*Update the snapshot, we know parent of object is the container.*/
            snapshot = lv_snapshot_take(img, LV_COLOR_FORMAT_ARGB8888);
            if(snapshot == NULL)
                return;
            lv_image_set_src(snapshot_obj, snapshot);

        }
        lv_obj_set_pos(snapshot_obj, 0, st);
        lv_image_set_scale(snapshot_obj, 300 - st);
    }
}


void lv_example_tileview_2(void)
{
    lv_obj_t * tv = lv_tileview_create(lv_screen_active());

    /*Tile1: just a label*/
    lv_obj_t * tile1 = lv_tileview_add_tile(tv, 0, 0, LV_DIR_BOTTOM);
    /*lv_obj_t **/ btn1 = lv_button_create(tile1);
    lv_obj_set_size(btn1, 300, 300);
    lv_obj_center(btn1);

    /*Tile2: a button*/
    lv_obj_t * tile2 = lv_tileview_add_tile(tv, 0, 1, LV_DIR_TOP | LV_DIR_RIGHT);
    lv_obj_t * btn2 = lv_button_create(tile2);
    lv_obj_set_size(btn2, 300, 300);
    lv_obj_center(btn2);

    lv_obj_add_event_cb(tv, scroll_event_cb, LV_EVENT_SCROLL, NULL);
    lv_obj_add_event_cb(tv, scroll_event_cb, LV_EVENT_RELEASED, NULL);
}

0

评论区