Games-by-Mason/dear_imgui_zig
A Zig interface to Dear ImGui
refsA Zig interface for Dear ImGui.
Generated at build time from the JSON generated by dear_bindings.
See build.zig.zon, at the time of writing it's a recent commit on the docking branch. See Dear ImGui's readme for info on Dear ImGui branches.
Import the dear_imgui module provided by this package. It exports Dear ImGui types and functions, converted to standard Zig syntax. You can always check the generated file if you are unsure how the names map, but it should be fairly straightforward.
The static library for Dear ImGui, and supported backends, are provided as artifacts under the same name as the Zig modules. You can link Dear Imgui extensions to these.
Right now, this package only exports the following backends:
dear_imgui_vulkandear_imgui_sdl3Contributions are welcome if you'd like to add others. The process should be fairly straightforward.
dear_bindings generates a C wrapper for Dear ImGui, and a JSON file detailing the declarations.
The results of executing dear_bindings are cached in src/cached to avoid a Python dependency
(dear_bindings is implemented in Python.)
At build time, generate.zig is called on the relevant JSON files to generate a Zig module that links to the wrapper generated by dear_bindings.
dear_bindings does not provide enough data to generate perfect pointer types for all situations, but a reasonable conservative heuristic is used to avoid [*c] where possible. This could be improved in the future through whitelists.
Update build.zig.zon, and then if the headers changed, regenerate them into src/cached with dear_bindings.
Here's how to build cimgui.h:
python3 $DEAR_BINDINGS_PATH/dear_bindings.py -o src/cached/cimgui $DEAR_IMGUI_PATH/imgui.h
Here's how to build a backend, using Vulkan as an example:
python3 $DEAR_BINDINGS_PATH/dear_bindings.py --backend --imconfig-path $DEAR_IMGUI_PATH/imconfig.h -o src/cached/cimgui_impl_vulkan $DEAR_IMGUI_PATH/backends/imgui_impl_vulkan.h
If generator.zig fails, you may need to add missing values to the enumeration. std.json does not provide helpful errors at the time of writing, the easiest way to debug this is to comment out the actual generation code, and all fields in Header, adding them back until you figure out which are causing the issue.
You can also debug the generator with the generate command.
binary_to_compressed_cmisc/cpp/imgui_stdlib.cppIMGUI_IMPL_VULKAN_NO_PROTOTYPESVK_VERSION_1_3 or VK_KHR_dynamic_rendering)