forked from shahwali/knots
High performance immediate-mode GUI rendering library.
- Zig 95.9%
- WGSL 2.1%
- GLSL 1.5%
- C 0.5%
| examples | Move to Vulkan v1.3 | |
| src | more updates for 0.17 | |
| tests/snapshots | Add GPU rendering qoi snapshot tests | |
| .gitignore | init | |
| build.zig | more updates for 0.17 | |
| build.zig.zon | Merge branch 'shahwali-main' | |
| LICENSE.md | init | |
| README.md | Select GPU backends at compile time and improve UI accessibility ( #13 ) | |
Knots
Knots is a high performance cross-platform immediate-mode GUI library written in Zig.
Requirements
- Zig compiler, minimum version can be found in build.zig.zon. I try to keep up with the master branch.
- If using the Vulkan backend, glslc must be installed and accessible on the system. This is due to the shaders used in the Vulkan backend being compiled as part of building knots.
- On Linux, Wayland development packages are required: wayland-client, wayland-cursor, wayland-protocols, wayland-scanner, pkg-config, and xkbcommon.
Install
zig fetch --save git+https://codeberg.org/shahwali/knots.git
Minimal app
// build.zigconstGPUBackend=@import("knots").GPUBackend;constknots=b.dependency("knots",.{.target=target,.optimize=optimize,.gpu_backend=GPUBackend.vulkan});exe.root_module.addImport(knots.module("knots"));// ormod.addImport(knots.module("knots"));conststd=@import("std");constknots=@import("knots");pubfnmain(init:std.process.Init)!void{varapp=tryknots.App.init(init.io,init.gpa,.{.window=.{.width=1280,.height=720,.title="Playground",},});deferapp.deinit();tryapp.start(frameCb);}fnframeCb(app:*knots.App)!void{constsize=app.window.getSize();returnapp.e(.{knots.component.Rect{.width=.fixed(@floatFromInt(size.width)),.height=.fixed(@floatFromInt(size.height)),.padding=.init(16,16,16,16),.dir=.column,.key=.src(@src()),},});}Supported platforms:
| Platform | Supported GPU APIs |
|---|---|
| macOS | WebGPU and Vulkan (MoltenVK) |
| Linux | WebGPU and Vulkan |
| Windows | WebGPU and Vulkan |
| Web (emscripten) | WebGPU |
Distributing Vulkan applications on macOS
Knots checks for a bundled Vulkan loader before falling back to the system loader. A standalone application bundle using the Vulkan backend must include the loader, MoltenVK, and its ICD manifest:
MyApp.app/Contents/Frameworks/libvulkan.1.dylib
MyApp.app/Contents/Frameworks/libMoltenVK.dylib
MyApp.app/Contents/Resources/vulkan/icd.d/MoltenVK_icd.json
The manifest's library_path must resolve to the bundled libMoltenVK.dylib.
Examples
See examples, you can also try the web version of the playground here.
Goals
Below goals are listed in order of importance.
- Provide a way to build highly performant cross-platform desktop applications.
- UI code should get out of the way, letting the developer spend more time on actual problems.
- Minimal lean builds, fast compile times.
- Highly configurable, with sane defaults.
Known limitations
- Linux windowing is Wayland-only.
- Text rendering is UTF-8/codepoint based. HarfBuzz shaping, bidi layout, ligatures, font fallback, and IME composition are not implemented yet.