1/zenith391/zgt v0.129


As of now, Capy is NOT ready for use in production as I'm still making breaking changes


the glorius software in action

Introduction

Capy is a graphical user interface 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.

Usage

A simple application using capy:

const capy = @import("capy");
const std = @import("std");

pub fn main() !void {
    try capy.backend.init();

    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 = buttonClicked }),
                capy.Button(.{ .label = "Run",  .onclick = buttonClicked })
            }),
            // Expanded means the widget will take all the space it can
            // in the parent container
            capy.Expanded(
                capy.TextArea(.{ .text = "Hello World!" })
            )
        })
    );

    window.resize(800, 600);
    window.show();
    capy.runEventLoop();
}

fn buttonClicked(button: *capy.Button_Impl) !void {
    std.log.info("You clicked 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 zgt.Expanded( ... ) will tell it to take all the space it can.

Installation

If you're starting a new project, simply clone capy-template and follow build instructions

Otherwise if you're adding capy to an already existing project:

Before proceeding, you must first install the zigmod package manager. Then, in the folder of your project, you can execute the following commands:

zigmod init

In your build.zig, add:

diff --git a/usr/bin/ziglang/lib/zig/init-exe/build.zig b/build.zig
index 29b50b5..ccbb74b 100644
--- a/usr/bin/ziglang/lib/zig/init-exe/build.zig
+++ b/build.zig
@@ -1,6 +1,7 @@
 const std = @import("std");
+const deps = @import("deps.zig");

-pub fn build(b: *std.build.Builder) void {
+pub fn build(b: *std.build.Builder) !void {
     // Standard target options allows the person running `zig build` to choose
     // what target to build for. Here we do not override the defaults, which
     // means any target is allowed, and the default is native. Other options
@@ -11,7 +12,9 @@ pub fn build(b: *std.build.Builder) void {
     // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
     const mode = b.standardReleaseOptions();

-    const exe = b.addExecutable("$", "src/main.zig");
+    const exe = b.addExecutable("zgt-template", "src/main.zig");
+    const pathToCapy = ".zigmod/deps/git/github.com/zenith391/capy/";
+    try deps.imports.capy.install(exe, pathToCapy);
     exe.setTarget(target);
     exe.setBuildMode(mode);
     exe.install();

And in your zigmod.yml file, add:

diff --git a/default_zigmod.yml b/zigmod.yml
index e39f6f1..4774adb 100644
--- a/default_zigmod.yml
+++ b/zigmod.yml
@@ -2,4 +2,6 @@ id: Random ID
 name: Your app name
 license: Your license
 description: A description.
+build_dependencies:
+    - src: git https://github.com/zenith391/capy
 root_depedencies:

Finally, run

zigmod fetch

For more information, please look in the wiki

Supported platforms

A platform is considered supported only if it can be built from every other OS.

✅ Windows x86_64
✅ Windows i386

✅ Linux x86_64
✅ Linux i386
✅ Linux aarch64 (PinePhone, PineBook...)

✅ FreeBSD x86_64

✅ WebAssembly

🏃 macOS M1
🏃 macOS x86_64

  • ✅ Working and can be cross-compile from all platforms supported by Zig
  • 🏃 Planned

Note: As there's no "official" GUI library for Linux, GTK 3 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.

Package Contents

  • .vscode/tasks.json
  • .gitattributes
  • zigmod.lock
  • LICENSE
  • .github/window_with_a_button.png
  • .github/empty_window.png
  • ziglogo.png
  • include/zgt.h
  • zig.sum
  • examples/foo_app.zig
  • examples/tabs.zig
  • examples/entry.zig
  • examples/colors.zig
  • examples/calculator.zig
  • examples/graph.zig
  • examples/demo.zig
  • examples/fade.zig
  • examples/7gui/README.md
  • examples/7gui/temperature-converter.zig
  • examples/7gui/counter.zig
  • build.zig
  • zigmod.yml
  • build_zgt.zig
  • src/button.zig
  • src/image.zig
  • src/window.zig
  • src/scrollable.zig
  • src/tabs.zig
  • src/fuzz.zig
  • src/backends/gles/shaders/fragment.glsl
  • src/backends/gles/shaders/vertex.glsl
  • src/backends/gles/backend.zig
  • src/backends/shared.zig
  • src/backends/gtk/backend.zig
  • src/backends/gtk/windowbin.zig
  • src/backends/win32/gdip.zig
  • src/backends/win32/res/resource.rc
  • src/backends/win32/res/manifest.xml
  • src/backends/win32/res/i386.o
  • src/backends/win32/res/README.md
  • src/backends/win32/res/x86_64.o
  • src/backends/win32/gdiplus.def
  • src/backends/win32/backend.zig
  • src/backends/win32/win32.zig
  • src/backends/wasm/page.html
  • src/backends/wasm/backend.zig
  • src/backends/wasm/js.zig
  • src/color.zig
  • src/backend.zig
  • src/internal.zig
  • src/c_api.zig
  • src/style.zig
  • src/containers.zig
  • src/text.zig
  • src/main.zig
  • src/data.zig
  • src/widget.zig
  • src/menu.zig
  • src/canvas.zig
  • src/flat/button.zig
  • src/label.zig
  • src/png.zig
  • c_examples/zgt_app.c
  • c_examples/build
  • README.md
  • .gitignore

Dependencies

  • system_lib gtk+-3.0
  • system_lib c

Build Dependencies

  • git https://github.com/Luukdegram/apple_pie

History

Published On Tree @ Commit Size
v0.129 Fri, 29 Jul 2022 17:48:22 UTC Tree 328.941 KB
v0.128 Sun, 24 Jul 2022 01:10:30 UTC Tree 328.917 KB
v0.127 Sun, 24 Jul 2022 00:13:10 UTC Tree 327.430 KB
v0.126 Sat, 23 Jul 2022 23:38:32 UTC Tree 325.950 KB
v0.125 Fri, 22 Jul 2022 16:14:43 UTC Tree 325.912 KB
v0.124 Tue, 19 Jul 2022 19:16:49 UTC Tree 324.681 KB
v0.123 Tue, 19 Jul 2022 19:15:10 UTC Tree 324.681 KB
v0.122 Tue, 19 Jul 2022 19:13:56 UTC Tree 324.685 KB
v0.121 Tue, 19 Jul 2022 19:09:29 UTC Tree 324.680 KB
v0.120 Tue, 19 Jul 2022 18:53:13 UTC Tree 324.659 KB
v0.119 Tue, 19 Jul 2022 18:18:19 UTC Tree 324.458 KB
v0.118 Tue, 19 Jul 2022 00:27:09 UTC Tree 324.280 KB
v0.117 Tue, 19 Jul 2022 00:23:43 UTC Tree 324.533 KB
v0.116 Sun, 17 Jul 2022 23:20:14 UTC Tree 323.990 KB
v0.115 Sun, 17 Jul 2022 16:44:31 UTC Tree 321.873 KB
v0.114 Sun, 17 Jul 2022 16:41:53 UTC Tree 321.837 KB
v0.113 Sun, 17 Jul 2022 16:41:31 UTC Tree 321.835 KB
v0.112 Sat, 09 Jul 2022 14:51:59 UTC Tree 321.816 KB
v0.111 Thu, 07 Jul 2022 12:33:18 UTC Tree 321.271 KB
v0.110 Thu, 07 Jul 2022 10:20:24 UTC Tree 320.821 KB
v0.109 Wed, 06 Jul 2022 20:13:27 UTC Tree 320.564 KB
v0.108 Wed, 06 Jul 2022 19:11:17 UTC Tree 320.064 KB
v0.107 Wed, 06 Jul 2022 18:57:27 UTC Tree 319.628 KB
v0.106 Wed, 06 Jul 2022 11:03:44 UTC Tree 319.525 KB
v0.105 Wed, 06 Jul 2022 10:45:17 UTC Tree 317.845 KB
v0.104 Wed, 06 Jul 2022 10:42:06 UTC Tree 317.807 KB
v0.103 Wed, 06 Jul 2022 10:32:16 UTC Tree 317.170 KB
v0.102 Wed, 06 Jul 2022 10:16:32 UTC Tree 316.147 KB
v0.101 Sun, 03 Jul 2022 17:58:13 UTC Tree 315.653 KB
v0.100 Sun, 03 Jul 2022 17:55:40 UTC Tree 315.562 KB
v0.99 Mon, 27 Jun 2022 16:48:46 UTC Tree 315.632 KB
v0.98 Mon, 27 Jun 2022 16:48:23 UTC Tree 313.731 KB
v0.97 Mon, 27 Jun 2022 16:40:23 UTC Tree 313.498 KB
v0.96 Fri, 24 Jun 2022 16:49:38 UTC Tree 313.104 KB
v0.95 Fri, 24 Jun 2022 16:33:24 UTC Tree 312.491 KB
v0.94 Fri, 24 Jun 2022 16:16:07 UTC Tree 312.367 KB
v0.93 Sun, 19 Jun 2022 16:27:30 UTC Tree 325.177 KB
v0.92 Thu, 26 May 2022 13:12:06 UTC Tree 307.608 KB
v0.91 Sat, 21 May 2022 12:02:49 UTC Tree 305.862 KB
v0.90 Wed, 11 May 2022 12:22:16 UTC Tree 306.046 KB
v0.89 Wed, 11 May 2022 11:36:26 UTC Tree 306.052 KB
v0.88 Wed, 11 May 2022 11:34:46 UTC Tree 306.021 KB
v0.87 Wed, 11 May 2022 10:22:12 UTC Tree 303.782 KB
v0.86 Wed, 11 May 2022 10:21:39 UTC Tree 303.788 KB
v0.85 Sat, 07 May 2022 11:55:45 UTC Tree 302.838 KB
v0.84 Sun, 01 May 2022 17:11:41 UTC Tree 302.223 KB
v0.83 Sun, 01 May 2022 13:40:03 UTC Tree 301.834 KB
v0.82 Sun, 17 Apr 2022 15:03:36 UTC Tree 300.650 KB
v0.81 Sun, 17 Apr 2022 14:51:14 UTC Tree 299.985 KB
v0.80 Sat, 02 Apr 2022 12:25:54 UTC Tree 299.960 KB
v0.79 Sat, 02 Apr 2022 10:03:30 UTC Tree 299.603 KB
v0.78 Sat, 02 Apr 2022 10:03:03 UTC Tree 296.153 KB
v0.77 Sun, 27 Mar 2022 14:42:49 UTC Tree 295.533 KB
v0.76 Sun, 27 Mar 2022 14:33:48 UTC Tree 295.568 KB
v0.75 Sun, 27 Mar 2022 11:02:24 UTC Tree 292.192 KB
v0.74 Sun, 27 Mar 2022 09:45:08 UTC Tree 292.880 KB
v0.73 Thu, 24 Mar 2022 17:04:16 UTC Tree 292.293 KB
v0.72 Sat, 12 Mar 2022 13:55:51 UTC Tree 290.031 KB
v0.71 Sun, 06 Mar 2022 12:05:06 UTC Tree 289.152 KB
v0.70 Sun, 06 Mar 2022 12:04:04 UTC Tree 289.077 KB
v0.69 Mon, 28 Feb 2022 19:01:23 UTC Tree 285.321 KB
v0.68 Sun, 27 Feb 2022 20:49:55 UTC Tree 285.355 KB
v0.67 Sun, 27 Feb 2022 17:46:51 UTC Tree 284.031 KB
v0.66 Tue, 08 Feb 2022 08:29:58 UTC Tree 278.567 KB
v0.65 Mon, 10 Jan 2022 20:16:07 UTC Tree 272.271 KB
v0.64 Thu, 06 Jan 2022 21:05:30 UTC Tree 268.979 KB
v0.63 Thu, 06 Jan 2022 20:34:23 UTC Tree 268.314 KB
v0.62 Thu, 06 Jan 2022 20:22:23 UTC Tree 266.948 KB
v0.61 Thu, 06 Jan 2022 19:55:11 UTC Tree 266.964 KB
v0.60 Thu, 06 Jan 2022 18:09:24 UTC Tree 266.648 KB
v0.59 Thu, 06 Jan 2022 17:48:41 UTC Tree 264.889 KB
v0.58 Thu, 06 Jan 2022 17:23:16 UTC Tree 264.272 KB
v0.57 Thu, 06 Jan 2022 17:12:59 UTC Tree 247.466 KB
v0.56 Thu, 06 Jan 2022 17:09:16 UTC Tree 246.780 KB
v0.55 Fri, 31 Dec 2021 22:00:44 UTC Tree 246.780 KB
v0.54 Fri, 31 Dec 2021 13:01:41 UTC Tree 246.773 KB
v0.53 Thu, 30 Dec 2021 14:10:23 UTC Tree 244.419 KB
v0.52 Thu, 30 Dec 2021 13:40:08 UTC Tree 243.011 KB
v0.51 Thu, 30 Dec 2021 12:56:22 UTC Tree 242.161 KB
v0.50 Mon, 20 Dec 2021 23:43:12 UTC Tree 241.782 KB
v0.49 Mon, 20 Dec 2021 22:44:12 UTC Tree 240.518 KB
v0.48 Mon, 20 Dec 2021 18:59:10 UTC Tree 239.700 KB
v0.47 Mon, 20 Dec 2021 17:38:22 UTC Tree 237.691 KB
v0.46 Mon, 20 Dec 2021 16:32:15 UTC Tree 236.074 KB
v0.45 Sun, 12 Dec 2021 20:16:19 UTC Tree 215.202 KB
v0.44 Sun, 12 Dec 2021 17:38:58 UTC Tree 212.756 KB
v0.43 Sun, 12 Dec 2021 17:37:50 UTC Tree 212.738 KB
v0.42 Fri, 10 Dec 2021 07:08:40 UTC Tree 212.562 KB
v0.41 Thu, 09 Dec 2021 20:20:40 UTC Tree 212.477 KB
v0.40 Wed, 08 Dec 2021 20:05:59 UTC Tree 209.746 KB
v0.39 Wed, 08 Dec 2021 20:02:27 UTC Tree 209.774 KB
v0.38 Wed, 08 Dec 2021 18:28:53 UTC Tree 209.199 KB
v0.37 Wed, 08 Dec 2021 15:04:50 UTC Tree 208.412 KB
v0.36 Wed, 08 Dec 2021 14:11:15 UTC Tree 205.933 KB
v0.35 Wed, 08 Dec 2021 14:03:58 UTC Tree 206.002 KB
v0.34 Sun, 05 Dec 2021 11:11:11 UTC Tree 200.269 KB
v0.33 Mon, 29 Nov 2021 18:48:06 UTC Tree 199.715 KB
v0.32 Sun, 21 Nov 2021 17:50:38 UTC Tree 205.792 KB
v0.31 Sun, 21 Nov 2021 17:42:37 UTC Tree 205.675 KB
v0.30 Sun, 21 Nov 2021 17:11:09 UTC Tree 205.311 KB
v0.29 Sun, 21 Nov 2021 17:00:32 UTC Tree 204.479 KB
v0.28 Sun, 21 Nov 2021 15:22:27 UTC Tree 202.448 KB
v0.27 Sun, 21 Nov 2021 14:08:43 UTC Tree 198.979 KB
v0.26 Sun, 21 Nov 2021 14:07:33 UTC Tree 199.063 KB
v0.25 Sun, 21 Nov 2021 13:54:50 UTC Tree 198.862 KB
v0.24 Sun, 21 Nov 2021 13:43:17 UTC Tree 198.764 KB
v0.23 Sun, 21 Nov 2021 13:13:41 UTC Tree 196.643 KB
v0.22 Sun, 21 Nov 2021 13:13:03 UTC Tree 196.620 KB
v0.21 Sun, 14 Nov 2021 13:26:53 UTC Tree 195.284 KB
v0.20 Sun, 14 Nov 2021 13:06:00 UTC Tree 200.933 KB
v0.19 Thu, 11 Nov 2021 17:32:52 UTC Tree 199.200 KB
v0.18 Thu, 11 Nov 2021 16:47:18 UTC Tree 198.179 KB
v0.17 Tue, 09 Nov 2021 12:03:34 UTC Tree 193.024 KB
v0.16 Tue, 09 Nov 2021 11:41:28 UTC Tree 191.686 KB
v0.15 Sun, 07 Nov 2021 17:39:04 UTC Tree 191.693 KB
v0.14 Tue, 02 Nov 2021 19:56:19 UTC Tree 191.701 KB
v0.13 Tue, 02 Nov 2021 18:52:26 UTC Tree 188.061 KB
v0.12 Tue, 02 Nov 2021 18:17:39 UTC Tree 187.617 KB
v0.11 Sun, 24 Oct 2021 10:14:56 UTC Tree 172.924 KB
v0.10 Sun, 24 Oct 2021 10:14:14 UTC Tree 173.021 KB
v0.9 Sun, 24 Oct 2021 09:44:16 UTC Tree 171.969 KB
v0.8 Sun, 24 Oct 2021 09:08:49 UTC Tree 170.684 KB
v0.7 Sun, 05 Sep 2021 12:46:14 UTC Tree 103.392 KB
v0.6 Sat, 04 Sep 2021 20:08:50 UTC Tree 101.104 KB
v0.5 Wed, 25 Aug 2021 09:23:52 UTC Tree 100.850 KB
v0.4 Wed, 14 Jul 2021 09:33:12 UTC Tree 99.229 KB
v0.3 Thu, 01 Jul 2021 11:02:44 UTC Tree 94.751 KB
v0.2 Wed, 12 May 2021 19:34:43 UTC Tree 82.249 KB
v0.1 Mon, 12 Apr 2021 18:44:50 UTC Tree 68.051 KB