feat(ui): 重构设置界面为页面控制器架构

- 添加新的UI页面基础架构(ui_page.h),包含页面操作接口
- 创建设置页面控制器(ui_settings_controller.h/.c)来管理页面导航
- 实现具体的设置页面类型:根页面、BLE页面、主题页面
- 修改display_module.c以使用新的页面系统替代旧的状态机
- 移除过时的settings_ui.h头文件和相关状态结构
- 更新事件处理逻辑以使用页面指针而非状态数据传递
- 修改主界面实现以适配统一的页面接口标准
This commit is contained in:
2026-04-23 18:46:55 +08:00
parent fbdc5426be
commit 48968e7880
18 changed files with 828 additions and 625 deletions

View File

@@ -1,12 +1,10 @@
#ifndef BLINKY_SETTINGS_VIEW_EVENT_H_
#define BLINKY_SETTINGS_VIEW_EVENT_H_
#include <string.h>
#include <app_event_manager.h>
#include <app_event_manager_profiler_tracer.h>
#include "settings_ui.h"
#include "ui/ui_settings_page.h"
#ifdef __cplusplus
extern "C" {
@@ -14,22 +12,19 @@ extern "C" {
struct settings_view_event {
struct app_event_header header;
struct settings_ui_state state;
struct ui_settings_page *page;
bool animate;
};
APP_EVENT_TYPE_DECLARE(settings_view_event);
static inline void submit_settings_view_event(
const struct settings_ui_state *state)
static inline void submit_settings_view_event(struct ui_settings_page *page,
bool animate)
{
struct settings_view_event *event;
struct settings_view_event *event = new_settings_view_event();
if (state == NULL) {
return;
}
event = new_settings_view_event();
memcpy(&event->state, state, sizeof(event->state));
event->page = page;
event->animate = animate;
APP_EVENT_SUBMIT(event);
}

View File

@@ -1,56 +0,0 @@
#ifndef BLINKY_SETTINGS_UI_H_
#define BLINKY_SETTINGS_UI_H_
#include <stdbool.h>
#include <stdint.h>
#include "theme_color.h"
#ifdef __cplusplus
extern "C" {
#endif
#define SETTINGS_UI_ROOT_ITEM_COUNT 2U
#define SETTINGS_UI_BLE_SLOT_COUNT 3U
#define SETTINGS_UI_BLE_ITEM_COUNT 4U
#define SETTINGS_UI_THEME_OPTION_COUNT 6U
#define SETTINGS_UI_TITLE_MAX 20U
#define SETTINGS_UI_VALUE_MAX 24U
#define SETTINGS_UI_THEME_NAME_MAX 16U
enum settings_ui_page {
SETTINGS_UI_PAGE_ROOT = 0,
SETTINGS_UI_PAGE_BLE,
SETTINGS_UI_PAGE_THEME,
};
struct settings_ui_list_item {
char title[SETTINGS_UI_TITLE_MAX];
char value[SETTINGS_UI_VALUE_MAX];
};
struct settings_ui_theme_option {
char name[SETTINGS_UI_THEME_NAME_MAX];
struct theme_rgb color;
};
struct settings_ui_state {
bool active;
enum settings_ui_page page;
uint8_t root_selected;
uint8_t ble_selected;
uint8_t theme_selected;
uint8_t active_ble_slot;
struct theme_rgb accent;
struct settings_ui_list_item root_items[SETTINGS_UI_ROOT_ITEM_COUNT];
struct settings_ui_list_item ble_items[SETTINGS_UI_BLE_ITEM_COUNT];
struct settings_ui_theme_option
theme_options[SETTINGS_UI_THEME_OPTION_COUNT];
uint8_t theme_option_count;
};
#ifdef __cplusplus
}
#endif
#endif /* BLINKY_SETTINGS_UI_H_ */

66
inc/ui/ui_page.h Normal file
View File

@@ -0,0 +1,66 @@
#ifndef BLINKY_UI_PAGE_H_
#define BLINKY_UI_PAGE_H_
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
struct ui_page;
struct ui_page_ops {
void (*init)(struct ui_page *page);
void (*deinit)(struct ui_page *page);
void (*refresh)(struct ui_page *page);
};
struct ui_page {
const struct ui_page_ops *ops;
struct ui_page *parent;
bool initialized;
};
static inline void ui_page_init(struct ui_page *page)
{
if ((page == NULL) || (page->ops == NULL)) {
return;
}
if (page->initialized) {
return;
}
if (page->ops->init != NULL) {
page->ops->init(page);
}
page->initialized = true;
}
static inline void ui_page_deinit(struct ui_page *page)
{
if ((page == NULL) || !page->initialized || (page->ops == NULL)) {
return;
}
if (page->ops->deinit != NULL) {
page->ops->deinit(page);
}
page->initialized = false;
}
static inline void ui_page_refresh(struct ui_page *page)
{
if ((page == NULL) || !page->initialized ||
(page->ops == NULL) || (page->ops->refresh == NULL)) {
return;
}
page->ops->refresh(page);
}
#ifdef __cplusplus
}
#endif
#endif /* BLINKY_UI_PAGE_H_ */

View File

@@ -0,0 +1,38 @@
#ifndef BLINKY_UI_SETTINGS_CONTROLLER_H_
#define BLINKY_UI_SETTINGS_CONTROLLER_H_
#include <stdbool.h>
#include <stdint.h>
#include "theme_color.h"
#include "ui_page.h"
#include "ui_settings_page.h"
#ifdef __cplusplus
extern "C" {
#endif
void ui_settings_controller_open(void);
void ui_settings_controller_close(void);
bool ui_settings_controller_back(void);
void ui_settings_controller_select(void);
void ui_settings_controller_move(int8_t delta);
void ui_settings_controller_refresh(bool animate);
bool ui_settings_controller_is_active(void);
void ui_settings_controller_switch_to(struct ui_settings_page *page,
struct ui_page *parent);
const char *ui_settings_ble_current_label(void);
const char *ui_settings_ble_slot_label(uint8_t slot);
void ui_settings_ble_select_slot(uint8_t slot);
void ui_settings_ble_erase_current(void);
void ui_settings_theme_set_current(struct theme_rgb theme);
const char *ui_settings_theme_current_name(void);
uint8_t ui_settings_theme_current_index(void);
#ifdef __cplusplus
}
#endif
#endif /* BLINKY_UI_SETTINGS_CONTROLLER_H_ */

56
inc/ui/ui_settings_page.h Normal file
View File

@@ -0,0 +1,56 @@
#ifndef BLINKY_UI_SETTINGS_PAGE_H_
#define BLINKY_UI_SETTINGS_PAGE_H_
#include <stdint.h>
#include <lvgl.h>
#include "ui_page.h"
#ifdef __cplusplus
extern "C" {
#endif
struct ui_settings_page;
struct ui_settings_item;
typedef void (*ui_settings_item_draw_fn)(const struct ui_settings_item *item,
lv_obj_t *container);
struct ui_settings_item {
const char *icon;
const char *title;
const char *value;
ui_settings_item_draw_fn draw;
void *user_data;
};
struct ui_settings_page_ops {
struct ui_page_ops base;
uint8_t (*get_count)(struct ui_settings_page *page);
void (*get_item)(struct ui_settings_page *page, uint8_t index,
struct ui_settings_item *item);
void (*on_enter)(struct ui_settings_page *page);
void (*on_select)(struct ui_settings_page *page, uint8_t index);
void (*on_back)(struct ui_settings_page *page);
};
struct ui_settings_page {
struct ui_page base;
const struct ui_settings_page_ops *ops;
const char *title;
const char *hint;
uint8_t selected;
};
static inline struct ui_settings_page *ui_page_to_settings(struct ui_page *page)
{
return (struct ui_settings_page *)page;
}
#ifdef __cplusplus
}
#endif
#endif /* BLINKY_UI_SETTINGS_PAGE_H_ */