Files
MeowOS-SDK/sdk/test_meow_ui_swipe.c
T
AskaEth 432875d4e6 sdk: 宿主测试头注释按实测修订 + select T1 探针修正
- test_meow_ui_select: T1 选中高亮探针移到容器卡内(x=12),
  适配 M6.37 起的 listview 默认容器模式;6/6 PASS
- 各 test_*.c 头注释补 -Iinclude、meow_ui_nav.c 及精简源列表最小补集
  (theme/widgets/notif_gesture/overlay/suppress/sdk_fixes/pinyin/ime_fix)
- test_sb_statusbar 头注释给出可链接命令(--allow-multiple-definition)
- notify_post/ui_audio_host/p1p2p3 标注需主仓组件,公开仓跳过
- docs/APP_DEV_GUIDE.md: 去掉叠字与过强表述,改为 34/38 实测口径
2026-11-04 20:26:35 +08:00

211 lines
9.4 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.
/* test_meow_ui_swipe.c — 宿主验证列表行左滑删除(§5.5,M7.3 缺口 #9):
* T1 滑动手势判定与冲突消解:begin 命中可滑行返回 1;横向小位移 = swipe(move 返回 1 消费);
* 纵向大位移 = 滚动手势优先(move 返回 0 并取消本行 swipe);非启用行 begin 返回 0。
* T2 左滑超阈值 → 删除动画(meow_anim 滑出),结束后 on_delete 回调恰一次 + swipe 状态复位。
* T3 未超阈值 → 回弹,on_delete 不触发,swipe_dx 回到 0。
* T4 点按(无位移):begin 后 end(未 started)返回 0(App 走 tap_at),不触发 on_delete。
* T5 右露删除区像素:滑动中重绘列表 → 右露区画主题 error 底 + 行内容左移。
*
* 编译(宿主 gcc):
* gcc -o test_meow_ui_swipe test_meow_ui_swipe.c 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_pinyin.c meow_ui_draw.c meow_ui_view.c meow_ui_box.c meow_ui_anim.c meow_ui_scroll.c \
* meow_ui_img.c meow_ui_media.c meow_notify_ipc.c stb_image.c meow_ui_nav.c \
* -I. -Iinclude -DMEOW_UI_HOST_TEST -pthread -lm
* 运行:./test_meow_ui_swipe
*/
#include "meow_ui.h"
#include "meow_ui_internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static int g_pass = 0, g_fail = 0;
#define CHECK(cond, ...) do { \
if (cond) { g_pass++; } \
else { g_fail++; printf("FAIL %s:%d ", __FILE__, __LINE__); printf(__VA_ARGS__); printf("\n"); } \
} while (0)
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 || x < 0 || y < 0) { *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 near2(int a, int b) { int d = a - b; if (d < 0) d = -d; return d <= 14; }
static int px_near(int x, int y, int r, int g, int b)
{
int rr, gg, bb; rd_px(x, y, &rr, &gg, &bb);
return near2(rr, r) && near2(gg, g) && near2(bb, b);
}
static int region_has(int x, int y, int w, int h, int r, int g, int b)
{
int cnt = 0;
for (int dy = 0; dy < h; dy++)
for (int dx = 0; dx < w; dx++)
if (px_near(x + dx, y + dy, r, g, b)) cnt++;
return cnt;
}
#define UNPK(c, rr, gg, bb) do { (rr) = ((c) >> 16) & 0xFF; (gg) = ((c) >> 8) & 0xFF; (bb) = (c) & 0xFF; } while (0)
#define LVX 20
#define LVY 50
#define LVW 440
#define LVH 300
#define ITEM 56
#define CNT 10
static int del_count; /* on_delete 回调次数 */
static int del_idx; /* 最后一次删除 idx */
static void on_delete(int idx, void *ctx) { (void)ctx; del_count++; del_idx = idx; }
static int scount(void *ctx) { (void)ctx; return CNT; }
static void sbind(int idx, meow_lv_item *it, void *ctx)
{
(void)ctx;
memset(it, 0, sizeof *it);
static char t[32];
snprintf(t, sizeof t, "notif %d", idx);
it->title = t; it->icon_kind = MEOW_LIST_ICON_NONE; it->right = MEOW_LIST_RIGHT_NONE;
it->enabled = 1;
}
static meow_widget *make_list(void)
{
meow_widget *lv = meow_listview_create(LVX, LVY, LVW, LVH, 0, NULL, NULL, MEOW_LIST_SEL_NONE);
meow_listview_set_item_h(lv, ITEM);
meow_listview_set_vsource(lv, scount, sbind, NULL);
meow_listview_set_item_renderer(lv, 2, 0, 0); /* 双行、无图标、无尾件 */
meow_listview_set_swipe_delete(lv, 1, on_delete, NULL);
return lv;
}
/* 推进 meow_anim 直到 swipe 动画结束(模拟 on_tick 节拍)。 */
static void pump_swipe(meow_widget *lv)
{
int guard = 0;
while (meow_listview_swipe_active(lv) && guard++ < 80) {
meow_anim_tick();
usleep(10000);
}
meow_anim_tick();
}
int main(void)
{
meow_ui_opts o = { 480, 720 };
if (meow_ui_init(&o) != 0) { printf("init failed\n"); return 1; }
const meow_theme *th = meow_theme_get();
int err_r, err_g, err_b; UNPK(th->error, err_r, err_g, err_b);
int row0y = LVY + ITEM / 2; /* 行 0 中心 y(scroll=0) */
/* ============ T1 手势判定 / 冲突消解 ============ */
{
meow_widget *lv = make_list();
/* begin 命中可滑行行 → 1 */
CHECK(meow_listview_swipe_begin(lv, 100, row0y) == 1, "T1 begin on swipe row = 1");
/* 横向小位移 → 裁定 swipe,move 返回 1(消费) */
CHECK(meow_listview_swipe_move(lv, 40, row0y) == 1, "T1 move horizontal = 1 (consumed)");
int dx = meow_listview_swipe_offset(lv);
CHECK(dx == -60, "T1 dx=-60 got %d", dx);
/* 又一小位移(不超容差也不改变方向) */
CHECK(meow_listview_swipe_move(lv, 30, row0y) == 1, "T1 move horizontal 2 = 1");
CHECK(meow_listview_swipe_end(lv, 30, row0y) == 1, "T1 end started swipe = 1 (bounce)");
pump_swipe(lv);
CHECK(meow_listview_swipe_offset(lv) == 0, "T1 bounce back dx=0 got %d", meow_listview_swipe_offset(lv));
CHECK(del_count == 0, "T1 no delete on bounce");
meow_widget_free(lv);
}
{
/* 纵向大位移 → 滚动手势优先(move 返回 0 + 取消) */
meow_widget *lv = make_list();
CHECK(meow_listview_swipe_begin(lv, 100, row0y) == 1, "T1 begin2 = 1");
CHECK(meow_listview_swipe_move(lv, 100, row0y + 80) == 0, "T1 vertical move = 0 (yield to scroll)");
CHECK(meow_listview_swipe_active(lv) == 0, "T1 vertical cancels swipe");
CHECK(meow_listview_swipe_offset(lv) == 0, "T1 vertical dx=0");
meow_widget_free(lv);
}
{
/* 非启用行 begin → 0 */
meow_widget *lv = make_list();
meow_listview_set_swipe_delete(lv, 0, NULL, NULL);
CHECK(meow_listview_swipe_begin(lv, 100, row0y) == 0, "T1 disabled begin = 0");
meow_widget_free(lv);
}
/* ============ T2 超阈值 → 删除动画 + on_delete ============ */
{
del_count = 0; del_idx = -1;
meow_widget *lv = make_list();
CHECK(meow_listview_swipe_begin(lv, 100, row0y) == 1, "T2 begin = 1");
/* 左滑 200px(阈值=LVW*2/5=176)→ 超阈值 */
CHECK(meow_listview_swipe_move(lv, 100 - 200, row0y) == 1, "T2 move big left = 1");
CHECK(meow_listview_swipe_end(lv, 100 - 200, row0y) == 1, "T2 end = 1 (delete anim)");
CHECK(meow_listview_swipe_active(lv) == 1, "T2 delete anim active");
pump_swipe(lv);
CHECK(del_count == 1, "T2 on_delete fired once got %d", del_count);
CHECK(del_idx == 0, "T2 on_delete idx0 got %d", del_idx);
CHECK(meow_listview_swipe_active(lv) == 0, "T2 state reset inactive");
CHECK(meow_listview_swipe_offset(lv) == 0, "T2 dx reset 0 got %d", meow_listview_swipe_offset(lv));
meow_widget_free(lv);
}
/* ============ T3 未超阈值 → 回弹,on_delete 不触发 ============ */
{
del_count = 0;
meow_widget *lv = make_list();
CHECK(meow_listview_swipe_begin(lv, 100, row0y) == 1, "T3 begin = 1");
CHECK(meow_listview_swipe_move(lv, 55, row0y) == 1, "T3 move left 45px = 1");
CHECK(meow_listview_swipe_offset(lv) == -45, "T3 dx=-45 got %d", meow_listview_swipe_offset(lv));
CHECK(meow_listview_swipe_end(lv, 55, row0y) == 1, "T3 end = 1 (bounce anim)");
CHECK(meow_listview_swipe_active(lv) == 1, "T3 bounce active");
pump_swipe(lv);
CHECK(del_count == 0, "T3 on_delete NOT fired got %d", del_count);
CHECK(meow_listview_swipe_offset(lv) == 0, "T3 bounce dx=0 got %d", meow_listview_swipe_offset(lv));
CHECK(meow_listview_swipe_active(lv) == 0, "T3 inactive after bounce");
meow_widget_free(lv);
}
/* ============ T4 点按(无位移)= 行点击,end 返回 0 ============ */
{
del_count = 0;
meow_widget *lv = make_list();
CHECK(meow_listview_swipe_begin(lv, 100, row0y) == 1, "T4 begin = 1");
CHECK(meow_listview_swipe_end(lv, 100, row0y) == 0, "T4 tap end = 0 (let App tap_at)");
CHECK(del_count == 0, "T4 no delete on tap");
CHECK(meow_listview_swipe_active(lv) == 0, "T4 inactive after tap");
meow_widget_free(lv);
}
/* ============ T5 右露删除区像素(默认 renderer) ============ */
{
meow_widget *lv = make_list();
CHECK(meow_listview_swipe_begin(lv, 100, row0y) == 1, "T5 begin = 1");
CHECK(meow_listview_swipe_move(lv, 100 - 200, row0y) == 1, "T5 move big left = 1");
meow_ui_clear(th->bg);
meow_widget_draw(lv);
/* 右露区 [LVX+LVW+dx, row0, -dx, ITEM] = [260,50,200,56] → error 底 */
CHECK(region_has(270, row0y - ITEM / 2 + 4, 180, ITEM - 8, err_r, err_g, err_b) > 50,
"T5 delete reveal error bg got %d", region_has(270, row0y - ITEM / 2 + 4, 180, ITEM - 8, err_r, err_g, err_b));
meow_listview_swipe_end(lv, 100 - 200, row0y);
pump_swipe(lv);
meow_widget_free(lv);
}
meow_ui_shutdown();
printf("swipe: %d pass / %d fail\n", g_pass, g_fail);
return g_fail ? 1 : 0;
}