capy-ui/capy
๐ปBuild one codebase and get native UI on Windows, Linux and Web
362d12f4d91dfde84668e0befc5a8ca76659965a.zip
a4ea24f105902111633c6ae9f888b676ac5e36df.tar.gz
c3bd7f9d593d75c60e70f0a950f499e55bd2a965
0.14.0-dev.1911+3bf89f55c
/ 2024.10.0-mach
(Nominated Zig versions)
, it doesn't work on Zig 0.13.0
Introduction
Capy is a GUI library for Zig. It is mainly intended for creating applications using native controls from the operating system.
Capy is a declarative UI library aiming to be easy to write for and versatile.
It has been made with the goal to empower standalone UI applications, integration in games or any other rendering process is a non-goal.
Features
var window = try capy.Window.init();
try window.set(
capy.column(.{ .spacing = 10 }, .{ // have 10px spacing between each column's element
capy.row(.{ .spacing = 5 }, .{ // have 5px spacing between each row's element
capy.button(.{ .label = "Save", .onclick = @ptrCast(&buttonClicked) }),
capy.button(.{ .label = "Run", .onclick = @ptrCast(&buttonClicked) })
}),
// 'expanded' means the widget will take all the space it can
// in the parent container
capy.expanded(
capy.textArea(.{ .text = "Hello World!" })
)
})
);
window.setPreferredSize(800, 600);
window.show();
capy.runEventLoop();
}
fn buttonClicked(button: *capy.Button) !void {
std.log.info("You clicked the button with text {s}", .{button.getLabel()});
}
```
It is easy to add something like a button or a text area. The example can already be used to notice a widget's parameters are usually enclosed in anonymous
structs (.{ .label = "Save" }
). You can also see that simply wrapping a widget with capy.Expanded( ... )
will tell it to take all the space it can.
Contributing
Contributing can be as simple as opening an issue and detailling what bug you encountered or what feature you wish to have.
If you want to help the project more directly, you can fork the project and then create a pull request.
Supported platforms
A platform is considered supported only if it can be built to from every other OS.
Legends:
- โ
Working and can be cross-compile from all platforms supported by Zig
- ๐งช Experimental
- ๐ Planned
Desktop
โ
Windows x86_64
โ
Windows i386
๐ macOS M1
๐ macOS x86_64
โ
Linux x86_64
โ
Linux i386
โ
Linux aarch64 (PinePhone, PineBook...)
โ
FreeBSD x86_64
Mobile
๐งช Android
๐ iOS
Web
โ
WebAssembly
Note: As there's no "official" GUI library for Linux, GTK 4 has been chosen as it is the one
that works and can be configured on the most distros. It's also the reason Libadwaita won't
be adopted, as it's meant for GNOME and GNOME only by disallowing styling and integration
with other DEs.
Supported components
For now, not every platform supports the same components. So here's a list of the ones that are supported:
| |win32|macOS|GTK|Android|wasm|
|------------------|-----|-----|---|-----|-----|
|Button |โ
|โ
|โ
|โ
|โ
|
|Canvas |โ|โ|โ
|โ
|โ
|
|CheckBox |โ
|โ|โ
|โ|โ|
|Dropdown |โ
|โ|โ
|โ|โ|
|Image |โ|โ|โ
|โ|โ
|
|Label |โ
|โ
|โ
|โ
|โ
|
|Menu |โ|โ|โ|โ|โ|
|Navigation |โ|โ|โ|โ|โ|
|NavigationSidebar |โ|โ|โ
|โ|โ|
|Scrollable |โ
|โ|โ
|โ|โ|
|Slider |โ
|โ|โ
|โ|โ
|
|Tabs |โ
|โ|โ
|โ|โ|
|TextArea |โ
|โ|โ
|โ|โ|
|TextField |โ
|โ|โ
|โ
|โ
|
|Window |โ
|โ
|โ
|โ
|โ