From fd9dca924aa78659eb33b3c87f8a0d9352fc092d Mon Sep 17 00:00:00 2001 From: LHY0125 <3364451258@qq.com> Date: Mon, 16 Mar 2026 17:44:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20=E4=B8=BA=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=B7=BB=E5=8A=A0=E6=96=91=E9=A9=AC=E7=BA=B9?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E5=B9=B6=E7=A7=BB=E9=99=A4=E6=A8=AA=E7=BA=BF?= =?UTF-8?q?=E5=88=86=E9=9A=94=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 refresh_list_style 函数,根据行号奇偶性设置交替背景色 - 在列表加载、新增、删除、上下移动条目时自动刷新样式 - 移除原有的横线分隔符,使界面更简洁 - 调整主函数中控制台编码设置的位置 --- include/utils.h | 3 +++ src/callbacks.c | 13 +++++++++++++ src/main.c | 11 +---------- src/registry.c | 5 ++++- src/utils.c | 22 ++++++++++++++++++++++ 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/include/utils.h b/include/utils.h index b4aba0e..dd775a6 100644 --- a/include/utils.h +++ b/include/utils.h @@ -13,4 +13,7 @@ wchar_t* utf8_to_wide(const char* str); // 检查管理员权限 int check_admin(); +// 刷新列表样式(斑马纹) +void refresh_list_style(); + #endif // UTILS_H \ No newline at end of file diff --git a/src/callbacks.c b/src/callbacks.c index 405aaca..770e22f 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -1,6 +1,7 @@ #include "callbacks.h" #include "globals.h" #include "registry.h" +#include "utils.h" #include #include @@ -17,6 +18,8 @@ int btn_new_cb(Ihandle *self) IupSetAttributeId(list_path, "", count, buffer); IupSetInt(list_path, "COUNT", count); IupSetInt(list_path, "VALUE", count); + + refresh_list_style(); } } return IUP_DEFAULT; @@ -63,6 +66,8 @@ int btn_browse_cb(Ihandle *self) IupSetAttributeId(list_path, "", count, value); IupSetInt(list_path, "COUNT", count); IupSetInt(list_path, "VALUE", count); + + refresh_list_style(); } } IupDestroy(filedlg); @@ -77,6 +82,9 @@ int btn_del_cb(Ihandle *self) return IUP_DEFAULT; IupSetAttribute(list_path, "REMOVEITEM", "SELECTED"); + + // 重新刷新,因为删除了中间项,后面的奇偶性变了 + refresh_list_style(); return IUP_DEFAULT; } @@ -101,6 +109,9 @@ int btn_up_cb(Ihandle *self) IupSetAttributeId(list_path, "", selected - 1, buf_curr); IupSetInt(list_path, "VALUE", selected - 1); + + // 刷新样式(虽然颜色不需要变,但为了保险) + refresh_list_style(); return IUP_DEFAULT; } @@ -125,6 +136,8 @@ int btn_down_cb(Ihandle *self) IupSetAttributeId(list_path, "", selected + 1, buf_curr); IupSetInt(list_path, "VALUE", selected + 1); + + refresh_list_style(); return IUP_DEFAULT; } diff --git a/src/main.c b/src/main.c index 44d476a..f9e5676 100644 --- a/src/main.c +++ b/src/main.c @@ -21,14 +21,6 @@ Ihandle *btn_ok, *btn_cancel, *btn_help; // 主函数 int main(int argc, char **argv) { - // 设置控制台编码为UTF-8,防止中文乱码 -#ifdef _WIN32 - system("chcp 65001 > nul"); // 设置控制台编码为UTF-8 - SetConsoleOutputCP(65001); // 设置控制台输出编码 - SetConsoleCP(65001); // 设置控制台输入编码 - _mkdir("records"); -#endif - // 强制设置 UTF8MODE 环境变量,必须在 IupOpen 之前 putenv("IUP_UTF8MODE=YES"); @@ -38,12 +30,11 @@ int main(int argc, char **argv) // 创建列表控件 list_path = IupFlatList(); IupSetAttribute(list_path, "EXPAND", "YES"); - IupSetAttribute(list_path, "HLINE", "YES"); - IupSetAttribute(list_path, "HLINECOLOR", "100 100 100"); // 灰色 IupSetAttribute(list_path, "ITEMPADDING", "5x5"); IupSetAttribute(list_path, "BACKCOLOR", "255 255 255"); IupSetAttribute(list_path, "BORDER", "YES"); IupSetAttribute(list_path, "CANFOCUS", "YES"); + IupSetAttribute(list_path, "HLINE", "NO"); // 禁用横线,使用斑马纹 // IupFlatList 不支持 VISIBLELINES,高度由 EXPAND 和布局决定 // 创建右侧按钮 diff --git a/src/registry.c b/src/registry.c index a29bef8..1b9f6bb 100644 --- a/src/registry.c +++ b/src/registry.c @@ -84,7 +84,10 @@ void load_path() IupSetInt(list_path, "COUNT", count); // 显式设置列表项数量 IupSetInt(list_path, "VALUE", 1); // 选中第一项 - + + // 刷新斑马纹样式 + refresh_list_style(); + char status_msg[100]; sprintf(status_msg, "状态: 已加载 %d 个条目", count); IupSetAttribute(lbl_status, "TITLE", status_msg); diff --git a/src/utils.c b/src/utils.c index d346a8b..8514d69 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,4 +1,5 @@ #include "utils.h" +#include "globals.h" #include #include #include @@ -36,4 +37,25 @@ int check_admin() return 1; } return 0; +} + +// 刷新列表样式(斑马纹) +void refresh_list_style() +{ + if (!list_path) + return; + int count = IupGetInt(list_path, "COUNT"); + for (int i = 1; i <= count; i++) + { + // 奇数行:白色 + // 偶数行:极浅灰色 (245 245 245) + if (i % 2 == 0) + { + IupSetAttributeId(list_path, "ITEMBGCOLOR", i, "245 245 245"); + } + else + { + IupSetAttributeId(list_path, "ITEMBGCOLOR", i, "255 255 255"); + } + } } \ No newline at end of file