v0.1.0-alpha
官网Home
docs/overview

zenit 开发手册The zenit manual

用 Zig 构建真正原生的 macOS 桌面界面。zenit 把窗口、GPU 渲染、文本、输入法与无障碍收进一个清晰的 UI 模型;这份手册带你从第一扇窗口走到可维护的生产应用。Build truly native macOS desktop UI in Zig. zenit folds windows, GPU rendering, text, input methods and accessibility into one clear UI model; this manual takes you from your first window to a maintainable production app.

0.15.2Zig 版本Zig version
Metal当前 GPU 后端Current GPU backend
2 tiers公开 API:ui.X 与 ui.<group>.XPublic API: ui.X and ui.<group>.X
src/main.zig
const std = @import("std");
const ui = @import("ui");
const App = @import("zenit_app").App;

fn mountUi(cx: *ui.Cx, _: *ui.Scope) anyerror!*ui.Node {
    return ui.text(cx, "Hello, zenit!", .{
        .font_size = cx.tokens.font_size.xxxl,
        .color = cx.tokens.color.fg_primary,
    });
}

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();

    const app = try App.init(gpa.allocator(), .{
        .window = .{ .title = "Hello" },
    });
    defer app.deinit();
    try app.runWith(mountUi);
}
用 Claude Code 或其他 Agent 开发?先装上 zenit UI dev Skill。Building with Claude Code or another agent? Install the zenit UI dev Skill first.

它把这份手册、组件选型表和真实项目踩过的坑打包成 Agent 能按需加载的说明,写出的代码直接符合 zenit 的约定。It packs this manual, the component decision table and real-project pitfalls into instructions your agent loads on demand, so the code it writes follows zenit conventions.

推荐学习路径Learning path

按顺序完成一次,约 45 分钟,你就拥有独立开发 zenit 应用所需的完整心智模型。Work through it once, in order — about 45 minutes — and you’ll have the whole mental model for building zenit apps on your own.

你将使用的架构The architecture you use

应用只依赖稳定的公开层,平台与渲染细节由 zenit 接管。Apps depend only on the stable public layer; zenit owns platform and rendering.

LAYERS
zenit.attach(dep, exe) 只给你的可执行文件加上 ui 与 zenit_app 两个模块导入,并编译原生桥接、链接系统框架。内部模块不在应用的构建图里,不是「约定不要用」,而是根本导入不到。zenit.attach(dep, exe) adds exactly two module imports to your executable — ui and zenit_app — then compiles the native bridges and links the system frameworks. Internal modules aren’t in your build graph at all: not “please don’t”, but “can’t”.

不只是一组 APIMore than a set of APIs

这三项能力贯穿运行时、文本与工程工具;每一项都有可运行的演示和真实窗口证据。These three run through the runtime, the text stack and the tooling — each backed by a runnable demo and real-window evidence.

三条开发原则Three principles

遵守它们,代码能在 zenit 快速演进的阶段保持清晰。Follow them and your code stays clear while zenit is still moving fast.

01
只从公开层导入Import only from the public layer

应用代码使用 ui.*、ui.<group>.* 与 zenit_app.App,不要深入内部目录。Use ui.*, ui.<group>.* and zenit_app.App — never reach into internal directories.

02
让数据决定 UILet data drive the UI

持久状态放进 Signal 或绑定状态;派生值用 Memo,副作用用 Effect。Persistent state lives in Signals or bound state; derive with Memo, side-effect with Effect.

03
Token 优先Tokens first

颜色、字号、间距与圆角来自主题;确需脱离刻度时,用 ui.arb 明确表达。Color, type, spacing and radii come from the theme; when you must go off-scale, say so with ui.arb.

zenit · 双授权Dual-licensed开源项目可按 GPL-3.0-only 免费使用;闭源或商业产品需要商业授权。Free for open-source projects under GPL-3.0-only; closed-source or commercial products need a commercial license.可联系作者:Contact the author: zongyi.xzy#gmail.com(# 换成 @) (replace # with @)zenit 5f9add5+wip 2026-09-30