Files
AskaEth 54857bc0fd sdk(ui): 字符串资源外置(i18n 雏形 §13)—— meow_str_* + 内嵌双语表 + TF 覆盖表 + 控件接入
公开 SDK 前把 SDK/App 硬编码文案外置:新增 meow_str/meow_strf/meow_str_set_locale/
meow_str_locale,按当前 locale 取串(永不 NULL),第三方开发者可做多语言。

- 新增 include/meow_ui_str.h + meow_ui_str.c:取串优先级 = TF 覆盖表 > 内嵌当前语言
  (en_us→en 其余→zh) > 内嵌内置默认(zh_cn) > 原样返回 id。内嵌双语表(common.* 21 条 +
  ime.* 9 条);热路径零 malloc(编译期静态表 + ≤256 静态覆盖数组);纯 libc 宿主可单测。
- locale 存系统设置 settings.conf 的 ui.locale(默认 zh_cn,首次调用惰性读取);
  meow_str_set_locale 即时切换 + 重载覆盖表 + best-effort 持久化(流式改写保留其它行)。
- TF 覆盖表 MeowData/<pkg>/strings/<locale>.txt(id=text 行,UTF-8,'=' 两侧去空白);
  无卡/无文件/无该 id → 回落内嵌。meow_strf 用调用方缓冲(snprintf 语义,重入安全)。
- SDK 控件接入:dialog 默认按钮 OK/CANCEL + INPUT 占位、IME 键面/徽标(空格/确定/拼英/
  ?123/清/拼音/(无候选)/中)改走 meow_str;空态/加载态给 App 提供 common.no_data/loading。
- 测试:新增 test_meow_ui_str.c(内嵌回退/TF 覆盖优先级/未知 id 回退/切 locale 即时生效/
  查找正确性/meow_strf,tmp+env 两模式);全量宿主回归(widgets/dispatch/box/anim/scroll/
  listvirt/theme/ime_fix/pinyin/overlay/notif/sdk_input_keys/p1p2p3/config/vol/sb_collapse/
  notify_*) 0 回归;交叉 zig-mipsel -Wall -Wextra 0 warning。
- 文档:MEOW_APP_SDK.md 新增 §13(字符串资源/i18n,遗留顺延为 §14);docs/APP_DEV_GUIDE.md
  新增 §7.11。各宿主 test_*.c 头注释补 meow_ui_str.c 编译依赖。

边界(§13.7):仅 zh_cn/en_us 整串取用;不做复数规则 / BiDi / RTL / 动态字体回退(雏形)。
2026-09-02 02:37:38 +08:00

