Giter Site home page Giter Site logo

capy-ui / capy Goto Github PK

View Code? Open in Web Editor NEW
1.3K 17.0 56.0 19.86 MB

๐Ÿ’ปBuild one codebase and get native UI on Windows, Linux and Web

Home Page: https://capy-ui.org

License: Mozilla Public License 2.0

Zig 96.36% GLSL 0.04% HTML 0.06% Shell 0.01% C 0.12% JavaScript 3.07% Nix 0.23% Java 0.10%
zig gui ui zig-package ziglang cross-platform linux windows cross-platform-gui gui-library

capy's Introduction

Capy

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

Target Zig Version: 0.12.0-dev.3180+83e578a18 (2024.3.0-mach)


Code Coverage MPL-2.0 License

the glorius software in action

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

  • Use Zig for frontend and backend
  • Accessibility: compatibility with almost all accessibility tools
  • Cross-platform
  • Uses the target OS toolkit
  • Cross-compilable from any platform to any other platform
  • Tiny executables - Every example's size < 2MB, which is smaller than 'hello world' in Go

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 = @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 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.

Getting Started

Note: Capy targets Zig master so please try to get the latest version

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

Otherwise or for more information, please look in the docs.

You can questions and receive updates on the #capy-ui Matrix channel.

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.

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

  • โœ… Working and can be cross-compile from all platforms supported by Zig
  • ๐Ÿงช Experimental
  • ๐Ÿƒ Planned

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.

capy's People

Contributors

adjectiveallison avatar aryalaadi avatar bnyro avatar brainwo avatar desttinghim avatar dubbathony avatar dvmason avatar frmdstryr avatar iddev5 avatar jernejp21 avatar marler8997 avatar mochalins avatar mseiler-png avatar tapiot avatar thechampagne avatar traxar avatar trnxdev avatar truemedian avatar wukgdu avatar ymndoseijin avatar zenith391 avatar zigster64 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

capy's Issues

Failed to run `zig build run` with zig-template in Linux

After following the instructions in the Installation section, I successfully installed zigmod and cloned the zig-template repository. Then, I proceeded to run zigmod fetch.

Unfortunately, the command zig build run did not execute successfully and produced the following output:

/usr/local/bin/zig build-exe /home/user/repo/capy-template/src/main.zig -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cloudproviders -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -lgtk-3 -lgdk-3 -lz -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lc --cache-dir /home/user/repo/capy-template/zig-cache --global-cache-dir /home/user/.cache/zig --name capy-template --mod capy:zigimg,zigwin32:/home/user/repo/capy-template/.zigmod/deps/git/github.com/capy-ui/capy/src/main.zig --mod zigimg::/home/user/repo/capy-template/.zigmod/deps/git/github.com/capy-ui/capy/vendor/zigimg/zigimg.zig --mod zigwin32::/home/user/repo/capy-template/.zigmod/deps/git/github.com/capy-ui/capy/vendor/zigwin32/win32.zig --deps zigwin32,capy --subsystem native --listen=-
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
run transitive failure
โ””โ”€ run capy-template transitive failure
   โ””โ”€ zig build-exe capy-template Debug native failure
error: the following build command failed with exit code 1:
/home/user/repo/capy-template/zig-cache/o/c57cda9fce30b471e9394c5d12b926d5/build /usr/local/bin/zig /home/user/repo/capy-template /home/user/repo/capy-template/zig-cache /home/user/.cache/zig run

Zig version: 0.11.0-dev.3803+7ad104227
zigmod version: zigmod r86 linux x86_64 musl
OS: Arch Linux (x86_64, 6.3.9-arch1-1)

I'm not sure if the error is related to the build argument (win32) since this is my first time using Zig.

zig version 0.12.0-dev.2159+7916cf6f8 build changes

std.build no longer exists. This brings up issues in build_capy.zig.

std.Build.CompileStep also no longer exists. std.Build.Step.Compile might be the replacement?

