add routine
Right-clicking will add the corresponding file to the corresponding project directory.
Modify the menu_test_demo.c file as follows
/*********************
* INCLUDES
*********************/
#include "../../lv_100ask_teach_demos.h"
#if LV_USE_MENU_TEST_DEMO
#include "menu_test_demo.h"
/*********************
* DEFINES
*********************/
/**********************
* STATIC VARIABLES
**********************/
void MENU_TEST_GUI_APP(void)
{
}
#endif /* LV_USE_MENU_TEST_DEMO */
Modify the menu_test_demo.h file as follows
#ifndef MENU_TEST_DEMO_H
#define MENU_TEST_DEMO_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_100ask_teach_demos.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void MENU_TEST_GUI_APP(void);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* MENU_TEST_DEMO_H */
In lv_100ask_teach_demos.h, include the header file menu_test_demo.h of the routine, use the relative path
Define the macro switch USE_MENU_TEST_DEMO in the header file lv_100ask_teach_demos_conf.h
Call the test function MENU_TEST_GUI_APP in the main function
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, 320, 240, NULL);
/*Output prompt information to the console, you can also use printf() to print directly*/
LV_LOG_USER("LVGL initialization completed!");
//printf("www.100ask.net: Lvgl initialization complete!\n");
/*Run the demo*/
//lv_100ask_demo_course_2_1_1(); // 基础对象(lv_obj),"Hello, LVGL!"
//lv_100ask_demo_course_2_2_2(); // 基础对象的大小(size)
//lv_100ask_demo_course_2_2_3(); // 基础对象的位置(position)
//lv_100ask_demo_course_2_2_4(); // 基础对象的盒子模型(border-box)
//lv_100ask_demo_course_2_2_5(); // 基础对象的样式(styles)
//lv_100ask_demo_course_2_2_6(); // 基础对象的事件(events)、事件冒泡
//lv_100ask_demo_course_3_1_1(); // 组件(widgets): 标签(label)的用法
//lv_100ask_demo_course_3_1_2(); // 组件(widgets): 标签(label),显示中文
//lv_100ask_demo_course_3_2_1(); // 组件(widgets): 按钮(lv_btn)的用法
//lv_100ask_demo_course_3_3_1(); // 组件(widgets): 使用物理按键代替触摸(groups)
//lv_100ask_demo_course_3_4_1(); // 组件(widgets): 开关(lv_switch)的用法
//lv_100ask_demo_course_3_5_1(); // 组件(widgets): 复选框(lv_checkbox)的用法
//lv_100ask_demo_course_3_6_1(); // 组件(widgets): 下拉列表(lv_dropdown))的用法
//lv_100ask_demo_course_3_7_1(); // 组件(widgets): 滚轮(lv_roller)的用法
//lv_100ask_demo_course_3_8_1(); // 组件(widgets): 进度条(lv_bar)的用法
//lv_100ask_demo_course_3_9_1(); // 组件(widgets): 进度条(lv_slider)的用法
//lv_100ask_page_manager_simple_test();
MENU_TEST_GUI_APP();
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*/
}
return 0;
}
The page manager uses
configuration
Download lv_lib_100ask_masterf and place it in the folder shown in the figure, the code download address
Create the ccd_test_demo folder and place it in the figure. ccd_test_demo.c needs to use the page manager in lv_100ask_page_manager.c.
ccd_test2_demo.c file
ccd_test2_demo.h file
lv_lib_100ask.h file #include “test/ccd_test2_demo/ccd_test2_demo.h”
lv_lib_100ask_conf.h file #define CCD_TEST 1
Finally add the program in the box to lv_lib_100ask_conf_internal.h file
After the above steps You can use the interface functions in the page manager
program modification
Page Manager Library Functions
Modify the function lv_100ask_page_manager_set_open_page, no longer call the back button creation function lv_page_back_btn_create, let the user customize the button style
if (lv_obj_get_child_cnt(obj) == 0)
{
page->init(obj); //传入obj参数执行函数指针 page->init(obj);初始化页面,创建返回按钮
}
User Defined Program
主页面,不需要返回按键
void init_main_page(lv_obj_t * page)
{
}
子页面
void init_page1(lv_obj_t * page)
{
lv_obj_t * cont = lv_obj_create(parent);
//返回按钮
lv_obj_t *back_btn=lv_btn_create(cont);
lv_obj_set_size(back_btn, 60,40);
lv_obj_set_pos(back_btn,250,30);
lv_obj_t *label=lv_label_create(back_btn);
lv_obj_set_style_text_font(label,&ch_word,0); //设置ch_word为当前label字体
lv_label_set_text(label, "返回");
lv_obj_center(label);
lv_obj_add_event_cb(back_btn, lv_page_back_event_cb, LV_EVENT_CLICKED, lv_obj_get_parent(parent));
}
Register key event callback function lv_page_back_event_cb, the function is to return to the main page