void lv_port_disp_init(void)
{
/*-------------------------
* Initialize your display
* -----------------------*/
disp_init();
/*------------------------------------
* Create a display and set a flush_cb
* -----------------------------------*/
lv_display_t * disp = lv_display_create(MY_DISP_HOR_RES, MY_DISP_VER_RES);
lv_display_set_flush_cb(disp, disp_flush);
/* Example 1
* One buffer for partial rendering*/
static lv_color_t buf_1_1[MY_DISP_HOR_RES * 10]; /*A buffer for 10 rows*/
lv_display_set_buffers(disp, buf_1_1, NULL, sizeof(buf_1_1), LV_DISPLAY_RENDER_MODE_PARTIAL);
// /* Example 2
// * Two buffers for partial rendering
// * In flush_cb DMA or similar hardware should be used to update the display in the background.*/
// static lv_color_t buf_2_1[MY_DISP_HOR_RES * 10];
// static lv_color_t buf_2_2[MY_DISP_HOR_RES * 10];
// lv_display_set_buffers(disp, buf_2_1, buf_2_2, sizeof(buf_2_1), LV_DISPLAY_RENDER_MODE_PARTIAL);
// /* Example 3
// * Two buffers screen sized buffer for double buffering.
// * Both LV_DISPLAY_RENDER_MODE_DIRECT and LV_DISPLAY_RENDER_MODE_FULL works, see their comments*/
// static lv_color_t buf_3_1[MY_DISP_HOR_RES * MY_DISP_VER_RES];
// static lv_color_t buf_3_2[MY_DISP_HOR_RES * MY_DISP_VER_RES];
// lv_display_set_buffers(disp, buf_3_1, buf_3_2, sizeof(buf_3_1), LV_DISPLAY_RENDER_MODE_DIRECT);
}
添加4个按钮:
void lv_example_button_1(void)
{
lv_obj_t *label;
dropdown_font = &lv_font_montserrat_22;
dropdown_width = 150;
btn1 = lv_button_create(lv_screen_active());
lv_obj_set_size(btn1, 200 , 50);
lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -40);
lv_obj_remove_flag(btn1, LV_OBJ_FLAG_PRESS_LOCK);
label = lv_label_create(btn1);
lv_label_set_text(label, "Button");
lv_obj_set_style_text_font(label, dropdown_font, LV_PART_MAIN);
lv_obj_set_width(label, dropdown_width);
lv_obj_center(label);
btn2 = lv_button_create(lv_screen_active());
lv_obj_set_size(btn2 , 200 , 50);
lv_obj_add_event_cb(btn2, event_handler, LV_EVENT_ALL, NULL);
lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 40);
lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
lv_obj_set_height(btn2, LV_SIZE_CONTENT);
label = lv_label_create(btn2);
lv_label_set_text(label, "Toggle");
lv_obj_set_style_text_font(label, dropdown_font, LV_PART_MAIN);
lv_obj_set_width(label, dropdown_width);
lv_obj_center(label);
btn3 = lv_button_create(lv_screen_active());
lv_obj_set_size(btn3, 200 , 50);
lv_obj_add_event_cb(btn3, event_handler, LV_EVENT_ALL, NULL);
lv_obj_align(btn3, LV_ALIGN_CENTER, 300, -40);
lv_obj_remove_flag(btn3, LV_OBJ_FLAG_PRESS_LOCK);
label = lv_label_create(btn3);
lv_label_set_text(label, "Button");
lv_obj_set_style_text_font(label, dropdown_font, LV_PART_MAIN);
lv_obj_set_width(label, dropdown_width);
lv_obj_center(label);
btn4 = lv_button_create(lv_screen_active());
lv_obj_set_size(btn4 , 200 , 50);
lv_obj_add_event_cb(btn4, event_handler, LV_EVENT_ALL, NULL);
lv_obj_align(btn4, LV_ALIGN_CENTER, 300 , 40);
lv_obj_add_flag(btn4, LV_OBJ_FLAG_CHECKABLE);
lv_obj_set_height(btn4, LV_SIZE_CONTENT);
label = lv_label_create(btn4);
lv_label_set_text(label, "Toggle");
lv_obj_set_style_text_font(label, dropdown_font, LV_PART_MAIN);
lv_obj_set_width(label, dropdown_width);
lv_obj_center(label);
}