
Zgui: Native Rust UI with fine-grained signals, CSS, and a retained GPU renderer
A native Rust UI framework with fine-grained reactivity, real CSS and a retained GPU renderer.
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
A native Rust UI framework with fine-grained reactivity, real CSS and a retained GPU renderer.
Documentation · Getting started · Components · Discord
zgui combines a Leptos-style programming model with a browser-engine-style rendering pipeline. Components run once. Signals update only the parts of the interface that read them, and every stage after that (style, layout, paint and the final pixels) keeps the work it can reuse. Windows are native and drawn with wgpu. There is no webview, HTML or JavaScript.
zgui is experimental and changes often. Expect breaking changes between 0.x releases.
A slightly larger counter is in examples/counter.rs:
cargo run -p zgui-examples --example counter
Components and theming
zgui-ui ports most of shadcn/ui: buttons, fields, selects, menus, dialogs, popovers, toasts, tabs, sidebars, tables, charts, calendars and more. Headless primitives for focus, dismissal, anchored positioning and roving selection are available on their own in zgui-ui-primitives.
use zgui::prelude::; use zgui_ui::prelude::;
#[component] fn Deploy() -> impl IntoView { let branch = RwSignal::new_local("main".to_owned()); let migrate = RwSignal::new_local(true);
view! { Card { CardHeader { CardTitle {"Deploy storefront"} CardDescription {"Ships the branch to production."} } CardContent { Input(value = branch, label = "Branch") Switch(checked = migrate, a11y:label = "Run migrations") } CardFooter { Button(variant = ButtonVariant::Outline) {"Preview"} Button {"Deploy"} } } } }
Every component reads its look from design tokens: colors, radii, spacing, shadows, type and motion. A theme sets some or all of them, and ThemeProvider applies it to a window or a subtree. Changing a theme at runtime is a signal write.
use zgui_ui_tokens::prelude::*;
let mocha = Theme::dark().with_css( "--zui-color-background: #1e1e2e; --zui-color-primary: #cba6f7; --zui-radius-base: 8px; --zui-space-base: 3.5px; --zui-shadow-sm: none; --zui-type-family-sans: 'Readex Pro';", );
view! { ThemeProvider(dark = mocha, scheme = ColorScheme::Dark) { Deploy() } }
See the component list and tokens and theming for everything that is available.
components + reactive_graph signals │ precise node mutations ▼ retained document │ restyle / relayout / repaint ▼ Stylo cascade → cephal layout + Parley text │ fragments, hit regions, damage ▼ retained paint recordings │ scene + damage rectangles ▼ wgpu renderer + Vello │ ▼ persistent render target
The stages follow a browser engine: document, cascade, layout, paint and composition. zgui uses a small native element vocabulary instead of HTML, and each stage is a replaceable, testable crate.
Each stage passes only the work it owes to the next:
A color change needs paint and no layout. Scrolling moves retained content and draws only the band that comes into view. Wide changes, such as a window resize or a new theme, still reach more nodes, and zgui exposes counters and headless probes so you can measure where that boundary is.
holokube: a Kubernetes desktop client.
zdt: a modal code editor with splits, a file tree, LSP, Git, terminals and coding-agent workflows.
Canora: a Spotify client with playback, playlists, search, custom window chrome and light and dark themes.
moqspeak: voice chat and screen sharing over Media over QUIC.
zgui-flow: node graphs and diagrams, in the style of React Flow.
zgui-editor: an embeddable code editor with incremental tree-sitter highlighting, multiple cursors and large-file support.
zgui-terminal: an embeddable terminal emulator with scrollback, selection and modern keyboard protocols.
Comparison with other Rust UI frameworks
These notes compare architecture and project scope. They are not benchmark results. A sparse update changes one small part of a large interface. A wide update changes many nodes or a shared dependency. In every framework, layout can make either kind of update wider.
The maturity notes reflect the upstream repositories and documentation on 2026-08-27.
Iced organizes an application as state, messages, update and view. The model is explicit and easy to trace: widgets produce messages, update changes state, and view describes the result.
Iced is a strong choice when an Elm-style message flow, a mature widget set, web support or a software-rendering fallback matter most. For a wide, frequently changing desktop interface, its view-level boundary gives the application author more of the performance work than zgui's dependency-driven model.
egui is an immediate-mode UI library. Application code reads and changes state while it declares the visible controls, on every requested frame.
egui's strength is simplicity. It is fast enough, and often the best trade, for debug tools, game and engine overlays, and applications with a small or simple interface. zgui targets the other end: large, flex-heavy desktop interfaces where retained layout and sparse updates pay for the extra machinery.
GPUI is Zed's hybrid immediate and retained UI framework. State lives in framework-owned Entity<T> values and is accessed through explicit application, window and entity contexts.
GPUI is production-tested. That is different from an efficient update architecture. Zed is fast because it is carefully engineered: its application chrome is simple, and difficult paths such as the editor and long lists use specialized elements and caches. The framework makes sparse CPU work easy to widen, and its manual caching model buys no capability that needs that coarseness. zgui also offers custom layout and painting, raw GPU surfaces and a replaceable renderer, and in addition derives dependencies automatically and retains work through the later pipeline stages.
Floem also builds its main view tree once and updates it with signals. Its reactive API is inspired by Leptos, with Floem's own implementation.
Floem is the most direct alternative when build-once views and signals come first, especially if you prefer typed Rust styling to CSS. Its application-side incrementality is close to zgui's. The largest difference is how far that incrementality continues into painting and composition.
Dioxus Native renders a Dioxus virtual DOM through Blitz instead of a system webview. Blitz and zgui share several building blocks: Stylo for CSS, Parley for text, AccessKit for accessibility and a GPU renderer. Blitz uses Taffy for layout, and zgui uses cephal.
Dioxus Native is attractive when you want to share Dioxus components and skills across web, webview and native renderers. zgui specializes in native application UI and binding-level incrementality.
Add zgui, and the component library if you want it, from crates.io:
[dependencies] zgui = "0.1" zgui-ui = "0.1" zgui-ui-tokens = "0.1"
zgui builds on stable Rust 1.90 or later. On Linux, install pkg-config, libxkbcommon, libwayland, the X11 libraries (libx11, libxcb, libxcursor, libxi, libxrandr) and fontconfig.
The zgui repository patches fontique, the font collection under the text engine, so that it keeps resolved font families from one paragraph to the next and, on Linux, keeps the system font collection in a cache file between launches (ZGUI_FONT_CACHE=off disables it). A crates.io build uses the released fontique, which shows the same text and resolves fonts more slowly. To use the patched copy, add this to your application's Cargo.toml:
[patch.crates-io] fontique = { git = "https://github.com/zortax/zgui", tag = "v0.1.0" }
To run the examples, clone the repository. Some examples to try:
cargo run -p zgui-ui --example gallery cargo run -p zgui-examples --example todo cargo run -p zgui-examples --example vector cargo run -p zgui-examples --example surface
The examples/ directory also covers async work, multiple windows, images, canvas drawing, custom elements, custom shaders and custom window chrome. The installation guide walks through a first application.
Ask questions and share what you build on Discord. Read CONTRIBUTING.md before you open a pull request.
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。