/* * meow_ui_global.c — App 跨 Activity 控件(§6.1 ②,SDK 托管骨架)。 * * SDK 维护一个全局控件列表(钉在 App 的 Activity 栈之上、跨 Activity 常驻): * - 渲染:meow_ui_gfx present() 每帧在 active activity 内容之上、全局状态栏之下调 * meow_ui_global_render()(遍历列表调 render_cb); * - 触摸:meow_ui_input TAP 分发先给 meow_ui_global_hit(x,y)——命中返回 1=消费, * 否则落到 active activity 页面控件(①)。 * * 骨架(待 B2 细化):无 z 序细分/无按压态管理/无命中区排布——App 的 render/hit 回调 * 自行决定绘制与命中。跨 Activity 常驻由「列表不随 Activity 栈变化」天然保证。 */ #include "meow_ui.h" #define MEOW_GLOBAL_MAX 16 typedef struct { int id; meow_global_render_fn render; meow_global_hit_fn hit; void *ctx; } gentry; static gentry g_globals[MEOW_GLOBAL_MAX]; static int g_global_n = 0; void meow_ui_global_add(int id, meow_global_render_fn r, meow_global_hit_fn h, void *ctx) { for (int i = 0; i < g_global_n; i++) if (g_globals[i].id == id) return; /* 同 id 幂等(重复 add 不新增,骨架) */ if (g_global_n >= MEOW_GLOBAL_MAX) return; g_globals[g_global_n].id = id; g_globals[g_global_n].render = r; g_globals[g_global_n].hit = h; g_globals[g_global_n].ctx = ctx; g_global_n++; } void meow_ui_global_remove(int id) { for (int i = 0; i < g_global_n; i++) { if (g_globals[i].id == id) { g_globals[i] = g_globals[--g_global_n]; return; } } } void meow_ui_global_render(void) { for (int i = 0; i < g_global_n; i++) if (g_globals[i].render) g_globals[i].render(g_globals[i].ctx); } int meow_ui_global_hit(int x, int y) { for (int i = 0; i < g_global_n; i++) if (g_globals[i].hit && g_globals[i].hit(g_globals[i].ctx, x, y)) return 1; return 0; }