Skip to content

Add Dear ImGui internal, and cimgui_docking Zig module.#5

Merged
floooh merged 7 commits intomainfrom
imgui-internal
Jul 12, 2025
Merged

Add Dear ImGui internal, and cimgui_docking Zig module.#5
floooh merged 7 commits intomainfrom
imgui-internal

Conversation

@floooh
Copy link
Owner

@floooh floooh commented Jul 12, 2025

  • make the imgui_internal.h API available in the code-generated src/cimgui.h and src-docking/cimgui.h
  • make the docking branch available to Zig via a module cimgui_docking
  • remove the outdated zimgui.h bindings (those were without C prefix but without prefix some C bindings function names collide with Win32 OS functions (like GetCursor).

@floooh
Copy link
Owner Author

floooh commented Jul 12, 2025

Ok, @dom3d this is my alternative attempt.

There's 2 Zig modules cimgui and cimgui_docking, both contain the internal API.

This is how it works in the upstream project (by selectin between docking and non-docking via zig build or zig build -Ddocking.

floooh/sokol-zig-imgui-sample#3

E.g. the build.zig:

https://github.com/floooh/sokol-zig-imgui-sample/blob/imgui-docking/build.zig

...and the demo code:

https://github.com/floooh/sokol-zig-imgui-sample/blob/imgui-docking/src/main.zig

I don't access any internal API in this demo though.

The important part in the build zig is this:

https://github.com/floooh/sokol-zig-imgui-sample/blob/73f956662769b1c084e8d6cd9c2f8aa417ce9eb6/build.zig#L12-L15

E.g. for injecting the cimgui C header path into the sokol C library it's important to not confuse the src-docking and src path in the cimgui package, I forgot this at first and the result was that sokol_imgui.h was compiled with the non-docking version and the Zig code with the docking version - the result was that the demo appeared to work, but no docking was possible (which is actually surprising, I would have expected all sorts of weird crashes).

I may need to come up with a more fool-proof version later to select between the docking and non-docking version...

@floooh
Copy link
Owner Author

floooh commented Jul 12, 2025

PS: ok I added a helper function getConfig() to the dcimgui/build.zig which makes it harder to mess up the Zig module and C header path:

https://github.com/floooh/sokol-zig-imgui-sample/blob/1658708bd2ed7bd80107f94bcace45933fcc5162/build.zig#L13-L17

I'll probably merge all that stuff on Sunday evening or Monday.

@floooh floooh merged commit 3b98e0a into main Jul 12, 2025
6 checks passed
@floooh
Copy link
Owner Author

floooh commented Jul 12, 2025

...I just went ahead and merged it already today ;)

@kassane
Copy link

kassane commented Jul 13, 2025

cimgui_internal.h have <immintrin.h>, unsupported by importC.

@floooh
Copy link
Owner Author

floooh commented Jul 13, 2025

@kassane is that a blocker for the D bindings? The internal API is still in a separate C header (cimgui_internal.h), so I guess the D bindings can just ignore that and only run cimgui.h through the importC step?

The other option might be to enable the C preprocessor define IMGUI_DISABLE_SSE for the importC step.

...but I'll also write a Dear ImGui ticket, it looks wrong that the imgui_internal.h header depends on intrinsics (instead of only the implementation).

@floooh
Copy link
Owner Author

floooh commented Jul 13, 2025

Ah, it's used here in header as inline code:

https://github.com/ocornut/imgui/blob/336d9212fc25055a52107c70441c11acd12e8bb9/imgui_internal.h#L474-L476

...but still, using the IMGUI_DISABLE_SSE should fix that problem I think.

@kassane
Copy link

kassane commented Jul 13, 2025

using the IMGUI_DISABLE_SSE should fix that problem I think.

Yeah! fixed in sokol-d/src/imgui/c/dcimgui.c.

sdouglas added a commit to sdouglas/dcimgui that referenced this pull request Nov 17, 2025
Bring CMakeLists.txt in line with build.zig by adding cimgui_internal.cpp
to all library configurations. This was missing despite being part of the
source list since PR floooh#5 (July 2025) which added internal API exposure.

The build.zig correctly includes cimgui_internal.cpp in imgui_sources,
but CMakeLists.txt was never updated to match. This affects CMake/fips users
who would be missing internal API implementations.

Changes:
- Add src/cimgui_internal.cpp to both fips and non-fips imgui libraries
- Add src-docking/cimgui_internal.cpp to both imgui-docking libraries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants