feat: 添加第二屏幕及其事件处理功能

- 在 CMakeLists.txt 中添加 ui_Screen2.c 源文件以支持新屏幕
- 新增 ui_events.c 和 ui_events.h,定义按钮点击事件处理函数
- 实现 ui_Screen2.c,构建第二屏幕的 UI 组件和事件回调
- 更新 ui.c 以初始化和加载第二屏幕
- 更新相关头文件,确保新屏幕与现有结构兼容
This commit is contained in:
2026-07-01 22:02:31 +08:00
parent 55bbe951fe
commit 73e62c4dfd
9 changed files with 211 additions and 2 deletions
+1
View File
@@ -8,6 +8,7 @@ idf_component_register(SRCS
"ui/ui.c" "ui/ui.c"
"ui/ui_helpers.c" "ui/ui_helpers.c"
"ui/screens/ui_Screen1.c" "ui/screens/ui_Screen1.c"
"ui/screens/ui_Screen2.c"
"ui/widgets/ui_comp_hook.c" "ui/widgets/ui_comp_hook.c"
PRIV_REQUIRES PRIV_REQUIRES
esp_wifi esp_wifi
+19 -1
View File
@@ -1,4 +1,22 @@
#include "ui_handlers.h" #include "ui_handlers.h"
#include "ui_events.h" #include "ui_events.h"
/* Add callback implementations here when SquareLine Studio generates events. */ void update_year_action(lv_event_t * e)
{
(void)e;
}
void click_button_two(lv_event_t * e)
{
(void)e;
}
void click_button_three(lv_event_t * e)
{
(void)e;
}
void click_button_one(lv_event_t * e)
{
(void)e;
}
+5
View File
@@ -0,0 +1,5 @@
// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.6.1
// LVGL version: 9.2.2
// Project name: HeavenlyHeroStar
+116
View File
@@ -0,0 +1,116 @@
// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.6.1
// LVGL version: 9.2.2
// Project name: HeavenlyHeroStar
#include "../ui.h"
lv_obj_t * ui_Screen2 = NULL;
lv_obj_t * ui_Button1 = NULL;
lv_obj_t * ui_Button2 = NULL;
lv_obj_t * ui_Button3 = NULL;
lv_obj_t * ui_Label2 = NULL;
lv_obj_t * ui_Label4 = NULL;
lv_obj_t * ui_Label5 = NULL;
// event funtions
void ui_event_Button1(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
if(event_code == LV_EVENT_CLICKED) {
click_button_two(e);
}
}
void ui_event_Button2(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
if(event_code == LV_EVENT_CLICKED) {
click_button_three(e);
}
}
void ui_event_Button3(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
if(event_code == LV_EVENT_CLICKED) {
click_button_one(e);
}
}
// build funtions
void ui_Screen2_screen_init(void)
{
ui_Screen2 = lv_obj_create(NULL);
lv_obj_remove_flag(ui_Screen2, LV_OBJ_FLAG_SCROLLABLE); /// Flags
ui_Button1 = lv_button_create(ui_Screen2);
lv_obj_set_width(ui_Button1, 100);
lv_obj_set_height(ui_Button1, 80);
lv_obj_set_align(ui_Button1, LV_ALIGN_CENTER);
lv_obj_add_flag(ui_Button1, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags
lv_obj_remove_flag(ui_Button1, LV_OBJ_FLAG_SCROLLABLE); /// Flags
ui_Button2 = lv_button_create(ui_Screen2);
lv_obj_set_width(ui_Button2, 100);
lv_obj_set_height(ui_Button2, 80);
lv_obj_set_x(ui_Button2, 0);
lv_obj_set_y(ui_Button2, 100);
lv_obj_set_align(ui_Button2, LV_ALIGN_CENTER);
lv_obj_add_flag(ui_Button2, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags
lv_obj_remove_flag(ui_Button2, LV_OBJ_FLAG_SCROLLABLE); /// Flags
ui_Button3 = lv_button_create(ui_Screen2);
lv_obj_set_width(ui_Button3, 100);
lv_obj_set_height(ui_Button3, 80);
lv_obj_set_x(ui_Button3, 0);
lv_obj_set_y(ui_Button3, -100);
lv_obj_set_align(ui_Button3, LV_ALIGN_CENTER);
lv_obj_add_flag(ui_Button3, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags
lv_obj_remove_flag(ui_Button3, LV_OBJ_FLAG_SCROLLABLE); /// Flags
ui_Label2 = lv_label_create(ui_Screen2);
lv_obj_set_width(ui_Label2, LV_SIZE_CONTENT); /// 1
lv_obj_set_height(ui_Label2, LV_SIZE_CONTENT); /// 1
lv_obj_set_align(ui_Label2, LV_ALIGN_CENTER);
lv_label_set_text(ui_Label2, "Ctrl+C");
ui_Label4 = lv_label_create(ui_Screen2);
lv_obj_set_width(ui_Label4, LV_SIZE_CONTENT); /// 1
lv_obj_set_height(ui_Label4, LV_SIZE_CONTENT); /// 1
lv_obj_set_x(ui_Label4, 0);
lv_obj_set_y(ui_Label4, 100);
lv_obj_set_align(ui_Label4, LV_ALIGN_CENTER);
lv_label_set_text(ui_Label4, "Ctrl+V");
ui_Label5 = lv_label_create(ui_Screen2);
lv_obj_set_width(ui_Label5, LV_SIZE_CONTENT); /// 1
lv_obj_set_height(ui_Label5, LV_SIZE_CONTENT); /// 1
lv_obj_set_x(ui_Label5, 0);
lv_obj_set_y(ui_Label5, -100);
lv_obj_set_align(ui_Label5, LV_ALIGN_CENTER);
lv_label_set_text(ui_Label5, "Ctrl+X");
lv_obj_add_event_cb(ui_Button1, ui_event_Button1, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_Button2, ui_event_Button2, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_Button3, ui_event_Button3, LV_EVENT_ALL, NULL);
}
void ui_Screen2_screen_destroy(void)
{
if(ui_Screen2) lv_obj_del(ui_Screen2);
// NULL screen variables
ui_Screen2 = NULL;
ui_Button1 = NULL;
ui_Button2 = NULL;
ui_Button3 = NULL;
ui_Label2 = NULL;
ui_Label4 = NULL;
ui_Label5 = NULL;
}
+33
View File
@@ -0,0 +1,33 @@
// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.6.1
// LVGL version: 9.2.2
// Project name: HeavenlyHeroStar
#ifndef UI_SCREEN2_H
#define UI_SCREEN2_H
#ifdef __cplusplus
extern "C" {
#endif
// SCREEN: ui_Screen2
extern void ui_Screen2_screen_init(void);
extern void ui_Screen2_screen_destroy(void);
extern lv_obj_t * ui_Screen2;
extern void ui_event_Button1(lv_event_t * e);
extern lv_obj_t * ui_Button1;
extern void ui_event_Button2(lv_event_t * e);
extern lv_obj_t * ui_Button2;
extern void ui_event_Button3(lv_event_t * e);
extern lv_obj_t * ui_Button3;
extern lv_obj_t * ui_Label2;
extern lv_obj_t * ui_Label4;
extern lv_obj_t * ui_Label5;
// CUSTOM VARIABLES
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif
+3 -1
View File
@@ -31,11 +31,13 @@ void ui_init(void)
false, LV_FONT_DEFAULT); false, LV_FONT_DEFAULT);
lv_disp_set_theme(dispp, theme); lv_disp_set_theme(dispp, theme);
ui_Screen1_screen_init(); ui_Screen1_screen_init();
ui_Screen2_screen_init();
ui____initial_actions0 = lv_obj_create(NULL); ui____initial_actions0 = lv_obj_create(NULL);
lv_disp_load_scr(ui_Screen1); lv_disp_load_scr(ui_Screen2);
} }
void ui_destroy(void) void ui_destroy(void)
{ {
ui_Screen1_screen_destroy(); ui_Screen1_screen_destroy();
ui_Screen2_screen_destroy();
} }
+1
View File
@@ -19,6 +19,7 @@ extern "C" {
///////////////////// SCREENS //////////////////// ///////////////////// SCREENS ////////////////////
#include "screens/ui_Screen1.h" #include "screens/ui_Screen1.h"
#include "screens/ui_Screen2.h"
///////////////////// VARIABLES //////////////////// ///////////////////// VARIABLES ////////////////////
+26
View File
@@ -0,0 +1,26 @@
// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.6.1
// LVGL version: 9.2.2
// Project name: HeavenlyHeroStar
#include "ui.h"
void update_year_action(lv_event_t * e)
{
// Your code here
}
void click_button_two(lv_event_t * e)
{
// Your code here
}
void click_button_three(lv_event_t * e)
{
// Your code here
}
void click_button_one(lv_event_t * e)
{
// Your code here
}
+7
View File
@@ -10,6 +10,13 @@
extern "C" { extern "C" {
#endif #endif
#include "lvgl.h"
void update_year_action(lv_event_t * e);
void click_button_two(lv_event_t * e);
void click_button_three(lv_event_t * e);
void click_button_one(lv_event_t * e);
#ifdef __cplusplus #ifdef __cplusplus
} /*extern "C"*/ } /*extern "C"*/
#endif #endif