# core-ui (ghboke) **Repository Path**: xwadmin/core-ui-ghboke ## Basic Information - **Project Name**: core-ui (ghboke) - **Description**: 镜像加速 简化,重构的UI库 C API风格。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2026-04-17 - **Last Updated**: 2026-07-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

CORE UI

English · 中文  ·  📖 在线文档

**Core UI** 是一个现代化的 Windows 桌面 UI 框架,底层基于 **Direct2D / Direct3D 11** 硬件加速渲染,对齐 Microsoft **Fluent 2** 视觉语言,把从按钮、文本框到 Flyout、Dialog、TitleBar 的 25+ 个内置控件统一在一套**纯 C API**(250+ 个导出函数)之下——Rust、Go、Python、C#、Delphi 乃至 Lua 都能直接调用,不需要写 C++ 绑定层。界面推荐用 **`.uix` 单文件组件**(Vue 3 SFC 风格:`` + ` ``` - **Vue 3 Options API**:`data()` / `computed` / `methods`,QuickJS-NG (ES2020+) 求值 - **响应式系统**:Proxy + WatchEffect,`{{ expr }}` / `:attr` / `v-if` / `v-for` / `v-model` / `@click` 自动收集依赖、增量重渲染 - **CSS 子集**:类 / 标签 / 后代选择器、伪类(`:hover` / `:disabled`)、Flexbox、`var(--*)` CSS 变量主题 - **i18n 内置**:`{{ $t('welcome') }}` 自动查 `.lang` 文件,运行时 `ui_page_set_locale` 切语言 - **声明式右键菜单**:`` + `` / `` ### 🌐 纯 C API,所有语言都能调 ```c #include ui_init_with_theme(UI_THEME_LIGHT); UiPage page = ui_page_load_file(L"app.uix"); ui_page_set_locale(page, "zh"); UiWindow win = ui_page_open_window(page, NULL); /* 双向交换 reactive 状态 */ ui_page_set_int (page, "count", 42); ui_page_set_json(page, "items", "[{\"id\":1,\"label\":\"a\"}]"); char* j = ui_page_get_json(page, "items"); ui_page_free(j); ui_run(); ui_page_destroy(page); ``` - **250+ 导出函数**,句柄全部 `uint64_t`,没有一个 C++ 类型泄漏 - Rust / Go / Python / C# / Delphi / Pascal / Lua 全部能直接绑定 - 任意 widget(含 `` 自绘 widget)都能挂 `ui_widget_on_mouse_*` / `on_focus` / `on_wheel` 等全套事件回调,不再受"只有 button / input 能拿 onclick"的限制 ### 🔍 自动化 / 调试:控件可编程驱动 ```c ui_debug_click(win, btn); // 完整 mouse down/up,触发 onClick ui_debug_combo_select(win, combo, 2); // 选中第 3 项 + 触发 onChanged ui_debug_right_click_at(win, 300, 200); // 右键弹出注册的 context menu ui_debug_type_text(win, L"hello"); // 逐字符键盘输入 ``` - **60+ 个 `ui_debug_*` 函数**(click / hover / drag / wheel / key / focus / 子菜单 path 点击 …)+ 内置 **Named Pipe IPC**(45+ 命令),PowerShell / Python 一行驱动,为端到端测试、AI Agent 操作 UI、脚本化回归设计 - 完整参考见 **[`docs/debug-simulation.md`](./docs/debug-simulation.md)** ## 🚀 快速开始 ### 环境要求 - Windows 10 (1709+) · CMake 3.20+ · **MSVC 2019+ 或 clang-cl**(C++17)— 不支持 MinGW ### 构建 构建必须从 PowerShell 调用项目自带脚本(自动配置 vcvars64、用 llvm-rc 绕过 Windows SDK rc.exe 在 ninja 子进程里挂死的 bug): ```powershell powershell -NoProfile -ExecutionPolicy Bypass ` -File scripts/build-clang-cl.ps1 -Target core-ui ``` | Target | 产物 | |---|---| | `core-ui` | `core-ui.dll` + `core-ui.lib` 导入库(默认) | | `core-ui-static` | `core-ui-static.lib` 自包含静态归档(含 QuickJS) | | `ui-demo-uix` | `ui-demo-uix.exe` 单文件 demo(资源烤进 exe) | | `golden_runner` | `golden_runner.exe` 黄金图回归测试 | 加 `-Clean` 强制重建 build 目录;省略 `-Target` 编全部;`-Static` 产单 exe(无 DLL 依赖)。 ### Hello World 把上面 `.uix` 单文件组件那段存成 `hello.uix`,再写十行 C 胶水即可跑起来: ```cpp #include int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { ui_init_with_theme(UI_THEME_LIGHT); UiPage page = ui_page_load_file(L"hello.uix"); if (!page) return 1; UiWindow win = ui_page_open_window(page, NULL); if (!win) { ui_page_destroy(page); return 2; } int ret = ui_run(); ui_page_destroy(page); return ret; } ``` 就这么多。**没有 .vcxproj、没有 moc 预处理器、没有 XAML 编译器、没有 IDL。** ### 单 exe 打包(资源烤进可执行文件) ```cmake include(cmake/UiCoreHelpers.cmake) add_executable(my-app WIN32 main.cpp) target_link_libraries(my-app PRIVATE core-ui) ui_core_embed_text(my-app FILE app.uix OUT app.embed.h VAR k_app) ui_core_embed_text(my-app FILE lang/zh.lang OUT lang_zh.embed.h VAR k_lang_zh) ``` ```cpp UiPage page = ui_page_load_string(k_app); ui_page_load_language_string(page, "zh", k_lang_zh); ``` `demo/ui_demo_uix.cpp` 就是这种用法的最小完整例子(57 行胶水 + 单 `.uix` 文件 12 页 demo)。 ## 🧩 内置控件 / 标签 `.uix` 模板里的标签直接映射到原生 widget: | 类别 | 标签 | |---|---| | **容器** | `div`(Flexbox:`flex-direction` / `flex` / `gap` / `padding`)| | **文本** | `label`(多行、自动换行)| | **按钮** | `button`、`IconButton` | | **输入** | `input`(type=`text` / `password` / `checkbox` / `radio` / `range` / `number`)、`textarea` | | **选择** | `toggle`、`combobox` | | **状态** | `progressbar`,`badge` 类(CSS)| | **弹出** | `menu` / `menuitem` / `separator`、`Flyout`、`Dialog`、`Toast` | | **图像** | `img`、`svg`(内联),底层 `ImageView` 支持缩放 / 平移 / 裁剪 | | **窗口** | `TitleBar`(仅 `frameless="true"` 时使用) | 需要程序化构造时,C API 也提供 `ui_vbox` / `ui_hbox` / `ui_label` / `ui_button` / `ui_text_input` / `ui_combobox` / `ui_slider` / `ui_progress_bar` / `ui_image_view` / `ui_scroll_view` 等工厂函数。 ## 🎨 主题 内置 Fluent 2 深色 / 浅色主题,运行时一行切换: ```c ui_theme_set_mode(UI_THEME_DARK); ui_theme_set_mode(UI_THEME_LIGHT); ``` `.uix` 的 `