merge: task/UI-widgets 合入 v2-on-ui

任务 UI(1 个提交)经 task-worktree 回收:
- feat(UI组件): 新增数值编辑器/定值表/动作确认页三组件(道B task-5)
This commit is contained in:
2026-10-25 04:36:52 +08:00
8 changed files with 1356 additions and 0 deletions
+199
View File
@@ -0,0 +1,199 @@
/*
* 模块名称:UI 动作确认页(操作页共享实现)实现
* 模块功能:见 ui_page_action.h 头注释(确认链状态机 + 投递回报 + 表单页自绘)
* 适用平台:STM32F407ZGTx / PC 模拟器(两端共用)
* 作者:王建锋
* 创建日期:2026-10-25
* 修改记录:
* v1.0 2026-10-25 王建锋 创建(道B task-5 三组件之一)
*/
/* 头文件包含区 */
#include <string.h>
#include "ui_page_action.h"
#include "ui_content_page.h"
#include "ui_tokens.h"
/* 私有宏定义区 */
#define AC_PROMPT_Y 44 /* 问句/结果行 放置 y(内容区上三分之一) */
#define AC_STAGE_Y 66 /* 态标行("二次确认" / "ERR")放置 y */
#define AC_HINT_Y 110 /* 键提示行 放置 y */
/* 固定文案(用字均已入字体子集:二/次/确/认/取/消/返/回/越/界 及 ASCII) */
#define AC_STAGE2_TXT "二次确认"
#define AC_HINT_DO "ENTER=确认 ESC=取消"
#define AC_HINT_BACK "ENTER=返回"
#define AC_ERR_TXT "ERR"
/* 私有变量定义区 */
/*
* 模块单例:内容页框架全局单页(s_open 互斥),同一时刻至多一张操作页,
* 故钩子经"当前实例指针"取上下文即可成立(头注已载此约束;批 2 各跳板
* 各自 static 实例、先后开页互不冲突)
*/
static ui_page_action_t *s_act; /* 当前实例(NULL = 未在用) */
static content_page_def_t s_desc; /* 模板描述符(开页时按实例填充) */
/* 私有函数声明区 */
static void ac_draw_centered(lv_layer_t *a_layer, const char *a_text,
int32_t a_y, const lv_area_t *a_clip);
/* 函数定义区 */
/*
* 函数功能:居中绘制单行文本(框架 cp_draw_centered_text 同法,本文件私有一致拷贝)
* 入口参数:layer - 绘制层 lv_layer_t *
* text - 文本(Flash 字面量) const char *
* y - 放置 y int32_t
* clip - 重绘区 const lv_area_t *
* 返回值:无
* 限定条件:text 非空;条带(整宽 x0..159,高 UI_TEXT_BAND_H)与 clip 相交才绘制
*/
static void ac_draw_centered(lv_layer_t *a_layer, const char *a_text,
int32_t a_y, const lv_area_t *a_clip) {
lv_area_t t;
lv_draw_label_dsc_t ld;
/* 本 LVGL 版 lv_text_get_width:必须传 strlen(0 = 不测量返回 0,
* 传 -1 越串尾死循环——框架同款注释警示) */
t.x1 = 0;
t.x2 = UI_SCREEN_W - 1;
t.y1 = a_y;
t.y2 = a_y + UI_TEXT_BAND_H;
if (!((t.x1 <= a_clip->x2) && (a_clip->x1 <= t.x2) &&
(t.y1 <= a_clip->y2) && (a_clip->y1 <= t.y2))) {
return; /* 不相交(culling) */
}
lv_draw_label_dsc_init(&ld);
ld.base.layer = a_layer;
ld.text = a_text;
ld.text_static = 1u; /* Flash 字面量:不拷内存 */
ld.color = UI_COL_FG;
ld.ofs_x = (UI_SCREEN_W -
(int32_t)lv_text_get_width(a_text, (uint32_t)strlen(a_text), LV_FONT_DEFAULT, 0)) / 2;
ld.ofs_y = 0;
lv_draw_label(a_layer, &ld, &t);
}
/*
* 函数功能:自绘(框架内置区块之后:问句/态标/键提示 三行居中)
* 入口参数:layer - 绘制层 lv_layer_t *
* clip - 重绘区 const lv_area_t *
* 返回值:无
* 限定条件:经描述符 draw_cb 挂接,页面打开中(s_act 有效)
*/
static void ac_draw_cb(lv_layer_t *layer, const lv_area_t *clip) {
if ((s_act == NULL) || (s_act->prompt == NULL)) {
return;
}
/* 行 1:问句(stage 2 换成功结果行) */
if (s_act->stage == 2u) {
if (s_act->done_text != NULL) {
ac_draw_centered(layer, s_act->done_text, AC_PROMPT_Y, clip);
}
}
else {
ac_draw_centered(layer, s_act->prompt, AC_PROMPT_Y, clip);
}
/* 行 2:态标(二次确认 / 投递失败 ERR) */
if (s_act->stage == 1u) {
ac_draw_centered(layer, (s_act->err != 0u) ? AC_ERR_TXT : AC_STAGE2_TXT,
AC_STAGE_Y, clip);
}
/* 行 3:键提示 */
ac_draw_centered(layer, (s_act->stage == 2u) ? AC_HINT_BACK : AC_HINT_DO,
AC_HINT_Y, clip);
}
/*
* 函数功能:按键处理(确认链状态机)
* 入口参数:key - LVGL 键值 lv_key_t
* 返回值:true = 已消费;false = 交回框架(其余键忽略)
* 限定条件:经描述符 key_cb 挂接(key_intercept=0:LEFT 直接关页 = 取消,
* 不进本函数;ESC 恒关页框架保证,同样不进本函数)
* 函数说明:ENTER:stage0 -> stage1(二次确认);stage1 -> 投递 ok_cb:
* 接受且有 done_text -> stage2 回报,接受且无 done_text -> 直接关页,
* 拒收 -> err=1 留在 stage1;stage2 -> 关页返回
*/
static bool ac_key_cb(lv_key_t key) {
if (key != LV_KEY_ENTER) {
return false;
}
if (s_act == NULL) {
return false; /* 防御 */
}
if (s_act->stage == 0u) {
s_act->stage = 1u;
s_act->err = 0u;
ui_content_page_invalidate();
return true;
}
if (s_act->stage == 1u) {
bool ok = false;
if (s_act->ok_cb != NULL) {
ok = s_act->ok_cb(); /* 只投递请求,不等待执行结果 */
}
if (!ok) {
s_act->err = 1u;
ui_content_page_invalidate();
return true; /* ERR 显示,再 ENTER 重试 */
}
if (s_act->done_text == NULL) {
ui_content_page_close(); /* 成功即关页回菜单(无回报行形态) */
return true;
}
s_act->stage = 2u;
s_act->err = 0u;
ui_content_page_invalidate();
return true;
}
/* stage 2:已回报,ENTER 返回 */
ui_content_page_close();
return true;
}
/*
* 函数功能:开操作页(装载实例 + 复位 + 框架开页)
*/
bsp_err_t ui_page_action_open(ui_page_action_t *a_inst, uint8_t a_perm) {
if ((a_inst == NULL) || (a_inst->ok_cb == NULL) || (a_inst->prompt == NULL)) {
return BSP_ERR_PARAM;
}
if (ui_content_page_is_open() != false) {
return BSP_ERR_STATE; /* 框架单页互斥的显式化(失败原因对跳板可判) */
}
s_act = a_inst;
s_act->stage = 0u; /* 每次进入固定从一次确认开始 */
s_act->err = 0u;
(void)memset(&s_desc, 0, sizeof(s_desc));
s_desc.id = "action";
s_desc.title = (a_inst->title != NULL) ? a_inst->title : a_inst->prompt;
s_desc.hide_deco = 1u; /* 表单/操作页形态:无浅 V(用户密钥页先例) */
s_desc.hide_footer = 1u; /* 无页脚页码 */
s_desc.selectable = 0u; /* 无行列表 */
s_desc.key_intercept = 0u; /* LEFT 不拦截:关页 = 取消 */
s_desc.draw_cb = ac_draw_cb;
s_desc.key_cb = ac_key_cb;
if (ui_content_page_open(&s_desc, a_perm) == false) {
s_act = NULL; /* 开页失败不残留实例(钩子不会再被调) */
return BSP_ERR_NO_SPACE;
}
return BSP_OK;
}
+71
View File
@@ -0,0 +1,71 @@
/*
* 模块名称:UI 动作确认页(操作页共享实现,ui_page_action)
* 模块功能:可复用的"确认 -> 二次确认 -> 执行回报"操作页构建器——
* 强制复归 / 清除记录 / 手动录波等叶子共用同一页实现,
* 各自以一份实例(标题/问句/结果行/执行回调)开页;
* 执行回调只投递请求不阻塞(跨任务交接由页面跳板实现),
* 成功经 done_text 回报后再 ENTER 返回,done_text=NULL 成功即关页;
* 投递失败显示 ERR,下一次 ENTER 重新走二次确认
* 适用范围:Drivers/BSP/UI(表单页形态:无浅 V 装饰、无页脚——用户密钥页
* 跟随实机先例;ESC 恒关页 = 取消,LEFT 亦关页 = 取消)
* 说明:同一时刻仅一张操作页在用(内容页框架本就全局单页),模块以
* static 单例描述符 + 当前实例指针承载钩子上下文;页面跳板
* (批 2 各 ui_page_xxx)持 ui_page_action_t 实例并在自己的入口
* 调 ui_page_action_open()
* 作者:王建锋
* 创建日期:2026-10-25
* 修改记录:
* v1.0 2026-10-25 王建锋 创建(道B task-5 三组件之一;规格 =
* 页面扩充详细方案.md §3.4 装置维护操作页 +
* §4.2 ui_page_action bind(title, prompt, ok_cb)
* 二次确认、ok_cb 只投递不阻塞)
*/
#ifndef UI_PAGE_ACTION_H
#define UI_PAGE_ACTION_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#include "bsp_err.h" /* bsp_err_t(开页结果错误通道——BSP 公开 API 约定) */
/* 执行回调:只投递请求(事件位/消息队列),立即返回;
* 返回值:true = 投递被接受(页面转成功回报),false = 拒收(页面显示 ERR) */
typedef bool (*ui_page_action_ok_fn)(void);
/* 操作页实例(配置字段 Flash 指针 + 运行态);
* 用法:页面跳板 static 一份、花括号初始化配置,开页经 ui_page_action_open */
typedef struct {
const char *title; /* Flash:页标题(框架头部居中) */
const char *prompt; /* Flash:确认问句(如"确认复归所有保护?"——
问句用字须已入字体子集) */
const char *done_text; /* Flash:成功后结果行(如"已请求复归");
NULL = 成功后直接关页回菜单 */
ui_page_action_ok_fn ok_cb; /* 必填:执行投递 */
uint8_t stage; /* 运行态:0 一次确认 / 1 二次确认 / 2 完成回报 */
uint8_t err; /* 运行态:1 = 上轮投递被拒(显示 ERR) */
} ui_page_action_t;
/*
* 函数功能:开操作页(装载实例 + 复位确认态 + 经内容页框架开页)
* 入口参数:inst - 操作页实例(配置字段须已填好;ok_cb 不得为 NULL)
* ui_page_action_t *
* perm - 授予权限(ui_perm_t;由跳板决定传什么权限,
* 组件不拦权限只拦 ok_cb 为空)
* 返回值:BSP_OK = 已开页;BSP_ERR_PARAM = 参数无效;
* BSP_ERR_STATE = 已有页面打开(框架单页互斥);
* BSP_ERR_NO_SPACE = 框架开页失败(池不足等) bsp_err_t
* 限定条件:uiTask 上下文;每次进入从一次确认开始(不跨次保留 stage)
* 函数说明:键语义——ENTER 推进确认链(0->1->执行->2),ESC/LEFT 关页取消;
* stage=2 时 ENTER 关页返回
*/
bsp_err_t ui_page_action_open(ui_page_action_t *a_inst, uint8_t a_perm);
#ifdef __cplusplus
}
#endif
#endif /* UI_PAGE_ACTION_H */
+398
View File
@@ -0,0 +1,398 @@
/*
* 模块名称:UI 数值编辑共享组件(ui_w_editor)实现
* 模块功能:见 ui_w_editor.h 头注释(逐位步进编辑 + 范围校验 + 光标反显绘制)
* 适用平台:STM32F407ZGTx / PC 模拟器(两端共用)
* 作者:王建锋
* 创建日期:2026-10-25
* 修改记录:
* v1.0 2026-10-25 王建锋 创建(道B task-5 三组件之一;编辑交互对齐
* ui_page_net_cfg 的"反显光标 + 键全消费"模式,
* 差异:字节 -> 十进制数字位、0..255 环绕 -> 0..9
* 环绕、新增 min/max 提交把关)
*/
/* 头文件包含区 */
#include <string.h>
#include "ui_w_editor.h"
#include "ui_tokens.h"
/* 私有宏定义区 */
#define ED_MAX_DECIMALS 3u /* 定点小数位上限(decimals 有效域) */
#define ED_HINT_GAP 4 /* "越界"提示与值串末尾的水平间隙(px) */
#define ED_SAFE_POWER 7u /* 参与步进的数字位最大权值指数(10^7;再高
环绕步进可致 int32 溢出,该位锁定不动——
工程定值值串最长 6 位,正常编辑不触发) */
/* 函数定义区 */
/*
* 函数功能:10^n 幂(n <= ED_SAFE_POWER+1,调用侧已限定;用循环不用查表越界)
* 入口参数:n - 指数 uint8_t
* 返回值:10^n(n 超界时饱和返回最大值) uint32_t
* 限定条件:无
*/
static uint32_t ed_pow10(uint8_t a_n) {
uint32_t p = 1u;
uint8_t i;
for (i = 0u; (i < a_n) && (i < 9u); i++) {
p *= 10u;
}
return p;
}
/*
* 函数功能:工作值 -> 显示串("500" / "10.24" / "0.001")
* 入口参数:inst - 编辑器实例 const ui_w_editor_t *
* buf - 输出缓冲 char *
* len - 缓冲长度 uint32_t
* 返回值:无
* 限定条件:buf 非空;值非负(min >= 0 使用前提);decimals <= ED_MAX_DECIMALS
* 函数说明:不用 %*d 变宽(MicroLIB 支持性存疑),小数位 0..3 逐档定式;
* lv_snprintf 而非 snprintf(工程口径,且避开 MSVC C4819 格式串扫描)
*/
void ui_w_editor_fmt_scaled(int32_t a_value, uint8_t a_decimals, char *a_buf, uint32_t a_len) {
uint32_t scale = ed_pow10(a_decimals);
int32_t whole = a_value / (int32_t)scale;
int32_t frac = a_value % (int32_t)scale;
switch (a_decimals) {
case 1u:
(void)lv_snprintf(a_buf, a_len, "%d.%d", (int)whole, (int)frac);
break;
case 2u:
(void)lv_snprintf(a_buf, a_len, "%d.%02d", (int)whole, (int)frac);
break;
case 3u:
(void)lv_snprintf(a_buf, a_len, "%d.%03d", (int)whole, (int)frac);
break;
default:
(void)lv_snprintf(a_buf, a_len, "%d", (int)whole);
break;
}
}
/*
* 函数功能:工作值 -> 显示串(实例壳:转调 ui_w_editor_fmt_scaled)
*/
static void ed_format(const ui_w_editor_t *a_inst, char *a_buf, uint32_t a_len) {
ui_w_editor_fmt_scaled(a_inst->cur, a_inst->decimals, a_buf, a_len);
}
/*
* 函数功能:扫描值串,定位第 inst->digit 个数字字符并给出该位的定点权值
* 入口参数:inst - 编辑器实例(digit/decimals 有效) const ui_w_editor_t *
* buf - 值串(与 inst->cur 同步,ed_format 产物) const char *
* step_out - 输出:该位 +1 对 cur 的增量(= 10^权值指数) uint32_t *
* 返回值:该数字字符在串中的下标(无数字时 0) uint32_t
* 限定条件:inst->digit < inst->ndigits(调用方经 begin/recount 保证)
* 函数说明:权值指数 = 该位右侧的小数位数 + 更低的整数位数:
* 整数位:dec + (整数位数 - 1 - 位序);小数位:dec - 1 - 小数位序。
* 例 dec=2 值串 "12.34":'1'->1000 '2'->100 '3'->10 '4'->1
*/
static uint32_t ed_digit_info(const ui_w_editor_t *a_inst, const char *a_buf,
uint32_t *a_step_out) {
uint32_t total = (uint32_t)strlen(a_buf);
uint32_t dot = total; /* 小数点下标(total = 无小数点) */
uint32_t i;
uint32_t seen = 0u; /* 已扫过的数字字符数(= 当前数字的位序) */
uint32_t int_pos = 0u; /* 整数位内位序 */
uint32_t frac_pos = 0u; /* 小数位内位序 */
if (a_step_out != NULL) {
*a_step_out = 1u;
}
for (i = 0u; i < total; i++) {
if (a_buf[i] == '.') {
dot = i;
break;
}
}
for (i = 0u; i < total; i++) {
char c = a_buf[i];
if ((c < '0') || (c > '9')) {
continue;
}
if (seen == (uint32_t)a_inst->digit) {
uint32_t power;
if (i < dot) {
uint32_t n_int = 0u; /* 整数位数字个数(求该位权值用) */
uint32_t j;
for (j = 0u; j < dot; j++) {
if ((a_buf[j] >= '0') && (a_buf[j] <= '9')) {
n_int++;
}
}
power = (uint32_t)a_inst->decimals + (n_int - 1u) - int_pos;
}
else {
power = ((uint32_t)a_inst->decimals - 1u) - frac_pos;
}
if (a_step_out != NULL) {
*a_step_out = (power > ED_SAFE_POWER) ? 0u : ed_pow10((uint8_t)power);
}
return i;
}
if (i < dot) {
int_pos++;
}
else {
frac_pos++;
}
seen++;
}
return 0u;
}
/*
* 函数功能:重算 ndigits 并把数字光标夹回有效域(值位数随步进变化时防指空)
* 入口参数:inst - 编辑器实例 ui_w_editor_t *
* 返回值:无
* 限定条件:inst->cur 已更新
*/
static void ed_recount(ui_w_editor_t *a_inst) {
char buf[UI_BUF_STRLEN];
uint32_t i;
uint8_t n = 0u;
ed_format(a_inst, buf, sizeof(buf));
for (i = 0u; i < (uint32_t)strlen(buf); i++) {
if ((buf[i] >= '0') && (buf[i] <= '9')) {
n++;
}
}
a_inst->ndigits = n;
if (a_inst->digit >= n) {
a_inst->digit = (n > 0u) ? (uint8_t)(n - 1u) : 0u;
}
}
/*
* 函数功能:复位实例(清除编辑态与提示)
*/
void ui_w_editor_reset(ui_w_editor_t *a_inst) {
a_inst->editing = 0u;
a_inst->bad = 0u;
a_inst->digit = 0u;
a_inst->ndigits = 0u;
}
/*
* 函数功能:进入编辑(载入初始值与范围,光标落在个位)
*/
void ui_w_editor_begin(ui_w_editor_t *a_inst, int32_t a_value,
int32_t a_min_v, int32_t a_max_v, uint8_t a_decimals) {
char buf[UI_BUF_STRLEN];
uint32_t i;
uint8_t int_digits = 0u;
ui_w_editor_reset(a_inst);
a_inst->cur = (a_value < 0) ? 0 : a_value; /* 非负前提(防御钳 0) */
a_inst->min = (a_min_v < 0) ? 0 : a_min_v;
a_inst->max = (a_max_v < a_inst->min) ? a_inst->min : a_max_v;
a_inst->decimals = (a_decimals > ED_MAX_DECIMALS) ? (uint8_t)ED_MAX_DECIMALS : a_decimals;
if (a_inst->cur > a_inst->max) {
a_inst->cur = a_inst->max; /* 起点必须合法:个位光标才落在实位上 */
}
if (a_inst->cur < a_inst->min) {
a_inst->cur = a_inst->min;
}
/* 光标落个位 = 第 (整数位数 - 1) 个数字字符 */
ed_format(a_inst, buf, sizeof(buf));
for (i = 0u; i < (uint32_t)strlen(buf); i++) {
if (buf[i] == '.') {
break;
}
if ((buf[i] >= '0') && (buf[i] <= '9')) {
int_digits++;
}
}
a_inst->digit = (int_digits > 0u) ? (uint8_t)(int_digits - 1u) : 0u;
ed_recount(a_inst);
a_inst->editing = 1u;
}
/*
* 函数功能:查询是否处于编辑态
*/
bool ui_w_editor_is_editing(const ui_w_editor_t *a_inst) {
return (a_inst != NULL) && (a_inst->editing != 0u);
}
/*
* 函数功能:编辑态按键处理
*/
uint8_t ui_w_editor_key(ui_w_editor_t *a_inst, lv_key_t a_key) {
if ((a_inst == NULL) || (a_inst->editing == 0u)) {
return 0u;
}
a_inst->bad = 0u; /* 任意编辑键先清"越界"提示 */
switch (a_key) {
case LV_KEY_UP:
case LV_KEY_DOWN: {
char buf[UI_BUF_STRLEN];
uint32_t step;
int32_t dcur;
int32_t dnew;
ed_format(a_inst, buf, sizeof(buf));
(void)ed_digit_info(a_inst, buf, &step);
if (step == 0u) {
return 1u; /* 超安全权值位(ED_SAFE_POWER 之上):锁定该位 */
}
dcur = (a_inst->cur / (int32_t)step) % 10;
if (dcur < 0) {
dcur += 10; /* 非负前提下不触发;双保险 */
}
dnew = (a_key == LV_KEY_UP) ? ((dcur + 1) % 10) : ((dcur + 9) % 10);
a_inst->cur += (dnew - dcur) * (int32_t)step;
if (a_inst->cur < 0) {
a_inst->cur = 0; /* 双保险(0 减 1 走 dnew=9 环绕,本不应为负) */
}
ed_recount(a_inst);
return 1u;
}
case LV_KEY_LEFT:
if (a_inst->ndigits > 0u) {
a_inst->digit = (uint8_t)((a_inst->digit + a_inst->ndigits - 1u) % a_inst->ndigits);
}
return 1u;
case LV_KEY_RIGHT:
if (a_inst->ndigits > 0u) {
a_inst->digit = (uint8_t)((a_inst->digit + 1u) % a_inst->ndigits);
}
return 1u;
case LV_KEY_ENTER:
if ((a_inst->cur < a_inst->min) || (a_inst->cur > a_inst->max)) {
a_inst->bad = 1u; /* 越界:拒绝提交,留在编辑态显示"越界" */
return 1u;
}
a_inst->editing = 0u; /* 提交:调用方经 ui_w_editor_value 取回写 RAM 副本 */
return 1u;
default:
return 0u; /* ESC 到不了这里(框架恒拦截关页 = 取消编辑) */
}
}
/*
* 函数功能:取工作值
*/
int32_t ui_w_editor_value(const ui_w_editor_t *a_inst) {
return (a_inst != NULL) ? a_inst->cur : 0;
}
/*
* 函数功能:把工作值格式化为显示串(对外壳,供 refresh 值列复用)
*/
void ui_w_editor_format(const ui_w_editor_t *a_inst, char *a_buf, uint32_t a_len) {
if ((a_inst != NULL) && (a_buf != NULL) && (a_len > 0u)) {
ed_format(a_inst, a_buf, a_len);
}
}
/*
* 函数功能:判断两区域相交(与本目录各绘制文件同实现:static 局部、不跨文件共享)
* 入口参数:a - 区域 1 const lv_area_t *
* b - 区域 2 const lv_area_t *
* 返回值:true = 相交 bool
* 限定条件:无
*/
static bool ed_areas_intersect(const lv_area_t *a, const lv_area_t *b) {
int32_t x1 = (a->x1 > b->x1) ? a->x1 : b->x1;
int32_t y1 = (a->y1 > b->y1) ? a->y1 : b->y1;
int32_t x2 = (a->x2 < b->x2) ? a->x2 : b->x2;
int32_t y2 = (a->y2 < b->y2) ? a->y2 : b->y2;
return (x1 <= x2 && y1 <= y2);
}
/*
* 函数功能:编辑态自绘(数字光标反显盒 + "越界"提示)
*/
void ui_w_editor_draw(ui_w_editor_t *a_inst, lv_layer_t *a_layer,
const lv_area_t *a_clip, int32_t a_row_top,
int32_t a_text_dy, int32_t a_band_h, int32_t a_value_x) {
char buf[UI_BUF_STRLEN];
uint32_t step;
uint32_t cidx;
int32_t x0;
int32_t w;
lv_area_t box;
if ((a_inst == NULL) || (a_inst->editing == 0u) || (a_inst->ndigits == 0u)) {
return;
}
ed_format(a_inst, buf, sizeof(buf));
cidx = ed_digit_info(a_inst, buf, &step);
/* 光标反显盒:框住第 digit 个数字字符(左右各外扩 1px,net_cfg 同法) */
x0 = a_value_x + (int32_t)lv_text_get_width(buf, cidx, LV_FONT_DEFAULT, 0);
w = (int32_t)lv_text_get_width(buf + cidx, 1u, LV_FONT_DEFAULT, 0);
box.x1 = x0 - 1;
box.x2 = x0 + w;
box.y1 = a_row_top;
box.y2 = a_row_top + a_band_h - 1;
if (ed_areas_intersect(&box, a_clip)) {
lv_draw_rect_dsc_t fd;
lv_draw_label_dsc_t ld;
char seg[2];
lv_draw_rect_dsc_init(&fd);
fd.base.layer = a_layer;
fd.bg_color = UI_COL_SEL_BG;
fd.bg_opa = LV_OPA_COVER;
lv_draw_rect(a_layer, &fd, &box);
/* 只画光标单字符(整串会按盒宽折行溢出邻行——net_cfg 实测坑);
* 编辑行恒为选中行(白带),反显字色取黑 UI_COL_SEL_FG */
seg[0] = buf[cidx];
seg[1] = '\0';
lv_draw_label_dsc_init(&ld);
ld.base.layer = a_layer;
ld.text = seg;
ld.text_static = 0u; /* 栈缓冲(同帧有效) */
ld.color = UI_COL_SEL_FG;
ld.ofs_x = 1; /* box.x1 = x0-1,+1 回 x0(与框架行文本原点一致) */
ld.ofs_y = a_text_dy;
lv_draw_label(a_layer, &ld, &box);
}
/* "越界"提示:值串右侧(编辑行 = 选中白带行 -> 黑字可见) */
if (a_inst->bad != 0u) {
lv_area_t hb;
lv_draw_label_dsc_t ld;
hb.x1 = a_value_x +
(int32_t)lv_text_get_width(buf, (uint32_t)strlen(buf), LV_FONT_DEFAULT, 0) +
ED_HINT_GAP;
hb.x2 = UI_SCREEN_W - 1;
hb.y1 = a_row_top;
hb.y2 = a_row_top + a_band_h - 1;
if (ed_areas_intersect(&hb, a_clip)) {
lv_draw_label_dsc_init(&ld);
ld.base.layer = a_layer;
ld.text = "越界";
ld.text_static = 1u;
ld.color = UI_COL_SEL_FG; /* 白带内黑字(1bpp:black = 亮墨底反) */
ld.ofs_x = 0;
ld.ofs_y = a_text_dy;
lv_draw_label(a_layer, &ld, &hb);
}
}
}
+151
View File
@@ -0,0 +1,151 @@
/*
* 模块名称:UI 数值编辑共享组件(ui_w_editor)
* 模块功能:把"定点整数值(单位 = 10^decimals)的逐位编辑"收成一份可复用实现——
* 进/退编辑、按光标位 ±1 步进(上加下减)、左右移数字光标(首末环绕)、
* ENTER 提交(范围校验:越界拒绝并显示"越界"提示、留在编辑态);
* ESC 不处理(内容页框架恒拦截关页,未提交调整随之丢弃 = 取消);
* 编辑光标反显绘制与 ui_page_net_cfg 的字节光标同一画法;
* 只持渲染与输入抽象,不碰任何数据源——工作值经 ui_w_editor_value()
* 交回调用方(ui_w_setlist)统一写 RAM 副本
* 适用范围:Drivers/BSP/UI(列表页骨架几何由调用方传入,组件不自带)
* 说明:实例化使用(一个实例同一时刻只编一个值),调用方持有 ui_w_editor_t
* 实例——多个整定页各自独立实例,不跨页串态(同 ui_w_records 的
* 按实例存态教训);值一律非负(min >= 0 为使用前提,本工程定值全非负)
* 作者:王建锋
* 创建日期:2026-10-25
* 修改记录:
* v1.0 2026-10-25 王建锋 创建(并行分道方案 §5.2 道B task-5:定值整定的
* 数值编辑前置能力,规格 = 页面扩充详细方案.md §3.2.7
* 编辑交互表 + 页面补齐规划.md §3.2 能力表)
*/
#ifndef UI_W_EDITOR_H
#define UI_W_EDITOR_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#include "lvgl.h"
/* 数值编辑器实例(值用定点整数表达:单位 = 10^decimals,
* 如 10.24 A / decimals=2 -> 1024)
* 用法:调用方(页面 / ui_w_setlist)持有实例,进编辑前 begin() 载值与范围,
* 其余字段清零 = 非编辑态 */
typedef struct {
int32_t min; /* 下限(含;单位 10^decimals) */
int32_t max; /* 上限(含) */
int32_t cur; /* 工作值(编辑中实时变;未提交不回写数据源) */
uint8_t decimals; /* 小数位数 0..3 */
uint8_t editing; /* 1 = 编辑中 */
uint8_t bad; /* 1 = 上次 ENTER 越界被拒("越界"提示亮,下一次编辑键清除) */
uint8_t digit; /* 数字光标:第几个十进制数字字符(0 = 最高位) */
uint8_t ndigits; /* 当前值串的数字字符数(begin/步进时重算) */
} ui_w_editor_t;
/*
* 函数功能:进入编辑(载入初始值与范围,光标落在个位)
* 入口参数:inst - 编辑器实例 ui_w_editor_t *
* value - 初始值(单位 10^decimals) int32_t
* min_v - 下限(含;>= 0) int32_t
* max_v - 上限(含) int32_t
* decimals - 小数位数 0..3 uint8_t
* 返回值:无
* 限定条件:非编辑态调用;编辑中重复调用 = 先复位再进新值的编辑
*/
void ui_w_editor_begin(ui_w_editor_t *a_inst, int32_t a_value,
int32_t a_min_v, int32_t a_max_v, uint8_t a_decimals);
/*
* 函数功能:复位实例(清除编辑态与提示;页面 init_cb 开页时调用)
* 入口参数:inst - 编辑器实例 ui_w_editor_t *
* 返回值:无
* 限定条件:无
*/
void ui_w_editor_reset(ui_w_editor_t *a_inst);
/*
* 函数功能:查询是否处于编辑态
* 入口参数:inst - 编辑器实例 const ui_w_editor_t *
* 返回值:true = 编辑中 bool
* 限定条件:inst 非空(空按非编辑态处理)
*/
bool ui_w_editor_is_editing(const ui_w_editor_t *a_inst);
/*
* 函数功能:编辑态按键处理
* 入口参数:inst - 编辑器实例 ui_w_editor_t *
* key - LVGL 键值 lv_key_t
* 返回值:1 = 已消费(上下步进 / 左右移光标 / ENTER 提交或拒绝);
* 0 = 未消费(非编辑态调用,或方向键与 ENTER 之外的键)
* (键分发标志非错误通道,取 uint8_t 不用 bool——BSP 公开
* API 约定,见 bsp-err/err-type)
* 限定条件:非编辑态调用本函数恒返回 false(编辑态把守由调用方负责)
* 函数说明:1. 上下:当前光标位数字 +1/-1(0 与 9 环绕、无进位——越界由 ENTER 把关)
* 2. 左右:数字光标首末环绕
* 3. ENTER:范围校验通过 -> 退出编辑(提交值经 ui_w_editor_value 取回,
* 写回 RAM 副本由调用方负责);越界 -> 拒绝退出、置"越界"提示,
* 下一次任意编辑键先清提示
* 4. ESC 不到达本函数(内容页框架恒拦截关页 = 取消本次编辑,
* 工作值随 begin 丢弃,不落任何数据源)
*/
uint8_t ui_w_editor_key(ui_w_editor_t *a_inst, lv_key_t a_key);
/*
* 函数功能:取工作值
* 入口参数:inst - 编辑器实例 const ui_w_editor_t *
* 返回值:当前工作值(单位 10^decimals;inst 为空返回 0——直返数值形态,
* 无错误通道) int32_t
* 限定条件:编辑中与提交后均可取(提交判定 = 调用方观察 is_editing 变 false)
*/
int32_t ui_w_editor_value(const ui_w_editor_t *a_inst);
/*
* 函数功能:把当前工作值格式化为显示串("10.24" / "500")
* 入口参数:inst - 编辑器实例 const ui_w_editor_t *
* buf - 输出缓冲(建议 >= UI_BUF_STRLEN) char *
* len - 缓冲长度(含 NUL) uint32_t
* 返回值:无
* 限定条件:buf 非空;decimals <= 3
* 函数说明:与内部绘制共用同一格式化口径(刷新值列与光标定位同串一致)
*/
void ui_w_editor_format(const ui_w_editor_t *a_inst, char *a_buf, uint32_t a_len);
/*
* 函数功能:把任意定点整数值格式化为显示串(共享格式化单一规则源:
* 组件内部 ed_format 与本函数同一实现,值列显示与编辑光标天然同串)
* 入口参数:value - 定点值(单位 10^decimals;非负) int32_t
* decimals - 小数位数 0..3 uint8_t
* buf - 输出缓冲 char *
* len - 缓冲长度(含 NUL) uint32_t
* 返回值:无
* 限定条件:buf 非空
*/
void ui_w_editor_fmt_scaled(int32_t a_value, uint8_t a_decimals, char *a_buf, uint32_t a_len);
/*
* 函数功能:编辑态自绘(数字光标反显盒 + "越界"提示),在框架内置区块之后调用
* 入口参数:inst - 编辑器实例 ui_w_editor_t *
* layer - 绘制层 lv_layer_t *
* clip - 重绘区 const lv_area_t *
* row_top - 被编辑行行槽顶 y(调用方按列表骨架 + 当前页窗口换算) int32_t
* text_dy - 行文本垂直偏移(= 描述符 text_dy,通常 0) int32_t
* band_h - 选中白带高(反显盒高沿用,= 描述符 band_h) int32_t
* value_x - 值列 x(= 描述符 right_x) int32_t
* 返回值:无
* 限定条件:编辑中才绘制(非编辑态空操作);被编辑行在当前页窗口内由调用方保证
* 函数说明:1bpp 极性:反显 = 白底(UI_COL_SEL_BG)盒 + 黑字(UI_COL_SEL_FG)
* 重画光标位单字符(与 ui_page_net_cfg 编辑光标同法,含 culling;
* 只画单字符:整串传入会被 LVGL 按盒宽折行溢出到邻行——net_cfg 实测坑)
*/
void ui_w_editor_draw(ui_w_editor_t *a_inst, lv_layer_t *a_layer,
const lv_area_t *a_clip, int32_t a_row_top,
int32_t a_text_dy, int32_t a_band_h, int32_t a_value_x);
#ifdef __cplusplus
}
#endif
#endif /* UI_W_EDITOR_H */
+326
View File
@@ -0,0 +1,326 @@
/*
* 模块名称:UI 定值表共享组件(ui_w_setlist)实现
* 模块功能:见 ui_w_setlist.h 头注释(四视图共用列表渲染 + 整定输入抽象,
* 数据经回调注入,数值行走 ui_w_editor,二态行 ENTER 循环切换)
* 适用平台:STM32F407ZGTx / PC 模拟器(两端共用)
* 作者:王建锋
* 创建日期:2026-10-25
* 修改记录:
* v1.0 2026-10-25 王建锋 创建(道B task-5 三组件之一)
*/
/* 头文件包含区 */
#include <string.h>
#include "ui_w_setlist.h"
#include "ui_tokens.h"
/* 私有宏定义区 */
#define SL_SAVE_NAME "保存" /* 保存行名(字体子集已含 保/存) */
#define SL_WIN_ROWS UI_LIST_ROWS /* 窗口行数(与框架 rows_per_page 同令牌) */
/* 函数定义区 */
/*
* 函数功能:判断两区域相交(与本目录各绘制文件同实现:static 局部)
* 入口参数:a - 区域 1 const lv_area_t *
* b - 区域 2 const lv_area_t *
* 返回值:true = 相交 bool
* 限定条件:无
*/
static bool sl_areas_intersect(const lv_area_t *a, const lv_area_t *b) {
int32_t x1 = (a->x1 > b->x1) ? a->x1 : b->x1;
int32_t y1 = (a->y1 > b->y1) ? a->y1 : b->y1;
int32_t x2 = (a->x2 < b->x2) ? a->x2 : b->x2;
int32_t y2 = (a->y2 < b->y2) ? a->y2 : b->y2;
return (x1 <= x2 && y1 <= y2);
}
/*
* 函数功能:整定视图判定(挂了提交回调 = 有保存行、可编辑)
* 入口参数:inst - 定值表实例 const ui_w_setlist_t *
* 返回值:true = 整定视图 bool
* 限定条件:inst 非空由调用链保证
*/
static bool sl_is_rw(const ui_w_setlist_t *a_inst) {
return (a_inst->commit != NULL);
}
/*
* 函数功能:二态行串表长度(NULL 结尾)
* 入口参数:opts - 串表 const char *const *
* 返回值:条目数(>=1;空表防御返回 1) uint8_t
* 限定条件:无
*/
static uint8_t sl_opts_count(const char *const *a_opts) {
uint8_t n = 0u;
if (a_opts == NULL) {
return 1u;
}
while (a_opts[n] != NULL) {
n++;
}
return (n > 0u) ? n : 1u;
}
/*
* 函数功能:当前页窗口顶行下标(与框架 cp_draw_rows / cp_draw_footer 同式)
* 入口参数:inst - 定值表实例 const ui_w_setlist_t *
* 返回值:窗口顶行(全局下标) uint16_t
* 限定条件:编辑中行恒在选中行所在页(编辑态 ↑↓ 被编辑器消费,选中不移)
*/
static uint16_t sl_window_first(const ui_w_setlist_t *a_inst) {
uint16_t sel = ui_content_page_selected_row();
(void)a_inst;
return (uint16_t)((sel / SL_WIN_ROWS) * SL_WIN_ROWS);
}
/*
* 函数功能:行槽顶 y(窗口内)
* 入口参数:inst - 定值表实例 const ui_w_setlist_t *
* row - 全局行下标 uint16_t
* 返回值:行槽顶 y int32_t
* 限定条件:row 在当前窗口内(绘制侧由 bad/ed 行可见性决定,越窗行不绘)
*/
static int32_t sl_slot_y(const ui_w_setlist_t *a_inst, uint16_t a_row) {
return UI_LIST_TOP + ((int32_t)a_row - (int32_t)sl_window_first(a_inst)) * UI_ROW_PITCH;
}
/*
* 函数功能:开页复位(清编辑态)
*/
void ui_w_setlist_reset(ui_w_setlist_t *a_inst) {
ui_w_editor_reset(&a_inst->ed);
a_inst->ed_row = 0u;
}
/*
* 函数功能:总行数(数据行 + 保存行[整定视图])
*/
uint16_t ui_w_setlist_count(const ui_w_setlist_t *a_inst) {
if (a_inst->rows == NULL) {
return 0u;
}
return (uint16_t)(a_inst->count + (sl_is_rw(a_inst) ? 1u : 0u));
}
/*
* 函数功能:逐行取名/值(框架 refresh 转发)
*/
void ui_w_setlist_refresh(ui_w_setlist_t *a_inst, uint16_t a_row,
char *a_name, char *a_value) {
uint16_t total = ui_w_setlist_count(a_inst);
a_name[0] = '\0';
a_value[0] = '\0';
if ((a_inst->rows == NULL) || (a_row >= total)) {
return; /* 防御:空表/行越界(动态收缩瞬间) */
}
if (a_row < a_inst->count) {
const ui_w_setlist_row_t *r = &a_inst->rows[a_row];
(void)lv_snprintf(a_name, UI_BUF_STRLEN, "%s", r->name);
if (r->kind == UI_W_SETLIST_KIND_ENUM) {
int32_t idx = a_inst->get(r->id);
uint8_t n = sl_opts_count(r->opts);
if (idx < 0) {
idx = 0;
}
if (idx >= (int32_t)n) {
idx = (int32_t)n - 1;
}
(void)lv_snprintf(a_value, UI_BUF_STRLEN, "%s", r->opts[idx]);
return;
}
if ((a_inst->ed.editing != 0u) && (a_inst->ed_row == a_row)) {
ui_w_editor_format(&a_inst->ed, a_value, UI_BUF_STRLEN); /* 编辑实时串 */
}
else {
ui_w_editor_fmt_scaled(a_inst->get(r->id), r->decimals, a_value, UI_BUF_STRLEN);
}
return;
}
/* 保存行(整定视图最后一行;名"保存",值随交接态——net_cfg 保存行先例) */
(void)lv_snprintf(a_name, UI_BUF_STRLEN, "%s", SL_SAVE_NAME);
{
ui_w_setlist_st_t st = (a_inst->state != NULL) ? a_inst->state()
: UI_W_SETLIST_ST_IDLE;
switch (st) {
case UI_W_SETLIST_ST_WAIT:
(void)lv_snprintf(a_value, UI_BUF_STRLEN, "%s", "WAIT");
break;
case UI_W_SETLIST_ST_OK:
(void)lv_snprintf(a_value, UI_BUF_STRLEN, "%s", "OK");
break;
case UI_W_SETLIST_ST_FAIL:
(void)lv_snprintf(a_value, UI_BUF_STRLEN, "%s", "ERR");
break;
default:
(void)lv_snprintf(a_value, UI_BUF_STRLEN, "%s", "ENTER");
break;
}
}
}
/*
* 函数功能:按键处理(框架 key_cb 转发)
*/
uint8_t ui_w_setlist_key(ui_w_setlist_t *a_inst, lv_key_t a_key) {
uint16_t sel = ui_content_page_selected_row();
if (a_inst->rows == NULL) {
return 0u;
}
/* 编辑态:键先交编辑器 */
if (a_inst->ed.editing != 0u) {
if ((sel != a_inst->ed_row) || (sel >= a_inst->count)) {
/* 防御:编辑中选中被外部改动(正常不会——编辑态 ↑↓ 被消费)→ 弃编辑 */
ui_w_editor_reset(&a_inst->ed);
return 0u;
}
if (ui_w_editor_key(&a_inst->ed, a_key) == 0u) {
return 0u; /* 未消费键(本组件编辑态只接方向/ENTER) */
}
if (a_inst->ed.editing == 0u) {
/* ENTER 提交成功:值写 RAM 工作副本,落盘统一走保存行整表提交 */
a_inst->set(a_inst->rows[sel].id, ui_w_editor_value(&a_inst->ed));
}
ui_content_page_invalidate();
return 1u;
}
if (a_key == LV_KEY_ENTER) {
if (ui_content_page_is_editable() == false) {
return 0u; /* 只读权限 ENTER 一律忽略(框架内置也无 ENTER 语义) */
}
if (sel < a_inst->count) {
const ui_w_setlist_row_t *r = &a_inst->rows[sel];
if (r->kind == UI_W_SETLIST_KIND_NUM) {
ui_w_editor_begin(&a_inst->ed, a_inst->get(r->id),
r->min, r->max, r->decimals);
a_inst->ed_row = sel;
ui_content_page_invalidate();
return 1u;
}
/* 二态行:循环切换(控制字 告警<->跳闸、软压板 投入<->退出) */
{
int32_t cur = a_inst->get(r->id);
uint8_t n = sl_opts_count(r->opts);
int32_t nxt = cur + 1;
if ((cur < 0) || (cur >= (int32_t)n)) {
nxt = 0;
}
a_inst->set(r->id, nxt);
ui_content_page_invalidate();
return 1u;
}
}
if ((sel == a_inst->count) && sl_is_rw(a_inst)) {
/* 保存行(数据行之后的最后一行):整表提交投递(一次封存一次校验和,
* 显示由 state 回读) */
a_inst->commit();
ui_content_page_invalidate();
return 1u;
}
}
return 0u; /* 其余键交回框架:↑↓ 移选、LEFT 关页(编辑态才在上面消费) */
}
/*
* 函数功能:反显一个名区(保存失败越界行:白底黑字覆盖名文本区)
* 入口参数:inst - 定值表实例 const ui_w_setlist_t *
* layer - 绘制层 lv_layer_t *
* clip - 重绘区 const lv_area_t *
* row - 数据行下标 uint16_t
* 返回值:无
* 限定条件:行在当前窗口内(调用方已筛);编辑行不重复反显(选中带已反)
*/
static void sl_invert_name(const ui_w_setlist_t *a_inst, lv_layer_t *a_layer,
const lv_area_t *a_clip, uint16_t a_row) {
lv_area_t box;
int32_t top = sl_slot_y(a_inst, a_row);
box.x1 = UI_SEL_BAND_INSET_L;
box.x2 = UI_LIST_RIGHT_X - 3; /* 名区止于值列前留 3px 缝 */
box.y1 = top;
box.y2 = top + UI_ROW_BAND_H - 1;
if (!sl_areas_intersect(&box, a_clip)) {
return;
}
{
lv_draw_rect_dsc_t fd;
lv_draw_label_dsc_t ld;
char name[UI_BUF_STRLEN];
lv_draw_rect_dsc_init(&fd);
fd.base.layer = a_layer;
fd.bg_color = UI_COL_SEL_BG;
fd.bg_opa = LV_OPA_COVER;
lv_draw_rect(a_layer, &fd, &box);
(void)lv_snprintf(name, sizeof(name), "%s", a_inst->rows[a_row].name);
lv_draw_label_dsc_init(&ld);
ld.base.layer = a_layer;
ld.text = name;
ld.text_static = 0u; /* 栈缓冲(同帧有效) */
ld.color = UI_COL_SEL_FG;
ld.ofs_x = UI_LIST_LEFT_X - UI_SEL_BAND_INSET_L; /* ofs 相对 box.x1 */
ld.ofs_y = 0;
lv_draw_label(a_layer, &ld, &box);
}
}
/*
* 函数功能:自绘(编辑光标反显 + 越界行反显;框架内置区块之后)
*/
void ui_w_setlist_draw(ui_w_setlist_t *a_inst, lv_layer_t *a_layer,
const lv_area_t *a_clip) {
uint16_t first;
if (a_inst->rows == NULL) {
return;
}
first = sl_window_first(a_inst);
/* 1. 保存失败越界行反显(编辑行跳过:选中带已反,避免双重叠绘歧义) */
if (a_inst->bad != NULL) {
uint16_t total = ui_w_setlist_count(a_inst);
for (uint16_t r = first; (r < a_inst->count) && (r < total); r++) {
if ((r == a_inst->ed_row) && (a_inst->ed.editing != 0u)) {
continue;
}
if (r == ui_content_page_selected_row()) {
continue;
}
if (a_inst->bad(r)) {
sl_invert_name(a_inst, a_layer, a_clip, r);
}
}
}
/* 2. 数值编辑光标(含"越界"提示;几何交编辑器按传入行槽绘制) */
if (a_inst->ed.editing != 0u) {
if (a_inst->ed_row >= first) {
ui_w_editor_draw(&a_inst->ed, a_layer, a_clip,
sl_slot_y(a_inst, a_inst->ed_row),
0, UI_ROW_BAND_H, UI_LIST_RIGHT_X);
}
}
}
+193
View File
@@ -0,0 +1,193 @@
/*
* 模块名称:UI 定值表共享组件(ui_w_setlist)
* 模块功能:把"参数/定值/控制字/软压板"四类视图的列表渲染与整定输入抽象成
* 一份实现——行表 + 数据回调注入(取数/写工作副本/提交/状态回读/
* 越界行查询),同一份组件供多个页面实例复用:
* 查看视图(commit=NULL:无保存行、ENTER 无效)与整定视图
* (commit 非空:末行固定为"保存"行,ENTER 投递整表提交)只差绑定;
* 数值行走 ui_w_editor 逐位编辑(范围校验提交),二态文字行
* (控制字"告警/跳闸"、软压板"投入/退出")ENTER 直接切换;
* 保存失败后的越界行经 bad 回调反显高亮;
* 分页跟随内容页框架内置(8 行/页,UI_LIST_ROWS)
* 适用范围:Drivers/BSP/UI(标准列表页骨架几何:UI_LIST_TOP/ROW_PITCH/
* ROW_BAND_H/LIST_ROWS/RIGHT_X 令牌;页面描述符须 selectable=1、
* key_intercept=1、rows_per_page=UI_LIST_ROWS、text_dy=0)
* 说明:数据绑定全部经回调注入(批 2 ui_data/prot_set 交接时由页面薄跳板
* 提供实现),组件不 include 任何 App 头(分层门禁方向);
* 实例化使用——每个页面文件 static 一份实例,钩子包一层 &inst 转调
* (同 ui_w_records 模式)
* 作者:王建锋
* 创建日期:2026-10-25
* 修改记录:
* v1.0 2026-10-25 王建锋 创建(道B task-5;规格 = 页面扩充详细方案.md
* §3.2 四视图表/§3.2.6 查看与整定差别/§3.2.7 编辑
* 交互/§4.2 bind 要点;保存行 ENTER/WAIT/OK/ERR
* 沿用 ui_page_net_cfg 交接显示先例)
*/
#ifndef UI_W_SETLIST_H
#define UI_W_SETLIST_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#include "ui_content_page.h" /* lvgl(lv_key_t/lv_layer_t)+ 框架类型 */
#include "ui_w_editor.h"
/* 保存交接显示态(值列 ENTER/WAIT/OK/ERR,与 net_cfg 保存行同字面) */
typedef enum {
UI_W_SETLIST_ST_IDLE = 0, /* 空闲:保存行显示 ENTER */
UI_W_SETLIST_ST_WAIT, /* 请求已投递、属主任务处理中:WAIT */
UI_W_SETLIST_ST_OK, /* 上轮提交成功:OK */
UI_W_SETLIST_ST_FAIL /* 上轮提交失败:ERR */
} ui_w_setlist_st_t;
/* 行种类 */
#define UI_W_SETLIST_KIND_NUM 0u /* 数值行:ui_w_editor 逐位编辑(min/max/decimals 有效) */
#define UI_W_SETLIST_KIND_ENUM 1u /* 二态文字行:ENTER 在 opts 串表内循环切换 */
/*
* 视图行描述(Flash const 表,一行一条)
* 值通道统一 int32_t 定点:
* 数值行 = 工程量 * 10^decimals(如 10.24 A -> 1024)
* 二态行 = opts 串表下标(0/1/...)
*/
typedef struct {
const char *name; /* 中文名 <= 7 字(字体子集已预置) */
uint8_t id; /* 应用侧枚举 ID:组件只透传给回调,不解释语义 */
uint8_t kind; /* UI_W_SETLIST_KIND_NUM / _ENUM */
uint8_t decimals; /* 数值行小数位 0..3(二态行忽略) */
int32_t min; /* 数值行下限(含;>=0;二态行忽略) */
int32_t max; /* 数值行上限(含;二态行忽略) */
const char *const *opts; /* 二态行:NUL 结尾 Flash 字符串串表(数值行 NULL) */
} ui_w_setlist_row_t;
/* 数据回调组(均 uiTask 上下文、页面绘制/按键链内调用;实现由批 2 页面跳板提供,
* 组件不 include 任何 App 头——数据绑定经此注入) */
/*
* 函数功能:读某行当前值(数值行 = 工程量 * 10^decimals;二态行 = 串表下标)
* 入口参数:id - 行表登记的枚举 ID uint8_t
* 返回值:当前值 int32_t
*/
typedef int32_t (*ui_w_setlist_get_fn)(uint8_t a_id);
/*
* 函数功能:写某行 RAM 工作副本(不写盘;落盘统一经 commit 整表提交)
* 入口参数:id - 行枚举 ID uint8_t
* val - 新值(口径同 get) int32_t
* 返回值:无
*/
typedef void (*ui_w_setlist_set_fn)(uint8_t a_id, int32_t a_val);
/*
* 函数功能:整表提交(一次封存一次校验和;实现只投递请求到属主任务,不阻塞)
* 入口参数:无
* 返回值:无(投递结果经 state 回调回读)
*/
typedef void (*ui_w_setlist_commit_fn)(void);
/*
* 函数功能:保存交接态回读(保存行值列显示源)
* 入口参数:无
* 返回值:当前交接态 ui_w_setlist_st_t
*/
typedef ui_w_setlist_st_t (*ui_w_setlist_state_fn)(void);
/*
* 函数功能:查询某数据行是否为"保存失败越界行"(需反显高亮)
* 入口参数:row - 数据行下标(不含保存行) uint16_t
* 返回值:true = 需反显;false = 正常(提问谓词,非错误通道) bool
*/
typedef bool (*ui_w_setlist_bad_fn)(uint16_t a_row);
/*
* 定值表实例
* 用法(页面跳板示例,批 2):
* static ui_w_setlist_t s_sl = { .rows = s_rows, .count = N, .get = get, ... };
* count_cb -> ui_w_setlist_count(&s_sl)
* refresh -> ui_w_setlist_refresh(&s_sl, row, name, value)
* key_cb -> ui_w_setlist_key(&s_sl, key)
* draw_cb -> ui_w_setlist_draw(&s_sl, layer, clip)
* init_cb -> ui_w_setlist_reset(&s_sl)
*/
typedef struct {
const ui_w_setlist_row_t *rows; /* Flash 行表 */
uint16_t count; /* 数据行数(不含保存行) */
ui_w_setlist_get_fn get; /* 必填 */
ui_w_setlist_set_fn set; /* 必填(整定提交前的 RAM 副本写入口) */
ui_w_setlist_commit_fn commit; /* NULL = 查看视图(无保存行、禁编辑) */
ui_w_setlist_state_fn state; /* NULL = 保存行恒显示 ENTER */
ui_w_setlist_bad_fn bad; /* NULL = 不做越界行反显 */
ui_w_editor_t ed; /* 数值编辑实例 */
uint16_t ed_row; /* 编辑中行下标(仅 editing 时有效) */
} ui_w_setlist_t;
/*
* 函数功能:开页复位(清编辑态;接页面 init_cb)
* 入口参数:inst - 定值表实例 ui_w_setlist_t *
* 返回值:无
* 限定条件:无
*/
void ui_w_setlist_reset(ui_w_setlist_t *a_inst);
/*
* 函数功能:总行数(接框架 count_cb:数据行 + 保存行[仅整定视图])
* 入口参数:inst - 定值表实例 const ui_w_setlist_t *
* 返回值:总行数 uint16_t
* 限定条件:rows 非空(空表防御返回 0)
*/
uint16_t ui_w_setlist_count(const ui_w_setlist_t *a_inst);
/*
* 函数功能:逐行取数(接框架 refresh:名 = 行表、值 = 回调读/编辑器实时串/保存态)
* 入口参数:inst - 定值表实例 ui_w_setlist_t *
* row - 全局行下标 uint16_t
* name - 名输出缓冲(UI_BUF_STRLEN) char *
* value - 值输出缓冲(同上) char *
* 返回值:无
* 限定条件:页面打开(框架绘制链内调用)
* 函数说明:编辑中行的值列显示编辑器当前串(实时随 ↑↓ 变,同 net_cfg);
* 保存行(最后一行、整定视图)值 = ENTER/WAIT/OK/ERR(state 回调)
*/
void ui_w_setlist_refresh(ui_w_setlist_t *a_inst, uint16_t a_row,
char *a_name, char *a_value);
/*
* 函数功能:按键处理(接框架 key_cb;配合描述符 key_intercept=1 转发 LEFT)
* 入口参数:inst - 定值表实例 ui_w_setlist_t *
* key - LVGL 键值 lv_key_t
* 返回值:1 = 已消费(框架跳过内置);0 = 交回框架(↑↓ 移选、← 关页等)
* (键分发标志非错误通道,取 uint8_t——BSP 公开 API 约定)
* 限定条件:页面打开(内部经 ui_content_page_selected_row / is_editable 判态)
* 函数说明:1. 数值编辑中:↑↓ 步进 / ←→ 移位 / ENTER 提交(越界拒绝)全由
* ui_w_editor 消费;提交成功即经 set 回调写工作副本
* 2. 正常态 ENTER(可编辑权限):数值行进编辑(光标个位);
* 二态行循环切换;保存行投递整表提交(一次封存一次校验和,
* 整表提交口径见 页面补齐规划.md §3.2)
* 3. 只读权限 ENTER 一律不消费;ESC 恒关页(框架,未提交编辑丢弃,
* 已经 ENTER 提交到工作副本的调整保留、不落盘——net_cfg 先例)
*/
uint8_t ui_w_setlist_key(ui_w_setlist_t *a_inst, lv_key_t a_key);
/*
* 函数功能:自绘(接框架 draw_cb:编辑光标反显 + 保存失败越界行反显)
* 入口参数:inst - 定值表实例 ui_w_setlist_t *
* layer - 绘制层 lv_layer_t *
* clip - 重绘区 const lv_area_t *
* 返回值:无
* 限定条件:页面打开;框架内置区块(行/带/页脚)已绘完
* 函数说明:行槽 y 按标准列表骨架 + 当前页窗口换算(与框架 cp_draw_rows 同式:
* first = sel / UI_LIST_ROWS * UI_LIST_ROWS)
*/
void ui_w_setlist_draw(ui_w_setlist_t *a_inst, lv_layer_t *a_layer,
const lv_area_t *a_clip);
#ifdef __cplusplus
}
#endif
#endif /* UI_W_SETLIST_H */
+15
View File
@@ -3516,6 +3516,21 @@
<FileType>1</FileType>
<FilePath>..\Drivers\BSP\UI\ui_w_records.c</FilePath>
</File>
<File>
<FileName>ui_w_editor.c</FileName>
<FileType>1</FileType>
<FilePath>..\Drivers\BSP\UI\ui_w_editor.c</FilePath>
</File>
<File>
<FileName>ui_w_setlist.c</FileName>
<FileType>1</FileType>
<FilePath>..\Drivers\BSP\UI\ui_w_setlist.c</FilePath>
</File>
<File>
<FileName>ui_page_action.c</FileName>
<FileType>1</FileType>
<FilePath>..\Drivers\BSP\UI\ui_page_action.c</FilePath>
</File>
<File>
<FileName>ui_style.c</FileName>
<FileType>1</FileType>
+3
View File
@@ -97,6 +97,9 @@ set(UI_SOURCES
${UI_DIR}/ui_page_registry.c
${UI_DIR}/ui_style.c
${UI_DIR}/ui_w_records.c
${UI_DIR}/ui_w_editor.c
${UI_DIR}/ui_w_setlist.c
${UI_DIR}/ui_page_action.c
)
# 运行/自检记录引擎(双端共享核心 + 平台存储后端;MCU 端编 sys_log_mcu.c,见 Keil 工程)