Skip to content

Drop IMGUI_STB_NAMESPACE so dcimgui_internal.h compiles as C - #604

Open
pusewicz wants to merge 1 commit into
RandyGaul:masterfrom
pusewicz:drop-imgui-stb-namespace
Open

Drop IMGUI_STB_NAMESPACE so dcimgui_internal.h compiles as C#604
pusewicz wants to merge 1 commit into
RandyGaul:masterfrom
pusewicz:drop-imgui-stb-namespace

Conversation

@pusewicz

@pusewicz pusewicz commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Dear Bindings v0.19 leaves C++ scope syntax (ImStb::stbrp_node) in the namespaced branch of dcimgui_internal.h, so with IMGUI_STB_NAMESPACE set the header failed from C, and from any C++ file that did not include imgui_internal.h first. Reaching the DockBuilder from a C game needed an #undef between the two includes.

The only reason CF set the namespace was cute_draw.cpp, which compiled stb_truetype's implementation next to imgui_internal.h in one TU. Nothing there used ImGui, so the includes go and the define goes with them. The generated headers now carry no CF patches.

Separately, dcimgui.h includes imconfig.h from inside extern "C", which broke any C++ file that included dcimgui.h before cute.h. imconfig.h now restores C++ linkage around its cute_math.h include.

Both cases have guard tests. Trade-off: this restores vanilla ImGui behavior, so a downstream C++ TU that compiles its own stb_truetype implementation next to imgui_internal.h would clash, as cute_draw.cpp did.

🤖 Generated with Claude Code

https://claude.ai/code/session_013dQLMKSRz7vi8PHh9BQ5Jb

Dear Bindings v0.19 leaves C++ scope syntax (ImStb::stbrp_node) in the
namespaced branch of dcimgui_internal.h, so with the namespace set the
header failed in C, and in any C++ file that did not include
imgui_internal.h first. The only reason CF set the namespace was
cute_draw.cpp, which compiled stb_truetype's implementation next to
imgui_internal.h in one translation unit; those imgui includes were dead.

Remove the dead includes and the define, and put dcimgui_internal.h's
stbrp block back to the generator's layout, so the generated headers
carry no CF patches.

Also wrap imconfig.h's cute_math.h include in extern "C++": dcimgui.h
includes imconfig.h from inside extern "C", which broke any C++ file
that included dcimgui.h before cute.h.

Two guard tests cover both: test_dcimgui.c (internal header from plain
C) and test_dcimgui.cpp (dcimgui.h before cute.h).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013dQLMKSRz7vi8PHh9BQ5Jb
Copilot AI lite review requested due to automatic review settings September 3, 2026 00:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes are coherent with the stated failure modes and are guarded by new C and C++ compilation-order tests that should catch regressions.

Pull request overview

This PR adjusts Cute Framework’s Dear ImGui integration to eliminate the IMGUI_STB_NAMESPACE configuration (which caused dcimgui_internal.h to be non-C-compilable due to C++ scope syntax), and fixes a C++ include-order/linkage issue caused by dcimgui.h including imconfig.h from inside an extern "C" block. It also adds tests to guard both behaviors.

Changes:

  • Remove IMGUI_STB_NAMESPACE usage from CF’s Dear Bindings headers and related CF TU include patterns.
  • Fix C++ linkage when imconfig.h includes cute_math.h via a narrow extern "C++" restoration.
  • Add C and C++ compilation-order tests for dcimgui.h + dcimgui_internal.h, plus a short docs note.
File summaries
File Description
test/test_dcimgui.cpp Adds a C++ compile-order guard test (dcimgui headers included before cute.h).
test/test_dcimgui.c Adds a pure-C guard test that includes dcimgui_internal.h and touches internal API symbols.
test/main.cpp Registers the new dcimgui test suites in the test runner.
test/CMakeLists.txt Adds the new C and C++ test sources to the tests target.
src/cute_draw.cpp Removes ImGui header includes from the TU that compiles stb_truetype implementation.
libraries/imgui/imconfig.h Restores C++ linkage around #include <cute_math.h> to avoid extern "C" issues.
libraries/imgui/dcimgui.h Stops defining IMGUI_STB_NAMESPACE in the generated C bindings header.
libraries/imgui/dcimgui_internal.h Aligns the ImVector_stbrp_node_im_t instantiation with the non-namespaced branch.
docs/topics/dear_imgui.md Documents supported include order and how to include dcimgui_internal.h.
Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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