feat(ui): 重构设置界面为页面控制器架构
- 添加新的UI页面基础架构(ui_page.h),包含页面操作接口 - 创建设置页面控制器(ui_settings_controller.h/.c)来管理页面导航 - 实现具体的设置页面类型:根页面、BLE页面、主题页面 - 修改display_module.c以使用新的页面系统替代旧的状态机 - 移除过时的settings_ui.h头文件和相关状态结构 - 更新事件处理逻辑以使用页面指针而非状态数据传递 - 修改主界面实现以适配统一的页面接口标准
This commit is contained in:
@@ -19,10 +19,10 @@
|
||||
#include "module_lifecycle.h"
|
||||
#include "mode_switch_event.h"
|
||||
#include "settings_mode_event.h"
|
||||
#include "settings_ui.h"
|
||||
#include "settings_view_event.h"
|
||||
#include "theme_rgb_update_event.h"
|
||||
#include "theme_color.h"
|
||||
#include "ui/ui_page.h"
|
||||
#include "ui/ui_main.h"
|
||||
#include "ui/ui_settings.h"
|
||||
|
||||
@@ -38,9 +38,8 @@ struct display_module_ctx {
|
||||
const struct device *backlight_dev;
|
||||
uint32_t backlight_idx;
|
||||
struct ui_main_model ui_model;
|
||||
struct settings_ui_state settings_ui;
|
||||
struct ui_settings_page *settings_page;
|
||||
bool settings_active;
|
||||
bool settings_ui_valid;
|
||||
bool lvgl_initialized;
|
||||
char date_text[DATETIME_EVENT_DATE_TEXT_LEN];
|
||||
char time_text[DATETIME_EVENT_TIME_TEXT_LEN];
|
||||
@@ -81,6 +80,11 @@ static struct display_module_ctx ctx = {
|
||||
.time_text = "00:00:00",
|
||||
};
|
||||
|
||||
static struct ui_page *main_page(void)
|
||||
{
|
||||
return ui_main_page_get(&ctx.ui_model, ctx.date_text, ctx.time_text);
|
||||
}
|
||||
|
||||
static int backlight_set(bool on)
|
||||
{
|
||||
if (on) {
|
||||
@@ -133,11 +137,16 @@ static int do_start(void)
|
||||
ctx.lvgl_initialized = true;
|
||||
|
||||
lvgl_lock();
|
||||
ui_main_init(&ctx.ui_model, ctx.date_text, ctx.time_text);
|
||||
ui_settings_init(NULL);
|
||||
ui_page_init(main_page());
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
lvgl_lock();
|
||||
if (!ctx.settings_active) {
|
||||
ui_page_init(main_page());
|
||||
}
|
||||
lvgl_unlock();
|
||||
|
||||
err = backlight_set(true);
|
||||
if (err) {
|
||||
LOG_ERR("Backlight enable failed (%d)", err);
|
||||
@@ -175,15 +184,11 @@ static void refresh_ui(void)
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.settings_active && !ctx.settings_ui_valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
lvgl_lock();
|
||||
if (ctx.settings_active) {
|
||||
ui_settings_refresh(&ctx.settings_ui, true);
|
||||
if (ctx.settings_active && (ctx.settings_page != NULL)) {
|
||||
ui_settings_show(ctx.settings_page, true);
|
||||
} else {
|
||||
ui_main_refresh_all(&ctx.ui_model, ctx.date_text, ctx.time_text);
|
||||
ui_page_refresh(main_page());
|
||||
}
|
||||
lvgl_unlock();
|
||||
}
|
||||
@@ -223,7 +228,6 @@ static bool app_event_handler(const struct app_event_header *aeh)
|
||||
ctx.ui_model.theme_color = (lv_color_t)LV_COLOR_MAKE(event->theme.r,
|
||||
event->theme.g,
|
||||
event->theme.b);
|
||||
ctx.settings_ui.accent = event->theme;
|
||||
refresh_ui();
|
||||
return false;
|
||||
}
|
||||
@@ -233,17 +237,24 @@ static bool app_event_handler(const struct app_event_header *aeh)
|
||||
cast_settings_mode_event(aeh);
|
||||
|
||||
ctx.settings_active = event->active;
|
||||
ctx.settings_ui_valid = false;
|
||||
if (!ctx.settings_active) {
|
||||
ctx.settings_page = NULL;
|
||||
}
|
||||
if (!ctx.lvgl_initialized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
lvgl_lock();
|
||||
if (!ctx.settings_active) {
|
||||
ui_settings_set_visible(false);
|
||||
ui_main_set_visible(true);
|
||||
ui_main_refresh_all(&ctx.ui_model, ctx.date_text,
|
||||
ctx.time_text);
|
||||
if (ctx.settings_active) {
|
||||
ui_page_deinit(main_page());
|
||||
ui_settings_init();
|
||||
if (ctx.settings_page != NULL) {
|
||||
ui_settings_show(ctx.settings_page, false);
|
||||
}
|
||||
} else {
|
||||
ui_settings_deinit();
|
||||
ui_page_init(main_page());
|
||||
ui_page_refresh(main_page());
|
||||
}
|
||||
lvgl_unlock();
|
||||
return false;
|
||||
@@ -253,18 +264,13 @@ static bool app_event_handler(const struct app_event_header *aeh)
|
||||
const struct settings_view_event *event =
|
||||
cast_settings_view_event(aeh);
|
||||
|
||||
ctx.settings_ui = event->state;
|
||||
ctx.settings_ui_valid = true;
|
||||
ctx.settings_page = event->page;
|
||||
if (ctx.settings_active && ctx.lvgl_initialized) {
|
||||
lvgl_lock();
|
||||
ui_settings_refresh(&ctx.settings_ui, false);
|
||||
ui_main_set_visible(false);
|
||||
ui_settings_set_visible(true);
|
||||
ui_settings_show(ctx.settings_page, event->animate);
|
||||
lvgl_unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
refresh_ui();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user