diff --git a/patch_v2/meow_launcherd/test_menu_row_gap.c b/patch_v2/meow_launcherd/test_menu_row_gap.c new file mode 100644 index 0000000..206c722 --- /dev/null +++ b/patch_v2/meow_launcherd/test_menu_row_gap.c @@ -0,0 +1,67 @@ +/* meow_launcherd/test_menu_row_gap.c — 宿主验证:主界面列表模式圆角卡列表项外边距 + * (item margin/gap)几何。纯整数运算,不链 SDK / 不开设备: + * gcc test_menu_row_gap.c -o test_menu_row_gap && ./test_menu_row_gap + * + * 断言集(对应「相邻 item 顶之间 = item 高 + gap」的可见形式): + * ① 相邻卡顶间距 = MENU_LIST_ROW_H(= 卡高 + gap;SDK 行距不变); + * ② 卡片间可见外距 = MENU_LIST_ROW_GAP; + * ③ 卡在其行高内上下对称内缩 → 内容(按行高垂直居中)落卡中心; + * ④ 滚动偏移只整体平移,不改变上述间距/对称。 + * + * 几何公式与 patch_v2/meow_launcherd/main_menu.c 的 menu_row_card_y/menu_row_card_h 同源: + * 卡顶 = 行顶 + gap/2;卡高 = 行高 - gap。 + */ +#include +#include + +#define MENU_LIST_ROW_H 60 /* 行距(SDK listview item_h,不变) */ +#define MENU_LIST_ROW_GAP 8 + +/* 与 main_menu.c menu_row_card_y / menu_row_card_h 同源(上下对称内缩)。 */ +static int menu_row_card_y(int row_top) { return row_top + MENU_LIST_ROW_GAP / 2; } +static int menu_row_card_h(int h) { return h - MENU_LIST_ROW_GAP; } +/* 行顶 = list_y + idx*item(SDK listview 布局:行距=item)。 */ +static int row_top(int idx, int item, int list_y, int off) { return list_y + idx * item - off; } + +int main(void) +{ + const int item = MENU_LIST_ROW_H; + const int gap = MENU_LIST_ROW_GAP; + const int list_y = 100; + + int y0 = menu_row_card_y(row_top(0, item, list_y, 0)); + int y1 = menu_row_card_y(row_top(1, item, list_y, 0)); + int h = menu_row_card_h(item); + + /* ① 卡相对行顶对称内缩 gap/2;卡高=item-gap;卡高+gap=item */ + assert(y0 == list_y + gap / 2); + assert(h == item - gap); + assert(h + gap == item); + + /* ① 相邻卡顶间距 = item(顶到顶 = 卡高 + gap) */ + assert(y1 - y0 == item); + + /* ② 卡片间可见外距 = gap(卡 0 底 到 卡 1 顶) */ + assert(y1 - (y0 + h) == gap); + + /* ③ 卡中心 == 行中心(内容按行高居中 → 落卡中心) */ + assert(y0 - gap / 2 + item / 2 == y0 + h / 2); + /* 上行底到卡底 = gap/2(下对称) */ + assert((list_y + item) - (y0 + h) == gap / 2); + + /* ④ 滚动偏移只平移,不改变间距/对称(任意 off) */ + for (int off = 0; off <= 2 * item; off += item / 2) { + int r2 = row_top(2, item, list_y, off); + int r3 = row_top(3, item, list_y, off); + int a2 = menu_row_card_y(r2); + int a3 = menu_row_card_y(r3); + assert(a3 - a2 == item); + assert(a3 - (a2 + h) == gap); + assert(a2 - r2 == gap / 2); + assert((r2 + item) - (a2 + h) == gap / 2); + } + + printf("PASS menu_row_gap=%d card_h=%d top2top=%d visible_gap=%d symmetric=1\n", + gap, h, item, gap); + return 0; +}