Files
MeowOS-SDK/app.c
T
MeowOS d1a3cce7f1 refactor(hello): 视图框架批次② — hello.c 拆分为 app.c+ui/{home,full,demo}.c+ui/common/chrome.c+logic/{notify,state}.c(定案B: demo视图态留ui/;定案b: page导航包装activity栈);test_p1p2p3_repro 改多文件链接形态 (agent-177)
hello f45ba051→c06b3b4f; mipsel -Wall -Wextra 0 warning; 宿主 P1c/P2/P3+widgets 全 PASS
出入(诚实): view on_draw/on_event 路径暂未启用(注册表直绘已覆盖, on_draw 双画风险), 留批③实测; home/full 仍手绘未迁注册表
2026-08-31 03:31:09 +08:00

116 lines
4.1 KiB
C
Raw 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.
/* app.c — hello 应用装配层:main + 组装 + 事件分发。
*
* 职责(SDK_VIEW_FRAMEWORK_DESIGN.md §B.2):main 只做初始化/建页/跑事件循环/清理;把
* meow_ui_run 的平铺输入回调(key/tap/swipe/tick/touch)路由到当前活动页(home/full/demo)。
* 页面切换统一走 meow_view_page_push/pop(活动栈 + on_enter/on_leave 的唯一驱动,App 不再
* 分别调 activity_push/pop)。业务变化经 logic 监听器送回 UI(见 ui/home.c)。
*
* 契约(MEOW_APP_SDK.md §1/§3/§6):应用只调 meow_ui API。
*/
#include "hello_internal.h"
#include <signal.h>
/* Dialog / BottomSheet(阻塞模态;非控件,main() 创建一次,demo 页打开/关) */
meow_dialog *g_dlg;
meow_sheet *g_sheet;
static meow_view *g_home_view;
static meow_view *g_full_view;
static meow_view *g_demo_view;
static void on_sigterm(int s) { (void)s; meow_ui_request_exit(); }
/* ============================================================ */
/* 事件分发:meow_ui_run 平铺回调 → 当前页 */
/* ============================================================ */
static void app_on_key(int keycode, int is_down)
{
(void)keycode; (void)is_down;
meow_log(MEOW_LOG_DEBUG, "key");
}
static void app_on_tap(int x, int y)
{
if (demo_is_active()) { demo_on_tap(x, y); return; }
if (full_is_active()) { meow_view_page_pop(); return; } /* 全屏:点任意处回 home */
home_on_tap(x, y);
}
static void app_on_swipe(int dir, int dx, int dy)
{
(void)dy;
if (demo_is_active()) { demo_swipe(dir, dx); return; }
if (dir == MEOW_SWIPE_LEFT) {
if (full_is_active()) { meow_view_page_pop(); }
else { meow_log(MEOW_LOG_INFO, "exit:swipe"); meow_ui_request_exit(); }
}
}
/* M2.71-bug2/6:拖动过程回调(只对 demo 页有意义;home/全屏不拖拽)。 */
static void app_on_touch_down(int x, int y)
{
if (demo_is_active()) demo_touch_down(x, y);
}
static void app_on_touch_move(int x, int y)
{
if (demo_is_active()) demo_touch_move(x, y);
}
static void app_on_swipe_progress(int x_start, int dx)
{
meow_ui_swipe_hint(x_start + dx);
}
static void app_on_tick(void)
{
uint64_t now = meow_ui_time_ms();
if (demo_is_active()) { demo_tick(now); return; }
static uint64_t last = 0; /* home/全屏计时:1s 一跳(demo 不计数,同旧) */
if (now - last >= 1000) { last = now; logic_secs_add(1); }
}
/* ============================================================ */
/* main */
/* ============================================================ */
int main(void)
{
meow_log(MEOW_LOG_INFO, "start");
meow_ui_opts o = { 480, 720 };
if (meow_ui_init(&o) != 0) { meow_log(MEOW_LOG_ERROR, "init failed"); return 1; }
meow_theme_add_listener(NULL);
signal(SIGTERM, on_sigterm);
/* Dialog / BottomSheet 实例(阻塞模态;打开前排空残留触摸由 SDK 处理) */
g_dlg = meow_dialog_create(MEOW_DLG_SELECT, "Pick a fruit");
const char *items[] = { "Apple", "Banana", "Cherry" };
meow_dialog_set_items(g_dlg, items, 3, 1);
g_sheet = meow_sheet_create("Options", 0);
meow_sheet_add_item(g_sheet, "Copy");
meow_sheet_add_item(g_sheet, "Delete");
meow_sheet_add_item(g_sheet, "Share");
/* 建三页 view(on_create 建各自控件/状态)+ 弹层实例 */
g_home_view = home_view_create();
g_full_view = full_view_create();
g_demo_view = demo_view_create();
/* 进入根页(activity_push + home on_enter → home_redraw) */
meow_view_page_push(ACT_HOME);
meow_ui_events ev = { app_on_key, app_on_tap, app_on_swipe, app_on_tick, app_on_swipe_progress,
app_on_touch_down, app_on_touch_move };
meow_ui_run(&ev);
/* 清理:meow_view_free 触发各页 on_destroy(home 控件 / demo 内容+chrome) */
meow_view_free(g_full_view);
meow_view_free(g_demo_view);
meow_view_free(g_home_view);
meow_dialog_free(g_dlg);
meow_sheet_free(g_sheet);
meow_ui_shutdown();
meow_log(MEOW_LOG_INFO, "exit");
return 0;
}