重构显示逻辑为 MVP 架构,进行显示模块的解耦

This commit is contained in:
2026-03-24 19:52:22 +08:00
parent a4bf0962b2
commit 0690d6a00e
42 changed files with 2207 additions and 1417 deletions

View File

@@ -0,0 +1,79 @@
#include "test_common.h"
#include <string.h>
#include "../src/Drv/key.h"
#include "../src/Drv/menu/presenter/menu_navigator.h"
static int g_exec_count = 0;
static int on_exec(void)
{
g_exec_count++;
return 0;
}
static void build_two_level(MenuNavState *nav, tagMenuItem *root, tagMenuItem *child_a, tagMenuItem *child_b)
{
memset(nav, 0, sizeof(*nav));
memset(root, 0, sizeof(*root));
memset(child_a, 0, sizeof(*child_a));
memset(child_b, 0, sizeof(*child_b));
root->byClass = 0;
root->wPos = 1;
root->ptLower = child_a;
root->ptBefore = root;
root->ptBehind = root;
child_a->byClass = 1;
child_a->wPos = 1;
child_a->ptHigher = root;
child_a->ptBefore = child_b;
child_a->ptBehind = child_b;
child_a->pfnWinProc = on_exec;
child_b->byClass = 1;
child_b->wPos = 2;
child_b->ptHigher = root;
child_b->ptBefore = child_a;
child_b->ptBehind = child_a;
child_b->pfnWinProc = on_exec;
nav->ptHead = root;
nav->ptCurrent = child_a;
nav->ptCurBak = child_a;
nav->ptRoute[0] = root;
nav->ptRoute[1] = child_a;
}
int main(void)
{
MenuNavState nav;
tagMenuItem root;
tagMenuItem a;
tagMenuItem b;
MenuNavResult result;
build_two_level(&nav, &root, &a, &b);
result = MenuNavigator_ProcessKey(&nav, KEY_D);
ASSERT_EQ_INT(1, result.needRefresh);
ASSERT_TRUE(nav.ptCurrent == &b);
result = MenuNavigator_ProcessKey(&nav, KEY_U);
ASSERT_EQ_INT(1, result.needRefresh);
ASSERT_TRUE(nav.ptCurrent == &a);
g_exec_count = 0;
result = MenuNavigator_ProcessKey(&nav, KEY_ENT);
ASSERT_EQ_INT(0, result.needRefresh);
ASSERT_EQ_INT(1, g_exec_count);
result = MenuNavigator_ProcessKey(&nav, KEY_ESC);
ASSERT_EQ_INT(1, result.skipRenderThisRound);
ASSERT_TRUE(nav.ptCurrent == root.ptLower);
ASSERT_TRUE(nav.ptRoute[0] == &root);
return 0;
}