Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Hejsil/zig-nuklear

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zig-nuklear

WIP bindings for Nuklear.

Goals

  • Provide an API simular to Nuklear, but with improvements thrown in where it makes sense.
  • Support using Nuklear with or without libc.
    • Provide default implementations for overridable Nuklear function in Zig if libc is unwanted.

Usage

This is an example with no backend. See examples/main.zig for a full example using glfw and opengl.

build.zig

const Nuklear = @import("zig-nuklear/build.zig");
const std = @import("std");

const Builder = std.build.Builder;

pub fn build(b: *Builder) void {
    const mode = b.standardReleaseOptions();
    const target = b.standardTargetOptions(.{});

    const nk = Nuklear.init(b, .{});

    const exe = b.addExecutable("main", "main.zig");
    nk.addTo(exe, .{});

    // Link to your backend here!

    exe.setBuildMode(mode);
    exe.setTarget(target);
    exe.install();
}

main.zig

const nk = @import("nuklear");
const std = @import("std");

pub fn main() !void {
    const allocator = // Choose your allocator!
    const font = // Initialize your font!
    const ctx = &nk.init(allocator, font);
    defer nk.free(ctx);

    while (
        // Backend is running
    ) {
        nk.input.begin(ctx);

        // Forward events from backend to Nuklear here!

        nk.input.end(ctx);

        if (nk.window.begin(ctx, &nk.id(opaque {}), nk.rect(0, 0, 200, 200), .{
            .title = "hello world",
            .border = true,
            .moveable = true,
            .closable = true,
            .minimizable = true,
            .background = false,
            .scalable = true,
        })) |_| {
            nk.layout.rowDynamic(ctx, 0, 1);
            nk.text.label(ctx, "Hello world!", .mid_right);
            if (nk.button.label(ctx, "Hello world!"))
                std.log.info("Hello world!", .{});
        }
        nk.window.end(ctx);

        // Render gui out to your backend here!

        nk.clear(ctx);
    }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published