I believe there were some changes to adding modules as well.
For example, this:

    const zigimg = b.createModule(.{
        .source_file = .{ .path = prefix ++ "/vendor/zigimg/zigimg.zig" },
    });

Might need to be changed to this:

    const zigimg = b.createModule(.{
        .root_source_file = .{ .path = prefix ++ "/vendor/zigimg/zigimg.zig" },
    });

This is the same issues as reported on the template repo: capy-ui/zig-template#10

zgt install with zigmod doesn't work

zig version : 0.10.0-dev.3050+e05487746
OS: 5.3.0-64-generic #58-Ubuntu SMP x86_64 GNU/Linux
zigmod: custom version with a commit on top of zigmod master to fix a breaking change in zig version mentioned above

Following instruction in the README, my zig build ends with the following error

./src/main.zig:6:12: error: container '.zgt' has no member called 'backend'
    try zgt.backend.init();

On closer inspection, it looks like the pkg root of zgt is set to .zigmod/deps/git/github/zenith391/zgt/build_zgt.zig.
Here is the deps.zig entry

pub const _deeztnhr07fk = Package{
        .directory = dirs._deeztnhr07fk,
        .pkg = Pkg{ .name = "zgt", .source = .{ .path = dirs._deeztnhr07fk ++ "/build_zgt.zig" }, .dependencies = null },
        .system_libs = &.{ "gtk+-3.0", "c" },
    };

build_zgt.zig is the main entrypoint in zgt's zigmod.yml file.

If however, I manually tweak this path to point to _deeztnhr07fk ++ "src/main.zig" instead of build_zgt.zig, it works fine. and I get a UI rendered on my desktop.

Did something change in zigmod or zig that broke this behaviour, or is the install fn in build_zgt.zig not supposed to be run, or is it supposed to run using an additional step such as deps.doSomething() ?

C API

Why it's not fully implemented ?

Accessibility: Missing keyboard navigability and focus

First of all, let me thank you for mentioning accessibility straight in the main Readme file for the repo, it's hugely appreciated. As a screen reader user and a software engineer myself, I'm in constant search of modern accessible solutions implementing native UIs for different platforms. Now to the issue itself.

Steps to reproduce

  • clone the repo in Windows.
  • Open your Windows Terminal in PowerShell or whatever you use
  • Do zig build calculator
  • When the calculator is run, try to navigate with your keyboard using Tab or your arrow keys.
    Expected result: The focus should be placed somewhere in the window on first run, probably in the edit field; Tab key should move through the buttons and other controls.
    Actual Result: Nothing happens. As a screen reader user, I can only emulate mouse clicks which is far from being accessible and usable.

Add a WinUI3 look

Due to the way WinUI 3 is designed and due to the fact that it has no C ABI interface available for it, I don't think using it directly is doable.

What can be done however is to render it with the win32 backend while somehow keeping accessibility support.

This could be done with open-sourced WPF data which includes stylesheets for every Windows theme or just use https://github.com/lepoco/wpfui/tree/main/src/Wpf.Ui/Styles

Another interesting resource is https://github.com/lepoco/wpfui which ports Fluent design to simple XAML style files.

If it's done, it would be interesting to offer it windowlessly (with the gles/webgpu/something else backend?) so that it's not bound by the same 10,000 handles limit as win32.

Another interesting perspective is how to support having one executable with modern Windows UI while still having the option to fallback to win32, but is this even a necessary use case? You can certainly ship two executables in this case.

build error on windows

I just got compile error :

LLD Link... error(link): DLL import library for -lgdiplus not found
error: DllImportLibraryNotFound
zguit...The following command exited with error code 1:
C:\zig_10_dev\zig.exe build-exe E:\Study\zig\zguit\src\main.zig --cache-dir E:\Study\zig\zguit\zig-cache --global-cache-dir C:\Users\mahdimz\AppData\Local\zig --name zguit --pkg-begin zgt E:\Study\zig\zguit.zigmod\deps\git\github.com\zenith391\zgt\src\main.zig --pkg-end --enable-cache
error: the following build command failed with exit code 1:
E:\Study\zig\zguit\zig-cache\o\482da269c4a3f97e41f4573cc88c823a\build.exe C:\zig_10_dev\zig.exe E:\Study\zig\zguit E:\Study\zig\zguit\zig-cache C:\Users\mahdimz\AppData\Local\zig run

