cimgui.zig

[!WARNING] If you are using the docking branch it won’t be updated anymore and there won’t be more *-docking tags. Please use the -Ddocking option instead.

cimgui.zig

This is a fork of ocornut/imgui packaged for Zig

Why this fork ?

The intention under this fork is to package ocornut/imgui for Zig. So:

  • Unnecessary files have been deleted,
  • The build system has been replaced with build.zig,
  • dearimgui/dear_bindings generates the C binding,
  • A cron runs every day to check ocornut/imgui, dearimgui/dear_bindings and other dependencies. Then it updates this repository if a new release is available.

How to use it

The goal of this repository is not to provide a Zig binding for ocornut/imgui. The point of this repository is to abstract the ocornut/imgui compilation process with Zig (which is not easy to maintain) to let you focus on your application. So you can use cimgui.zig:

cimgui.zig as a library

If you want to add cimgui.zig as a library to your project, you can do the following:

Fetch this repository:

$ zig fetch --save git+https://github.com/tiawl/cimgui.zig.git

Add it to your build.zig :

const std = @import("std");
+const cimgui = @import("cimgui_zig");
+const Renderer = cimgui.Renderer;
+const Platform = cimgui.Platform;

pub fn build(b: *std.Build) void {
    // -- snip --

+    const cimgui_dep = b.dependency("cimgui_zig", .{
+        .target = target,
+        .optimize = optimize,
+        .platforms = &[_]Platform{.GLFW},
+        .renderers = &[_]Renderer{.Vulkan},
+        // .docking = true, // Default value: false
+    });
+
+    const cimgui_lib = cimgui_dep.artifact("cimgui");

    // The following conditional is only necessary for OpenGL backends:
+    if (cimgui_lib.root_module.import_table.get("gl")) |gl_module| {
+        exe.root_module.addImport("gl", gl_module);
+    }

    // Where `exe` represents your executable/library to link to
+    exe.linkLibrary(cimgui_lib);

    // -- snip --
}

And that’s it ! You’re ready to go ! See the examples directory on how to move forward from there.

Backends

The backends are separated in two categories: the platforms (handling windows, events, …) and the renderers (draw to screen, ..).

Platform

  • GLFW
  • SDL3
  • SDLGPU3 (technically a renderer but needs linkage against OpenGL/Vulkan)

Renderers

As you can see, these backends do not support all of those supported by ImGUI. Adding a backend is a bit of work because of the needed maintenance. Please do not ask for backends to be added if you don’t feel like adding them yourselves !

Dependencies

The Zig part of this package is relying on the latest Zig release (0.15.2) and will only be updated for the next one. It you use a more recent Zig version, please consider the zig-nightly branch and *-nightly tags.

For other dependencies see the build.zig.zon

zig build options

These additional options have been implemented to cover main usecases:

  -Drenderers=[enum_list]      Specify the renderer backends
                                 Supported Values:
                                   Vulkan
                                   OpenGL3
                                   Metal
  -Dplatforms=[enum_list]      Specify the platform backends
                                 Supported Values:
                                   GLFW
                                   SDL3
                                   SDLGPU3
  -Ddocking=[bool]             master or docking ocornut/imgui branch ?

These additional options have mainly been implemented for maintainability tasks but they maybe could be useful for edge usecases:

  -Dlist-renderers=[bool]      Print available renderer backends. This options prevail on list-platforms option
  -Dlist-platforms=[bool]      Print available platform backends
  -Dseparator=[string]         Used separator instead of default newline character
  -Dfetch=[bool]               Update build.zig.zon then stop execution
  -Dupdate=[bool]              Update binding
  -Dverbose=[bool]             Enabled toolbox debug logging

License

This repository is not subject to a unique License:

The parts of this repository originated from this repository are dedicated to the public domain. See the LICENSE file for more details.

For other parts, it is subject to the License restrictions their respective owners choosed. By design, the public domain code is incompatible with the License notion. In this case, the License prevails. So if you have any doubt about a file property, open an issue.