Giter Site home page Giter Site logo

ruulul / capy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from capy-ui/capy

0.0 0.0 0.0 683 KB

Cross-platform library for making true native GUIs in Zig

Home Page: https://github.com/capy-ui/capy/wiki

License: MIT License

Shell 0.04% C 0.33% HTML 2.13% GLSL 0.15% Zig 97.35%

capy's Introduction

Capy: a GUI library for Zig

GUIs in Zig, but idiomatic

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 capy.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("capy-template", "src/main.zig");
+    const pathToCapy = ".zigmod/deps/git/github.com/zenith391/capy/";
     exe.setTarget(target);
     exe.setBuildMode(mode);
+    try deps.imports.capy.install(exe, pathToCapy);
     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.

capy's People

Contributors

zenith391 avatar frmdstryr avatar iddev5 avatar marler8997 avatar zigster64 avatar tapiot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.