my system info is:

OS Name: Microsoft Windows 11 Enterprise
OS Version: 10.0.22000 N/A Build 22000
System Type: x64-based PC
Processor(s): 1 Processor(s) Installed.
[01]: Intel64 Family 6 Model 158 Stepping 10 GenuineIntel ~2592 Mhz

This happens when the following message is displayed:
LLVM Emit Object...

Error when building

Building on windows

Guessing it's due to this commit, or one nearby it:
34bf939

repro:

mkdir something
cd something
git clone https://github.com/capy-ui/zig-template .
zigmod fetch (repeat until it stops erroring. it errors the first time for me fairly often with "git clone https://github.com/capy-ui/capy failed")
zig build

expected:
it builds without errors

actual:

C:\dev\something\.zigmod\deps\git\github.com\capy-ui\capy\android\Sdk.zig:431:39: error: expected error union type, found '[]u8'
        break :blk buf.toOwnedSlice() catch unreachable;
                   ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
referenced by:
    install: C:\dev\something\.zigmod\deps\git\github.com\capy-ui\capy\build_capy.zig:133:32
    build: C:\dev\something\build.zig:40:26
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

Need an example on how to use Capy as a package.

Hello,

I understood that the concept of packages isn't clearly defined in Zig, at least in the latest nigthly build.

Yet, I think it would help to have an example on how to use Capy as a package for a new Zig project.

Best regards.

FLTK backend

