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);
}
版权归属:
Storen
许可协议:
本文使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
评论区