mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-05-10 02:09:46 +08:00
feat(ui): 为路径列表添加斑马纹样式并移除横线分隔符
- 新增 refresh_list_style 函数,根据行号奇偶性设置交替背景色 - 在列表加载、新增、删除、上下移动条目时自动刷新样式 - 移除原有的横线分隔符,使界面更简洁 - 调整主函数中控制台编码设置的位置
This commit is contained in:
@@ -13,4 +13,7 @@ wchar_t* utf8_to_wide(const char* str);
|
|||||||
// 检查管理员权限
|
// 检查管理员权限
|
||||||
int check_admin();
|
int check_admin();
|
||||||
|
|
||||||
|
// 刷新列表样式(斑马纹)
|
||||||
|
void refresh_list_style();
|
||||||
|
|
||||||
#endif // UTILS_H
|
#endif // UTILS_H
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "callbacks.h"
|
#include "callbacks.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "registry.h"
|
#include "registry.h"
|
||||||
|
#include "utils.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@@ -17,6 +18,8 @@ int btn_new_cb(Ihandle *self)
|
|||||||
IupSetAttributeId(list_path, "", count, buffer);
|
IupSetAttributeId(list_path, "", count, buffer);
|
||||||
IupSetInt(list_path, "COUNT", count);
|
IupSetInt(list_path, "COUNT", count);
|
||||||
IupSetInt(list_path, "VALUE", count);
|
IupSetInt(list_path, "VALUE", count);
|
||||||
|
|
||||||
|
refresh_list_style();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return IUP_DEFAULT;
|
return IUP_DEFAULT;
|
||||||
@@ -63,6 +66,8 @@ int btn_browse_cb(Ihandle *self)
|
|||||||
IupSetAttributeId(list_path, "", count, value);
|
IupSetAttributeId(list_path, "", count, value);
|
||||||
IupSetInt(list_path, "COUNT", count);
|
IupSetInt(list_path, "COUNT", count);
|
||||||
IupSetInt(list_path, "VALUE", count);
|
IupSetInt(list_path, "VALUE", count);
|
||||||
|
|
||||||
|
refresh_list_style();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IupDestroy(filedlg);
|
IupDestroy(filedlg);
|
||||||
@@ -77,6 +82,9 @@ int btn_del_cb(Ihandle *self)
|
|||||||
return IUP_DEFAULT;
|
return IUP_DEFAULT;
|
||||||
|
|
||||||
IupSetAttribute(list_path, "REMOVEITEM", "SELECTED");
|
IupSetAttribute(list_path, "REMOVEITEM", "SELECTED");
|
||||||
|
|
||||||
|
// 重新刷新,因为删除了中间项,后面的奇偶性变了
|
||||||
|
refresh_list_style();
|
||||||
return IUP_DEFAULT;
|
return IUP_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,6 +109,9 @@ int btn_up_cb(Ihandle *self)
|
|||||||
IupSetAttributeId(list_path, "", selected - 1, buf_curr);
|
IupSetAttributeId(list_path, "", selected - 1, buf_curr);
|
||||||
|
|
||||||
IupSetInt(list_path, "VALUE", selected - 1);
|
IupSetInt(list_path, "VALUE", selected - 1);
|
||||||
|
|
||||||
|
// 刷新样式(虽然颜色不需要变,但为了保险)
|
||||||
|
refresh_list_style();
|
||||||
return IUP_DEFAULT;
|
return IUP_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,6 +136,8 @@ int btn_down_cb(Ihandle *self)
|
|||||||
IupSetAttributeId(list_path, "", selected + 1, buf_curr);
|
IupSetAttributeId(list_path, "", selected + 1, buf_curr);
|
||||||
|
|
||||||
IupSetInt(list_path, "VALUE", selected + 1);
|
IupSetInt(list_path, "VALUE", selected + 1);
|
||||||
|
|
||||||
|
refresh_list_style();
|
||||||
return IUP_DEFAULT;
|
return IUP_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-10
@@ -21,14 +21,6 @@ Ihandle *btn_ok, *btn_cancel, *btn_help;
|
|||||||
// 主函数
|
// 主函数
|
||||||
int main(int argc, char **argv)
|
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 之前
|
// 强制设置 UTF8MODE 环境变量,必须在 IupOpen 之前
|
||||||
putenv("IUP_UTF8MODE=YES");
|
putenv("IUP_UTF8MODE=YES");
|
||||||
|
|
||||||
@@ -38,12 +30,11 @@ int main(int argc, char **argv)
|
|||||||
// 创建列表控件
|
// 创建列表控件
|
||||||
list_path = IupFlatList();
|
list_path = IupFlatList();
|
||||||
IupSetAttribute(list_path, "EXPAND", "YES");
|
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, "ITEMPADDING", "5x5");
|
||||||
IupSetAttribute(list_path, "BACKCOLOR", "255 255 255");
|
IupSetAttribute(list_path, "BACKCOLOR", "255 255 255");
|
||||||
IupSetAttribute(list_path, "BORDER", "YES");
|
IupSetAttribute(list_path, "BORDER", "YES");
|
||||||
IupSetAttribute(list_path, "CANFOCUS", "YES");
|
IupSetAttribute(list_path, "CANFOCUS", "YES");
|
||||||
|
IupSetAttribute(list_path, "HLINE", "NO"); // 禁用横线,使用斑马纹
|
||||||
// IupFlatList 不支持 VISIBLELINES,高度由 EXPAND 和布局决定
|
// IupFlatList 不支持 VISIBLELINES,高度由 EXPAND 和布局决定
|
||||||
|
|
||||||
// 创建右侧按钮
|
// 创建右侧按钮
|
||||||
|
|||||||
@@ -85,6 +85,9 @@ void load_path()
|
|||||||
IupSetInt(list_path, "COUNT", count); // 显式设置列表项数量
|
IupSetInt(list_path, "COUNT", count); // 显式设置列表项数量
|
||||||
IupSetInt(list_path, "VALUE", 1); // 选中第一项
|
IupSetInt(list_path, "VALUE", 1); // 选中第一项
|
||||||
|
|
||||||
|
// 刷新斑马纹样式
|
||||||
|
refresh_list_style();
|
||||||
|
|
||||||
char status_msg[100];
|
char status_msg[100];
|
||||||
sprintf(status_msg, "状态: 已加载 %d 个条目", count);
|
sprintf(status_msg, "状态: 已加载 %d 个条目", count);
|
||||||
IupSetAttribute(lbl_status, "TITLE", status_msg);
|
IupSetAttribute(lbl_status, "TITLE", status_msg);
|
||||||
|
|||||||
+22
@@ -1,4 +1,5 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "globals.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <iup.h>
|
#include <iup.h>
|
||||||
@@ -37,3 +38,24 @@ int check_admin()
|
|||||||
}
|
}
|
||||||
return 0;
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user