Would you be open to having FLTK as an alternative backend? It's very lightweight, themable, stable, cross-platform and may be a good fallback for *nix systems that don't have GTK (and there's existing Zig bindings so implementing should be fairly easy). I'd be happy to work on it if there is any interest

Qt Backend

Obviously interop c++ โ€‹โ€‹is quite complex.
However, perhaps a possibility begins to emerge.

Qt widgets (C binding)

Zig master compile error

The repo fails to build with the latest zig master

Robert@Roberts-MacBook-Pro-2 ~/z/capy (master)> zig build
/Users/Robert/zig/capy/build.zig:14:34: error: no field or member function named 'getOsTag' in 'Build.ResolvedTarget'
    const broken = switch (target.getOsTag()) {
                           ~~~~~~^~~~~~~~~
/Users/Robert/zig/zig/build/stage3/lib/zig/std/Build.zig:2276:28: note: struct declared here
pub const ResolvedTarget = struct {

For loop update

I have noticed that for loop syntax is not up to date with the latest zig.

Previous syntax for index of for loop elements:
for (items) |item, index|

New syntax for index of for loop elements:
for (items, 0..) |item, index|

I have created pull request #35. Hope it helps.

switch to GTK4

GTK3 has been pretty much discontinued now in favor of GTK4, so maybe zgt should upgrade.

Android minimal example build fails

Hi, I installed android toolchains and tried out the minimal example. The build just failed without much informative message. Here is the error log:

zig build-lib zig-app-template Debug arm-linux-android: error: error: FileNotFound

zig build-lib zig-app-template Debug arm-linux-android: error: the following command exited with error code 1:
/snap/zig/8241/zig build-lib /home/guest/capy/android/examples/minimal/main.zig -lGLESv2 -lEGL -landroid -llog -lOpenSLES -lc -fno-strip --eh-frame-hdr --emit-relocs -ffunction-sections --libc /home/guest/capy/android/zig-cache/o/772661454c1a207791cf82d527dbd848/android-21-armeabi.conf --cache-dir /home/guest/capy/android/zig-cache --global-cache-dir /home/guest/.cache/zig --name zig-app-template -dynamic -fcompiler-rt --export-table -target arm-linux-android -mcpu baseline --mod android:build_options:/home/guest/capy/android/android/src/android-support.zig --mod build_options::/home/guest/capy/android/zig-cache/android-sdk/o/da4e75a248e66d1fb50b480fabdb61a443cc0dc1/build_options.zig --deps android -D ANDROID -L /home/guest/AndroidSDK/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/21 -fPIC --listen=- 
zig build-lib zig-app-template Debug aarch64-linux-android: error: error: FileNotFound

zig build-lib zig-app-template Debug aarch64-linux-android: error: the following command exited with error code 1:
/snap/zig/8241/zig build-lib /home/guest/capy/android/examples/minimal/main.zig -lGLESv2 -lEGL -landroid -llog -lOpenSLES -lc -fno-strip --eh-frame-hdr --emit-relocs -ffunction-sections --libc /home/guest/capy/android/zig-cache/o/c448dff7de25b11b419e5e2c87f3afe8/android-21-arm64.conf --cache-dir /home/guest/capy/android/zig-cache --global-cache-dir /home/guest/.cache/zig --name zig-app-template -dynamic -fcompiler-rt --export-table -target aarch64-linux-android -mcpu generic+el2vmsa+el3+v8a --mod android:build_options:/home/guest/capy/android/android/src/android-support.zig --mod build_options::/home/guest/capy/android/zig-cache/android-sdk/o/da4e75a248e66d1fb50b480fabdb61a443cc0dc1/build_options.zig --deps android -D ANDROID -L /home/guest/AndroidSDK/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21 -fPIC --listen=- 
zig build-lib zig-app-template Debug x86-linux-android: error: error: FileNotFound

zig build-lib zig-app-template Debug x86-linux-android: error: the following command exited with error code 1:
/snap/zig/8241/zig build-lib /home/guest/capy/android/examples/minimal/main.zig -lGLESv2 -lEGL -landroid -llog -lOpenSLES -lc -fno-strip --eh-frame-hdr --emit-relocs -ffunction-sections -z notext --libc /home/guest/capy/android/zig-cache/o/53675ee38eb2f0ae617a7fc2c292f3e7/android-21-x86.conf --cache-dir /home/guest/capy/android/zig-cache --global-cache-dir /home/guest/.cache/zig --name zig-app-template -dynamic -fcompiler-rt --export-table -target x86-linux-android -mcpu pentium4 --mod android:build_options:/home/guest/capy/android/android/src/android-support.zig --mod build_options::/home/guest/capy/android/zig-cache/android-sdk/o/da4e75a248e66d1fb50b480fabdb61a443cc0dc1/build_options.zig --deps android -D ANDROID -L /home/guest/AndroidSDK/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/i686-linux-android/21 -fPIC --listen=- 
zig build-lib zig-app-template Debug x86_64-linux-android: error: error: FileNotFound

zig build-lib zig-app-template Debug x86_64-linux-android: error: the following command exited with error code 1:
/snap/zig/8241/zig build-lib /home/guest/capy/android/examples/minimal/main.zig -lGLESv2 -lEGL -landroid -llog -lOpenSLES -lc -fno-strip --eh-frame-hdr --emit-relocs -ffunction-sections --libc /home/guest/capy/android/zig-cache/o/fcc90ab1fe0cfa1912035de7e1ec31d5/android-21-x86_64.conf --cache-dir /home/guest/capy/android/zig-cache --global-cache-dir /home/guest/.cache/zig --name zig-app-template -dynamic -fcompiler-rt --export-table -target x86_64-linux-android -mcpu x86_64 --mod android:build_options:/home/guest/capy/android/android/src/android-support.zig --mod build_options::/home/guest/capy/android/zig-cache/android-sdk/o/da4e75a248e66d1fb50b480fabdb61a443cc0dc1/build_options.zig --deps android -D ANDROID -L /home/guest/AndroidSDK/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/21 -fPIC --listen=- 
Build Summary: 10/19 steps succeeded; 4 failed (disable with --summary none)
install transitive failure
โ”œโ”€ install generated to app-template.apk transitive failure
โ”‚  โ””โ”€ run /home/guest/AndroidSDK/build-tools/33.0.1/zipalign (app-template.apk) transitive failure
โ”‚     โ”œโ”€ run zip_add (unaligned-app-template.apk) transitive failure
โ”‚     โ”‚  โ”œโ”€ zig build-lib zig-app-template Debug aarch64-linux-android failure
โ”‚     โ”‚  โ”œโ”€ zig build-lib zig-app-template Debug aarch64-linux-android (+2 more reused dependencies)
โ”‚     โ”‚  โ”œโ”€ zig build-lib zig-app-template Debug arm-linux-android failure
โ”‚     โ”‚  โ”œโ”€ zig build-lib zig-app-template Debug arm-linux-android (+2 more reused dependencies)
โ”‚     โ”‚  โ”œโ”€ zig build-lib zig-app-template Debug x86_64-linux-android failure
โ”‚     โ”‚  โ”œโ”€ zig build-lib zig-app-template Debug x86_64-linux-android (+2 more reused dependencies)
โ”‚     โ”‚  โ”œโ”€ zig build-lib zig-app-template Debug x86-linux-android failure
โ”‚     โ”‚  โ””โ”€ zig build-lib zig-app-template Debug x86-linux-android (+2 more reused dependencies)
โ”‚     โ”œโ”€ run zip_add (unaligned-app-template.apk) (+11 more reused dependencies)
โ”‚     โ”œโ”€ run zip_add (unaligned-app-template.apk) (+11 more reused dependencies)
โ”‚     โ”œโ”€ run zip_add (unaligned-app-template.apk) (+11 more reused dependencies)
โ”‚     โ””โ”€ run zip_add (unaligned-app-template.apk) (+11 more reused dependencies)
โ””โ”€ run /home/guest/AndroidSDK/build-tools/33.0.1/apksigner transitive failure
   โ”œโ”€ run /home/guest/AndroidSDK/build-tools/33.0.1/zipalign (app-template.apk) (+6 more reused dependencies)
   โ””โ”€ run /home/guest/AndroidSDK/build-tools/33.0.1/zipalign (app-template.apk) (+6 more reused dependencies)
error: the following build command failed with exit code 1:
/home/guest/capy/android/zig-cache/o/c413452fbd24ad7346207403f4147997/build /snap/zig/8241/zig /home/guest/capy/android /home/guest/capy/android/zig-cache /home/guest/.cache/zig -Dexample=minimal

AudioGenerator code prevents compiling if target isn't wasm.

src/audio.zig:17:18: error: root struct of file 'backend' has no member named 'AudioGenerator'
    peer: backend.AudioGenerator,
          ~~~~~~~^~~~~~~~~~~~~~~
src/backend.zig:1:1: note: struct declared here

The title is my current theory as to why it won't compile.
Related to this commit: b927197

Maybe defining a stub for non-wasm backends would be a good move?
Or some conditional to not even import audio on non initialized backends?

Broken on zig 0.12.0 as well as 0.11.0

For both versions I got the same error.

Path', found '*const [97:0]u8'
                .x86_64 => step.addObjectFile(prefix ++ "/src/backends/win32/res/x86_64.o"),
                                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Windows\zig-windows-x86_64-0.11.0\lib\std\Build.zig:1672:22: note: union declared here
pub const LazyPath = union(enum) {
                     ^~~~~
C:\Windows\zig-windows-x86_64-0.11.0\lib\std\Build\Step\Compile.zig:1013:46: note: parameter type declared here
pub fn addObjectFile(self: *Compile, source: LazyPath) void {

ScrollView isn't implemented in the win32 backend

warning: 'fade' is broken (disabled by default)
.\src\scrollable.zig:10:19: error: container '.zgt.backend' has no member called 'ScrollView'
    peer: ?backend.ScrollView = null,
                  ^
error: foo_app...
error: The following command exited with error code 1:
C:\dev\tools\zig\zig.exe build-exe C:\dev\zig-sandbox\zgt\examples\foo_app.zig -lcomctl32 -lgdi32 -lgdiplus C:\dev\zig-sandbox\zgt\src\backends\win32\res\x86_64.o --cache-dir C:\dev\zig-sandbox\zgt\zig-cache --global-cache-dir C:\Users\mattn\AppData\Local\zig --name foo_app --pkg-begin zgt C:\dev\zig-sandbox\zgt\src\main.zig --pkg-end --subsystem windows --enable-cache 
error: the following build command failed with exit code 1:
C:\dev\zig-sandbox\zgt\zig-cache\o\c5bb151f340779c19e22c63211bb2228\build.exe C:\dev\tools\zig\zig.exe C:\dev\zig-sandbox\zgt C:\dev\zig-sandbox\zgt\zig-cache C:\Users\mattn\AppData\Local\zig

It seems that ScollView does not defined on Windows.

Add wrapping to Row and Column

Add wrapping to Row and Column. This means that if it was given less space than its preferred, it would wrap instead of overflowing into nothingness.

MacOS platform support?

currently macos backend only creates window object and doesn't show the window(because macos requires NSApplication run), also it doesn't support any widgets. And the cpu usage at 99 %. So it literally impossible to go beyond a running app without the window

I am willing to contribute.

GTK window is not re-rendering

I'm having issues with updating contents of the window. For example, examples/hacker-news.zig - the new labels are not rendering until I manually change window size.

Fedora Linux 37, X11, zig-linux-x86_64-0.12.0-dev.389+61b70778b, 50606cc

Fail to build executable with `zigmod` and the latest `zig`

I followed https://github.com/zenith391/zgt/wiki/Installation to set up zgt. And when I tried building the first application I got the following error:

$ zig build run
./deps.zig:69:36: error: no member named 'path' in struct 'std.build.Pkg'
        .pkg = Pkg{ .name = "zgt", .path = .{ .path = dirs._deeztnhr07fk ++ "/src/main.zig" }, .dependencies = null },

I use the current latest zig,

$ zig version
0.10.0-dev.2751+08459ff1c

And in the latest version, there is no longer path in the std.build.Pkg:
https://github.com/ziglang/zig/blob/08459ff1c21d546c55e2ae954126e121ee88972e/lib/std/build.zig#L1355-L1359

After I replaced path with source, everything is okay.

I don't know which version of zig you're using, and I can't find anything about this in the documentation. Maybe I missed. If not, please consider specify the zig version in the document. Or migrate to the latest zig and fix the deps.zig.

build.zig.zon support

If I'm not mistaken and my use of the undocumented zig 0.11 package manager is error free, capy needs changes for downstream build.zig.zon to work. Either that, or zig 0.11's experimental package manager isn't capable of pulling in capy yet.

build_capy.zig:18:20: error: no field named 'builder' in struct 'Build.CompileStep'
    const b = step.builder;

What's a working recipe to use capy with build.zig.zon?

No patch attached because I don't know what the fix is or if capy actually needs one.

Button callback not invoked

The button callback gets not invoked on Windows. Maybe I am stupid (I am just toying around with zig and capy and learn as I go).

const std = @import("std");
const capy = @import("capy");
pub usingnamespace capy.cross_platform;

pub fn main() !void {
    try capy.backend.init();
    var window = try capy.Window.init();
    window.setPreferredSize(600, 800);
    window.setTitle("ArtGit");
    std.debug.print("Hello?", .{});
    try window.set(capy.Button(.{ .label = "Some text", .onclick = onButtonClicked }));
    window.show();
    capy.runEventLoop();
}

fn onButtonClicked(button: *anyopaque) !void {
    std.debug.print("wow", .{});
    var btn = @as(*capy.Button_Impl, @ptrCast(@alignCast(button)));
    btn.setLabel("Was clicked");
}

Observed behaviour

Window is created, the button has the label "Some text" and on click nothing happens.

Expected behaviour

Windows is created, the button has the label "Some text" and on click "wow" is printed and the label text is set to "Was clicked".

Sys Info

Windows 10
Zig: 0.11.0-dev.3937+78eb3c561

unable to build

Sorry i'm quite new to zig but i'm unable to build zgt on windows.

image

I also tried with the syntax I found on zig documentation

usingnamespace @import("std.os.windows.user32");
usingnamespace @import("std.os.windows.kernel32");

same result

I was able to build other simple projects like the pacman.zig that use sokol libraries

I tried with zig 0.7.1 and 0.8.0-current, same results.

Broken on newer zig versions (not sure since when)

At somepoint they changed something that now you cant just pass a string, you need to pass a
"LazyPath". Something like:

b.someFunc(.{.path="/file/path"});

and some other changes too.

user@user-NC-A315-51-56HD ~/D/d/zgui (main)> zig build run
/home/user/Documents/dev/zgui/.zigmod/deps/git/github.com/capy-ui/capy/build_capy.zig:147:54: error: expected type 'Build.LazyPath', found '*const [102:0]u8'
                .x86_64 => step.addObjectFile(prefix ++ "/src/backends/win32/res/x86_64.o"),
                                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/.local/bin/zig-linux-x86_64-0.12.0-dev.1+a327d8b99/lib/std/Build.zig:1672:22: note: union declared here
pub const LazyPath = union(enum) {
                     ^~~~~
/home/user/.local/bin/zig-linux-x86_64-0.12.0-dev.1+a327d8b99/lib/std/Build/Step/Compile.zig:1013:46: note: parameter type declared here
pub fn addObjectFile(self: *Compile, source: LazyPath) void {
                                             ^~~~~~~~
referenced by:
    build: /home/user/Documents/dev/zgui/build.zig:23:42
    runBuild__anon_7154: /home/user/.local/bin/zig-linux-x86_64-0.12.0-dev.1+a327d8b99/lib/std/Build.zig:1639:37
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

Not really sure.

Tried on 0.12.0-dev.1+a327d8b99 and zig-0.11.0-dev.4408+9e19969e0

Compiler Error

I just downloaded zig 0.12 on Windows 10 and I added, the sole line to import capy into the default program right at the top. It does not compile moreover upon looking up this error message, as of 0.12 zig compiler now happily enforces all variables requiring to be mutated at least once unless declared with const. This is my first real zig project I'm trying and I only just started, I might download 0.11 to use as a temporary workaround. I'd think this was my system if I didn't put two and two together.

https://ziggit.dev/t/error-local-variable-is-never-mutated/2238/20

C:\Users\Tim.Heath\AppData\Local\zig\p\12201751d2094cde9630bc080e6ce1d8982ff03bdd30a3103abd21321a8361a7e39d\android\build\auto-detect.zig:158:13: error: local variable is never mutated
        var android_studio_key: HKEY = for ([_]HKEY{ HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE }) |root_key| {

This caught me entirely off guard because I just downloaded zig totally fresh, set my path, and went to follow the guide at the below link (not exactly but just one step at a time towards my goal).

https://capy-ui.org/docs/getting-started/first-application/

Binding text of TextArea with Gtk doesn't update text on editing

Hey,
first of all thanks for spending so much efforts into the project, it's my favorite one for building desktop apps :)

I've been trying to build a very simple text editor and came across the issue that when the user edits a text inside a text area, the text doesn't update inside the bound DataWrapper.
However, when setting the text via DataWrapper#set the text inside the TextArea updates properly and the text can be correctly read with DataWrapper#get. I will leave a small example program below.

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

var text = capy.DataWrapper([]const u8).of("");

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

    var window = try capy.Window.init();
    var textArea = capy.TextArea(.{}).bind("text", &text);

    // Setting the text programmatically works fine and prints out correctly
    textArea.setText("Text set programmatically");
    std.debug.print("{s}", .{text.get()});

    try window.set(capy.Column(.{ .spacing = 0 }, .{
        &textArea,
        capy.Button(.{ .label = "Print", .onclick = &printText }),
    }));

    window.setTitle("test");
    window.resize(800, 600);
    window.show();

    capy.runEventLoop();
}

fn printText(_: *anyopaque) anyerror!void {
    // Printing the text after the user edited the text field manually doesn't show the updated text
    std.debug.print("{s}", .{text.get()});
}

I have only tested this with the Gtk backend so far, thus I can't say how other backends behave.

`TextArea` not implemented on win32 backend

I followed the instructions, but I seem to get these errors on Windows. On Debian the exact same setup seems to work fine. Any suggestions on how to fix this? I am using capy version f926cfb8855f83942d7291be3179f82db7827ba9.

.\.zigmod\deps\git\github.com\zenith391\capy\src\text.zig:11:19: error: container '.capy.backend' has no member called 'TextArea'
    peer: ?backend.TextArea = null,
                  ^
.\.zigmod\deps\git\github.com\zenith391\capy\src\button.zig:38:17: error: no member named 'setEnabled' in struct '.capy.backends.win32.backend.Button'
        peer.*.?.setEnabled(newValue);
                ^

Support styling

Are there any plans to support styles? Like background colors and the label font size.

Zig tracking issue

This is a tracking issue for upstream Zig. (see Third Party Tracking Issues)
Overall, Zig is really great and its cross-compilation abilities are great for GUIs, but some (planned) proposals and bug fixes would make it better:

  • async/await (regression introduced in stage2). A lot of tasks in user interfaces are asynchronous, whether it's loading a resource or updating data on a remote server, async is important to have. Right now I'm having hacky solutions with capy.http which has an async-looking API but is actually synchronous and capy.assets which is entirely synchronous as of now, including when fetching resources over HTTP.
  • issue #12325 (regression introduced in stage2) is blocking me from having event handlers like fn buttonClicked(button: *capy.Button) !void instead of a more generic fn buttonClicked(button: *anyopaque) !void. Having to manually @ptrCast decreases the ease of use of the API.
  • The compiler crashes while trying to generate capy's documentation
  • (maybe) issue #1717, while it's been closed as not implemented, it would be useful in a lot of cases like Atom.dependOn instead of using the bizarre status quo of struct { fn a() void {} }.a

Fails to build on linux

When running 'zig build run' on linux x86_64 I get the following error:

/home/luke/.cache/zig/p/12201751d2094cde9630bc080e6ce1d8982ff03bdd30a3103abd21321a8361a7e39d/android/build/auto-detect.zig:158:13: error: local variable is never mutated
        var android_studio_key: HKEY = for ([_]HKEY{ HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE }) |root_key| {
            ^~~~~~~~~~~~~~~~~~
/home/luke/.cache/zig/p/12201751d2094cde9630bc080e6ce1d8982ff03bdd30a3103abd21321a8361a7e39d/android/build/auto-detect.zig:158:13: note: consider using 'const'
/home/luke/.cache/zig/p/12201751d2094cde9630bc080e6ce1d8982ff03bdd30a3103abd21321a8361a7e39d/build_capy.zig:103:20: error: no field or member function named 'do' in 'http.Server.Response'
            try res.do();
                ~~~^~~
/usr/local/bin/zig-folder/lib/std/http/Server.zig:295:22: note: struct declared here
pub const Response = struct {
                     ^~~~~~
referenced by:
    make: /home/luke/.cache/zig/p/12201751d2094cde9630bc080e6ce1d8982ff03bdd30a3103abd21321a8361a7e39d/build_capy.zig:65:54
    create: /home/luke/.cache/zig/p/12201751d2094cde9630bc080e6ce1d8982ff03bdd30a3103abd21321a8361a7e39d/build_capy.zig:38:40
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

This is using the capy starter template without any modifications (https://github.com/capy-ui/zig-template)

OS: Pop!_OS 22.04 LTS
GNOME Version: 42.9
Windowing system: X11

Ziq version: 0.12.0-dev.1856+94c63f31f
(also tried 0.11 and got the same error).

Thanks in advance.

Missing dropdown menus

Currently capy is missing dropdown menus. It would be very helpful in many cases to have support for dropdown menus.

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.