158 lines
9.7 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* test_p1p2p3_repro.c — 宿主复现并校验 P1/P2/P3 三个真机问题的修复(离屏 480x720,16bpp)。
*
* 方法:直接驱动拆分后 hello 的 demo 真实函数(demo_paint / demo_rebuild_to / demo_touch_down)
* 与 demo 视图态(extern,见 ../hello_app/hello_internal.h),对 back_buf 做像素断言。
* 这样测的是「真实 demo 代码 + 真实 SDK」,不是模拟桩。不依赖 /dev/fb0 / 字库 / launcher。
*
* 批次② 变化:hello.c 已拆为 app.c + ui/{home,full,demo}.c + ui/common/chrome.c +
* logic/{notify,state}.c;本文件不再 #include hello.c,改为 extern 驱动 demo 层并链接多文件。
* 批次③ 变化:ui/home、ui/demo 子目录化(ui/home/home.c + ui/demo/demo.c),demo 列表区块抽成
* CONTAINER 子视图 ui/demo/list/list.c;下表编译路径相应更新(断言未弱化)。
*
* 覆盖:
* P1 z-order 叠层:圆形进度条(实时重绘)与 FAB 浮层重叠时,局部重绘不再清掉/盖住 FAB。
* (批次① 后为 P1c:set_z(g_fab,999)+invalidate(r_prc),显式 z 不依赖绘制先后。)
* P2 list 焦点:命中非 list 区域时释放列表焦点、切页滚动(不再沿用旧焦点继续滚列表)。
* P3 list 脏区:W_LIST 绘制已裁剪到视口;滚动(非整行偏移)+选中行不再向标题间隙/底缘下泄漏。
*
* 编译(宿主 gcc,链真实 gfx/sys/theme/vol/log/widget/input/activity/dialog/ime/img/config/
* notify/ipc + 打桩 font/global(test_host_stub) + stb_image + hello 拆分层):
* 1) 单独编译 app.c 并把 main 改名 hello_app_main(否则与本文件 main 冲突):
* gcc -c -Wall -Wextra -DMEOW_UI_HOST_TEST -Dmain=hello_app_main \
* -I. -I../hello_app ../hello_app/app.c -o app.o
* 2) 编译本文件 + 其余 hello 模块 + SDK 源 + 打桩,链接 app.o:
* gcc -Wall -Wextra -DMEOW_UI_HOST_TEST -o test_p1p2p3_repro test_p1p2p3_repro.c app.o \
* test_host_stub.c meow_ui_gfx.c meow_ui_sys.c meow_ui_theme.c meow_ui_vol.c meow_ui_log.c \
* meow_ui_widget.c meow_ui_input.c meow_ui_activity.c meow_ui_dialog.c meow_ui_ime.c meow_ui_str.c \
* meow_ui_img.c meow_ui_config.c meow_ui_notify.c meow_notify_ipc.c meow_ui_draw.c \
* meow_ui_view.c meow_ui_nav.c meow_ui_media.c stb_image.c \
* ../hello_app/ui/home/home.c ../hello_app/ui/full.c ../hello_app/ui/demo/demo.c \
* ../hello_app/ui/demo/list/list.c ../hello_app/ui/common/chrome.c \
* ../hello_app/logic/notify.c ../hello_app/logic/state.c \
* -I. -I../hello_app -I../meow_launcherd -pthread -lm
* 运行:MEOW_UI_DUMP=/tmp/repro.ppm ./test_p1p2p3_repro (optional,dump 最终屏幕)
*
* 预期 RESULT: ALL PASS(P1c/P2/P3 断言真实有效,未弱化)。
*/
#include "meow_ui.h"
#include "meow_ui_internal.h"
#include "../hello_app/hello_internal.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* ---- 像素读取 ---- */
static void rd_px(int x, int y, int *r, int *g, int *b)
{
unsigned char *bb = meow_ui_back_buf();
int line = meow_ui_back_buf_pitch(), bpp = meow_ui_back_buf_bpp();
if (!bb) { *r=*g=*b=0; return; }
if (bpp == 16) {
uint16_t px = *(uint16_t *)(bb + (size_t)y * line + (size_t)x * 2);
*r = (((px >> 11) & 0x1F) << 3) | ((px >> 11) & 0x1F) >> 2;
*g = (((px >> 5) & 0x3F) << 2) | ((px >> 5) & 0x3F) >> 4;
*b = ((px & 0x1F) << 3) | ((px & 0x1F) >> 2);
} else {
uint32_t px = *(uint32_t *)(bb + (size_t)y * line + (size_t)x * 4);
*r = (px >> 16) & 0xFF; *g = (px >> 8) & 0xFF; *b = px & 0xFF;
}
}
static int near(int a, int b) { int d = a - b; if (d < 0) d = -d; return d <= 12; }
static int is_bg(int r, int g, int b)
{
const meow_theme *th = meow_theme_get();
int br = (th->bg >> 16) & 0xFF, bg = (th->bg >> 8) & 0xFF, bb = th->bg & 0xFF;
return near(r, br) && near(g, bg) && near(b, bb);
}
static void pr_px(const char *tag, int x, int y)
{
int r, g, b; rd_px(x, y, &r, &g, &b);
printf(" %-26s px(%d,%d)=%02X%02X%02X %s\n", tag, x, y, r, g, b, is_bg(r, g, b) ? "[bg]" : "[ink]");
}
int main(void)
{
setenv("MEOW_UI_DUMP", "/tmp/repro.ppm", 1);
meow_ui_opts o = { 480, 720 };
if (meow_ui_init(&o) != 0) { printf("init failed\n"); return 1; }
meow_ui_activity_push(ACT_DEMO); /* demo 控件 owner=ACT_DEMO,命中/绘制对齐 */
demo_init(); /* 建造 chrome + 内容(scroll=0),owner=ACT_DEMO */
int fails = 0;
/* ================= P1 / P1c:局部重绘不盖浮层(FAB,须显式置顶) =================
* 场景:scroll=0 时圆形进度 r_prc(413..453,605..645) 与 FAB(406..462,616..672) 重叠。
* demo_paint 整帧后 FAB 在上(demo_init set_z(g_fab,999) 显式置顶)。随后「局部重绘进度条」:
* 旧(清底+只画进度条+flush 其矩形)→ FAB 重叠区被清掉;
* 新(SDK meow_ui_invalidate:清底 + 按 z 重画重叠区完整 z 栈)→ FAB 保持。
* P1c:set_z(g_fab,999) 后 invalidate(r_prc),断言 FAB 重叠点(434,622) 仍=demo_paint 后值
* (显式 z 不依赖绘制先后——置顶在重绘前显式给出,下层重绘不抹上层)。 */
demo_paint();
int fx = r_fab.x + 28, fy = r_fab.y + 6; /* FAB 内、远离 "+" 文本处 → (434,622) */
int s0r, s0g, s0b; rd_px(fx, fy, &s0r, &s0g, &s0b);
printf("P1 scene (demo_paint) FAB-overlap "); pr_px("scene", fx, fy);
if (is_bg(s0r, s0g, s0b))
printf(" [warn] expected FAB ink at scene, got bg — geometry assumptions off\n");
/* 旧式局部重绘:清底+只画进度条(复现根因) */
{
const meow_theme *th = meow_theme_get();
meow_progress_set(g_dprc, 30);
meow_ui_fill_rect(r_prc.x, r_prc.y, r_prc.w, r_prc.h, th->bg);
meow_widget_draw(g_dprc);
meow_ui_flush_region(r_prc.x, r_prc.y, r_prc.w, r_prc.h);
}
int obr, obg, obb; rd_px(fx, fy, &obr, &obg, &obb);
printf("P1 old-partial (clear+single draw) "); pr_px("old", fx, fy);
if (is_bg(obr, obg, obb)) printf(" [BUG-CONFIRMED] old path erased FAB overlap (bg)\n");
else printf(" [note] old path did NOT erase FAB here (color %02X%02X%02X)\n", obr, obg, obb);
/* P1c:显式置顶 + SDK 局部重画(invalidate 按 z 重画重叠栈) */
demo_paint(); /* 还原场景 */
meow_widget_set_z(g_fab, 999); /* 重新显式置顶(P1c 要求) */
meow_progress_set(g_dprc, 30);
meow_ui_invalidate(r_prc.x, r_prc.y, r_prc.w, r_prc.h);
int nbr, nbg, nbb; rd_px(fx, fy, &nbr, &nbg, &nbb);
printf("P1c set_z(999)+invalidate(r_prc) "); pr_px("p1c", fx, fy);
if (near(s0r, nbr) && near(s0g, nbg) && near(s0b, nbb))
printf(" P1-PASS explicit z:FAB preserved over live progress redraw\n");
else { printf(" P1-FAIL FAB not preserved (scene %02X%02X%02X vs p1c %02X%02X%02X)\n",
s0r, s0g, s0b, nbr, nbg, nbb); fails++; }
/* ================= P2:列表焦点按本次触摸绑定/释放 =================
* demo_touch_down 命中非 list 区域时应释放列表焦点 → 页滚动,而不是继续滚列表。 */
g_demo_focus = 1; /* 模拟此前点过列表(焦点留存) */
g_demo = 1; /* demo 页已进入(demo_touch_down 前置闸门) */
demo_touch_down(240, 300); /* 非 list 非 slider 的内容区 */
printf("P2 touch_down(240,300) with focus=1 -> drag_list=%d drag_page=%d focus=%d\n",
g_drag_list, g_drag_page, g_demo_focus);
if (g_drag_list == 0 && g_drag_page == 1 && g_demo_focus == 0)
printf(" P2-PASS non-list touch releases focus, drags page\n");
else { printf(" P2-FAIL (expected drag_page=1 focus=0; got drag_list=%d drag_page=%d focus=%d)\n",
g_drag_list, g_drag_page, g_demo_focus); fails++; }
/* ================= P3:列表滚动 W_LIST 视口外泄漏 =================
* 把页面 scroll 拉到底,列表上屏;再把列表 scroll 设非整行倍数 + 选中一个跨底/跨顶行,
* 观察视口外(标题间隙/底缘下)是否漏出选中行填充(标脏泄漏 = 标题栏/底部卡脏区)。 */
demo_rebuild_to(100000); /* clamp 到 max,列表上屏 */
printf("P3 list rect = (%d,%d,%d,%d)\n", r_list.x, r_list.y, r_list.w, r_list.h);
/* 顶部泄漏:选中行0 + scroll=20 → 行0 ry=top-20,填充越顶泄漏 */
meow_list_set_selected(g_dlc, 0); meow_list_set_scroll(g_dlc, 20);
meow_ui_invalidate(r_list.x, r_list.y, r_list.w, r_list.h);
int ux = r_list.x + 10, uy = r_list.y - 5; /* 列表顶上方 5px(标题间隙) */
int ur, ug, ub; rd_px(ux, uy, &ur, &ug, &ub);
printf("P3 top-leak "); pr_px("above-top", ux, uy);
if (is_bg(ur, ug, ub)) printf(" P3-top-PASS no leak into title gap\n");
else { printf(" P3-top-FAIL leaked into title gap\n"); fails++; }
/* 底部泄漏:选中行4 + scroll=20 → 行4 ry=590..630 越底泄漏 */
meow_list_set_selected(g_dlc, 4); meow_list_set_scroll(g_dlc, 20);
meow_ui_invalidate(r_list.x, r_list.y, r_list.w, r_list.h);
int dx = r_list.x + 10, dy_ = r_list.y + r_list.h + 5; /* 列表底下方 5px */
int dr, dg, db; rd_px(dx, dy_, &dr, &dg, &db);
printf("P3 bot-leak "); pr_px("below-bottom", dx, dy_);
if (is_bg(dr, dg, db)) printf(" P3-bottom-PASS no leak below list\n");
else { printf(" P3-bottom-FAIL leaked below list\n"); fails++; }
printf(fails ? "\nRESULT: %d FAIL(S)\n" : "\nRESULT: ALL PASS\n", fails);
return fails;
}