Description
Hi, I met a weird thing only when use two screen-sized buffer.
I want to test the parent-child property.
When I drag the child, the size of the parent will change.(as shown in gif)
(The situation happens only when I use two screen-sized buffers)
I appreciate any suggestions.
Code to reproduce
The code block(s) should be formatted like:
int main(int argc, char* argv[]){
lv_init();
//2,Initialize your drivers.
hal_init();
input_arg = atoi(argv[1]);
static lv_disp_buf_t disp_buf;
static lv_color_t buf_1[LV_HOR_RES_MAX * LV_VER_RES_MAX]; //LV_VER_RES_MAX
static lv_color_t buf_2[LV_HOR_RES_MAX * LV_VER_RES_MAX]; /*Declare a buffer for 100 lines*/
lv_disp_buf_init(&disp_buf, buf_1, buf_2, LV_HOR_RES_MAX * LV_VER_RES_MAX); /*Initialize the display buffer*/
lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
disp_drv.flush_cb = my_disp_flush_ex; /*Set your driver function*/
disp_drv.buffer = &disp_buf; /*Assign the buffer to the display*/
//disp_drv.monitor_cb = my_monitor_cb;
lv_disp_drv_register(&disp_drv); /*Finally register the driver*/
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); /*Descriptor of a input device driver*/
indev_drv.type = LV_INDEV_TYPE_POINTER; /*Touch pad is a pointer-like device*/
indev_drv.read_cb = my_touchpad_read; /*Set your driver function*/
lv_indev_drv_register(&indev_drv); /*Finally register the driver*/
printf("display and input device set ok!\n");
setStyle();
ParentChildren();
bool quit = false;
SDL_Event e;
while(!quit){
while(SDL_PollEvent(&e) != 0){
switch(e.type){
case SDL_QUIT:
quit = true;
break;
case SDL_MOUSEBUTTONDOWN:
gInput.pressed = true;
gInput.x = e.motion.x;
gInput.y = e.motion.y;
printf("state= %d, x=%d, y=%d\n", e.button.state, e.motion.x, e.motion.y);
break;
case SDL_MOUSEBUTTONUP:
gInput.pressed = false;
printf("state= %d, x=%d, y=%d\n", e.button.state, e.motion.x, e.motion.y);
break;
case SDL_MOUSEMOTION:
gInput.x = e.motion.x;
gInput.y = e.motion.y;
//printf("mouse motion, x=%d, y=%d\n", e.motion.x, e.motion.y);
break;
}
}
}
static lv_style_t style1;
static lv_style_t style2;
void setStyle(){
lv_style_init(&style1);
lv_style_init(&style2);
lv_style_set_bg_color(&style1, LV_STATE_DEFAULT, LV_COLOR_GREEN);
lv_style_set_bg_color(&style2, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_click(lv_scr_act(), false);
}
void ParentChildren(){
lv_obj_t * button = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(button, 300,300);
lv_obj_set_pos(button, 250,250);
lv_obj_set_drag(button,true);
lv_obj_add_style(button,LV_OBJ_PART_MAIN,&style1);
lv_obj_t * button2 = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(button2, 100,100);
lv_obj_set_pos(button2,100,100);
lv_obj_add_style(button2, LV_OBJ_PART_MAIN,&style2);
lv_obj_set_drag(button2,true);
lv_obj_set_parent(button2, button);
}
oid my_disp_flush_ex(struct _disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p){
int32_t x1 = area->x1;
int32_t x2 = area->x2;
int32_t y1 = area->y1;
int32_t y2 = area->y2;
uint32_t w = x2 - x1 + 1;
for(int32_t y = y1; y <= y2; y++) {
memcpy(&tft_buf[y * LV_HOR_RES_MAX + x1], color_p, w * sizeof(lv_color_t));
color_p += w;
}
SDL_UpdateTexture(gTexture, NULL, tft_buf, LV_HOR_RES_MAX * sizeof(uint32_t));
SDL_RenderClear(gRenderer);
SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);
SDL_RenderPresent(gRenderer)
lv_disp_flush_ready(disp); //Indicate you are ready with the flushing
}