在百问网的lvgl codeblock源码上开发,
通过构建一个普通obj和style,obj添加style后,在while中计数100次后更改style的bg_color,发现掉不掉用
lv_obj_invalidate(obj),obj的样式都会变,所以样式改变是不需要通知obj吗?
代码如下:
static lv_style_t my_style_page;
lv_obj_t* page_test;
static void my_style_page_init(lv_style_t* p_style);
void my_style_init(void )
{
my_style_page_init(&my_style_page);
}
static void my_style_page_init(lv_style_t* p_style)
{
lv_style_init(p_style);
lv_style_set_bg_color(p_style,lv_color_make(134,134,236));
lv_style_set_pad_all(p_style,0);
}
void my_page_test(void )
{
page_test = lv_obj_create(lv_scr_act());
lv_obj_set_size(page_test,100,100);
lv_obj_set_align(page_test,LV_ALIGN_TOP_MID);
lv_obj_align(page_test,LV_ALIGN_CENTER,0,0);
lv_obj_add_style(page_test,&my_style_page,LV_PART_MAIN);
//lv_obj_remove_style(page_test,&my_style_page,LV_PART_MAIN);
lv_obj_t* page_test_child = lv_obj_create(page_test);
lv_obj_set_size(page_test_child,50,50);
lv_obj_align(page_test_child,LV_ALIGN_TOP_MID,-25,0);
}
void style_change(void )
{
lv_style_set_bg_color(&my_style_page,lv_color_make(0xff,0xff,0xff));
//lv_obj_invalidate(page_test);
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int nCmdShow)
{
/Initialize LittlevGL/
lv_init();
/*Initialize the HAL for LittlevGL*/
lv_win32_init(hInstance, SW_SHOWNORMAL, 1024, 600, NULL);
/*Output prompt information to the console, you can also use printf() to print directly*/
LV_LOG_USER("LVGL initialization completed!");
my_style_init();
my_page_test();
uint16_t i =0;
while(!lv_win32_quit_signal) {
/* Periodically call the lv_task handler.
* It could be done in a timer interrupt or an OS task too.*/
lv_task_handler();
usleep(10000); /*Just to let the system breath*/
if(i > 101)
{}
else if(i > 100)
style_change();
else
i++;
}
return 0;
}